mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-24 05:39:35 +02:00
Trim icon name. Filter private bookmarks if user is not authenticated
This commit is contained in:
parent
d94a6cea5a
commit
6281994be8
5 changed files with 26 additions and 4 deletions
|
@ -11,6 +11,7 @@ const getAllCategories = asyncWrapper(async (req, res, next) => {
|
|||
const { useOrdering: orderType } = await loadConfig();
|
||||
|
||||
let categories;
|
||||
let output;
|
||||
|
||||
// categories visibility
|
||||
const where = req.isAuthenticated ? {} : { isPublic: true };
|
||||
|
@ -21,7 +22,6 @@ const getAllCategories = asyncWrapper(async (req, res, next) => {
|
|||
{
|
||||
model: Bookmark,
|
||||
as: 'bookmarks',
|
||||
where,
|
||||
},
|
||||
],
|
||||
order: [[Sequelize.fn('lower', Sequelize.col('Category.name')), 'ASC']],
|
||||
|
@ -33,7 +33,6 @@ const getAllCategories = asyncWrapper(async (req, res, next) => {
|
|||
{
|
||||
model: Bookmark,
|
||||
as: 'bookmarks',
|
||||
where,
|
||||
},
|
||||
],
|
||||
order: [[orderType, 'ASC']],
|
||||
|
@ -41,9 +40,20 @@ const getAllCategories = asyncWrapper(async (req, res, next) => {
|
|||
});
|
||||
}
|
||||
|
||||
if (req.isAuthenticated) {
|
||||
output = categories;
|
||||
} else {
|
||||
// filter out private bookmarks
|
||||
output = categories.map((c) => c.get({ plain: true }));
|
||||
output = output.map((c) => ({
|
||||
...c,
|
||||
bookmarks: c.bookmarks.filter((b) => b.isPublic),
|
||||
}));
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: categories,
|
||||
data: output,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue