Release v2.13.1
This commit is contained in:
@@ -253,10 +253,18 @@ function createUploadSyncService(options) {
|
||||
|
||||
function normalizeUploadReference(uploadPath) {
|
||||
const value = String(uploadPath || '').trim();
|
||||
if (!value || !value.startsWith('/media/')) {
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
if (value.startsWith('/media/')) {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
const parsed = new URL(value);
|
||||
return parsed.pathname.startsWith('/media/') ? parsed.pathname : null;
|
||||
} catch (_error) {
|
||||
return null;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function getUploadRelativePath(uploadPath) {
|
||||
@@ -313,6 +321,13 @@ function createUploadSyncService(options) {
|
||||
if (reference) {
|
||||
refs.add(reference);
|
||||
}
|
||||
const embeddedReferences = current.match(/\/media\/[^"'\s<>)]+/g) || [];
|
||||
embeddedReferences.forEach(function (embeddedReference) {
|
||||
const normalizedReference = normalizeUploadReference(embeddedReference);
|
||||
if (normalizedReference) {
|
||||
refs.add(normalizedReference);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return refs;
|
||||
@@ -364,32 +379,21 @@ function createUploadSyncService(options) {
|
||||
return Number(slideRows[0].ref_count || 0) + Number(thumbnailRows[0].ref_count || 0) + Number(templateRows[0].ref_count || 0);
|
||||
}
|
||||
|
||||
async function removeUnusedUploadFiles(pool, uploadDir, uploadPaths) {
|
||||
const uniquePaths = Array.from(new Set((uploadPaths || []).map(normalizeUploadReference).filter(Boolean)));
|
||||
for (let i = 0; i < uniquePaths.length; i += 1) {
|
||||
const uploadPath = uniquePaths[i];
|
||||
const referenceCount = await countUploadReferences(pool, uploadPath);
|
||||
if (referenceCount > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const filePath = resolveUploadFilePath(uploadDir, uploadPath);
|
||||
if (String(uploadPath || '').startsWith('/media/player-cache/')) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
await fs.promises.unlink(filePath);
|
||||
} catch (error) {
|
||||
if (error && error.code !== 'ENOENT') {
|
||||
console.warn('Unable to remove unused upload file:', filePath, error);
|
||||
}
|
||||
}
|
||||
queuePlayerUploadSync({
|
||||
type: 'delete',
|
||||
uploadPath: uploadPath,
|
||||
uploadDir: uploadDir
|
||||
});
|
||||
async function uploadFileExists(uploadDir, uploadPath) {
|
||||
const filePath = resolveUploadFilePath(uploadDir, uploadPath);
|
||||
if (!filePath) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
await fs.promises.access(filePath, fs.constants.F_OK);
|
||||
return true;
|
||||
} catch (_error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeUnusedUploadFiles(pool, uploadDir, uploadPaths) {
|
||||
return;
|
||||
}
|
||||
|
||||
async function collectUploadPathsFromDirectory(uploadDir) {
|
||||
@@ -981,6 +985,10 @@ function createUploadSyncService(options) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isLocalLikeBaseUrl(taskPayload.playerInternalBaseUrl) && await uploadFileExists(operation.localUploadDir, removedUploadRef)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const deleted = await removeUploadFileFromPlayer(removedUploadRef, operation.localUploadDir, taskPayload.playerInternalBaseUrl, taskPayload.playerIdentifier);
|
||||
if (!deleted) {
|
||||
queuePlayerUploadSync({
|
||||
|
||||
Reference in New Issue
Block a user