Skip to content

Conversation

@SanduRajapakse
Copy link

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.

@auto-assign auto-assign bot requested a review from NGPixel January 5, 2023 23:21
@SanduRajapakse
Copy link
Author

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

@myml
Copy link
Contributor

myml commented Jan 6, 2023

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

图片

@SanduRajapakse
Copy link
Author

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
Copy link
Author

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

@myml
Copy link
Contributor

myml commented Jan 6, 2023

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

@SanduRajapakse
Copy link
Author

SanduRajapakse commented Jan 6, 2023

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?

@okke-formsma
Copy link

okke-formsma commented Mar 2, 2023

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.

@parksj10
Copy link

parksj10 commented Mar 8, 2023

@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...

@NGPixel
Copy link
Member

NGPixel commented Mar 9, 2023

@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).

@okke-formsma
Copy link

@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

@NGPixel
Copy link
Member

NGPixel commented Mar 9, 2023

@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.

@SanduRajapakse
Copy link
Author

SanduRajapakse commented Mar 15, 2023

@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
Copy link
Author

@NGPixel Can you please review this?

@derw0lf
Copy link

derw0lf commented Feb 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants