From b1729f19aa1fd71ed0a987306065f239f6a1029c Mon Sep 17 00:00:00 2001 From: LaoShui <79132480+laoshuikaixue@users.noreply.github.com> Date: Thu, 19 Feb 2026 11:52:19 +0800 Subject: [PATCH] =?UTF-8?q?style(code):=20=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将长参数列表拆分为多行以提高可读性 - 标准化函数调用中的逗号使用 - 统一对象和数组的换行格式 - 更新 ESLint 配置中的 ECMA 版本至 2020,以支持 ES2020 语法(包括 Optional Chaining) - 优化代码缩进和对齐方式 - 确保所有文件中的代码风格一致性 --- eslint.config.js | 2 +- module/cloud.js | 9 +++++++-- module/cloud_upload_token.js | 5 ++++- module/voice_upload.js | 11 +++++++++-- plugins/songUpload.js | 6 +++++- server.js | 24 ++++++++++++++---------- 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 7e1d03c..2e569fb 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -16,7 +16,7 @@ const compat = new FlatCompat({ module.exports = defineConfig([ { languageOptions: { - ecmaVersion: 2018, + ecmaVersion: 2020, sourceType: 'module', parserOptions: { parser: 'babel-eslint', diff --git a/module/cloud.js b/module/cloud.js index cf33fa2..f3c93c8 100644 --- a/module/cloud.js +++ b/module/cloud.js @@ -14,7 +14,9 @@ let mm module.exports = async (query, request) => { mm = require('music-metadata') - query.songFile.name = Buffer.from(query.songFile.name, 'latin1').toString('utf-8') + query.songFile.name = Buffer.from(query.songFile.name, 'latin1').toString( + 'utf-8', + ) const ext = getFileExtension(query.songFile.name) const filename = sanitizeFilename(query.songFile.name) const bitrate = 999000 @@ -59,7 +61,10 @@ module.exports = async (query, request) => { if (useTemp) { metadata = await mm.parseFile(query.songFile.tempFilePath) } else { - metadata = await mm.parseBuffer(query.songFile.data, query.songFile.mimetype) + metadata = await mm.parseBuffer( + query.songFile.data, + query.songFile.mimetype, + ) } const info = metadata.common if (info.title) songName = info.title diff --git a/module/cloud_upload_token.js b/module/cloud_upload_token.js index c7ff727..6e7f3d9 100644 --- a/module/cloud_upload_token.js +++ b/module/cloud_upload_token.js @@ -35,7 +35,10 @@ module.exports = async (query, request) => { { bucket: bucket, ext: ext, - filename: filename.replace(/\.[^.]+$/, '').replace(/\s/g, '').replace(/\./g, '_'), + filename: filename + .replace(/\.[^.]+$/, '') + .replace(/\s/g, '') + .replace(/\./g, '_'), local: false, nos_product: 3, type: 'audio', diff --git a/module/voice_upload.js b/module/voice_upload.js index 79c9b8a..986fa71 100644 --- a/module/voice_upload.js +++ b/module/voice_upload.js @@ -82,9 +82,16 @@ module.exports = async (query, request) => { while (offset < fileSize) { let chunk if (useTempFile) { - chunk = await readFileChunk(query.songFile.tempFilePath, offset, Math.min(blockSize, fileSize - offset)) + chunk = await readFileChunk( + query.songFile.tempFilePath, + offset, + Math.min(blockSize, fileSize - offset), + ) } else { - chunk = query.songFile.data.slice(offset, Math.min(offset + blockSize, fileSize)) + chunk = query.songFile.data.slice( + offset, + Math.min(offset + blockSize, fileSize), + ) } const res3 = await axios({ diff --git a/plugins/songUpload.js b/plugins/songUpload.js index 6bc7e6b..379c6a0 100644 --- a/plugins/songUpload.js +++ b/plugins/songUpload.js @@ -1,7 +1,11 @@ const { default: axios } = require('axios') const createOption = require('../util/option.js') const logger = require('../util/logger.js') -const { getUploadData, getFileExtension, sanitizeFilename } = require('../util/fileHelper') +const { + getUploadData, + getFileExtension, + sanitizeFilename, +} = require('../util/fileHelper') module.exports = async (query, request) => { const ext = getFileExtension(query.songFile.name) diff --git a/server.js b/server.js index 1bc6e86..3bc25ba 100644 --- a/server.js +++ b/server.js @@ -182,17 +182,21 @@ async function consturctServer(moduleDefs) { const MAX_UPLOAD_SIZE_BYTES = MAX_UPLOAD_SIZE_MB * 1024 * 1024 app.use(express.json({ limit: `${MAX_UPLOAD_SIZE_MB}mb` })) - app.use(express.urlencoded({ extended: false, limit: `${MAX_UPLOAD_SIZE_MB}mb` })) + app.use( + express.urlencoded({ extended: false, limit: `${MAX_UPLOAD_SIZE_MB}mb` }), + ) - app.use(fileUpload({ - limits: { - fileSize: MAX_UPLOAD_SIZE_BYTES - }, - useTempFiles: true, - tempFileDir: require('os').tmpdir(), - abortOnLimit: true, - parseNested: true - })) + app.use( + fileUpload({ + limits: { + fileSize: MAX_UPLOAD_SIZE_BYTES, + }, + useTempFiles: true, + tempFileDir: require('os').tmpdir(), + abortOnLimit: true, + parseNested: true, + }), + ) /** * Cache