Fix Token API compatibility

This commit is contained in:
2026-07-22 22:30:26 -04:00
parent 1ef868e23c
commit e910a492ba
3 changed files with 25 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
FROM node:20-alpine
WORKDIR /app
COPY nodejs/package*.json ./
RUN ls -la
RUN npm ci --omit=dev
+15
View File
@@ -21,6 +21,21 @@ class Token extends Model {
return false
}
}
static async get(pk, ...args) {
const result = await super.get(pk, ...args);
if (!result) {
const error = new Error('EntryNotFound');
error.name = 'EntryNotFound';
error.status = 404;
throw error;
}
return result;
}
async remove() {
return this.delete();
}
}
class AuthToken extends Token{
+5 -3
View File
@@ -23,9 +23,11 @@ router.get('/', async function(req, res, next){
router.get('/:name', async function(req, res, next){
try{
return res.json({
results: await tokens[req.params.name].list({detail: !!req.query.detail})
});
let results = await tokens[req.params.name].list();
if (!req.query.detail) {
results = results.map(r => r.token || r.id);
}
return res.json({ results });
}catch(error){
next(error);
}