refactor: enhance extension installation process with overwrite confirmation

if store extension exists in DB but not disk, also ask if need to overwrite it.
This commit is contained in:
Huakun Shen 2025-01-11 21:58:27 -05:00
parent 836a92cf14
commit 0af6ef2d0a
2 changed files with 19 additions and 2 deletions

View File

@ -81,7 +81,6 @@
.installFromTarballUrl(tarballUrl, installDir, installExtras)
.then(() => toast.success(`Plugin ${ext.name} Installed`))
.then((loadedExt) => {
console.log("loadedExt", loadedExt);
supabaseAPI.incrementDownloads({
identifier: ext.identifier,
version: ext.version
@ -151,7 +150,6 @@
</script>
<svelte:window on:keydown={handleKeydown} />
<Button onclick={() => toast.success("Hello")}>Toast</Button>
<Button
variant="outline"
size="icon"

View File

@ -55,6 +55,25 @@ export async function installTarball(
}
await fs.remove(extInstallPath, { recursive: true })
}
// find extension in db, if exists, ask user if they want to overwrite it
const exts = await db.getAllExtensionsByIdentifier(manifest.kunkun.identifier)
if (exts.length > 0) {
const overwrite = await dialog.ask(
`Extension ${manifest.kunkun.identifier} already exists in database (but not on disk), do you want to overwrite it?`
)
if (!overwrite) {
return Promise.reject("Extension Already Exists")
}
if (exts[0].path) {
console.log(
"delete extension in db (overwrite in order to install a new version)",
exts[0].path
)
await db.deleteExtensionByPath(exts[0].path)
}
}
await fs.rename(decompressDest, extInstallPath)
await db.createExtension({
identifier: manifest.kunkun.identifier,