1
0

update: include old data in history table

This commit is contained in:
alikia2x (寒寒) 2025-11-23 13:12:54 +08:00
parent 54feba5deb
commit 92db443e6b
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 56209E0CCD8420C6
3 changed files with 25 additions and 21 deletions

View File

@ -134,7 +134,10 @@ const songInfoUpdateHandler = new Elysia({ prefix: "/song" }).use(requireAuth).p
objectId: songID,
changeType: "update-song",
changedBy: user!.unqId,
data: updatedData.length > 0 ? updatedData[0] : null
data: updatedData.length > 0 ? {
old: info,
new: updatedData[0]
} : null
});
return {
message: "Successfully updated song info.",

View File

@ -34,23 +34,24 @@ export async function insertIntoSongs(aid: number) {
.returning();
return data;
}
const data = await db
.insert(songs)
.values({
aid,
publishedAt: drizzleSQL`SELECT published_at FROM bilibili_metadata WHERE aid = ${aid}`,
duration: drizzleSQL`SELECT duration FROM bilibili_metadata WHERE aid = ${aid}`,
image: drizzleSQL`SELECT cover_url FROM bilibili_metadata WHERE aid = ${aid}`,
producer: drizzleSQL`
SELECT username
FROM bilibili_user bu
JOIN bilibili_metadata bm
ON bm.uid = bu.uid
WHERE bm.aid = ${aid}
`
})
.onConflictDoNothing()
.returning();
const data = await sql`
INSERT INTO songs (aid, published_at, duration, image, producer)
VALUES (
$1,
(SELECT published_at FROM bilibili_metadata WHERE aid = ${aid}),
(SELECT duration FROM bilibili_metadata WHERE aid = ${aid}),
(SELECT cover_url FROM bilibili_metadata WHERE aid = ${aid}),
(
SELECT username
FROM bilibili_user bu
JOIN bilibili_metadata bm
ON bm.uid = bu.uid
WHERE bm.aid = ${aid}
)
)
ON CONFLICT DO NOTHING
RETURNING *
`
return data;
}

View File

@ -21,8 +21,8 @@ const app = express();
app.use("/", serverAdapter.getRouter());
app.listen(5000, () => {
console.log("Running on 5000...");
console.log("For the UI, open http://localhost:5000/");
app.listen(5086, () => {
console.log("Running on 5086...");
console.log("For the UI, open http://localhost:5086/");
console.log("Make sure Redis is running on port 6379 by default");
});