From 4e7196182c99692880886f1d4b78e7313a47c775 Mon Sep 17 00:00:00 2001 From: Max Nuding Date: Thu, 13 Apr 2023 16:18:30 +0200 Subject: [PATCH] Fixed posts not saving correctly after DB migration --- src/lib/mastodon/response.ts | 1 - src/lib/server/db.ts | 25 +++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/lib/mastodon/response.ts b/src/lib/mastodon/response.ts index 5f544c3..bee9da9 100644 --- a/src/lib/mastodon/response.ts +++ b/src/lib/mastodon/response.ts @@ -24,5 +24,4 @@ export interface Account { display_name: string; url: string; avatar: string; - avatar_static: string; } diff --git a/src/lib/server/db.ts b/src/lib/server/db.ts index 66d801d..7ec423b 100644 --- a/src/lib/server/db.ts +++ b/src/lib/server/db.ts @@ -201,24 +201,22 @@ export async function savePost(post: Post): Promise { const account = post.account; db.run( ` - INSERT INTO accounts (id, acct, username, display_name, url, avatar, avatar_static) - VALUES(?, ?, ?, ?, ?, ?, ?) - ON CONFLICT(id) + INSERT INTO accounts (id, acct, username, display_name, url, avatar) + VALUES(?, ?, ?, ?, ?, ?) + ON CONFLICT(url) DO UPDATE SET acct=excluded.acct, username=excluded.username, display_name=excluded.display_name, - url=excluded.url, - avatar=excluded.avatar, - avatar_static=excluded.avatar_static;`, + id=excluded.id, + avatar=excluded.avatar;`, [ account.id, account.acct, account.username, account.display_name, account.url, - account.avatar, - account.avatar_static + account.avatar ], (err) => { if (err !== null) { @@ -229,12 +227,12 @@ export async function savePost(post: Post): Promise { db.run( ` INSERT INTO posts (id, content, created_at, url, account_id) - VALUES (?, ?, ?, ?, ?) ON CONFLICT(id) DO UPDATE SET + VALUES (?, ?, ?, ?, ?) ON CONFLICT(url) DO UPDATE SET content=excluded.content, created_at=excluded.created_at, - url=excluded.url, + id=excluded.id, account_id=excluded.account_id;`, - [post.id, post.content, post.created_at, post.url, post.account.id], + [post.id, post.content, post.created_at, post.url, post.account.url], (postErr) => { if (postErr !== null) { console.error(`Could not insert post ${post.url}`, postErr); @@ -259,7 +257,7 @@ export async function savePost(post: Post): Promise { } db.run( 'INSERT INTO poststags (post_id, tag_url) VALUES (?, ?)', - [post.id, tag.url], + [post.url, tag.url], (posttagserr) => { if (posttagserr !== null) { console.error( @@ -369,8 +367,7 @@ export async function getPosts(since: string | null, before: string | null, limi username: row.username, display_name: row.display_name, url: row.account_url, - avatar: row.avatar, - avatar_static: '' + avatar: row.avatar } as Account } as Post; });