mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
edc56bc457
Introduce manual import workflow and download permission support. Adds a Prisma migration and schema field (users.download_access) to track per-user download access, and updates admin UI to toggle global and per-user download access. Implements new APIs: filesystem browse, manual-import endpoint, download-access settings, audiobook download-status, and on-demand download-token generation. Adds frontend components for manual import and related tests, plus documentation for the manual-import feature and the documentation-agent prompt. Key files: prisma/migrations/20260212000000_add_download_access_permission/migration.sql, prisma/schema.prisma, src/app/api/admin/filesystem/browse/route.ts, src/app/api/admin/manual-import/route.ts, src/app/api/admin/settings/download-access/route.ts, src/app/api/requests/[id]/download-token/route.ts, src/app/api/audiobooks/[asin]/download-status/route.ts, and updated admin users pages/components and permissions util.
94 lines
2.5 KiB
TypeScript
94 lines
2.5 KiB
TypeScript
/**
|
|
* Component: Current User Route
|
|
* Documentation: documentation/backend/services/auth.md
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { requireAuth, AuthenticatedRequest } from '@/lib/middleware/auth';
|
|
import { prisma } from '@/lib/db';
|
|
import { resolvePermission, getGlobalBooleanSetting } from '@/lib/utils/permissions';
|
|
|
|
/**
|
|
* GET /api/auth/me
|
|
* Get current authenticated user information
|
|
*/
|
|
export async function GET(request: NextRequest) {
|
|
return requireAuth(request, async (req: AuthenticatedRequest) => {
|
|
if (!req.user) {
|
|
return NextResponse.json(
|
|
{
|
|
error: 'Unauthorized',
|
|
message: 'User not authenticated',
|
|
},
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
// Fetch full user details from database
|
|
const user = await prisma.user.findUnique({
|
|
where: { id: req.user.id },
|
|
select: {
|
|
id: true,
|
|
plexId: true,
|
|
plexUsername: true,
|
|
plexEmail: true,
|
|
role: true,
|
|
isSetupAdmin: true,
|
|
avatarUrl: true,
|
|
authProvider: true,
|
|
createdAt: true,
|
|
lastLoginAt: true,
|
|
interactiveSearchAccess: true,
|
|
downloadAccess: true,
|
|
},
|
|
});
|
|
|
|
if (!user) {
|
|
return NextResponse.json(
|
|
{
|
|
error: 'NotFound',
|
|
message: 'User not found',
|
|
},
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
// Determine if user is local admin (setup admin with local authentication)
|
|
const isLocalAdmin = user.isSetupAdmin && user.plexId.startsWith('local-');
|
|
|
|
// Resolve effective permissions
|
|
const globalInteractiveSearch = await getGlobalBooleanSetting('interactive_search_access', true);
|
|
const effectiveInteractiveSearch = resolvePermission(
|
|
user.role,
|
|
user.interactiveSearchAccess,
|
|
globalInteractiveSearch
|
|
);
|
|
|
|
const globalDownload = await getGlobalBooleanSetting('download_access', true);
|
|
const effectiveDownload = resolvePermission(
|
|
user.role,
|
|
user.downloadAccess,
|
|
globalDownload
|
|
);
|
|
|
|
return NextResponse.json({
|
|
user: {
|
|
id: user.id,
|
|
plexId: user.plexId,
|
|
username: user.plexUsername,
|
|
email: user.plexEmail,
|
|
role: user.role,
|
|
isLocalAdmin: isLocalAdmin,
|
|
avatarUrl: user.avatarUrl,
|
|
authProvider: user.authProvider,
|
|
createdAt: user.createdAt,
|
|
lastLoginAt: user.lastLoginAt,
|
|
permissions: {
|
|
interactiveSearch: effectiveInteractiveSearch,
|
|
download: effectiveDownload,
|
|
},
|
|
},
|
|
});
|
|
});
|
|
}
|