mirror of
https://github.com/kunkunsh/kunkun.git
synced 2025-05-24 13:45:03 +00:00

* refactor: replace comlink with kkrpc * fix: import path in api pkg and btn styling in ui iframe page * fix: fixed fetch API from kkRPC migrate * refactor: replace comlink-stdio with kkrpc * update deno lock * bump @kksh/api * update API version * publish api pkg again to fix kkrpc version * update pnpm lock * dep: fix dependency problems * dep: update deno.lock * chore: remove 2 submodules they were added only for integration development * update pnpm lock * fix: test template path * format: with prettier * downgrade next version * ci: try to fix next build on windows * try to fix CI * Revert "try to fix CI" This reverts commit b9c63c392f50f1d2d3ceec406e49b1af2348c740. * upgrade tauri-api-adapter * try to fix next * remove templates from pnpm workspace * update CI test * publish @kksh/api with upgraded tauri-api-adapter to fix nextjs template
79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
import { db, unregisterExtensionWindow } from "@kksh/api/commands"
|
|
import type { Ext as ExtInfoInDB, ExtPackageJsonExtra } from "@kksh/api/models"
|
|
import { loadExtensionManifestFromDisk } from "@kksh/extension"
|
|
import { error as sbError } from "@sveltejs/kit"
|
|
import { join } from "@tauri-apps/api/path"
|
|
import { exists, readTextFile } from "@tauri-apps/plugin-fs"
|
|
import { error } from "@tauri-apps/plugin-log"
|
|
import { goto } from "$app/navigation"
|
|
import { toast } from "svelte-sonner"
|
|
import type { PageLoad } from "./$types"
|
|
|
|
// : Promise<{
|
|
// extPath: string
|
|
// scriptPath: string
|
|
// // workerScript: string
|
|
// pkgJsonPath: string
|
|
// cmdName: string
|
|
// loadedExt: ExtPackageJsonExtra
|
|
// extInfoInDB: ExtInfoInDB
|
|
// }>
|
|
|
|
export const load: PageLoad = async ({ url }) => {
|
|
// both query parameter must exist
|
|
|
|
const extPath = url.searchParams.get("extPath")
|
|
const cmdName = url.searchParams.get("cmdName")
|
|
if (!extPath || !cmdName) {
|
|
toast.error("Invalid extension path or url")
|
|
error("Invalid extension path or url")
|
|
goto("/")
|
|
}
|
|
|
|
let _loadedExt: ExtPackageJsonExtra | undefined
|
|
try {
|
|
_loadedExt = await loadExtensionManifestFromDisk(await join(extPath!, "package.json"))
|
|
} catch (err) {
|
|
error(`Error loading extension manifest: ${err}`)
|
|
toast.error("Error loading extension manifest", {
|
|
description: `${err}`
|
|
})
|
|
goto("/")
|
|
}
|
|
const loadedExt = _loadedExt!
|
|
const extInfoInDB = await db.getUniqueExtensionByPath(loadedExt.extPath)
|
|
if (!extInfoInDB) {
|
|
toast.error("Unexpected Error", {
|
|
description: `Extension ${loadedExt.kunkun.identifier} not found in database. Run Troubleshooter.`
|
|
})
|
|
goto("/")
|
|
}
|
|
const pkgJsonPath = await join(extPath!, "package.json")
|
|
if (!(await exists(extPath!))) {
|
|
sbError(404, `Extension not found at ${extPath}`)
|
|
}
|
|
if (!(await exists(pkgJsonPath))) {
|
|
sbError(404, `Extension package.json not found at ${pkgJsonPath}`)
|
|
}
|
|
|
|
const cmd = loadedExt.kunkun.templateUiCmds.find((cmd) => cmd.name === cmdName)
|
|
if (!cmd) {
|
|
sbError(404, `Command ${cmdName} not found in extension ${loadedExt.kunkun.identifier}`)
|
|
}
|
|
const scriptPath = await join(loadedExt.extPath, cmd.main)
|
|
if (!(await exists(scriptPath))) {
|
|
sbError(404, `Command script not found at ${scriptPath}`)
|
|
}
|
|
|
|
// const workerScript = await readTextFile(scriptPath)
|
|
return {
|
|
extPath: extPath!,
|
|
pkgJsonPath,
|
|
scriptPath,
|
|
// workerScript,
|
|
cmdName: cmdName!,
|
|
loadedExt,
|
|
extInfoInDB: extInfoInDB!
|
|
}
|
|
}
|