touchups after refactor

This commit is contained in:
Christian Beutel
2025-01-03 00:13:59 +01:00
parent 871481a84e
commit 0d2e71c2f6
32 changed files with 1157 additions and 45 deletions

View File

@@ -1,4 +1,5 @@
import { pb } from "$lib/pocketbase";
import { handleError } from "$lib/util/api_util";
import { error, json, type RequestEvent } from "@sveltejs/kit";
import { z } from "zod";
@@ -13,7 +14,7 @@ export async function POST(event: RequestEvent) {
const r = await pb.collection('users').confirmPasswordReset(safeData.token, safeData.password, safeData.passwordConfirm);
return json(r);
} catch (e: any) {
throw error(e.status, e);
throw handleError(e);
}
}

View File

@@ -1,4 +1,5 @@
import { pb } from "$lib/pocketbase";
import { handleError } from "$lib/util/api_util";
import { error, json, type RequestEvent } from "@sveltejs/kit";
import { z } from "zod";
@@ -15,7 +16,7 @@ export async function POST(event: RequestEvent) {
const r = await pb.collection('users').authWithPassword(safeData.email ?? safeData.username!, data.password);
return json(r);
} catch (e: any) {
throw error(e.status, e);
throw handleError(e);
}
}

View File

@@ -4,6 +4,7 @@ import { env as private_env } from "$env/dynamic/private";
import { pb } from "$lib/pocketbase";
import { error, json, type RequestEvent } from "@sveltejs/kit";
import { z } from "zod";
import { handleError } from "$lib/util/api_util";
const redirectURL = private_env.ORIGIN + "/login/redirect"
@@ -18,7 +19,7 @@ export async function GET(event: RequestEvent) {
}
return json(r)
} catch (e: any) {
throw error(e.status, e);
throw handleError(e);
}
}
@@ -40,7 +41,7 @@ export async function POST(event: RequestEvent) {
)
return json(r)
} catch (e: any) {
throw error(e.status, e);
throw handleError(e);
}
}

View File

@@ -5,13 +5,13 @@ import { z } from "zod";
export async function GET(event: RequestEvent) {
const safeParams = z.object({
collection: z.string().length(15),
collection: z.string(),
record: z.string().length(15),
file: z.string()
}).safeParse(event.params)
if (!safeParams.success) {
throw error(400, 'Invalid params')
throw error(400, safeParams.error)
}
const parts = [];

View File

@@ -1,7 +1,7 @@
import type { Notification } from '$lib/models/notification';
import type { UserAnonymous } from '$lib/models/user';
import { pb } from '$lib/pocketbase';
import { Collection, list } from '$lib/util/api_util';
import { Collection, handleError, list } from '$lib/util/api_util';
import { error, json, type RequestEvent } from '@sveltejs/kit';
export async function GET(event: RequestEvent) {
@@ -17,6 +17,6 @@ export async function GET(event: RequestEvent) {
}
return json(r)
} catch (e: any) {
throw error(e.status, e);
throw handleError(e);
}
}