From dd7bc37c8b01a9eec9d8050dbedfd0a2b55d8c3f Mon Sep 17 00:00:00 2001 From: Skye Date: Thu, 9 Mar 2023 20:30:18 +0900 Subject: [PATCH] what am I doing --- src/lib/packwiz-types.ts | 36 ++++++++++--------------------- src/lib/rpc-types.ts | 10 +++++++++ src/lib/types-zod.ts | 6 ++++++ src/routes/create/+page.server.ts | 13 ++++++----- src/routes/create/+page.svelte | 2 ++ 5 files changed, 35 insertions(+), 32 deletions(-) create mode 100644 src/lib/rpc-types.ts diff --git a/src/lib/packwiz-types.ts b/src/lib/packwiz-types.ts index ae7f584..ee7a74b 100644 --- a/src/lib/packwiz-types.ts +++ b/src/lib/packwiz-types.ts @@ -1,5 +1,13 @@ import { z } from 'zod'; +export const versionsSchema = z.object({ + minecraft: z.string(), + fabric: z.string().optional(), + forge: z.string().optional(), + liteloader: z.string().optional(), + quilt: z.string().optional() +}); + export const packSchema = z.object({ index: z.object({ file: z.string(), @@ -8,13 +16,7 @@ export const packSchema = z.object({ }), name: z.string(), 'pack-format': z.string().default('packwiz:1.0.0'), - versions: z.object({ - minecraft: z.string(), - fabric: z.string().optional(), - forge: z.string().optional(), - liteloader: z.string().optional(), - quilt: z.string().optional() - }), + versions: versionsSchema, author: z.string().optional(), description: z.string().optional(), version: z.string().optional() @@ -26,28 +28,12 @@ export const indexSchema = z.object({ .object({ file: z.string(), hash: z.string().regex(/^[a-fA-F0-9]+$/), - alias: z.string(), - 'hash-format': z.enum(['sha256', 'sha512', 'sha1', 'md5', 'murmur2']), + alias: z.string().optional(), + 'hash-format': z.enum(['sha256', 'sha512', 'sha1', 'md5', 'murmur2']).optional(), metafile: z.boolean().default(false), preserve: z.boolean().default(false) }) .array(), - update: z - .object({ - curseforge: z - .object({ - 'file-id': z.number(), - 'project-id': z.number() - }) - .optional(), - modrinth: z - .object({ - 'mod-id': z.string(), - version: z.string() - }) - .optional() - }) - .default({}) }); // export const metafileSchema = z.object({ diff --git a/src/lib/rpc-types.ts b/src/lib/rpc-types.ts new file mode 100644 index 0000000..2872431 --- /dev/null +++ b/src/lib/rpc-types.ts @@ -0,0 +1,10 @@ +import { z } from 'zod'; +import { versionsSchema } from './packwiz-types'; +import { fileTreeSchema } from './types-zod'; + +export const createRequestSchema = z.object({ + name: z.string(), + description: z.string(), + versions: versionsSchema, + tree: fileTreeSchema, +}) \ No newline at end of file diff --git a/src/lib/types-zod.ts b/src/lib/types-zod.ts index c816bc3..2dda95d 100644 --- a/src/lib/types-zod.ts +++ b/src/lib/types-zod.ts @@ -1,4 +1,5 @@ import { z } from 'zod'; +import { versionsSchema } from './packwiz-types'; export const revisionTagSchema = z.object({ type: z.enum(['alpha', 'beta', 'rc', 'stable']), @@ -8,6 +9,7 @@ export const revisionTagSchema = z.object({ export const fileInlineSchema = z.object({ type: z.literal('file'), inline: z.literal(true), + ignored: z.boolean(), metafile: z.boolean(), content: z.string().max(256 * 1024), sha1: z.string().regex(/^[a-f0-9]{40}$/), @@ -17,6 +19,7 @@ export const fileInlineSchema = z.object({ export const fileBlobSchema = z.object({ type: z.literal('file'), inline: z.literal(false), + ignored: z.boolean(), sha1: z.string().regex(/^[a-f0-9]{40}$/), sha512: z.string().regex(/^[a-f0-9]{128}$/) }); @@ -57,6 +60,7 @@ export const revisionDiffSchema = z.object({ tag: revisionTagSchema.optional(), type: z.literal('diff'), tree: diffSchema.array(), + versions: versionsSchema.optional(), message: z.string() }); @@ -65,6 +69,7 @@ export const revisionBaseSchema = z.object({ tag: revisionTagSchema.optional(), type: z.literal('base'), tree: fileTreeSchema, + versions: versionsSchema.optional(), message: z.string() }); @@ -74,6 +79,7 @@ export const modpackSchema = z.object({ _id: z.string().regex(/^[A-Za-z0-9_-]{21}$/), type: z.literal('modpack'), name: z.string(), + description: z.string(), author: z.string().email(), revisions: revisionSchema.array() }); diff --git a/src/routes/create/+page.server.ts b/src/routes/create/+page.server.ts index 409d9f4..2e7ba7b 100644 --- a/src/routes/create/+page.server.ts +++ b/src/routes/create/+page.server.ts @@ -1,11 +1,11 @@ import type { Actions } from './$types'; import { COUCHDB_DB_NAME, S3_BUCKET_NAME } from '$env/static/private'; import { fail, redirect } from '@sveltejs/kit'; -import { fileTreeSchema } from '$lib/types-zod'; import { get_blobs } from '$lib/utils'; import type { Modpack } from '$lib/types'; import { nanoid } from 'nanoid'; import { minioClient, nano } from '$lib/server/clients'; +import { createRequestSchema } from '$lib/rpc-types'; export const actions: Actions = { default: async (event) => { @@ -13,14 +13,12 @@ export const actions: Actions = { if (!session?.user) throw redirect(303, '/auth/signin'); const data = await event.request.formData(); const payload = data.get('payload'); - const title = data.get('title'); if (typeof payload != 'string') throw fail(400); - if (typeof title != 'string') throw fail(400); - const payload_decoded = fileTreeSchema.safeParse(JSON.parse(payload)); + const payload_decoded = createRequestSchema.safeParse(JSON.parse(payload)); if (!payload_decoded.success) { throw fail(400); } - const blobs = get_blobs(payload_decoded.data); + const blobs = get_blobs(payload_decoded.data.tree); for (const blob of blobs) { const file = data.get(blob.sha512); if (typeof file != 'object' || !file) throw fail(400); @@ -47,13 +45,14 @@ export const actions: Actions = { const document: Modpack = { type: 'modpack', _id: nanoid(), - name: title, + name: payload_decoded.data.name, + description: payload_decoded.data.description, author: session.user.email ?? 'unknown@nodomain', revisions: [ { id: nanoid(), type: 'base', - tree: payload_decoded.data, + tree: payload_decoded.data.tree, message: 'initial revision' } ] diff --git a/src/routes/create/+page.svelte b/src/routes/create/+page.svelte index 6db1ab0..892d98d 100644 --- a/src/routes/create/+page.svelte +++ b/src/routes/create/+page.svelte @@ -32,6 +32,7 @@ type: 'file', inline: true, metafile: true, + ignored: false, content: `name = "Quark" filename = "Quark-3.4-389.jar" side = "both" @@ -54,6 +55,7 @@ project-id = 243121 type: 'file', inline: true, metafile: true, + ignored: false, content: `name = "Waystones" filename = "waystones-forge-1.19-11.1.0.jar" side = "both"