Skip to content

Commit 0102ff6

Browse files
yp05327lunny
authored andcommitted
Fix broken image when editing comment with non-image attachments (go-gitea#32319)
Fix go-gitea#32316
1 parent bf53ab2 commit 0102ff6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

web_src/js/features/repo-issue-edit.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkd
44
import {createDropzone} from './dropzone.js';
55
import {GET, POST} from '../modules/fetch.js';
66
import {hideElem, showElem} from '../utils/dom.js';
7+
import {isImageFile} from '../utils/image.js';
78
import {attachRefIssueContextPopup} from './contextpopup.js';
89
import {initCommentContent, initMarkupContent} from '../markup/content.js';
910

@@ -84,7 +85,9 @@ async function onEditContent(event) {
8485
for (const attachment of data) {
8586
const imgSrc = `${dropzone.getAttribute('data-link-url')}/${attachment.uuid}`;
8687
dz.emit('addedfile', attachment);
87-
dz.emit('thumbnail', attachment, imgSrc);
88+
if (isImageFile(attachment.name)) {
89+
dz.emit('thumbnail', attachment, imgSrc);
90+
}
8891
dz.emit('complete', attachment);
8992
fileUuidDict[attachment.uuid] = {submitted: true};
9093
dropzone.querySelector(`img[src='${imgSrc}']`).style.maxWidth = '100%';

web_src/js/utils/image.js

+4
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ export async function imageInfo(blob) {
4545

4646
return {width, dppx};
4747
}
48+
49+
export function isImageFile(name) {
50+
return /\.(jpe?g|png|gif|webp|svg|heic)$/i.test(name);
51+
}

0 commit comments

Comments
 (0)