'use strict'; const fs = require('fs'); const path = require('path'); const storage = require('../storage'); const UPLOADS_DIR = path.join(__dirname, '..', 'uploads'); const THUMBS_DIR = path.join(UPLOADS_DIR, '.thumbs'); function thumbFileFor(fp) { const base = path.basename(fp).replace(/\.[^.]+$/, '') + '.webp'; return path.join(THUMBS_DIR, base); } function thumbUnlinkFor(key) { const tp = thumbFileFor(key || ''); try { if (fs.existsSync(tp)) fs.unlinkSync(tp); } catch {} } function safeUnlink(relPath) { const key = storage.keyFromPath(relPath); if (!key) return; storage.unlinkLocalOnly(key); if (!storage.isRemote()) return; storage.del(key).catch(err => console.error('Upload delete failed:', key, err.message)); } function unlinkMedia(list) { for (const p of list || []) { if (!p) continue; safeUnlink(p); thumbUnlinkFor(p); } } module.exports = { UPLOADS_DIR, THUMBS_DIR, thumbFileFor, thumbUnlinkFor, safeUnlink, unlinkMedia, };