You've already forked obsidian-visualiser
Add page and user monitoring in admin. Add permission editing in administration.
This commit is contained in:
@@ -1,3 +1,50 @@
|
||||
export default defineEventHandler((e) => {
|
||||
return [];
|
||||
import { ne, sql } from 'drizzle-orm';
|
||||
import useDatabase from '~/composables/useDatabase';
|
||||
import { explorerContentTable } from '~/db/schema';
|
||||
import { hasPermissions } from '~/shared/auth.util';
|
||||
|
||||
export default defineEventHandler(async (e) => {
|
||||
const session = await getUserSession(e);
|
||||
|
||||
if(!session || !session.user || !hasPermissions(session.user.permissions, ['admin']))
|
||||
{
|
||||
throw createError({
|
||||
statusCode: 401,
|
||||
message: 'Unauthorized',
|
||||
});
|
||||
}
|
||||
|
||||
const db = useDatabase();
|
||||
const content = db.select({
|
||||
path: explorerContentTable.path,
|
||||
owner: explorerContentTable.owner,
|
||||
title: explorerContentTable.title,
|
||||
type: explorerContentTable.type,
|
||||
size: sql<number>`CASE WHEN ${explorerContentTable.content} IS NULL THEN 0 ELSE length(${explorerContentTable.content}) END`.as('size'),
|
||||
navigable: explorerContentTable.navigable,
|
||||
private: explorerContentTable.private,
|
||||
order: explorerContentTable.order,
|
||||
visit: explorerContentTable.visit,
|
||||
timestamp: explorerContentTable.timestamp,
|
||||
}).from(explorerContentTable).all();
|
||||
|
||||
content.sort((a, b) => {
|
||||
return a.path.split('/').length - b.path.split('/').length;
|
||||
});
|
||||
|
||||
for(let i = 0; i < content.length; i++)
|
||||
{
|
||||
const path = content[i].path.substring(0, content[i].path.lastIndexOf('/'));
|
||||
if(path !== '')
|
||||
{
|
||||
const parent = content.find(e => e.path === path);
|
||||
|
||||
if(parent)
|
||||
{
|
||||
content[i].private = content[i].private || parent.private;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return content.filter(e => e.type !== 'folder');
|
||||
})
|
||||
Reference in New Issue
Block a user