Huakun Shen ce42409a39
Feature: Quick Link (#17)
* feat: add page for add quick link (not working yet)

* upgrade @kksh/svelte5

* fix: infinite recursive footer

* dep: add @kksh/svelte5 to ui package

* dep: add supabase-js

* dep: add @iconify/svelte

* style: modify StoreExtDetail width control

* fixed: UI for extension store detail

* feat: add page to create quick link

* feat: display quick links in cmd palette

* snapshot

* show queries in command input

* feat: quick link fully implemented

* refactor: format all with prettier

* feat: add icon picker for quick link adder

* fix: make invert for icon optional, caused many types to crash
2024-11-07 12:26:06 -05:00

58 lines
1.4 KiB
TypeScript

import { db } from "@kksh/api/commands"
import {
CmdTypeEnum,
ExtCmd,
ExtPackageJson,
ExtPackageJsonExtra,
Icon,
QuickLinkCmd
} from "@kksh/api/models"
import * as v from "valibot"
export async function upsertExtension(extPkgJson: ExtPackageJson, extFullPath: string) {
const extInDb = await db.getUniqueExtensionByIdentifier(extPkgJson.kunkun.identifier)
if (!extInDb) {
// create this extension in database
await db.createExtension({
identifier: extPkgJson.kunkun.identifier,
version: extPkgJson.version,
path: extFullPath
})
}
}
export async function createQuickLinkCommand(name: string, link: string, icon: Icon) {
const extension = await db.getExtQuickLinks()
return db.createCommand({
extId: extension.extId,
name,
cmdType: CmdTypeEnum.QuickLink,
data: JSON.stringify({
link,
icon
}),
enabled: true
})
}
export async function getAllQuickLinkCommands(): Promise<QuickLinkCmd[]> {
const extension = await db.getExtQuickLinks()
const cmds = await db.getCommandsByExtId(extension.extId)
return cmds
.map((cmd) => {
try {
cmd.data = JSON.parse(cmd.data)
const parsedData = v.safeParse(QuickLinkCmd, cmd)
if (!parsedData.success) {
console.warn("Fail to parse quick link command", cmd)
console.error(v.flatten(parsedData.issues))
return null
}
return parsedData.output
} catch (error) {
return null
}
})
.filter((cmd) => cmd !== null)
}