mirror of
https://github.com/chuot/rdio-scanner.git
synced 2026-08-13 08:33:00 -06:00
Add pruneDays to settings and logic to prune older calls
This commit is contained in:
parent
6900c55cee
commit
76c6e40a74
|
|
@ -18,7 +18,7 @@ Environment=PORT=3000
|
|||
Environment=HTTP_FORWARDED_COUNT=1
|
||||
Environment=ROOT_URL=http://radio
|
||||
Environment=MONGO_URL=mongodb://localhost:27017/rdio-scanner
|
||||
Environment=METEOR_SETTINGS={"apiKeys":["30851354-741b-4b7e-a126-4b56cca99732","5ab8dc98-6274-4f6e-8b50-68eab246a1dc","b29eb8b9-9bcd-4e6e-bb4f-d244ada12736"]}
|
||||
Environment=METEOR_SETTINGS={"apiKeys":["b29eb8b9-9bcd-4e6e-bb4f-d244ada12736"],"pruneDays":30}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
api="http://127.0.0.1:3000/talkgroups"
|
||||
key="30851354-741b-4b7e-a126-4b56cca99732"
|
||||
key="b29eb8b9-9bcd-4e6e-bb4f-d244ada12736"
|
||||
|
||||
basename=$(basename $2)
|
||||
csv="$2"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
api="http://127.0.0.1:3000/upload"
|
||||
key="30851354-741b-4b7e-a126-4b56cca99732"
|
||||
key="b29eb8b9-9bcd-4e6e-bb4f-d244ada12736"
|
||||
|
||||
basename="${2%.*}"
|
||||
jsonfile="$basename.json"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
{
|
||||
"apiKeys": [
|
||||
"30851354-741b-4b7e-a126-4b56cca99732",
|
||||
"5ab8dc98-6274-4f6e-8b50-68eab246a1dc",
|
||||
"b29eb8b9-9bcd-4e6e-bb4f-d244ada12736"
|
||||
]
|
||||
"apiKeys": ["b29eb8b9-9bcd-4e6e-bb4f-d244ada12736"],
|
||||
"pruneDays": 30
|
||||
}
|
||||
|
|
@ -40,10 +40,11 @@ if (Meteor.isServer) {
|
|||
const apiKeys = Meteor.settings.apiKeys;
|
||||
|
||||
if (key && Array.isArray(apiKeys) && apiKeys.find((apiKey) => apiKey === key)) {
|
||||
audio = 'data:audio/mpeg;base64,' + Buffer.from(audio, 'binary').toString('base64');
|
||||
|
||||
try {
|
||||
const call = new Call(Object.assign({}, JSON.parse(json), { audio, system }));
|
||||
const call = new Call(Object.assign({}, JSON.parse(json), {
|
||||
audio: urlEncode('audio/mpeg', audio),
|
||||
system,
|
||||
}));
|
||||
|
||||
Calls.collection.insert(call, (error: Meteor.Error) => {
|
||||
res.writeHead(error ? 500 : 200);
|
||||
|
|
@ -63,9 +64,39 @@ if (Meteor.isServer) {
|
|||
|
||||
form.parse(req);
|
||||
|
||||
pruneCalls();
|
||||
|
||||
} else {
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function base64Encode(value: any): string {
|
||||
return Buffer.from(value, 'binary').toString('base64');
|
||||
}
|
||||
|
||||
function urlEncode(mimeType: string, value: any): string {
|
||||
return `data:${mimeType};base64,${base64Encode(value)}`;
|
||||
}
|
||||
|
||||
function getPruneDays(): number | null {
|
||||
const pruneDays = Meteor.settings.pruneDays;
|
||||
return typeof pruneDays === 'number' ? pruneDays : null;
|
||||
}
|
||||
|
||||
function pruneCalls(): void {
|
||||
const pruneDays = getPruneDays();
|
||||
|
||||
if (pruneDays !== null) {
|
||||
const currentDate = new Date();
|
||||
const dateLimit = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate() - pruneDays);
|
||||
|
||||
Calls.collection.remove({
|
||||
createdAt: {
|
||||
$lt: dateLimit,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue