From cc6dc8c68b6435269bb64f7a78840db7d060a25f Mon Sep 17 00:00:00 2001 From: keyan Date: Mon, 19 Jun 2023 14:40:24 -0500 Subject: [PATCH] add daily discussion thread permalink --- next.config.js | 4 ++++ pages/api/daily.js | 17 +++++++++++++++++ .../20230619193610_daily_squatter/migration.sql | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 pages/api/daily.js create mode 100644 prisma/migrations/20230619193610_daily_squatter/migration.sql diff --git a/next.config.js b/next.config.js index 3f582c8e..3e9207b4 100644 --- a/next.config.js +++ b/next.config.js @@ -107,6 +107,10 @@ module.exports = withPWA({ source: '/guide', destination: '/items/81862' }, + { + source: '/daily', + destination: '/api/daily' + }, { source: '/.well-known/lnurlp/:username', destination: '/api/lnurlp/:username' diff --git a/pages/api/daily.js b/pages/api/daily.js new file mode 100644 index 00000000..0d3936cb --- /dev/null +++ b/pages/api/daily.js @@ -0,0 +1,17 @@ +import models from '../../api/models' + +export default async (_, res) => { + // get the latest daily discussion thread + // this should probably be made more generic + // eg if the title changes this will break + // ... but this will need to change when we have more subs anyway + const [{ id }] = await models.$queryRaw(` + SELECT id + FROM "Item" + WHERE "pinId" IS NOT NULL + AND title = 'Daily discussion thread' + ORDER BY created_at DESC + LIMIT 1`) + + res.redirect(`/items/${id}`) +} diff --git a/prisma/migrations/20230619193610_daily_squatter/migration.sql b/prisma/migrations/20230619193610_daily_squatter/migration.sql new file mode 100644 index 00000000..8f1be567 --- /dev/null +++ b/prisma/migrations/20230619193610_daily_squatter/migration.sql @@ -0,0 +1,2 @@ +UPDATE users SET name = 'daily_squatter' WHERE name = 'daily'; +INSERT INTO "users" ("name") VALUES ('daily'); \ No newline at end of file