fix: Admin consent logs - implement Export CSV, fix delete, switch to better-sqlite3
- Replace Astro DB with better-sqlite3 for reliable SQLite access - Implement Export CSV feature in admin panel - Fix delete consent function (make it global) - Add better-sqlite3 dependency
This commit is contained in:
39
src/pages/api/consent/[sessionId].ts
Normal file
39
src/pages/api/consent/[sessionId].ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import Database from 'better-sqlite3';
|
||||
import { join } from 'path';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
const DB_PATH = join(process.cwd(), 'data', 'consent.db');
|
||||
|
||||
function getDb() {
|
||||
return new Database(DB_PATH);
|
||||
}
|
||||
|
||||
export const DELETE: APIRoute = async ({ params }) => {
|
||||
try {
|
||||
const sessionId = params.sessionId;
|
||||
if (!sessionId) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Missing sessionId' }),
|
||||
{ status: 400, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
const db = getDb();
|
||||
const stmt = db.prepare('DELETE FROM ConsentLog WHERE sessionId = ?');
|
||||
stmt.run(sessionId);
|
||||
db.close();
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({ success: true, message: 'Consent deleted' }),
|
||||
{ status: 200, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error deleting consent:', error);
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Failed to delete consent' }),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user