build view count
This commit is contained in:
@@ -70,6 +70,10 @@ if (!memesCols.find((c) => c.name === 'share_count')) {
|
||||
db.exec('ALTER TABLE memes ADD COLUMN share_count INTEGER NOT NULL DEFAULT 0');
|
||||
}
|
||||
|
||||
if (!memesCols.find((c) => c.name === 'view_count')) {
|
||||
db.exec('ALTER TABLE memes ADD COLUMN view_count INTEGER NOT NULL DEFAULT 0');
|
||||
}
|
||||
|
||||
// Indexes that depend on migrated columns — created after columns are guaranteed to exist
|
||||
db.exec(`
|
||||
CREATE INDEX IF NOT EXISTS idx_memes_collection_id ON memes(collection_id);
|
||||
|
||||
@@ -31,6 +31,9 @@ export async function shareRoutes(app: FastifyInstance) {
|
||||
return reply.status(404).send('Not found');
|
||||
}
|
||||
|
||||
// Count every visit to the share page as a link click
|
||||
db.prepare('UPDATE memes SET view_count = view_count + 1 WHERE id = ?').run(meme.id);
|
||||
|
||||
const base = getBaseUrl(req as any);
|
||||
const pageUrl = `${base}/m/${meme.id}`;
|
||||
const imageUrl = `${base}/images/${meme.file_path}`;
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface Meme {
|
||||
collection_id: number | null;
|
||||
ocr_text: string | null;
|
||||
share_count: number;
|
||||
view_count: number;
|
||||
created_at: string;
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user