-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from kantimam/deploy
Deploy
- Loading branch information
Showing
18 changed files
with
572 additions
and
365 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
client/node_modules/@types/react/node_modules/csstype/README.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
589 changes: 330 additions & 259 deletions
589
client/node_modules/@types/react/node_modules/csstype/index.d.ts
Large diffs are not rendered by default.
Oops, something went wrong.
107 changes: 42 additions & 65 deletions
107
client/node_modules/@types/react/node_modules/csstype/index.js.flow
Large diffs are not rendered by default.
Oops, something went wrong.
30 changes: 15 additions & 15 deletions
30
client/node_modules/@types/react/node_modules/csstype/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { Card, CardContent, CardHeader, Typography } from '@material-ui/core' | ||
import React from 'react' | ||
|
||
const index = () => { | ||
const Dashboard = (props) => { | ||
console.log(props) | ||
return ( | ||
<div> | ||
<h1>hey</h1> | ||
</div> | ||
<Card> | ||
<CardHeader title="Dashboard"/> | ||
<CardContent> | ||
<Typography> | ||
|
||
</Typography> | ||
</CardContent> | ||
</Card> | ||
) | ||
} | ||
|
||
export default index | ||
export default Dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { getRepository } from "typeorm"; | ||
import { deleteKey } from "../controllers/keyController"; | ||
import { Reader } from "../entity/Reader"; | ||
import { ReaderKey } from "../entity/ReaderKey"; | ||
import { client } from "../mqtt/connection"; | ||
import arrayDifference from "../util/arrayDifference"; | ||
|
||
|
||
export async function updateDeviceKeys(readerId, keys: ReaderKey[]){ | ||
const readerResult = await getRepository(Reader).findOne(readerId, {relations: ["readerKeys", "readerKeys.key"]}) | ||
|
||
const addedKeys=arrayDifference(keys, readerResult.readerKeys, (a, b)=>{ | ||
return a?.key?.uid===b?.key?.uid; | ||
}) // items that are in array 1 but not in 2 | ||
|
||
const removedKeys=arrayDifference(readerResult.readerKeys, keys, (a, b)=>{ | ||
return a.keyId===b.keyId; | ||
}) // items that are in array 2 but not in 1 | ||
|
||
console.log(`keys added`) | ||
console.log(addedKeys); | ||
console.log("keys removed"); | ||
console.log(removedKeys); | ||
|
||
|
||
// delete all keys that were just removed from the DB from the device too | ||
try { | ||
await deleteDeviceKeys(readerResult, removedKeys); | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
|
||
} | ||
|
||
export function deleteDeviceKeys(reader: Reader, keys: ReaderKey[]): Promise<void>{ | ||
return new Promise((resolve, reject)=>{ | ||
|
||
const deleteUser=(readerKey: ReaderKey)=>{ | ||
if(client.connected && readerKey && readerKey.key){ | ||
client.publish('devnfc', JSON.stringify({ | ||
cmd: "deletuid", | ||
doorip: reader.ip, | ||
doorname: reader.readerName, | ||
uid: readerKey.key.uid | ||
})); | ||
}else { | ||
cleanupAndReject(); | ||
} | ||
} | ||
const cleanup=()=>{ | ||
clearTimeout(mqttTimeout); | ||
client.off("message", mqttMessageHandler) | ||
|
||
} | ||
|
||
const cleanupAndResolve=()=>{ | ||
cleanup(); | ||
resolve(); | ||
|
||
} | ||
const cleanupAndReject=()=>{ | ||
cleanup(); | ||
reject(); | ||
} | ||
|
||
if(!keys.length){ // if there are no keys just resolve | ||
resolve(); | ||
} | ||
|
||
let mqttTimeout; | ||
const mqttMaxResponseTime: number=4000; // give the device max 4 seconds between messages and otherwise return | ||
|
||
|
||
const mqttMessageHandler=(topic: string, message: Buffer)=> { | ||
if(topic==="devnfc/devicestate" || topic==="/devnfc/devicestate"){ | ||
const messageString = message.toString() | ||
const messageJSON = JSON.parse(messageString) | ||
if(messageJSON.deviceName===reader.readerName){ // make sure message comes from the same controller | ||
if(messageJSON.cmd==="deleteUserState"){ | ||
if(keys.length){ // after the delete is comfirmed by the device try to remove the key from the array | ||
const keyIndex=keys.findIndex(item=>item.key.uid===messageJSON.deletedUID); // check if array has key with same uid | ||
if(keyIndex!==-1){ // if key was found remove it | ||
keys.splice(keyIndex, 1); | ||
clearTimeout(mqttTimeout); // only after successfully removing a key restart the early return timer | ||
mqttTimeout=setTimeout(cleanupAndReject, mqttMaxResponseTime); | ||
} | ||
|
||
} | ||
// filtering might have failed to we check again if there are keys left | ||
if(keys.length>0){ | ||
// if there are still keys left to delete send the next request | ||
deleteUser(keys[0]); | ||
}else { | ||
// otherwise we are done | ||
cleanupAndResolve(); | ||
} | ||
console.log(messageJSON); | ||
} | ||
} | ||
} | ||
} | ||
|
||
client.on("message", mqttMessageHandler) | ||
|
||
deleteUser(keys[0]); | ||
|
||
mqttTimeout=setTimeout(cleanupAndReject, mqttMaxResponseTime) | ||
}) | ||
|
||
} |
Oops, something went wrong.