]> BookStack Code Mirror - bookstack/commitdiff
Updated image drop handling to respect original file name
authorDan Brown <redacted>
Tue, 7 Jun 2022 13:59:00 +0000 (14:59 +0100)
committerDan Brown <redacted>
Tue, 7 Jun 2022 13:59:00 +0000 (14:59 +0100)
Now uses the previously timestamp gen name as a backup to the original
name. Aligns with the image manager upload which uses the original name
where given.

Closes #3470

resources/js/wysiwyg/drop-paste-handling.js

index ace74dd334e03c8a17bcfbf527ae3d178ac44295..0529f6b6cdd110f00335b3a5c2785df608e7fe71 100644 (file)
@@ -60,13 +60,7 @@ async function uploadImageFile(file, pageId) {
         throw new Error(`Not an image file`);
     }
 
-    let ext = 'png';
-    if (file.name) {
-        let fileNameMatches = file.name.match(/\.(.+)$/);
-        if (fileNameMatches.length > 1) ext = fileNameMatches[1];
-    }
-
-    const remoteFilename = "image-" + Date.now() + "." + ext;
+    const remoteFilename = file.name || `image-${Date.now()}.png`;
     const formData = new FormData();
     formData.append('file', file, remoteFilename);
     formData.append('uploaded_to', pageId);