Skip to content

Commit a3b7b98

Browse files
lunnyyp05327
andauthored
Fix broken image when editing comment with non-image attachments (#32319) (#32345)
Backport #32319 Fix #32316 --------- Co-authored-by: yp05327 <[email protected]>
1 parent 898f852 commit a3b7b98

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

+5-2
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,10 +85,12 @@ 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+
dropzone.querySelector(`img[src='${imgSrc}']`).style.maxWidth = '100%';
91+
}
8892
dz.emit('complete', attachment);
8993
fileUuidDict[attachment.uuid] = {submitted: true};
90-
dropzone.querySelector(`img[src='${imgSrc}']`).style.maxWidth = '100%';
9194
const input = document.createElement('input');
9295
input.id = attachment.uuid;
9396
input.name = 'files';

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)