40 lines
1.6 KiB
JavaScript
40 lines
1.6 KiB
JavaScript
function registerFontSyncTask(options) {
|
|
const backgroundTaskQueue = options && options.backgroundTaskQueue;
|
|
const uploadSyncService = options && options.uploadSyncService;
|
|
|
|
if (!backgroundTaskQueue || !uploadSyncService) {
|
|
throw new Error('registerFontSyncTask requires the font sync dependencies.');
|
|
}
|
|
|
|
backgroundTaskQueue.setTaskHandler('font-sync', async function (task) {
|
|
const payload = task && task.payload ? task.payload : task || {};
|
|
const uploadDir = String(payload.uploadDir || '').trim();
|
|
const playerIdentifier = String(payload.playerIdentifier || payload.deviceId || '').trim();
|
|
const operations = Array.isArray(payload.operations)
|
|
? payload.operations
|
|
: Array.isArray(payload.uploadPaths)
|
|
? payload.uploadPaths.map(function (uploadPath) {
|
|
return { type: String(payload.action || 'put').trim().toLowerCase(), uploadPath: uploadPath };
|
|
})
|
|
: [];
|
|
|
|
if (!uploadDir || !operations.length) {
|
|
return;
|
|
}
|
|
|
|
for (let i = 0; i < operations.length; i += 1) {
|
|
const operation = operations[i] || {};
|
|
const uploadPath = String(operation.uploadPath || '').trim();
|
|
if (!uploadPath) {
|
|
continue;
|
|
}
|
|
if (String(operation.type || '').trim().toLowerCase() === 'delete') {
|
|
await uploadSyncService.removeUploadFileFromPlayer(uploadPath, uploadDir, undefined, playerIdentifier);
|
|
} else {
|
|
await uploadSyncService.pushUploadFileToPlayer(uploadPath, uploadDir, undefined, playerIdentifier);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = { registerFontSyncTask }; |