swadhinbiswas Fix: Add date validation in analysis.ts to prevent RangeError · 1/20/2026
a7662cd
31 lines · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { createStorageAdapter } from "@/lib/storage";
import type { APIRoute } from "astro";
import { withErrorHandler } from "@/lib/errors";
import { logger } from "@/lib/logger";
import { badRequest, forbidden, success } from "@/lib/api";

export const POST: APIRoute = withErrorHandler(async ({ request, locals }) => {
    const user = locals.user;
    if (!user?.isAdmin) {
        return forbidden();
    }

    let config;
    try {
        config = await request.json();
    } catch (e) {
        return badRequest("Invalid JSON");
    }

    if (!config.type) return badRequest("Type required");

    const adapter = createStorageAdapter(config);
    const testKey = `test-connection-${Date.now()}.txt`;
    await adapter.put(testKey, Buffer.from("test connection"));
    await adapter.delete(testKey);

    logger.info({ adminId: user.id, storageType: config.type }, "Storage connection test successful");

    return success({ success: true });
});