35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { FastifyInstance } from 'fastify';
|
|
import { DbService } from '../services/db.service.js';
|
|
|
|
export default async function quarantineRoutes(fastify: FastifyInstance, options: { dbService: DbService }) {
|
|
const { dbService } = options;
|
|
|
|
// List all disliked tracks (HIDDEN + WARNED states)
|
|
fastify.get('/dislikes', async () => {
|
|
return await dbService.getDislikedTracks();
|
|
});
|
|
|
|
// Restore a disliked track back to LIBRARY
|
|
fastify.post('/dislikes/:trackId/restore', async (request, reply) => {
|
|
const { trackId } = request.params as { trackId: string };
|
|
const entry = await dbService.getDislikeByTrackId(trackId);
|
|
if (!entry) {
|
|
return reply.code(404).send({ error: 'Dislike record not found' });
|
|
}
|
|
await dbService.restoreDislike(trackId);
|
|
return reply.send({ status: 'restored' });
|
|
});
|
|
|
|
// Hard-delete a disliked track immediately (skips grace period)
|
|
fastify.delete('/dislikes/:trackId', async (request, reply) => {
|
|
const { trackId } = request.params as { trackId: string };
|
|
const entry = await dbService.getDislikeByTrackId(trackId);
|
|
if (!entry) {
|
|
return reply.code(404).send({ error: 'Dislike record not found' });
|
|
}
|
|
const userId = (request.headers['x-user-id'] as string) || '00000000-0000-0000-0000-000000000000';
|
|
await dbService.permanentlyDeleteTrack(userId, trackId, entry.track_path);
|
|
return reply.send({ status: 'deleted' });
|
|
});
|
|
}
|