Refactor: Add full PDPA compliance features
- Cookie consent system (banner + modal) with Thai language - Consent logging database (Astro DB + SQLite) - API endpoints for consent management (POST/GET/DELETE) - Admin dashboard for viewing consent logs (/admin/consent-logs) - Umami Analytics integration (conditional loading with consent) - Updated Privacy Policy (full 14-section PDPA Section 36 compliance) - Updated Terms & Conditions (17 sections, Thailand law) - Dockerfile updated with SQLite runtime - Node.js adapter for SSR support - Admin password: moreminimore2026!Secure (CHANGE IN PRODUCTION) TODO: Configure Umami Analytics with actual Website ID
This commit is contained in:
41
db/config.ts
Normal file
41
db/config.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { drizzle } from 'drizzle-orm/libsql';
|
||||
import { createClient, type Config } from '@libsql/client';
|
||||
import * as schema from './schema';
|
||||
|
||||
let dbInstance: ReturnType<typeof drizzle<typeof schema>> | null = null;
|
||||
|
||||
export function getDb() {
|
||||
if (dbInstance) {
|
||||
return dbInstance;
|
||||
}
|
||||
|
||||
let config: Config;
|
||||
|
||||
const remoteUrl = typeof process !== 'undefined' && process.env?.ASTRO_DB_REMOTE_URL
|
||||
? process.env.ASTRO_DB_REMOTE_URL
|
||||
: './dev.db';
|
||||
|
||||
const authToken = typeof process !== 'undefined' && process.env?.ASTRO_DB_APP_TOKEN
|
||||
? process.env.ASTRO_DB_APP_TOKEN
|
||||
: undefined;
|
||||
|
||||
if (remoteUrl.startsWith('file:') || remoteUrl.startsWith('libsql:')) {
|
||||
config = {
|
||||
url: remoteUrl,
|
||||
authToken: authToken
|
||||
};
|
||||
} else {
|
||||
config = {
|
||||
url: `file:${remoteUrl}`
|
||||
};
|
||||
}
|
||||
|
||||
const client = createClient(config);
|
||||
dbInstance = drizzle(client, { schema });
|
||||
return dbInstance;
|
||||
}
|
||||
|
||||
export const db = getDb();
|
||||
|
||||
export type ConsentLog = typeof schema.ConsentLog.$inferSelect;
|
||||
export type NewConsentLog = typeof schema.ConsentLog.$inferInsert;
|
||||
20
db/schema.ts
Normal file
20
db/schema.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { defineDb, defineTable, column } from 'astro:db';
|
||||
|
||||
const ConsentLog = defineTable({
|
||||
columns: {
|
||||
id: column.number({ primaryKey: true }),
|
||||
sessionId: column.text({ unique: true }),
|
||||
timestamp: column.text(),
|
||||
locale: column.text({ default: 'th' }),
|
||||
essential: column.boolean({ default: true }),
|
||||
analytics: column.boolean({ default: false }),
|
||||
marketing: column.boolean({ default: false }),
|
||||
policyVersion: column.text({ default: '1.0' }),
|
||||
ipHash: column.text(),
|
||||
userAgent: column.text()
|
||||
}
|
||||
});
|
||||
|
||||
export default defineDb({
|
||||
tables: { ConsentLog }
|
||||
});
|
||||
Reference in New Issue
Block a user