Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve attachment upload methods #30513

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tyroneyeh
Copy link
Contributor

Close #20130
And add a method to drag and drop files to the text area

Can anyone help with testing and review?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 16, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 16, 2024
const fileName = file.name.slice(0, file.name.lastIndexOf('.'));
const fileText = `\\[${fileName}\\]\\(/attachments/${file.uuid}\\)`;
editor.value(editor.value().replace(new RegExp(`<img [\\s\\w"=]+ alt="${fileName}" src="/attachments/${file.uuid}">`, 'g'), '').replace(new RegExp(`\\!${fileText}`, 'g'), '').replace(new RegExp(fileText, 'g'), ''));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use https://github.com/sindresorhus/escape-string-regexp here, later to be replaced with https://github.com/tc39/proposal-regex-escaping.

Also, this function should have some unit tests.

dz.emit('addedfile', attachment);
dz.emit('thumbnail', attachment, imgSrc);
if (/\.(jpg|jpeg|png|gif|bmp|svg)$/i.test(attachment.name)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to get the mime type into here and use it instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attachment variable has no type attribute. This information is obtained from the database. The database does not record the file type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typesniffer package in the backend that returns the mime type based on filename. Possible to use here?

func DetectContentType(data []byte) SniffedType {

web_src/js/utils/dom.js Outdated Show resolved Hide resolved
web_src/js/utils/dom.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/js size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy and paste the images has list legend
3 participants