Add music player
This commit is contained in:
1 parent
c820672803
commit
40604b4a04
17 files changed
+1153
No files matched your search
@@ -0,0 +1,8 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { getPlaylistTracks } from '#lib/server/music';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
export const GET: RequestHandler = async () => {
|
||||
const tracks = await getPlaylistTracks();
|
||||
return json(tracks, { headers: { 'Cache-Control': 'no-store' } });
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { isPlaylistVideo, streamTrackAsMp3 } from '#lib/server/music';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
export const GET: RequestHandler = ({ params, url }) => {
|
||||
if (!isPlaylistVideo(params.id)) error(404, 'Song not found');
|
||||
|
||||
const requestedStart = Number(url.searchParams.get('start') ?? 0);
|
||||
const startSeconds = Number.isFinite(requestedStart) && requestedStart > 0 ? Math.floor(requestedStart) : 0;
|
||||
|
||||
return new Response(streamTrackAsMp3(params.id, startSeconds), {
|
||||
headers: {
|
||||
'Content-Type': 'audio/mpeg',
|
||||
'Cache-Control': 'no-store'
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user