fix: handle legacy non-JSON logo paths when replacing logo
When uploading a new logo, the code tries to delete the old logo file. This failed when the old path was stored as a raw path (legacy format) instead of JSON-serialized. Added check to handle both formats.
This commit is contained in:
@@ -326,8 +326,12 @@ router.post('/logo', adminAuth, requirePermission('settings.edit'), upload.singl
|
|||||||
.first();
|
.first();
|
||||||
|
|
||||||
if (oldLogoSetting && oldLogoSetting.setting_value) {
|
if (oldLogoSetting && oldLogoSetting.setting_value) {
|
||||||
const oldPath = JSON.parse(oldLogoSetting.setting_value);
|
|
||||||
try {
|
try {
|
||||||
|
// Handle both JSON-serialized and legacy raw path values
|
||||||
|
let oldPath = oldLogoSetting.setting_value;
|
||||||
|
if (oldPath.startsWith('"')) {
|
||||||
|
oldPath = JSON.parse(oldPath);
|
||||||
|
}
|
||||||
await fs.unlink(oldPath);
|
await fs.unlink(oldPath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to delete old logo:', error);
|
console.error('Failed to delete old logo:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user