what am I doing
This commit is contained in:
parent
8e8e82350d
commit
dd7bc37c8b
5 changed files with 35 additions and 32 deletions
|
@ -1,5 +1,13 @@
|
||||||
import { z } from 'zod';
|
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({
|
export const packSchema = z.object({
|
||||||
index: z.object({
|
index: z.object({
|
||||||
file: z.string(),
|
file: z.string(),
|
||||||
|
@ -8,13 +16,7 @@ export const packSchema = z.object({
|
||||||
}),
|
}),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
'pack-format': z.string().default('packwiz:1.0.0'),
|
'pack-format': z.string().default('packwiz:1.0.0'),
|
||||||
versions: z.object({
|
versions: versionsSchema,
|
||||||
minecraft: z.string(),
|
|
||||||
fabric: z.string().optional(),
|
|
||||||
forge: z.string().optional(),
|
|
||||||
liteloader: z.string().optional(),
|
|
||||||
quilt: z.string().optional()
|
|
||||||
}),
|
|
||||||
author: z.string().optional(),
|
author: z.string().optional(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
version: z.string().optional()
|
version: z.string().optional()
|
||||||
|
@ -26,28 +28,12 @@ export const indexSchema = z.object({
|
||||||
.object({
|
.object({
|
||||||
file: z.string(),
|
file: z.string(),
|
||||||
hash: z.string().regex(/^[a-fA-F0-9]+$/),
|
hash: z.string().regex(/^[a-fA-F0-9]+$/),
|
||||||
alias: z.string(),
|
alias: z.string().optional(),
|
||||||
'hash-format': z.enum(['sha256', 'sha512', 'sha1', 'md5', 'murmur2']),
|
'hash-format': z.enum(['sha256', 'sha512', 'sha1', 'md5', 'murmur2']).optional(),
|
||||||
metafile: z.boolean().default(false),
|
metafile: z.boolean().default(false),
|
||||||
preserve: z.boolean().default(false)
|
preserve: z.boolean().default(false)
|
||||||
})
|
})
|
||||||
.array(),
|
.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({
|
// export const metafileSchema = z.object({
|
||||||
|
|
10
src/lib/rpc-types.ts
Normal file
10
src/lib/rpc-types.ts
Normal 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,
|
||||||
|
})
|
|
@ -1,4 +1,5 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { versionsSchema } from './packwiz-types';
|
||||||
|
|
||||||
export const revisionTagSchema = z.object({
|
export const revisionTagSchema = z.object({
|
||||||
type: z.enum(['alpha', 'beta', 'rc', 'stable']),
|
type: z.enum(['alpha', 'beta', 'rc', 'stable']),
|
||||||
|
@ -8,6 +9,7 @@ export const revisionTagSchema = z.object({
|
||||||
export const fileInlineSchema = z.object({
|
export const fileInlineSchema = z.object({
|
||||||
type: z.literal('file'),
|
type: z.literal('file'),
|
||||||
inline: z.literal(true),
|
inline: z.literal(true),
|
||||||
|
ignored: z.boolean(),
|
||||||
metafile: z.boolean(),
|
metafile: z.boolean(),
|
||||||
content: z.string().max(256 * 1024),
|
content: z.string().max(256 * 1024),
|
||||||
sha1: z.string().regex(/^[a-f0-9]{40}$/),
|
sha1: z.string().regex(/^[a-f0-9]{40}$/),
|
||||||
|
@ -17,6 +19,7 @@ export const fileInlineSchema = z.object({
|
||||||
export const fileBlobSchema = z.object({
|
export const fileBlobSchema = z.object({
|
||||||
type: z.literal('file'),
|
type: z.literal('file'),
|
||||||
inline: z.literal(false),
|
inline: z.literal(false),
|
||||||
|
ignored: z.boolean(),
|
||||||
sha1: z.string().regex(/^[a-f0-9]{40}$/),
|
sha1: z.string().regex(/^[a-f0-9]{40}$/),
|
||||||
sha512: z.string().regex(/^[a-f0-9]{128}$/)
|
sha512: z.string().regex(/^[a-f0-9]{128}$/)
|
||||||
});
|
});
|
||||||
|
@ -57,6 +60,7 @@ export const revisionDiffSchema = z.object({
|
||||||
tag: revisionTagSchema.optional(),
|
tag: revisionTagSchema.optional(),
|
||||||
type: z.literal('diff'),
|
type: z.literal('diff'),
|
||||||
tree: diffSchema.array(),
|
tree: diffSchema.array(),
|
||||||
|
versions: versionsSchema.optional(),
|
||||||
message: z.string()
|
message: z.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,6 +69,7 @@ export const revisionBaseSchema = z.object({
|
||||||
tag: revisionTagSchema.optional(),
|
tag: revisionTagSchema.optional(),
|
||||||
type: z.literal('base'),
|
type: z.literal('base'),
|
||||||
tree: fileTreeSchema,
|
tree: fileTreeSchema,
|
||||||
|
versions: versionsSchema.optional(),
|
||||||
message: z.string()
|
message: z.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -74,6 +79,7 @@ export const modpackSchema = z.object({
|
||||||
_id: z.string().regex(/^[A-Za-z0-9_-]{21}$/),
|
_id: z.string().regex(/^[A-Za-z0-9_-]{21}$/),
|
||||||
type: z.literal('modpack'),
|
type: z.literal('modpack'),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
|
description: z.string(),
|
||||||
author: z.string().email(),
|
author: z.string().email(),
|
||||||
revisions: revisionSchema.array()
|
revisions: revisionSchema.array()
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import type { Actions } from './$types';
|
import type { Actions } from './$types';
|
||||||
import { COUCHDB_DB_NAME, S3_BUCKET_NAME } from '$env/static/private';
|
import { COUCHDB_DB_NAME, S3_BUCKET_NAME } from '$env/static/private';
|
||||||
import { fail, redirect } from '@sveltejs/kit';
|
import { fail, redirect } from '@sveltejs/kit';
|
||||||
import { fileTreeSchema } from '$lib/types-zod';
|
|
||||||
import { get_blobs } from '$lib/utils';
|
import { get_blobs } from '$lib/utils';
|
||||||
import type { Modpack } from '$lib/types';
|
import type { Modpack } from '$lib/types';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import { minioClient, nano } from '$lib/server/clients';
|
import { minioClient, nano } from '$lib/server/clients';
|
||||||
|
import { createRequestSchema } from '$lib/rpc-types';
|
||||||
|
|
||||||
export const actions: Actions = {
|
export const actions: Actions = {
|
||||||
default: async (event) => {
|
default: async (event) => {
|
||||||
|
@ -13,14 +13,12 @@ export const actions: Actions = {
|
||||||
if (!session?.user) throw redirect(303, '/auth/signin');
|
if (!session?.user) throw redirect(303, '/auth/signin');
|
||||||
const data = await event.request.formData();
|
const data = await event.request.formData();
|
||||||
const payload = data.get('payload');
|
const payload = data.get('payload');
|
||||||
const title = data.get('title');
|
|
||||||
if (typeof payload != 'string') throw fail(400);
|
if (typeof payload != 'string') throw fail(400);
|
||||||
if (typeof title != 'string') throw fail(400);
|
const payload_decoded = createRequestSchema.safeParse(JSON.parse(payload));
|
||||||
const payload_decoded = fileTreeSchema.safeParse(JSON.parse(payload));
|
|
||||||
if (!payload_decoded.success) {
|
if (!payload_decoded.success) {
|
||||||
throw fail(400);
|
throw fail(400);
|
||||||
}
|
}
|
||||||
const blobs = get_blobs(payload_decoded.data);
|
const blobs = get_blobs(payload_decoded.data.tree);
|
||||||
for (const blob of blobs) {
|
for (const blob of blobs) {
|
||||||
const file = data.get(blob.sha512);
|
const file = data.get(blob.sha512);
|
||||||
if (typeof file != 'object' || !file) throw fail(400);
|
if (typeof file != 'object' || !file) throw fail(400);
|
||||||
|
@ -47,13 +45,14 @@ export const actions: Actions = {
|
||||||
const document: Modpack = {
|
const document: Modpack = {
|
||||||
type: 'modpack',
|
type: 'modpack',
|
||||||
_id: nanoid(),
|
_id: nanoid(),
|
||||||
name: title,
|
name: payload_decoded.data.name,
|
||||||
|
description: payload_decoded.data.description,
|
||||||
author: session.user.email ?? 'unknown@nodomain',
|
author: session.user.email ?? 'unknown@nodomain',
|
||||||
revisions: [
|
revisions: [
|
||||||
{
|
{
|
||||||
id: nanoid(),
|
id: nanoid(),
|
||||||
type: 'base',
|
type: 'base',
|
||||||
tree: payload_decoded.data,
|
tree: payload_decoded.data.tree,
|
||||||
message: 'initial revision'
|
message: 'initial revision'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
type: 'file',
|
type: 'file',
|
||||||
inline: true,
|
inline: true,
|
||||||
metafile: true,
|
metafile: true,
|
||||||
|
ignored: false,
|
||||||
content: `name = "Quark"
|
content: `name = "Quark"
|
||||||
filename = "Quark-3.4-389.jar"
|
filename = "Quark-3.4-389.jar"
|
||||||
side = "both"
|
side = "both"
|
||||||
|
@ -54,6 +55,7 @@ project-id = 243121
|
||||||
type: 'file',
|
type: 'file',
|
||||||
inline: true,
|
inline: true,
|
||||||
metafile: true,
|
metafile: true,
|
||||||
|
ignored: false,
|
||||||
content: `name = "Waystones"
|
content: `name = "Waystones"
|
||||||
filename = "waystones-forge-1.19-11.1.0.jar"
|
filename = "waystones-forge-1.19-11.1.0.jar"
|
||||||
side = "both"
|
side = "both"
|
||||||
|
|
Loading…
Reference in a new issue