From 3dfa3fd5cd6c34ef6cd7ffb5e8a6a4cac10a90e3 Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Wed, 18 Mar 2026 19:56:54 +0800 Subject: [PATCH] optimize deps --- web/app/components/base/voice-input/index.tsx | 2 +- web/app/components/base/voice-input/utils.ts | 61 +++++-------------- .../components/plugins/plugin-item/index.tsx | 16 ++--- web/eslint-suppressions.json | 28 ++++++++- web/vite.config.ts | 20 +++++- 5 files changed, 69 insertions(+), 58 deletions(-) diff --git a/web/app/components/base/voice-input/index.tsx b/web/app/components/base/voice-input/index.tsx index b78e88352a..9ae390a3ca 100644 --- a/web/app/components/base/voice-input/index.tsx +++ b/web/app/components/base/voice-input/index.tsx @@ -82,7 +82,7 @@ const VoiceInput = ({ const canvas = canvasRef.current! const ctx = ctxRef.current! ctx.clearRect(0, 0, canvas.width, canvas.height) - const mp3Blob = await convertToMp3(recorder.current as unknown as Parameters[0]) + const mp3Blob = convertToMp3(recorder.current) const mp3File = new File([mp3Blob], 'temp.mp3', { type: 'audio/mp3' }) const formData = new FormData() formData.append('file', mp3File) diff --git a/web/app/components/base/voice-input/utils.ts b/web/app/components/base/voice-input/utils.ts index 8b4455c119..8fbd1a8b17 100644 --- a/web/app/components/base/voice-input/utils.ts +++ b/web/app/components/base/voice-input/utils.ts @@ -1,55 +1,24 @@ -type RecorderLike = { - getWAV: () => ArrayBufferLike - getChannelData: () => { - left: ArrayBufferView - right?: ArrayBufferView | null - } +import lamejs from 'lamejs' +import BitStream from 'lamejs/src/js/BitStream' +import Lame from 'lamejs/src/js/Lame' +import MPEGMode from 'lamejs/src/js/MPEGMode' + +/* v8 ignore next - @preserve */ +if (globalThis) { + (globalThis as any).MPEGMode = MPEGMode + ; (globalThis as any).Lame = Lame + ; (globalThis as any).BitStream = BitStream } -const toInt16Array = (view: ArrayBufferView) => { - return new Int16Array(view.buffer, view.byteOffset, view.byteLength / 2) -} - -const loadLame = async () => { - const [ - lamejsModule, - bitStreamModule, - lameModule, - mpegModeModule, - ] = await Promise.all([ - import('lamejs'), - import('lamejs/src/js/BitStream'), - import('lamejs/src/js/Lame'), - import('lamejs/src/js/MPEGMode'), - ]) - - const lamejs = lamejsModule.default - const BitStream = bitStreamModule.default - const Lame = lameModule.default - const MPEGMode = mpegModeModule.default - - /* v8 ignore next - @preserve */ - if (globalThis) { - ; (globalThis as any).MPEGMode = MPEGMode - ; (globalThis as any).Lame = Lame - ; (globalThis as any).BitStream = BitStream - } - - return lamejs -} - -export const convertToMp3 = async (recorder: RecorderLike) => { - const lamejs = await loadLame() - const wavBuffer = recorder.getWAV() - const wavView = wavBuffer instanceof DataView ? wavBuffer : new DataView(wavBuffer) - const wav = lamejs.WavHeader.readHeader(wavView) +export const convertToMp3 = (recorder: any) => { + const wav = lamejs.WavHeader.readHeader(recorder.getWAV()) const { channels, sampleRate } = wav const mp3enc = new lamejs.Mp3Encoder(channels, sampleRate, 128) const result = recorder.getChannelData() const buffer: BlobPart[] = [] - const leftData = toInt16Array(result.left) - const rightData = result.right ? toInt16Array(result.right) : null + const leftData = result.left && new Int16Array(result.left.buffer, 0, result.left.byteLength / 2) + const rightData = result.right && new Int16Array(result.right.buffer, 0, result.right.byteLength / 2) const remaining = leftData.length + (rightData ? rightData.length : 0) const maxSamples = 1152 @@ -65,7 +34,7 @@ export const convertToMp3 = async (recorder: RecorderLike) => { let mp3buf = null if (channels === 2) { - right = rightData?.subarray(i, i + maxSamples) || null + right = rightData.subarray(i, i + maxSamples) mp3buf = mp3enc.encodeBuffer(left, right) } else { diff --git a/web/app/components/plugins/plugin-item/index.tsx b/web/app/components/plugins/plugin-item/index.tsx index 9a39bc936b..3f658c63a8 100644 --- a/web/app/components/plugins/plugin-item/index.tsx +++ b/web/app/components/plugins/plugin-item/index.tsx @@ -11,6 +11,7 @@ import { import * as React from 'react' import { useCallback, useMemo } from 'react' import { useTranslation } from 'react-i18next' +import { gte } from 'semver' import Tooltip from '@/app/components/base/tooltip' import useRefreshPluginList from '@/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list' import { API_PREFIX } from '@/config' @@ -19,7 +20,6 @@ import { useGlobalPublicStore } from '@/context/global-public-context' import { useRenderI18nObject } from '@/hooks/use-i18n' import useTheme from '@/hooks/use-theme' import { cn } from '@/utils/classnames' -import { gte } from '@/utils/semver' import { getMarketplaceUrl } from '@/utils/var' import Badge from '../../base/badge' import { Github } from '../../base/icons/src/public/common' @@ -164,8 +164,8 @@ const PluginItem: FC = ({ /> {category === PluginCategoryEnum.extension && ( <> -
·
-
+
·
+
= ({ && ( <> -
{t('from', { ns: 'plugin' })}
+
{t('from', { ns: 'plugin' })}
GitHub
@@ -196,7 +196,7 @@ const PluginItem: FC = ({ && ( <>
-
+
{t('from', { ns: 'plugin' })} {' '} marketplace @@ -210,7 +210,7 @@ const PluginItem: FC = ({ <>
-
Local Plugin
+
Local Plugin
)} @@ -219,14 +219,14 @@ const PluginItem: FC = ({ <>
-
Debugging Plugin
+
Debugging Plugin
)}
{/* Deprecated */} {source === PluginSource.marketplace && enable_marketplace && isDeprecated && ( -
+
· {t('deprecated', { ns: 'plugin' })} diff --git a/web/eslint-suppressions.json b/web/eslint-suppressions.json index 4c39986dac..b613b64691 100644 --- a/web/eslint-suppressions.json +++ b/web/eslint-suppressions.json @@ -175,6 +175,19 @@ "count": 18 } }, + "app/(shareLayout)/components/authenticated-layout.tsx": { + "tailwindcss/enforce-consistent-class-order": { + "count": 1 + } + }, + "app/(shareLayout)/components/splash.tsx": { + "react-hooks-extra/no-direct-set-state-in-use-effect": { + "count": 1 + }, + "tailwindcss/enforce-consistent-class-order": { + "count": 1 + } + }, "app/(shareLayout)/webapp-reset-password/check-code/page.tsx": { "no-restricted-imports": { "count": 1 @@ -2841,7 +2854,7 @@ }, "app/components/base/voice-input/utils.ts": { "ts/no-explicit-any": { - "count": 3 + "count": 4 } }, "app/components/base/with-input-validation/index.stories.tsx": { @@ -4963,6 +4976,11 @@ "count": 1 } }, + "app/components/plugins/install-plugin/install-from-local-package/steps/install.tsx": { + "tailwindcss/enforce-consistent-class-order": { + "count": 2 + } + }, "app/components/plugins/install-plugin/install-from-local-package/steps/uploading.tsx": { "tailwindcss/enforce-consistent-class-order": { "count": 1 @@ -4979,6 +4997,11 @@ "count": 1 } }, + "app/components/plugins/install-plugin/install-from-marketplace/steps/install.tsx": { + "tailwindcss/enforce-consistent-class-order": { + "count": 2 + } + }, "app/components/plugins/marketplace/description/index.tsx": { "tailwindcss/enforce-consistent-class-order": { "count": 9 @@ -5457,6 +5480,9 @@ "no-restricted-imports": { "count": 1 }, + "tailwindcss/enforce-consistent-class-order": { + "count": 7 + }, "ts/no-explicit-any": { "count": 1 } diff --git a/web/vite.config.ts b/web/vite.config.ts index 1995c3ed79..a6c7f5bd7c 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -81,10 +81,26 @@ export default defineConfig(({ mode }) => { }, environments: { rsc: { - optimizeDeps: { include: ['semver'] }, + optimizeDeps: { + include: [ + 'semver', + 'lamejs', + 'lamejs/src/js/BitStream', + 'lamejs/src/js/Lame', + 'lamejs/src/js/MPEGMode', + ], + }, }, ssr: { - optimizeDeps: { include: ['semver'] }, + optimizeDeps: { + include: [ + 'semver', + 'lamejs', + 'lamejs/src/js/BitStream', + 'lamejs/src/js/Lame', + 'lamejs/src/js/MPEGMode', + ], + }, }, }, }