e616713ec1
- Fix delete song route: remove reference to non-existent audio_files table, use audio_url directly from songs table instead - Fix CORS: allow 127.0.0.1 in addition to localhost in development mode - Fix cleanup service: remove audio_files reference, use SQLite datetime syntax
29 lines
785 B
TypeScript
29 lines
785 B
TypeScript
import { pool } from '../db/pool.js';
|
|
|
|
export interface CleanupResult {
|
|
deleted: number;
|
|
errors: number;
|
|
}
|
|
|
|
export async function runCleanupJob(): Promise<CleanupResult> {
|
|
// Local storage doesn't have expiring files - no cleanup needed
|
|
console.log('Cleanup job: No action needed for local storage');
|
|
return { deleted: 0, errors: 0 };
|
|
}
|
|
|
|
export async function cleanupDeletedSongs(): Promise<number> {
|
|
// Clean up songs without audio that are older than 7 days (SQLite syntax)
|
|
const result = await pool.query(
|
|
`DELETE FROM songs
|
|
WHERE audio_url IS NULL
|
|
AND created_at < datetime('now', '-7 days')
|
|
RETURNING id`
|
|
);
|
|
|
|
const count = result.rowCount || 0;
|
|
if (count > 0) {
|
|
console.log(`Cleaned up ${count} orphaned songs`);
|
|
}
|
|
return count;
|
|
}
|