diff --git a/backend/build.gradle b/backend/build.gradle index 2a17b3d..97dbe06 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation("me.shedaniel:linkie-core:1.0.121") implementation("io.ktor:ktor-server-cors:2.2.3") implementation("io.ktor:ktor-server-content-negotiation:2.2.3") + implementation("io.ktor:ktor-server-compression:2.2.3") implementation("io.ktor:ktor-server-status-pages:2.2.3") implementation("io.ktor:ktor-client-content-negotiation:2.2.3") implementation("io.ktor:ktor-serialization-kotlinx-json:2.2.3") diff --git a/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt b/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt index 2e43bcc..e707f8d 100644 --- a/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt +++ b/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt @@ -7,17 +7,16 @@ import io.ktor.serialization.kotlinx.json.* import io.ktor.server.application.* import io.ktor.server.engine.* import io.ktor.server.netty.* +import io.ktor.server.plugins.compression.* import io.ktor.server.plugins.contentnegotiation.* import io.ktor.server.plugins.cors.routing.* import io.ktor.server.plugins.statuspages.* import io.ktor.server.response.* import io.ktor.server.routing.* -import kotlinx.serialization.json.addJsonObject -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put -import kotlinx.serialization.json.putJsonArray +import kotlinx.serialization.json.* import me.shedaniel.linkie.Namespaces import me.shedaniel.linkie.RemapperDaemon +import me.shedaniel.linkie.namespaces.MojangSrgNamespace import me.shedaniel.linkie.utils.tryToVersion import me.shedaniel.linkie.web.deps.depsCycle import me.shedaniel.linkie.web.deps.startDepsCycle @@ -30,6 +29,11 @@ fun main() { startLinkie() embeddedServer(Netty, port = 6969) { install(CORS) { anyHost() } + install(Compression) { + gzip { + matchContentType(ContentType.Application.Json) + } + } install(IgnoreTrailingSlash) install(ContentNegotiation) { json(json) @@ -140,6 +144,39 @@ fun main() { } }) } + get("api/mappings") { + val namespaceStr = call.parameters["namespace"]?.lowercase() ?: throw IllegalArgumentException("No namespace specified") + val version = call.parameters["version"] ?: throw IllegalArgumentException("No version specified") + val namespace = Namespaces.namespaces[namespaceStr] ?: throw IllegalArgumentException("No namespace found for $namespaceStr") + val defaultVersion = namespace.defaultVersion.takeIf { it in namespace.getAllSortedVersions() } ?: namespace.getAllSortedVersions().first() + val provider = version.let { namespace.getProvider(it) }.takeUnless { it.isEmpty() } ?: namespace.getProvider(defaultVersion) + val noIntermediary = namespace == MojangSrgNamespace + call.respond(buildJsonObject { + provider.get().allClasses.forEach { clazz -> + var intermediaryName = clazz.intermediaryName + var mappedName = clazz.mappedName + if (noIntermediary) { + intermediaryName = mappedName ?: intermediaryName + mappedName = null + } + val obj = buildJsonObject { + clazz.members.filter { it.mappedName != null && it.mappedName != it.intermediaryName }.forEach { member -> + put(member.intermediaryName, member.mappedName) + } + } + if (obj.isNotEmpty() || (mappedName != null && mappedName != intermediaryName)) { + putJsonObject(intermediaryName) { + obj.entries.forEach { (key, value) -> + put(key, value) + } + if (mappedName != null && mappedName != intermediaryName) { + put("mappedName", mappedName) + } + } + } + } + }) + } } } }.start(wait = true) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 7e58078..273037b 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -14,6 +14,7 @@ "nprogress": "^0.2.0", "pinia": "^2.0.20", "pinia-plugin-persistedstate": "^3.2.1", + "prism-code-editor": "^3.2.1", "prismjs": "^1.29.0", "tailwind-gradient-mask-image": "^1.0.0", "vite-plugin-prismjs": "^0.0.11", @@ -6198,6 +6199,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/prism-code-editor": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/prism-code-editor/-/prism-code-editor-3.2.1.tgz", + "integrity": "sha512-6IxKeCWPogFX7J5gNHQPheiWjA4PMUxHoSZBpUca3fsNJynUkSSAdSXYH+KuzkIdxNIrM9p9NKNwK8Dc5Tzmew==" + }, "node_modules/prismjs": { "version": "1.29.0", "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.29.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index aa48ea7..6329891 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,6 +16,7 @@ "nprogress": "^0.2.0", "pinia": "^2.0.20", "pinia-plugin-persistedstate": "^3.2.1", + "prism-code-editor": "^3.2.1", "prismjs": "^1.29.0", "tailwind-gradient-mask-image": "^1.0.0", "vite-plugin-prismjs": "^0.0.11", diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 082e4cb..27c9c32 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -7,6 +7,7 @@ import Alerts from "./components/Alerts.vue" import {useI18nStore} from "./app/i18n-store" import {isTauri, tauriInit} from "./app/tauri/tauri" import Tauri from "./components/tauri/Tauri.vue" +import {useI18n} from "vue-i18n" export default defineComponent({ data() { @@ -66,6 +67,10 @@ export default defineComponent({ this.allowTransition = true }, 1000) }, + setup() { + const { t } = useI18n() + return { t } + } }) diff --git a/frontend/src/app/backend.ts b/frontend/src/app/backend.ts index 0b26a77..69c6172 100644 --- a/frontend/src/app/backend.ts +++ b/frontend/src/app/backend.ts @@ -1,6 +1,6 @@ import axios, {AxiosResponse} from "axios" import {isTauri} from "./tauri/tauri" -import {LocationQuery, useRoute} from "vue-router" +import {LocationQuery, RouteLocationNormalizedLoaded, useRoute} from "vue-router" export const backendServer = "https://linkieapi.shedaniel.me" export const localBackendServer = "http://localhost:6969" @@ -57,8 +57,8 @@ export function reqStatusSource(namespace: string): Promise - \ No newline at end of file diff --git a/frontend/src/components/navbar/NavbarButton.vue b/frontend/src/components/navbar/NavbarButton.vue index b90fd58..8402a59 100644 --- a/frontend/src/components/navbar/NavbarButton.vue +++ b/frontend/src/components/navbar/NavbarButton.vue @@ -3,27 +3,20 @@ 'px-4 py-3 rounded-lg transition-all duration-100 normal-case flex items-center', bold ? 'text-xl font-bold' : 'font-medium', hoverDim ? 'hover:opacity-70' : '', - ]" :to="{path: (href ?? ''), query: {}}"> + ]" :to="{path: href, query: {}}"> - diff --git a/frontend/src/components/navbar/NavbarDropdown.vue b/frontend/src/components/navbar/NavbarDropdown.vue index 7f07307..67db810 100644 --- a/frontend/src/components/navbar/NavbarDropdown.vue +++ b/frontend/src/components/navbar/NavbarDropdown.vue @@ -28,8 +28,8 @@ -