This commit is contained in:
2026-08-11 23:54:21 +02:00
parent ebd7855f15
commit 3f7958f869

View File

@@ -380,14 +380,11 @@ export const handleUpload = async (req, res, self) => {
for (const tagName of tags) { for (const tagName of tags) {
let tagRow = await db`select id from tags where normalized = slugify(${tagName}) limit 1`; let tagRow = await db`select id from tags where normalized = slugify(${tagName}) limit 1`;
let tagId; if (tagRow.length === 0) {
if (tagRow.length > 0) { await db`insert into tags ${db({ tag: tagName }, 'tag')}`;
tagId = tagRow[0].id; tagRow = await db`select id from tags where normalized = slugify(${tagName}) limit 1`;
} else {
const newTag = await db`insert into tags ${db({ name: tagName, normalized: tagName })} returning id`;
tagId = newTag[0].id;
} }
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) { if (comment && comment.length > 0) {
@@ -401,8 +398,11 @@ export const handleUpload = async (req, res, self) => {
const ocTags = ['oc', 'original content']; const ocTags = ['oc', 'original content'];
for (const ocName of ocTags) { for (const ocName of ocTags) {
let tagRow = await db`select id from tags where normalized = slugify(${ocName}) limit 1`; 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; if (tagRow.length === 0) {
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 ${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`;
} }
} }