umstellung auf claud
This commit is contained in:
1 parent
79c5f0c5cd
commit
5bb4e063da
171 files changed
+5471
-1333
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { BACKEND_URL } from '@/_config/backend';
|
||||
|
||||
type BackupFileRouteContext = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
const UNSAFE_FILENAME_CHARACTERS = /[^A-Za-z0-9_.-]/g;
|
||||
|
||||
// Nur der letzte Pfadteil wird als Download-Name verwendet,
|
||||
// unsichere Zeichen werden ersetzt.
|
||||
function toDownloadFilename(file: string): string {
|
||||
const lastPathPart = file.split('/').pop();
|
||||
|
||||
return lastPathPart?.replace(UNSAFE_FILENAME_CHARACTERS, '_') ?? 'backup.json';
|
||||
}
|
||||
|
||||
export async function GET(request: Request, { params }: BackupFileRouteContext) {
|
||||
const { id } = await params;
|
||||
const file = new URL(request.url).searchParams.get('file') ?? 'manifest.json';
|
||||
|
||||
const backupFileUrl = `${BACKEND_URL}/rk2/backups/${encodeURIComponent(id)}/file`
|
||||
+ `?file=${encodeURIComponent(file)}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(backupFileUrl, { cache: 'no-store' });
|
||||
|
||||
if (!response.ok) {
|
||||
return new Response('Sicherungsdatei nicht verfügbar', { status: response.status });
|
||||
}
|
||||
|
||||
const filename = toDownloadFilename(file);
|
||||
|
||||
return new Response(response.body, {
|
||||
headers: {
|
||||
'Content-Type': response.headers.get('Content-Type') ?? 'application/json',
|
||||
'Content-Disposition': 'attachment; filename="' + filename + '"',
|
||||
'Cache-Control': 'no-store',
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
return new Response('Keine Verbindung zum Backend', { status: 502 });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user