Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

39 righe
1.3 KiB

  1. import { NextResponse } from 'next/server';
  2. import { stat } from 'node:fs/promises';
  3. import path from 'node:path';
  4. import { checkSystemBin } from '@/lib/system-bins';
  5. import { restoreFromZipFile } from '@/lib/restore-zip';
  6. export const dynamic = 'force-dynamic';
  7. export const maxDuration = 600;
  8. const PRESET_PATH = path.join(process.cwd(), 'factory', 'preset.zip');
  9. export async function POST() {
  10. if (!(await checkSystemBin('unzip', '-v'))) {
  11. return NextResponse.json(
  12. { error: "Cannot perform Factory Reset: the 'unzip' command is not installed on the server. Ask the administrator to install it." },
  13. { status: 503 },
  14. );
  15. }
  16. try {
  17. await stat(PRESET_PATH);
  18. } catch {
  19. return NextResponse.json(
  20. { error: 'No factory preset is configured on this server: factory/preset.zip is missing. Ask a developer to create a preset first (either via "Save as Factory Preset" in admin or by uploading factory/preset.zip manually).' },
  21. { status: 404 },
  22. );
  23. }
  24. const result = await restoreFromZipFile(PRESET_PATH);
  25. if (!result.ok) {
  26. return NextResponse.json({ error: result.error, detail: result.detail }, { status: result.status });
  27. }
  28. return NextResponse.json({
  29. ok: true,
  30. restored: { cards: result.cards, portals: result.portals },
  31. previousDataBackup: result.previousBackup,
  32. });
  33. }