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
base: main
Are you sure you want to change the base?
Conversation
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'), '')); | ||
} |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
gitea/modules/typesniffer/typesniffer.go
Line 85 in d1ba5f4
func DetectContentType(data []byte) SniffedType { |
Co-authored-by: silverwind <me@silverwind.io>
Close #20130
And add a method to drag and drop files to the text area
Can anyone help with testing and review?