mirror of
https://github.com/chuot/rdio-scanner.git
synced 2026-08-13 16:33:01 -06:00
Fix missing aliases feature since last code refactoring
This commit is contained in:
parent
8dae9ecce8
commit
e8d8996ae0
|
|
@ -1,4 +1,4 @@
|
|||
# Rdio Scanner v3.1
|
||||
# Rdio Scanner v3.1.1
|
||||
|
||||
*Rdio Scanner* is a progressive web interface designed to act like an old school police radio scanner. It integrates all frontend / backend components to manage audio files from different sources.
|
||||
|
||||
|
|
|
|||
|
|
@ -645,7 +645,7 @@ export class AppRdioScannerComponent implements OnDestroy, OnInit {
|
|||
private async loadCall(call: RdioScannerCall = {}): Promise<RdioScannerCall | null> {
|
||||
const query = await this.appRdioScannerCallQuery.fetch({ id: call.id }).toPromise();
|
||||
|
||||
Object.assign(call, query.data.rdioScannerCall);
|
||||
Object.assign(call, this.transformCall(query.data.rdioScannerCall));
|
||||
|
||||
return call;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "rdio-scanner",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"private": true,
|
||||
"main": "run.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
const transaction = await queryInterface.sequelize.transaction();
|
||||
|
||||
try {
|
||||
await queryInterface.addColumn('rdioScannerCalls', 'audioName', Sequelize.STRING, { transaction });
|
||||
|
||||
await queryInterface.addColumn('rdioScannerCalls', 'audioType', Sequelize.STRING, { transaction });
|
||||
|
||||
await queryInterface.addColumn('rdioScannerSystems', 'aliases', { allowNull: false, defaultValue: [], type: Sequelize.JSON }, { transaction });
|
||||
|
||||
await transaction.commit();
|
||||
|
||||
} catch (err) {
|
||||
await transaction.rollback();
|
||||
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
const transaction = queryInterface.sequelize.transaction();
|
||||
|
||||
try {
|
||||
await transaction.commit();
|
||||
|
||||
await queryInterface.removeColumn('rdioScannerCalls', 'audioName', Sequelize.STRING, { transaction });
|
||||
|
||||
await queryInterface.removeColumn('rdioScannerCalls', 'audioType', Sequelize.STRING, { transaction });
|
||||
|
||||
await queryInterface.removeColumn('rdioScannerSystems', 'aliases', Sequelize.JSON, { transaction });
|
||||
|
||||
} catch (err) {
|
||||
await transaction.rollback();
|
||||
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
@ -10,6 +10,14 @@ function rdioScannerCallFactory(sequelize) {
|
|||
type: DataTypes.BLOB('long'),
|
||||
allowNull: false,
|
||||
},
|
||||
audioName: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
audioType: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
emergency: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ class RdioScannerSystem extends Model { }
|
|||
|
||||
function rdioScannerSystemFactory(sequelize) {
|
||||
RdioScannerSystem.init({
|
||||
aliases: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: [],
|
||||
allowNull: false,
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
const TrunkRecorderAliasUpload = require('./trunk-recorder-alias-upload');
|
||||
const TrunkRecorderCallUpload = require('./trunk-recorder-call-upload');
|
||||
const TrunkRecorderSystemUpload = require('./trunk-recorder-system-upload');
|
||||
|
||||
class Routes {
|
||||
constructor(models, pubsub, router) {
|
||||
this.trunkRecorderAliasUpload = new TrunkRecorderAliasUpload(models, pubsub);
|
||||
this.trunkRecorderCallUpload = new TrunkRecorderCallUpload(models, pubsub);
|
||||
this.trunkRecorderSystemUpload = new TrunkRecorderSystemUpload(models, pubsub);
|
||||
|
||||
router.use(this.trunkRecorderAliasUpload.path, this.trunkRecorderAliasUpload.middleware);
|
||||
router.use(this.trunkRecorderCallUpload.path, this.trunkRecorderCallUpload.middleware);
|
||||
router.use(this.trunkRecorderSystemUpload.path, this.trunkRecorderSystemUpload.middleware);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
'use strict';
|
||||
|
||||
const multer = require('multer');
|
||||
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
|
||||
const validateApiKey = require('../helpers/validate-api-keys');
|
||||
|
||||
class TrunkRecorderAliasUpload {
|
||||
constructor(models, pubsub) {
|
||||
return {
|
||||
path: '/api/trunk-recorder-alias-upload',
|
||||
|
||||
middleware: (req, res) => upload.fields([
|
||||
{ name: 'csv', maxCount: 1 },
|
||||
{ name: 'key', maxCount: 1 },
|
||||
{ name: 'system', maxCount: 1 },
|
||||
])(req, res, async (err) => {
|
||||
if (err instanceof multer.MulterError) {
|
||||
res.send(`${err.message}: ${err.field}\n`);
|
||||
|
||||
} else if (err) {
|
||||
res.send(`${err.message}\n`);
|
||||
|
||||
} else {
|
||||
const key = req.body.key;
|
||||
|
||||
const system = parseInt(req.body.system, 10);
|
||||
|
||||
const aliases = [];
|
||||
|
||||
if (!validateApiKey(key, system)) {
|
||||
return res.send(`Api key is invalid for system ${system}.\n`);
|
||||
}
|
||||
|
||||
const csv = req.files.csv[0].buffer.toString()
|
||||
.split(/\n/)
|
||||
.filter((l) => l.length && !/^\s*#/.test(l));
|
||||
|
||||
for (const line of csv) {
|
||||
const vals = line.split(',');
|
||||
|
||||
aliases.push({
|
||||
name: vals[1],
|
||||
uid: parseInt(vals[0], 10),
|
||||
})
|
||||
}
|
||||
|
||||
const rec = await models.rdioScannerSystem.findOne({ where: { system } });
|
||||
|
||||
if (rec) {
|
||||
try {
|
||||
await rec.update({ aliases });
|
||||
|
||||
const systems = await models.rdioScannerSystem.findAll({ order: [['system', 'ASC']] });
|
||||
|
||||
res.send(`System ${rec.name} updated successfully.\n`);
|
||||
|
||||
pubsub.publish('rdioScannerSystems', { rdioScannerSystems: systems });
|
||||
|
||||
} catch (err) {
|
||||
res.send(err.message);
|
||||
}
|
||||
|
||||
} else {
|
||||
res.send(`Cannot update aliases for system #${system}.\n`);
|
||||
}
|
||||
}
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TrunkRecorderAliasUpload;
|
||||
|
|
@ -61,6 +61,8 @@ class TrunkRecorderCallUpload {
|
|||
|
||||
const data = {
|
||||
audio: req.files.audio[0].buffer,
|
||||
audioName: req.files.audio[0].originalname,
|
||||
audioType: req.files.audio[0].mimetype,
|
||||
emergency: !!meta.emergency,
|
||||
freq: parseInt(meta.freq, 10),
|
||||
freqList: Array.isArray(meta.freqList) ? meta.freqList : [],
|
||||
|
|
|
|||
2
server/package-lock.json
generated
2
server/package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "rdio-scanner-server",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "rdio-scanner-server",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"private": true,
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue