diff --git a/client/components/modals/authors/EditModal.vue b/client/components/modals/authors/EditModal.vue index 7ac5dc74c..3256629cb 100644 --- a/client/components/modals/authors/EditModal.vue +++ b/client/components/modals/authors/EditModal.vue @@ -20,7 +20,7 @@ {{ $strings.ButtonSubmit }} {{ $strings.ButtonCancel }} diff --git a/server/controllers/AuthorController.js b/server/controllers/AuthorController.js index aeb391b56..4cec9d79c 100644 --- a/server/controllers/AuthorController.js +++ b/server/controllers/AuthorController.js @@ -276,14 +276,21 @@ class AuthorController { // 1. File upload (express-fileupload) if (req.files && req.files.image) { const uploadedFile = req.files.image - const uploadsDir = Path.join(global.MetadataPath, 'uploads') + const uploadsDir = Path.join(global.MetadataPath, 'authors') if (!fs.existsSync(uploadsDir)) { fs.mkdirSync(uploadsDir, { recursive: true }) } - const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9) - const fileName = 'image-' + uniqueSuffix + Path.extname(uploadedFile.name) + + // Use author ID as filename instead of random suffix + const fileName = `${req.author.id}${Path.extname(uploadedFile.name)}` const filePath = Path.join(uploadsDir, fileName) + + // Remove existing file if it exists + if (fs.existsSync(filePath)) { + fs.unlinkSync(filePath) + } + await uploadedFile.mv(filePath) imagePath = filePath }