what am I doing

This commit is contained in:
Skye 2023-03-09 20:30:18 +09:00
parent 8e8e82350d
commit dd7bc37c8b
Signed by: me
GPG key ID: 0104BC05F41B77B8
5 changed files with 35 additions and 32 deletions

View file

@ -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({

10
src/lib/rpc-types.ts Normal file
View file

@ -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,
})

View file

@ -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()
});

View file

@ -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'
}
]

View file

@ -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"