mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-09 20:12:10 +10:00
* fix: release workflow * feat: move mostly to internal tasks system * feat: migrate object clean to new task system * fix: release not getting good base version * chore: set version v0.3.0 * chore: style * feat: basic task concurrency * feat: temp pages to fill in page links * feat: inital i18n support * feat: localize store page * chore: style * fix: weblate doesn't like multifile thing * fix: update nuxt * feat: improved error logging * fix: using old task api * feat: basic translation docs * feat: add i18n eslint plugin * feat: translate store and auth pages * feat: more translation progress * feat: admin dash i18n progress * feat: enable update check by default in prod * fix: using wrong i18n keys * fix: crash in library sources page * feat: finish i18n work * fix: missing i18n translations * feat: use twemoji for emojis * feat: sanatize object ids * fix: EmojiText's alt text * fix: UserWidget not using links * feat: cache and auth for emoji api * fix: add more missing translations
42 lines
949 B
TypeScript
42 lines
949 B
TypeScript
import { ArkErrors } from "arktype";
|
|
import { configure } from "arktype/config";
|
|
import type { H3Event } from "h3";
|
|
|
|
export const throwingArktype = configure({
|
|
onFail: (errors) => errors.throw(),
|
|
actual: () => "",
|
|
});
|
|
|
|
// be sure to specify both the runtime and static configs
|
|
|
|
declare global {
|
|
interface ArkEnv {
|
|
onFail: typeof throwingArktype.onFail;
|
|
}
|
|
}
|
|
|
|
export async function readDropValidatedBody<T>(
|
|
event: H3Event,
|
|
validate: (data: object) => T,
|
|
): Promise<T> {
|
|
const _body = await readBody(event);
|
|
try {
|
|
return validate(_body);
|
|
} catch (e) {
|
|
const t = await useTranslation(event);
|
|
|
|
if (e instanceof ArkErrors) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: t("errors.invalidBody", [e.summary]),
|
|
});
|
|
}
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: t("errors.invalidBody", [
|
|
e instanceof Error ? e.message : `${e}`,
|
|
]),
|
|
});
|
|
}
|
|
}
|