uga aga
This commit is contained in:
@@ -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`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user