Release: weekly deploy
This commit is contained in:
BIN
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
@@ -19,6 +19,37 @@ function localPath(rel) {
|
|||||||
return path.join(IMAGE_DIR, rel);
|
return path.join(IMAGE_DIR, rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sleep(ms) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPaintingThumbRel(rel) {
|
||||||
|
if (!rel) return false;
|
||||||
|
return rel.replace(/\\/g, '/').startsWith('paintings/thumbs/');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unlinkWithRetry(absPath, attempts = 5) {
|
||||||
|
if (!absPath || !fs.existsSync(absPath)) return;
|
||||||
|
|
||||||
|
for (let attempt = 1; attempt <= attempts; attempt++) {
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(absPath);
|
||||||
|
return;
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code === 'EBUSY' && attempt < attempts) {
|
||||||
|
await sleep(200 * attempt);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unlinkOldThumbRel(thumbRel, imageRel) {
|
||||||
|
if (!thumbRel || thumbRel === imageRel || !isPaintingThumbRel(thumbRel)) return;
|
||||||
|
await unlinkWithRetry(localPath(thumbRel));
|
||||||
|
}
|
||||||
|
|
||||||
async function aspectRatio(filePath) {
|
async function aspectRatio(filePath) {
|
||||||
const meta = await sharp(filePath).metadata();
|
const meta = await sharp(filePath).metadata();
|
||||||
if (!meta.width || !meta.height) return null;
|
if (!meta.width || !meta.height) return null;
|
||||||
@@ -65,14 +96,8 @@ async function aspectRatio(filePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(thumbPath)) fs.unlinkSync(thumbPath);
|
await unlinkWithRetry(thumbPath);
|
||||||
if (
|
await unlinkOldThumbRel(row.thumbnail_path, row.image_path);
|
||||||
row.thumbnail_path &&
|
|
||||||
row.thumbnail_path !== thumbRel &&
|
|
||||||
fs.existsSync(localPath(row.thumbnail_path))
|
|
||||||
) {
|
|
||||||
fs.unlinkSync(localPath(row.thumbnail_path));
|
|
||||||
}
|
|
||||||
|
|
||||||
await generateThumbnailFromFull(fullPath, thumbPath);
|
await generateThumbnailFromFull(fullPath, thumbPath);
|
||||||
await pool.query(`UPDATE paintings SET thumbnail_path = $1 WHERE id = $2`, [thumbRel, row.id]);
|
await pool.query(`UPDATE paintings SET thumbnail_path = $1 WHERE id = $2`, [thumbRel, row.id]);
|
||||||
|
|||||||
Reference in New Issue
Block a user