Skip to content

Commit c0cd2fc

Browse files
committed
fix
1 parent 15f2c3f commit c0cd2fc

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

web_src/js/features/comp/EditorUpload.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {replaceTextareaSelection} from '../../utils/dom.js';
55
import {isUrl} from '../../utils/url.js';
66
import {extname} from '../../utils.js';
77
import {triggerEditorContentChanged} from './EditorMarkdown.js';
8-
import {getComboMarkdownEditor} from './ComboMarkdownEditor.js';
98

109
async function uploadFile(file, uploadUrl) {
1110
const formData = new FormData();
@@ -174,7 +173,7 @@ export function initTextareaPaste(textarea, dropzone) {
174173
}
175174
});
176175
textarea.addEventListener('drop', (e) => {
177-
const acceptedFiles = getComboMarkdownEditor(textarea).dropzone.getAttribute('data-accepts');
176+
const acceptedFiles = dropzone.getAttribute('data-accepts');
178177
const files = [];
179178
for (const item of e.dataTransfer?.items ?? []) {
180179
if (item?.kind !== 'file') continue;

web_src/js/features/dropzone.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export async function initDropzone(dropzoneEl) {
7878

7979
dzInst.on('removedfile', async (file) => {
8080
if (disableRemovedfileEvent) return;
81+
82+
// TODO: remove the link from editor
83+
8184
document.querySelector(`#dropzone-file-${file.uuid}`)?.remove();
8285
// when the uploaded file number reaches the limit, there is no uuid in the dict, and it doesn't need to be removed from server
8386
if (removeAttachmentUrl && fileUuidDict[file.uuid] && !fileUuidDict[file.uuid].submitted) {

web_src/js/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export function basename(path = '') {
88

99
// transform /path/to/file.ext to .ext
1010
export function extname(path = '') {
11+
const lastSlashIndex = path.lastIndexOf('/');
1112
const lastPointIndex = path.lastIndexOf('.');
13+
if (lastSlashIndex > lastPointIndex) return '';
1214
return lastPointIndex < 0 ? '' : path.substring(lastPointIndex);
1315
}
1416

@@ -142,3 +144,7 @@ export function serializeXml(node) {
142144
}
143145

144146
export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
147+
148+
export function isWellKnownImageFilename(fn) {
149+
return /\.(jpe?g|png|gif|webp|svg)$/i.test(fn);
150+
}

web_src/js/utils.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
basename, extname, isObject, stripTags, parseIssueHref,
33
parseUrl, translateMonth, translateDay, blobToDataURI,
4-
toAbsoluteUrl, encodeURLEncodedBase64, decodeURLEncodedBase64,
4+
toAbsoluteUrl, encodeURLEncodedBase64, decodeURLEncodedBase64, isWellKnownImageFilename,
55
} from './utils.js';
66

77
test('basename', () => {
@@ -15,6 +15,7 @@ test('extname', () => {
1515
expect(extname('/path/')).toEqual('');
1616
expect(extname('/path')).toEqual('');
1717
expect(extname('file.js')).toEqual('.js');
18+
expect(extname('/my.path/file')).toEqual('');
1819
});
1920

2021
test('isObject', () => {
@@ -112,3 +113,12 @@ test('encodeURLEncodedBase64, decodeURLEncodedBase64', () => {
112113
expect(Array.from(decodeURLEncodedBase64('YQ'))).toEqual(Array.from(uint8array('a')));
113114
expect(Array.from(decodeURLEncodedBase64('YQ=='))).toEqual(Array.from(uint8array('a')));
114115
});
116+
117+
test('isWellKnownImageFilename', () => {
118+
for (const filename of ['a.jpg', '/a.jpeg', '.file.png', '.webp', 'file.svg']) {
119+
expect(isWellKnownImageFilename(filename)).toBeTruthy();
120+
}
121+
for (const filename of ['', 'a.jpg.x', '/path.png/x', 'webp']) {
122+
expect(isWellKnownImageFilename(filename)).toBeFalsy();
123+
}
124+
});

web_src/js/utils/dom.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {debounce} from 'throttle-debounce';
2-
import {extname} from '../utils.js';
32

43
function elementsCall(el, func, ...args) {
54
if (typeof el === 'string' || el instanceof String) {

0 commit comments

Comments
 (0)