33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
// Internal sync trigger routes for player-driven queue flushes.
|
|
|
|
const { verifyRequestAuth } = require('#src/request-auth');
|
|
|
|
function requireRequestAuth(req, res, next) {
|
|
if (!verifyRequestAuth(req)) {
|
|
return res.status(401).json({ error: 'Request authentication required.' });
|
|
}
|
|
|
|
next();
|
|
}
|
|
|
|
module.exports = function registerInternalSyncRoutes(app, deps) {
|
|
const uploadSyncService = deps && deps.uploadSyncService;
|
|
const mediaDir = String(deps && deps.mediaDir || '').trim();
|
|
|
|
if (!uploadSyncService || typeof uploadSyncService.flushPendingPlayerUploadSyncs !== 'function' || typeof uploadSyncService.runMediaSyncTask !== 'function' || !mediaDir) {
|
|
throw new Error('registerInternalSyncRoutes requires the sync dependencies.');
|
|
}
|
|
|
|
app.post('/api/internal/sync/player-media', requireRequestAuth, async function (_req, res, next) {
|
|
try {
|
|
await uploadSyncService.runMediaSyncTask({
|
|
mode: 'initial',
|
|
uploadDir: mediaDir
|
|
});
|
|
await uploadSyncService.flushPendingPlayerUploadSyncs();
|
|
res.json({ ok: true });
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
}; |