mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2025-12-19 05:47:46 +00:00
feat tts clear cache (#175)
* feat tts clear cache * feat tts clear cache
This commit is contained in:
6
app.js
6
app.js
@@ -42,7 +42,9 @@ const {
|
||||
incrKey
|
||||
} = require('./lib/helpers/realtimedb-helpers');
|
||||
const {
|
||||
getTtsVoices
|
||||
getTtsVoices,
|
||||
getTtsSize,
|
||||
purgeTtsCache
|
||||
} = require('@jambonz/speech-utils')({
|
||||
host: process.env.JAMBONES_REDIS_HOST,
|
||||
port: process.env.JAMBONES_REDIS_PORT || 6379
|
||||
@@ -84,6 +86,8 @@ app.locals = {
|
||||
retrieveKey,
|
||||
deleteKey,
|
||||
getTtsVoices,
|
||||
getTtsSize,
|
||||
purgeTtsCache,
|
||||
lookupAppBySid,
|
||||
lookupAccountBySid,
|
||||
lookupAccountByPhoneNumber,
|
||||
|
||||
@@ -17,6 +17,7 @@ const isAdminScope = (req, res, next) => {
|
||||
|
||||
api.use('/BetaInviteCodes', isAdminScope, require('./beta-invite-codes'));
|
||||
api.use('/SystemInformation', isAdminScope, require('./system-information'));
|
||||
api.use('/TtsCache', isAdminScope, require('./tts-cache'));
|
||||
api.use('/ServiceProviders', require('./service-providers'));
|
||||
api.use('/VoipCarriers', require('./voip-carriers'));
|
||||
api.use('/Webhooks', require('./webhooks'));
|
||||
|
||||
15
lib/routes/api/tts-cache.js
Normal file
15
lib/routes/api/tts-cache.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const router = require('express').Router();
|
||||
|
||||
router.delete('/', async(req, res) => {
|
||||
const {purgeTtsCache} = req.app.locals;
|
||||
await purgeTtsCache();
|
||||
res.sendStatus(204);
|
||||
});
|
||||
|
||||
router.get('/', async(req, res) => {
|
||||
const {getTtsSize} = req.app.locals;
|
||||
const size = await getTtsSize();
|
||||
res.status(200).json({size});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
93
package-lock.json
generated
93
package-lock.json
generated
@@ -14,7 +14,7 @@
|
||||
"@google-cloud/speech": "^5.1.0",
|
||||
"@jambonz/db-helpers": "^0.9.0",
|
||||
"@jambonz/realtimedb-helpers": "^0.8.1",
|
||||
"@jambonz/speech-utils": "^0.0.12",
|
||||
"@jambonz/speech-utils": "^0.0.14",
|
||||
"@jambonz/time-series": "^0.2.5",
|
||||
"@jambonz/verb-specifications": "^0.0.21",
|
||||
"@soniox/soniox-node": "^1.1.0",
|
||||
@@ -1789,17 +1789,6 @@
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@jambonz/promisify-redis": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/promisify-redis/-/promisify-redis-0.0.6.tgz",
|
||||
"integrity": "sha512-9KmWV+ODDOPwdqijhgXOXkloGNm7nmCf3ch4D1vN46lh9FQLmnlQmEmBHIFaKB3vAgIgcMzNzcNmY23JGCGguA==",
|
||||
"dependencies": {
|
||||
"redis-commands": "^1.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"redis": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jambonz/realtimedb-helpers": {
|
||||
"version": "0.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.1.tgz",
|
||||
@@ -1810,21 +1799,20 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@jambonz/speech-utils": {
|
||||
"version": "0.0.12",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.0.12.tgz",
|
||||
"integrity": "sha512-0S5HlFmVLGw6AA7R1HBE08tgCjT4P7szqsMioDKVrrTA84/qqqb4Vv70zc0F63lM2qUU5OXUnA1RJUcVpo9imQ==",
|
||||
"version": "0.0.14",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.0.14.tgz",
|
||||
"integrity": "sha512-MslO3IOAyZ+iBNgBWi3WuK73k8eU30RGvk8bQ4Md0n2ZSPzK2YH2Lo6LleqpvoQrc1k51498tnnMGu1MXmW6ow==",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-polly": "^3.303.0",
|
||||
"@google-cloud/text-to-speech": "^4.2.1",
|
||||
"@grpc/grpc-js": "^1.8.13",
|
||||
"@jambonz/promisify-redis": "^0.0.6",
|
||||
"bent": "^7.3.12",
|
||||
"debug": "^4.3.4",
|
||||
"form-urlencoded": "^6.1.0",
|
||||
"google-protobuf": "^3.21.2",
|
||||
"ibm-watson": "^8.0.0",
|
||||
"ioredis": "^5.3.2",
|
||||
"microsoft-cognitiveservices-speech-sdk": "^1.26.0",
|
||||
"redis": "^3.1.2",
|
||||
"undici": "^5.21.0"
|
||||
}
|
||||
},
|
||||
@@ -7371,29 +7359,6 @@
|
||||
"node": ">= 12.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/redis": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz",
|
||||
"integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==",
|
||||
"dependencies": {
|
||||
"denque": "^1.5.0",
|
||||
"redis-commands": "^1.7.0",
|
||||
"redis-errors": "^1.2.0",
|
||||
"redis-parser": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/node-redis"
|
||||
}
|
||||
},
|
||||
"node_modules/redis-commands": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz",
|
||||
"integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ=="
|
||||
},
|
||||
"node_modules/redis-errors": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
|
||||
@@ -7413,14 +7378,6 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/redis/node_modules/denque": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
|
||||
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/regexp.prototype.flags": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.0.tgz",
|
||||
@@ -10400,14 +10357,6 @@
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
},
|
||||
"@jambonz/promisify-redis": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/promisify-redis/-/promisify-redis-0.0.6.tgz",
|
||||
"integrity": "sha512-9KmWV+ODDOPwdqijhgXOXkloGNm7nmCf3ch4D1vN46lh9FQLmnlQmEmBHIFaKB3vAgIgcMzNzcNmY23JGCGguA==",
|
||||
"requires": {
|
||||
"redis-commands": "^1.6.0"
|
||||
}
|
||||
},
|
||||
"@jambonz/realtimedb-helpers": {
|
||||
"version": "0.8.1",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/realtimedb-helpers/-/realtimedb-helpers-0.8.1.tgz",
|
||||
@@ -10418,21 +10367,20 @@
|
||||
}
|
||||
},
|
||||
"@jambonz/speech-utils": {
|
||||
"version": "0.0.12",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.0.12.tgz",
|
||||
"integrity": "sha512-0S5HlFmVLGw6AA7R1HBE08tgCjT4P7szqsMioDKVrrTA84/qqqb4Vv70zc0F63lM2qUU5OXUnA1RJUcVpo9imQ==",
|
||||
"version": "0.0.14",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.0.14.tgz",
|
||||
"integrity": "sha512-MslO3IOAyZ+iBNgBWi3WuK73k8eU30RGvk8bQ4Md0n2ZSPzK2YH2Lo6LleqpvoQrc1k51498tnnMGu1MXmW6ow==",
|
||||
"requires": {
|
||||
"@aws-sdk/client-polly": "^3.303.0",
|
||||
"@google-cloud/text-to-speech": "^4.2.1",
|
||||
"@grpc/grpc-js": "^1.8.13",
|
||||
"@jambonz/promisify-redis": "^0.0.6",
|
||||
"bent": "^7.3.12",
|
||||
"debug": "^4.3.4",
|
||||
"form-urlencoded": "^6.1.0",
|
||||
"google-protobuf": "^3.21.2",
|
||||
"ibm-watson": "^8.0.0",
|
||||
"ioredis": "^5.3.2",
|
||||
"microsoft-cognitiveservices-speech-sdk": "^1.26.0",
|
||||
"redis": "^3.1.2",
|
||||
"undici": "^5.21.0"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -14663,29 +14611,6 @@
|
||||
"resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz",
|
||||
"integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg=="
|
||||
},
|
||||
"redis": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz",
|
||||
"integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==",
|
||||
"requires": {
|
||||
"denque": "^1.5.0",
|
||||
"redis-commands": "^1.7.0",
|
||||
"redis-errors": "^1.2.0",
|
||||
"redis-parser": "^3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"denque": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
|
||||
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"redis-commands": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz",
|
||||
"integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ=="
|
||||
},
|
||||
"redis-errors": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"@google-cloud/speech": "^5.1.0",
|
||||
"@jambonz/db-helpers": "^0.9.0",
|
||||
"@jambonz/realtimedb-helpers": "^0.8.1",
|
||||
"@jambonz/speech-utils": "^0.0.12",
|
||||
"@jambonz/speech-utils": "^0.0.14",
|
||||
"@jambonz/time-series": "^0.2.5",
|
||||
"@jambonz/verb-specifications": "^0.0.21",
|
||||
"@soniox/soniox-node": "^1.1.0",
|
||||
|
||||
@@ -23,4 +23,5 @@ require('./system-information');
|
||||
require('./lcr-carriers-set-entries');
|
||||
require('./lcr-routes');
|
||||
require('./lcrs');
|
||||
require('./tts-cache');
|
||||
require('./docker_stop');
|
||||
|
||||
56
test/tts-cache.js
Normal file
56
test/tts-cache.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const test = require('tape') ;
|
||||
const jwt = require('jsonwebtoken');
|
||||
const ADMIN_TOKEN = '38700987-c7a4-4685-a5bb-af378f9734de';
|
||||
const authAdmin = {bearer: ADMIN_TOKEN};
|
||||
const request = require('request-promise-native').defaults({
|
||||
baseUrl: 'http://127.0.0.1:3000/v1'
|
||||
});
|
||||
const crypto = require('crypto');
|
||||
const logger = require('../lib/logger');
|
||||
|
||||
const {
|
||||
client,
|
||||
} = require('@jambonz/speech-utils')({
|
||||
host: process.env.JAMBONES_REDIS_HOST,
|
||||
port: process.env.JAMBONES_REDIS_PORT || 6379
|
||||
}, logger);
|
||||
|
||||
function makeSynthKey({account_sid = '', vendor, language, voice, engine = '', text}) {
|
||||
const hash = crypto.createHash('sha1');
|
||||
hash.update(`${language}:${vendor}:${voice}:${engine}:${text}`);
|
||||
return `tts${account_sid ? (':' + account_sid) : ''}:${hash.digest('hex')}`;
|
||||
}
|
||||
|
||||
test('tts-cache', async(t) => {
|
||||
const app = require('../app');
|
||||
try {
|
||||
// create caches
|
||||
const minRecords = 8;
|
||||
for (const i in Array(minRecords).fill(0)) {
|
||||
await client.set(makeSynthKey({vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
||||
}
|
||||
|
||||
let result = await request.get('/TtsCache', {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
|
||||
t.ok(result.size === minRecords, 'get cache correctly');
|
||||
|
||||
result = await request.delete('/TtsCache', {
|
||||
auth: authAdmin,
|
||||
resolveWithFullResponse: true,
|
||||
});
|
||||
t.ok(result.statusCode === 204, 'successfully deleted application after removing phone number');
|
||||
|
||||
result = await request.get('/TtsCache', {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
|
||||
t.ok(result.size === 0, 'deleted cache successfully');
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
t.end(err);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user