A data archive or restore ran inside its request, which sent nothing until tar finished: Bun closes a silent socket after 10s (its default idleTimeout in production) and a proxy cuts it at about 100s, so the page showed a network error while the archive kept going, and a retry said another backup was already running. The routes now start the run (startDataBackupRun, refused while the backup lock is held) and answer at once. The page follows it by polling api/admin/backups/data-status: an archive reloads once written, a restore once the status comes from a new process after its restart, and a failure shows its error. A run in progress survives a reload. Co-Authored-By: Claude Opus 5.5 <[email protected]>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import grabSuperAdminUser from "@/src/functions/backend/backups/grab-super-admin-user";
|
|
import grabDataBackups from "@/src/functions/backend/backups/grab-data-backups";
|
|
import { grabDataBackupRun } from "@/src/functions/backend/backups/data-backup-run";
|
|
import AppError from "@/src/utils/app-error";
|
|
import safeErrorMessage from "@/src/utils/safe-error-message";
|
|
import type { DataBackupStatus } from "@/src/types";
|
|
import type {
|
|
APIResponseObject,
|
|
BunextAPIRouteHandler,
|
|
} from "@moduletrace/bunext/types";
|
|
|
|
/**
|
|
* How the whole-data archive or restore this process started is going,
|
|
* with the archives as they stand, for the backups page to poll.
|
|
*/
|
|
export const handler: BunextAPIRouteHandler<
|
|
APIResponseObject<DataBackupStatus>
|
|
> = async ({ req }) => {
|
|
try {
|
|
if (req.method != "GET") {
|
|
throw new AppError(`Method not allowed`);
|
|
}
|
|
|
|
const user = await grabSuperAdminUser({ req });
|
|
|
|
if (!user?.id) {
|
|
return {
|
|
success: false,
|
|
msg: `Unauthorized`,
|
|
};
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
singleRes: {
|
|
run: grabDataBackupRun(),
|
|
data_backups: grabDataBackups(),
|
|
},
|
|
};
|
|
} catch (error: unknown) {
|
|
return { success: false, msg: safeErrorMessage({ error }) };
|
|
}
|
|
};
|