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