From 5fc85b610f2bc74f11ca45826cdbbc3bafaec204 Mon Sep 17 00:00:00 2001 From: Skye Date: Mon, 6 Mar 2023 19:28:26 +0900 Subject: [PATCH] afdsfdasafsd --- package.json | 2 - src/lib/modrinth.ts | 65 +++++++++++++++++ src/lib/packwiz-types.ts | 32 ++++---- src/lib/{ => server}/clients.ts | 0 src/routes/create/+page.server.ts | 2 +- src/routes/create/+page.svelte | 85 +++++++++++++--------- src/routes/create/FlattenedFileList.svelte | 26 ++++++- 7 files changed, 155 insertions(+), 57 deletions(-) create mode 100644 src/lib/modrinth.ts rename src/lib/{ => server}/clients.ts (100%) diff --git a/package.json b/package.json index d19242a..5bb79ef 100644 --- a/package.json +++ b/package.json @@ -46,11 +46,9 @@ "@auth/sveltekit": "^0.2.2", "@ltd/j-toml": "^1.38.0", "@rgossiaux/svelte-headlessui": "^1.0.2", - "@xmcl/modrinth": "^1.1.0", "minio": "^7.0.32", "nano": "^10.1.2", "nanoid": "^4.0.1", - "octokit": "^2.0.14", "svelte-feather-icons": "^4.0.0", "zod": "^3.20.6" } diff --git a/src/lib/modrinth.ts b/src/lib/modrinth.ts new file mode 100644 index 0000000..262df5f --- /dev/null +++ b/src/lib/modrinth.ts @@ -0,0 +1,65 @@ +import { z } from 'zod'; + +const searchProjectsResponse = z.object({ + hits: z.object({ + slug: z.string().regex(/^[\w!@$()`.+,"\-']{3,64}$/), + title: z.string(), + description: z.string(), + categories: z.string().array().default([]), + client_side: z.enum(["required", "optional", "unsupported"]), + server_side: z.enum(["required", "optional", "unsupported"]), + project_type: z.enum(["mod", "modpack", "resourcepack", "shader"]), + downloads: z.number(), + icon_url: z.string().url(), + color: z.number(), + project_id: z.string(), + author: z.string(), + display_categories: z.string().array().default([]), + versions: z.string().array(), + follows: z.number(), + date_created: z.string().datetime({offset: true}), + date_modified: z.string().datetime({offset: true}), + latest_version: z.string().optional(), + license: z.string(), + gallery: z.string().array().default([]), + featured_gallery: z.string().optional(), + }).array(), + offset: z.number(), + limit: z.number(), + total_hits: z.number() +}); + +const searchProjectsRequest = z.object({ + query: z.string().optional(), + facets: z.string().regex(/^(categories|versions|license|project_type):(.+)$/).array().array().default([]), + index: z.enum(["relevance", "downloads", "follows", "newest", "updated"]).default("relevance"), + offset: z.number().default(0), + limit: z.number().default(10), + filters: z.string().optional() +}); + +function searchProjectsRequestToUrlParams(request: z.infer): URLSearchParams { + const params = new URLSearchParams(); + if (typeof request.query != 'undefined') { + params.set("query", request.query); + } + params.set("facets", JSON.stringify(request.facets)); + params.set("index", request.index); + params.set("offset", request.offset.toString()); + params.set("limit", request.limit.toString()); + if (typeof request.filters != 'undefined') { + params.set("filters", request.filters); + } + return params; +} + +export async function searchProjects(request: z.input): Promise> { + const parsedRequest = searchProjectsRequest.parse(request); + const params = searchProjectsRequestToUrlParams(parsedRequest); + const response = await fetch("https://api.modrinth.com/v2/search?" + params.toString(), { + headers: { + "User-Agent": "NotModdermore/noversion (+https://git.skye.vg/me/not-moddermore/)" + } + }); + return searchProjectsResponse.parse(await response.json()); +} \ No newline at end of file diff --git a/src/lib/packwiz-types.ts b/src/lib/packwiz-types.ts index 70d967b..ae7f584 100644 --- a/src/lib/packwiz-types.ts +++ b/src/lib/packwiz-types.ts @@ -32,22 +32,22 @@ export const indexSchema = z.object({ 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({}) + 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/clients.ts b/src/lib/server/clients.ts similarity index 100% rename from src/lib/clients.ts rename to src/lib/server/clients.ts diff --git a/src/routes/create/+page.server.ts b/src/routes/create/+page.server.ts index 92b58a7..409d9f4 100644 --- a/src/routes/create/+page.server.ts +++ b/src/routes/create/+page.server.ts @@ -5,7 +5,7 @@ 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/clients'; +import { minioClient, nano } from '$lib/server/clients'; export const actions: Actions = { default: async (event) => { diff --git a/src/routes/create/+page.svelte b/src/routes/create/+page.svelte index ae2e1fa..37a382b 100644 --- a/src/routes/create/+page.svelte +++ b/src/routes/create/+page.svelte @@ -17,12 +17,14 @@ let fileTree: Folder = { type: 'folder', children: { - mods: { type: 'folder', children: { - "quark.pw.toml": { - type: 'file', - inline: true, - metafile: true, - content: `name = "Quark" + mods: { + type: 'folder', + children: { + 'quark.pw.toml': { + type: 'file', + inline: true, + metafile: true, + content: `name = "Quark" filename = "Quark-3.4-389.jar" side = "both" @@ -36,14 +38,15 @@ mode = "metadata:curseforge" file-id = 4366541 project-id = 243121 `, - sha1: '478805ce54b082dadb1042ccfb46a68cfde3fc35', - sha512: '5d364049ff53af2154ccae58dd53d2111ef592b21bff03705314cd6d12378cfeb6376b8bc3065ac59e1c9452447bec0eb345ecc19f0de1a17c20ea374f802f05' - }, - "waystones.pw.toml": { - type: 'file', - inline: true, - metafile: true, - content: `name = "Waystones" + sha1: '478805ce54b082dadb1042ccfb46a68cfde3fc35', + sha512: + '5d364049ff53af2154ccae58dd53d2111ef592b21bff03705314cd6d12378cfeb6376b8bc3065ac59e1c9452447bec0eb345ecc19f0de1a17c20ea374f802f05' + }, + 'waystones.pw.toml': { + type: 'file', + inline: true, + metafile: true, + content: `name = "Waystones" filename = "waystones-forge-1.19-11.1.0.jar" side = "both" @@ -57,14 +60,24 @@ hash = "24c5403c1d5791f977a0ba69f08cf7959169c685" mod-id = "LOpKHB2A" version = "2sIhirkG" `, - sha1: '25f4b57fbd8a985b4872bb8fdadd14580b0f9f81', - sha512: '125fb6fc706363753c1c201192024415a23c1098c8e44d5deeaf5448215d83108b9a9a5aba0a029dd9015eff536dc1da63d16c3be0d7f9e39d6f482b8ce008c3' + sha1: '25f4b57fbd8a985b4872bb8fdadd14580b0f9f81', + sha512: + '125fb6fc706363753c1c201192024415a23c1098c8e44d5deeaf5448215d83108b9a9a5aba0a029dd9015eff536dc1da63d16c3be0d7f9e39d6f482b8ce008c3' + } } - } } + } } }; let blobs: Blob[] = []; let isOpen = false; + + let searchTerm = ''; + async function search() { + // const result = await modrinthClient.searchProjects({ + // te + // }) + // console.log(result) + } @@ -74,30 +87,32 @@ version = "2sIhirkG" -

Mods

- +

Mods

+

Resource Packs

Shader Packs

- +
- Content 2 + {JSON.stringify(fileTree)}
- (isOpen = false)}> - - - Deactivate account - This will permanently deactivate your account - -

- Are you sure you want to deactivate your account? All of your data will be permanently removed. - This action cannot be undone. -

- - - + (isOpen = false)} class="fixed top-0 left-0 w-screen h-screen flex justify-center items-center"> + +
+ Add Mod + Add a mod to your modpack + +
diff --git a/src/routes/create/FlattenedFileList.svelte b/src/routes/create/FlattenedFileList.svelte index bdebca6..c5e5d74 100644 --- a/src/routes/create/FlattenedFileList.svelte +++ b/src/routes/create/FlattenedFileList.svelte @@ -1,8 +1,9 @@
    @@ -25,7 +37,15 @@
  • {#if mod[1].inline && mod[1].metafile} {@const parsed = metafileSchema.parse(toml.parse(mod[1].content))} -

    {parsed.name} ({mod[0].join('/')})

    +

    + {parsed.name} ({mod[0].join('/')}) + +

    {#if parsed.update.curseforge}