From 3f7958f869824306552dedf5999af922b8e7703b Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Tue, 11 Aug 2026 23:54:21 +0200 Subject: [PATCH] uga aga --- src/upload_handler.mjs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/upload_handler.mjs b/src/upload_handler.mjs index e2be31b..8dc9a74 100644 --- a/src/upload_handler.mjs +++ b/src/upload_handler.mjs @@ -380,14 +380,11 @@ export const handleUpload = async (req, res, self) => { for (const tagName of tags) { let tagRow = await db`select id from tags where normalized = slugify(${tagName}) limit 1`; - let tagId; - if (tagRow.length > 0) { - tagId = tagRow[0].id; - } else { - const newTag = await db`insert into tags ${db({ name: tagName, normalized: tagName })} returning id`; - tagId = newTag[0].id; + if (tagRow.length === 0) { + await db`insert into tags ${db({ tag: tagName }, 'tag')}`; + tagRow = await db`select id from tags where normalized = slugify(${tagName}) limit 1`; } - await db`insert into tags_assign ${db({ item_id: itemid, tag_id: tagId, user_id: req.session.id })} on conflict do nothing`; + await db`insert into tags_assign ${db({ item_id: itemid, tag_id: tagRow[0].id, user_id: req.session.id })} on conflict do nothing`; } if (comment && comment.length > 0) { @@ -401,8 +398,11 @@ export const handleUpload = async (req, res, self) => { const ocTags = ['oc', 'original content']; for (const ocName of ocTags) { let tagRow = await db`select id from tags where normalized = slugify(${ocName}) limit 1`; - let tagId = tagRow.length > 0 ? tagRow[0].id : (await db`insert into tags ${db({ name: ocName, normalized: ocName })} returning id`)[0].id; - await db`insert into tags_assign ${db({ item_id: itemid, tag_id: tagId, user_id: req.session.id })} on conflict do nothing`; + if (tagRow.length === 0) { + await db`insert into tags ${db({ tag: ocName }, 'tag')}`; + tagRow = await db`select id from tags where normalized = slugify(${ocName}) limit 1`; + } + await db`insert into tags_assign ${db({ item_id: itemid, tag_id: tagRow[0].id, user_id: req.session.id })} on conflict do nothing`; } }