wiki icon indicating copy to clipboard operation
wiki copied to clipboard

Prevent overwriting of uploaded pasted images

Open SanduRajapakse opened this issue 2 years ago • 14 comments

Problem: This issue has been discussed in the forum for the MD editor but is also present in the WYSIWYG editor as well. Discussion: https://feedback.js.wiki/wiki/p/ability-to-paste-images-into-md-editor

Images that are pasted into the application all have the filename image.png.

Solution: This PR appends the current timestamp to the image name to ensure there is no overlap in the filename and allows for uploads to occur without overwriting existing uploads.

Why: This is a very important feature for those who use this application for documentation as most developers use screenshots on their pages. Having to save screenshots and selecting them from the local system is time-consuming and inhibits application usage.

SanduRajapakse avatar Jan 05 '23 23:01 SanduRajapakse

Note: only images with the filename image.png will be updated. This should adhere to your rule about keeping the existing filename whenever possible.

SanduRajapakse avatar Jan 05 '23 23:01 SanduRajapakse

Hi! I use Chinese. The name of the picture on my clipboard is 图片.png

图片

myml avatar Jan 06 '23 02:01 myml

Hi! I use Chinese. The name of the picture on my clipboard is 图片.png

图片

Thanks for the reply. I didn't realize default filenames were internationalized. Let me see if I can update to support i18n defaults.

SanduRajapakse avatar Jan 06 '23 04:01 SanduRajapakse

Hi! I use Chinese. The name of the picture on my clipboard is 图片.png

图片

Hey, I need some help from you to reproduce this. I changed my local installation of Wiki.js to Chinese and that did not work, then I changed my browser language to Chinese and that still did not work. How do I get the uploaded image filename to not be in English?

You can see all of my tests here (the last few were uploaded after changing to Chinese:

image

SanduRajapakse avatar Jan 06 '23 05:01 SanduRajapakse

After change the language of the browser, restart Firefox and try.

myml avatar Jan 06 '23 07:01 myml

After change the language of the browser, restart Firefox and try.

image

Thanks! I got it working, but it has confirmed my fears. Since the filename comes from the browser, there is no way to look up the i18n term and make this work. This will need a different approach.

The easiest solution would be to add a unique key at the end of all filenames, but I assume not all users will like that. Can we add an option in the admin cp and make it opt-in? We can make it more advanced and allow admins to use whatever format they prefer...

@NGPixel Thoughts?

SanduRajapakse avatar Jan 06 '23 23:01 SanduRajapakse

Adding a timestamp to the name when this the file already exists in the folder may be a good idea? That would solve the issue for all potential names and not depend on the browser in any way.

okke-formsma avatar Mar 02 '23 20:03 okke-formsma

@NGPixel, any hesitation to this patch? currently when user upload an image with the same name it simply overwrites, which causes quite some aberrant behavior. This seems like the smallest code fix possible to rectify the issue...

parksj10 avatar Mar 08 '23 22:03 parksj10

@parksj10 It should be optional and off by default. Being able to overwrite a file is what most people expect (same behavior as most OS).

NGPixel avatar Mar 09 '23 00:03 NGPixel

@parksj10 It should be optional and off by default. Being able to overwrite a file is what most people expect (same behavior as most OS).

this is not true, if I paste a file with the same name in windows it will add (1) after the filename, and on mac it will append "copy", "copy 2", "copy 3" etc.

image

okke-formsma avatar Mar 09 '23 10:03 okke-formsma

@okke-formsma That's because you're copy/pasting from the same folder, which is essentially a duplicate action. Copy a file from any other location and you'll be prompted to overwrite it.

NGPixel avatar Mar 09 '23 12:03 NGPixel

@NGPixel I have updated the PR as per your request. I added a setting to the config and the feature is opt-in and should be off by default.

Here is an example of how it works. Note the first upload shown is with the setting disabled, all others are with it enabled.

image

Here is how the setting looks in the admin section: image

SanduRajapakse avatar Mar 15 '23 22:03 SanduRajapakse

@NGPixel Can you please review this?

SanduRajapakse avatar Jul 27 '23 20:07 SanduRajapakse

@NGPixel Is there a chance that this "feature" will be implemented?

derw0lf avatar Feb 05 '24 14:02 derw0lf