Implements MP3 320kbps download functionality using ffmpeg.wasm for industry-standard encoding with libmp3lame. Features: - New MP3_320 quality option in download settings UI - ID3v2.3 metadata writing (title, artist, album, cover art, ISRC, etc.) - Non-blocking encoding via Web Worker to keep UI responsive - Proper UTF-16 with BOM text encoding for international characters - Album artist fallback to track artist (mirrors FLAC/M4A behavior) - Automatic format detection for downloaded audio - Year validation to prevent writing NaN to ID3 tags Implementation: - mp3-encoder.js: Main encoder module with worker orchestration - mp3-encoder.worker.js: FFmpeg Web Worker for async encoding - id3-writer.js: ID3v2.3 tag writer with synchsafe size encoding - Updates to api.js, metadata.js, utils.js for MP3 support - Vite config excludes @ffmpeg packages from dep optimization Technical details: - Uses @ffmpeg/ffmpeg (libmp3lame 320kbps CBR, 44.1kHz) - FFmpeg binary lazy-loaded from CDN (~25MB, cached) - Encoding runs in separate thread (non-blocking UI) - Proper error handling with distinct encoding vs network errors - Memory-efficient: transfers ArrayBuffer with zero-copy Dependencies: - @ffmpeg/ffmpeg ^0.12.10 - @ffmpeg/util ^0.12.1 - Removed: package-lock.json (project uses bun.lock) Closes maintainer request to use ffmpeg.wasm instead of lamejs.
70 lines
2.6 KiB
JavaScript
70 lines
2.6 KiB
JavaScript
import { defineConfig } from 'vite';
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
import neutralino from 'vite-plugin-neutralino';
|
|
import authGatePlugin from './vite-plugin-auth-gate.js';
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const IS_NEUTRALINO = mode === 'neutralino';
|
|
|
|
return {
|
|
base: './',
|
|
resolve: {
|
|
alias: {
|
|
pocketbase: '/node_modules/pocketbase/dist/pocketbase.es.js',
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
exclude: ['pocketbase', '@ffmpeg/ffmpeg', '@ffmpeg/util'],
|
|
},
|
|
server: {
|
|
fs: {
|
|
allow: ['.', 'node_modules'],
|
|
},
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
emptyOutDir: true,
|
|
},
|
|
plugins: [
|
|
IS_NEUTRALINO && neutralino(),
|
|
authGatePlugin(),
|
|
VitePWA({
|
|
registerType: 'prompt',
|
|
workbox: {
|
|
globPatterns: ['**/*.{js,css,html,ico,png,svg,json}'],
|
|
cleanupOutdatedCaches: true,
|
|
maximumFileSizeToCacheInBytes: 3 * 1024 * 1024, // 3 MiB limit
|
|
// Define runtime caching strategies
|
|
runtimeCaching: [
|
|
{
|
|
urlPattern: ({ request }) => request.destination === 'image',
|
|
handler: 'CacheFirst',
|
|
options: {
|
|
cacheName: 'images',
|
|
expiration: {
|
|
maxEntries: 100,
|
|
maxAgeSeconds: 60 * 24 * 60 * 60, // 60 Days
|
|
},
|
|
},
|
|
},
|
|
{
|
|
urlPattern: ({ request }) =>
|
|
request.destination === 'audio' || request.destination === 'video',
|
|
handler: 'CacheFirst',
|
|
options: {
|
|
cacheName: 'media',
|
|
expiration: {
|
|
maxEntries: 50,
|
|
maxAgeSeconds: 60 * 24 * 60 * 60, // 60 Days
|
|
},
|
|
rangeRequests: true, // Support scrubbing
|
|
},
|
|
},
|
|
],
|
|
},
|
|
includeAssets: ['discord.html'],
|
|
manifest: false, // Use existing public/manifest.json
|
|
}),
|
|
],
|
|
};
|
|
});
|