mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
682836237b
Replaces scattered console statements with a unified RMABLogger across backend API routes and services. Adds LOG_LEVEL-based filtering, job-aware database persistence, and context-based logging. Updates documentation to describe the new logging system and usage patterns. Also documents qBittorrent CSRF header fix
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
/**
|
|
* Audiobookshelf Settings API
|
|
* Documentation: documentation/features/audiobookshelf-integration.md
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { requireAuth, requireAdmin, AuthenticatedRequest } from '@/lib/middleware/auth';
|
|
import { ConfigUpdate } from '@/lib/services/config.service';
|
|
import { RMABLogger } from '@/lib/utils/logger';
|
|
|
|
const logger = RMABLogger.create('API.Admin.Settings.Audiobookshelf');
|
|
|
|
export async function PUT(request: NextRequest) {
|
|
return requireAuth(request, async (req: AuthenticatedRequest) => {
|
|
return requireAdmin(req, async () => {
|
|
try {
|
|
const body = await request.json();
|
|
const { serverUrl, apiToken, libraryId, triggerScanAfterImport } = body;
|
|
|
|
const { getConfigService } = await import('@/lib/services/config.service');
|
|
const configService = getConfigService();
|
|
|
|
// Build updates array, skipping masked values
|
|
const updates: ConfigUpdate[] = [
|
|
{ key: 'audiobookshelf.server_url', value: serverUrl || '' },
|
|
{ key: 'audiobookshelf.library_id', value: libraryId || '' },
|
|
{ key: 'audiobookshelf.trigger_scan_after_import', value: triggerScanAfterImport === true ? 'true' : 'false' },
|
|
];
|
|
|
|
// Only update API token if it's not the masked placeholder
|
|
if (apiToken && !apiToken.startsWith('••••')) {
|
|
updates.push({
|
|
key: 'audiobookshelf.api_token',
|
|
value: apiToken,
|
|
encrypted: true,
|
|
});
|
|
}
|
|
|
|
// Update configuration
|
|
await configService.setMany(updates);
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: 'Audiobookshelf settings saved successfully'
|
|
});
|
|
} catch (error) {
|
|
logger.error('Failed to save Audiobookshelf settings', { error: error instanceof Error ? error.message : String(error) });
|
|
return NextResponse.json(
|
|
{ error: 'Failed to save settings' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
});
|
|
});
|
|
}
|