show number of tag usage

This commit is contained in:
Zutatensuppe 2021-06-03 23:46:09 +02:00
parent 38dc23d57b
commit 22585b92fe
8 changed files with 47 additions and 7 deletions

View file

@ -72,15 +72,29 @@ async function getExifOrientation(imagePath: string): Promise<number> {
})
}
const getAllTags = (db: Db): Tag[] => {
const query = `
select c.id, c.slug, c.title, count(*) as total from categories c
inner join image_x_category ixc on c.id = ixc.category_id
group by c.id order by total desc;`
return db._getMany(query).map(row => ({
id: parseInt(row.id, 10) || 0,
slug: row.slug,
title: row.title,
total: parseInt(row.total, 10) || 0,
}))
}
const getTags = (db: Db, imageId: number): Tag[] => {
const query = `
select * from categories c
inner join image_x_category ixc on c.id = ixc.category_id
where ixc.image_id = ?`
return db._getMany(query, [imageId]).map(row => ({
id: parseInt(row.number, 10) || 0,
id: parseInt(row.id, 10) || 0,
slug: row.slug,
title: row.title,
total: 0,
}))
}
@ -207,6 +221,7 @@ export default {
allImagesFromDisk,
imageFromDb,
allImagesFromDb,
getAllTags,
resizeImage,
getDimensions,
}

View file

@ -101,7 +101,7 @@ app.get('/api/newgame-data', (req, res): void => {
const tagSlugs: string[] = q.tags ? q.tags.split(',') : []
res.send({
images: Images.allImagesFromDb(db, tagSlugs, q.sort),
tags: db.getMany('categories', {}, [{ title: 1 }]),
tags: Images.getAllTags(db),
})
})