Something went wrong. Try again.
Periodic backups of ATProto repos and blobs safekeeper.dummy.cafe
atproto backup
Something went wrong. Try again.
3.3 kB · 107 lines
TSX
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108import { Elysia, ValidationError } from 'elysia';import { html, Html } from '@elysiajs/html';import { staticPlugin } from '@elysiajs/static';import { AlreadyExistsError, BadRequestError, CouldNotResolveDidError, KnownInternalServerError, NotAuthenticatedError, NotAuthorizedError, NotImplementedError, ResourceNotFoundError, UpstreamError} from './error';import { env } from './lib/env';import { startScheduler } from './lib/backup/scheduler';import RootLayout from './view/layout/root';import DashboardPage from './view/page/DashboardPage';import PdsPage from './view/page/PdsPage';import TrackedPage from './view/page/TrackedPage';import AccountsPage from './view/page/AccountsPage';import WipePage from './view/page/WipePage';import AuthController from './controller/AuthController';import BackupController from './controller/BackupController';import { isAuthed } from './plugin/auth';
const app = new Elysia() .use(html()) .use(staticPlugin({ assets: 'public', prefix: '/' })) .error({ [new NotImplementedError().message]: NotImplementedError, [new NotAuthenticatedError().message]: NotAuthenticatedError, [new NotAuthorizedError().message]: NotAuthorizedError, [new BadRequestError('EXAMPLE').message]: BadRequestError, [new ResourceNotFoundError().message]: ResourceNotFoundError, [new AlreadyExistsError('EXAMPLE').message]: AlreadyExistsError, [new KnownInternalServerError({}).message]: KnownInternalServerError, [new CouldNotResolveDidError().message]: CouldNotResolveDidError, [new UpstreamError('EXAMPLE').message]: UpstreamError }) .onError(({ code, error, path, request }) => { if ( typeof code !== 'number' && [ 'NOT_IMPLEMENTED', 'NOT_AUTHENTICATED', 'NOT_AUTHORIZED', 'BAD_REQUEST', 'RESOURCE_NOT_FOUND', 'ALREADY_EXISTS', 'NOT_FOUND', 'COULD_NOT_RESOLVE_DID', 'UPSTREAM_ERROR' ].includes(code) ) console.debug(error); else if (code === 'KNOWN_INTERNAL_SERVER_ERROR') console.error(error, JSON.stringify((error as KnownInternalServerError).internal)); else console.error(error);
if (path.startsWith('/api')) { switch (code) { case 'ALREADY_EXISTS': case 'BAD_REQUEST': case 'UPSTREAM_ERROR': return { code, details: (error as BadRequestError | UpstreamError).details }; case 'VALIDATION': return { code, details: JSON.parse((error as ValidationError).message) }; default: return { code: typeof code === 'string' ? code : code.toString() }; } }
return ( <RootLayout authed={isAuthed(request)}> <h1 class="text-2xl font-semibold">an error occurred</h1> <p>looks like there was a problem loading this page.</p> <pre safe class="text-sm font-mono p-4 border border-neutral-200 bg-white rounded-md whitespace-pre-wrap" > {String(code)} {'\n'} {(error as Error).message ?? ''} </pre> </RootLayout> ); }) .use(DashboardPage) .use(PdsPage) .use(TrackedPage) .use(AccountsPage) .use(WipePage) .use(AuthController) .use(BackupController) .listen(env.PORT);
// Start the periodic backup scheduler. This kicks off a backup on boot and// then re-triggers on BACKUP_INTERVAL_MS.startScheduler();
console.log( `safekeeper listening on http://${app.server?.hostname}:${app.server?.port}`);