mirror of
https://github.com/pawelmalak/flame.git
synced 2024-12-21 01:01:30 +03:00
Trim icon name. Filter private bookmarks if user is not authenticated
This commit is contained in:
parent
d94a6cea5a
commit
6281994be8
@ -9,7 +9,7 @@ const createApp = asyncWrapper(async (req, res, next) => {
|
||||
const { pinAppsByDefault } = await loadConfig();
|
||||
|
||||
let app;
|
||||
let _body = { ...req.body };
|
||||
let _body = { ...req.body, icon: req.body.icon.trim() };
|
||||
|
||||
if (req.file) {
|
||||
_body.icon = req.file.filename;
|
||||
|
@ -20,6 +20,10 @@ const updateApp = asyncWrapper(async (req, res, next) => {
|
||||
|
||||
let _body = { ...req.body };
|
||||
|
||||
if (_body.icon) {
|
||||
_body.icon = _body.icon.trim();
|
||||
}
|
||||
|
||||
if (req.file) {
|
||||
_body.icon = req.file.filename;
|
||||
}
|
||||
|
@ -12,6 +12,10 @@ const createBookmark = asyncWrapper(async (req, res, next) => {
|
||||
categoryId: parseInt(req.body.categoryId),
|
||||
};
|
||||
|
||||
if (_body.icon) {
|
||||
_body.icon = _body.icon.trim();
|
||||
}
|
||||
|
||||
if (req.file) {
|
||||
_body.icon = req.file.filename;
|
||||
}
|
||||
|
@ -24,6 +24,10 @@ const updateBookmark = asyncWrapper(async (req, res, next) => {
|
||||
categoryId: parseInt(req.body.categoryId),
|
||||
};
|
||||
|
||||
if (_body.icon) {
|
||||
_body.icon = _body.icon.trim();
|
||||
}
|
||||
|
||||
if (req.file) {
|
||||
_body.icon = req.file.filename;
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user