update: include old data in history table
This commit is contained in:
parent
54feba5deb
commit
92db443e6b
@ -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.",
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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");
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user