diff --git a/.gitignore b/.gitignore index 242fd79..5ddfabc 100644 --- a/.gitignore +++ b/.gitignore @@ -27,5 +27,4 @@ public/assets/fonts/cache .idea static/audio temp_audio -.stfolder -storage/ \ No newline at end of file +.stfolder \ No newline at end of file diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index a79b138..ddf336b 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -6,8 +6,6 @@ services: dockerfile: deploy/Dockerfile.web ports: - "127.0.0.1:3000:3000" - volumes: - - ./data/storage:/app/storage environment: - ORIGIN=http://localhost:3000 - MONGO_URL=mongodb://cat:meow@db:27017/amaoke?authSource=admin diff --git a/src/lib/server/songs.ts b/src/lib/server/songs.ts index 4c4f0f7..a2c09f2 100644 --- a/src/lib/server/songs.ts +++ b/src/lib/server/songs.ts @@ -8,10 +8,10 @@ import type { ObjectId } from 'mongodb' import '../ext' import { promises as fs } from 'fs' import path from 'path' +import { waitFor } from '../utils' import { separateSong } from './separator' -const CACHE_DIR = path.resolve('storage/audio') -export const getAudioFile = (songId: string, filename: string) => path.join(CACHE_DIR, songId, filename) +const CACHE_DIR = path.resolve('static/audio') const neCookie = async () => (await dbs.serverProps .findOne({ name: 'global_settings' }))?.netease_login_cookie diff --git a/src/routes/audio/[songId]/[file]/+server.ts b/src/routes/audio/[songId]/[file]/+server.ts deleted file mode 100644 index f2c7ab2..0000000 --- a/src/routes/audio/[songId]/[file]/+server.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { getAudioFile } from '$lib/server/songs'; -import { error } from '@sveltejs/kit'; -import fs from 'fs/promises'; -import path from 'path'; -import type { RequestHandler } from './$types'; - -export const GET: RequestHandler = async ({ params }) => { - const { songId, file } = params; - const filePath = getAudioFile(songId, file); - - try { - await fs.access(filePath); - } catch { - throw error(404, 'File not found'); - } - - const ext = path.extname(file).toLowerCase(); - let contentType = 'application/octet-stream'; - if (ext === '.mp3') contentType = 'audio/mpeg'; - if (ext === '.opus') contentType = 'audio/ogg'; - - const buffer = await fs.readFile(filePath); - - return new Response(buffer, { - headers: { - 'Content-Type': contentType, - 'Cache-Control': 'public, max-age=31536000' - } - }); -};