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