Skip to content

Commit b618bf7

Browse files
committed
update the source code of Upload Image
1 parent dfcd8a1 commit b618bf7

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

backend/server-upload.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ app.post('/upload-plugin', async (req, res) => {
181181
if ( imgIncludeExtTypes.test(f.name) ) {
182182

183183
const ext = /^.+\.([^.]+)$/.exec(f.name);
184-
let saveName = typeof symbol === 'undefined' ? f.name : `${typeof md5Enabled !== 'undefined' ? symbol + '-' + md5(symbol) : symbol}.${ext == null ? '' : ext[1]}`;
184+
185+
// Use Buffer to reconvert the encoding (if it is found to be Latin1 garbled)
186+
const safeNameOrgin = Buffer.from(f.name, 'latin1').toString('utf8');
187+
188+
189+
let saveName = typeof symbol === 'undefined' ? safeNameOrgin : `${typeof md5Enabled !== 'undefined' ? symbol + '-' + md5(symbol) : symbol}.${ext == null ? '' : ext[1]}`;
185190

186191
const tempPath = path.join(__dirname, '..', `/${STATIC_FILES_DIR}/_temp/`);
187192
const uploadPath = path.join(__dirname, '..', `/${STATIC_FILES_DIR}/_temp/`, saveName);
@@ -194,7 +199,14 @@ app.post('/upload-plugin', async (req, res) => {
194199

195200
// parse image
196201
const imgPath = `http://${HOST_NAME}:${PORT}/${STATIC_FILES_DIR}/_temp/${saveName}`;
197-
const paletteDataPromise = await getPaletteData(imgPath); // Promise
202+
203+
// Determine whether it is Chinese text.
204+
const hasChinese = (str) => {
205+
206+
return /[\u4e00-\u9fa5]/.test(str);
207+
};
208+
const paletteDataPromise = hasChinese(saveName) ? {} : await getPaletteData(imgPath); // Promise
209+
198210

199211

200212
// delete unnecessary files and folders

0 commit comments

Comments
 (0)