diff --git a/packages/builder/src/pages/builder/portal/account/upgrade.svelte b/packages/builder/src/pages/builder/portal/account/upgrade.svelte
index f0ee87bde5..a37625a5dc 100644
--- a/packages/builder/src/pages/builder/portal/account/upgrade.svelte
+++ b/packages/builder/src/pages/builder/portal/account/upgrade.svelte
@@ -10,6 +10,8 @@
Label,
ButtonGroup,
notifications,
+ CopyInput,
+ File
} from "@budibase/bbui"
import { auth, admin } from "stores/portal"
import { redirect } from "@roxi/routify"
@@ -21,44 +23,122 @@
$: license = $auth.user.license
$: upgradeUrl = `${$admin.accountPortalUrl}/portal/upgrade`
+ // LICENSE KEY
$: activateDisabled = !licenseKey || licenseKeyDisabled
-
- let licenseInfo
-
let licenseKeyDisabled = false
let licenseKeyType = "text"
let licenseKey = ""
let deleteLicenseKeyModal
+ // OFFLINE LICENSE
+ let installationIdentifier = undefined
+ let offlineLicense = undefined
+ const offlineLicenseExtensions = [
+ ".txt",
+ ]
+
// Make sure page can't be visited directly in cloud
$: {
if ($admin.cloud) {
$redirect("../../portal")
}
+
+ console.log({ offlineLicense })
}
- const activate = async () => {
+ // LICENSE KEY
+
+ const getLicenseKey = async () => {
try {
- await API.activateLicenseKey({ licenseKey })
- await auth.getSelf()
- await setLicenseInfo()
- notifications.success("Successfully activated")
+ licenseKey = await API.getLicenseKey()
+ if (licenseKey) {
+ licenseKey = "**********************************************"
+ licenseKeyType = "password"
+ licenseKeyDisabled = true
+ activateDisabled = true
+ }
} catch (e) {
- notifications.error(e.message)
+ console.error(e)
+ notifications.error("Error retrieving license key")
}
}
- const destroy = async () => {
+ const activateLicenseKey = async () => {
+ try {
+ await API.activateLicenseKey({ licenseKey })
+ await auth.getSelf()
+ await getLicenseKey()
+ notifications.success("Successfully activated")
+ } catch (e) {
+ console.error(e)
+ notifications.error("Error activating license key")
+ }
+ }
+
+ const deleteLicenseKey = async () => {
try {
await API.deleteLicenseKey({ licenseKey })
await auth.getSelf()
- await setLicenseInfo()
+ await getLicenseKey()
// reset the form
licenseKey = ""
licenseKeyDisabled = false
- notifications.success("Successfully deleted")
+ notifications.success("Offline license removed")
} catch (e) {
- notifications.error(e.message)
+ console.error(e)
+ notifications.error("Error deleting license key")
+ }
+ }
+
+ // OFFLINE LICENSE
+
+ const getOfflineLicense = async () => {
+ try {
+ const license = await API.getOfflineLicense()
+ if (license) {
+ offlineLicense = {
+ name: "license"
+ }
+ } else {
+ offlineLicense = undefined
+ }
+ } catch (e) {
+ console.error(e)
+ notifications.error("Error loading offline license")
+ }
+ }
+
+ async function activateOfflineLicense(offlineLicense) {
+ try {
+ await API.activateOfflineLicense({ offlineLicense })
+ await auth.getSelf()
+ await getOfflineLicense()
+ notifications.success("Successfully activated")
+ } catch (e) {
+ console.error(e)
+ notifications.error("Error activating offline license")
+ }
+ }
+
+ async function deleteOfflineLicense() {
+ try {
+ await API.deleteOfflineLicense()
+ await auth.getSelf()
+ await getOfflineLicense()
+ notifications.success("Successfully removed ofline license")
+ } catch (e) {
+ console.error(e)
+ notifications.error("Error upload offline license")
+ }
+ }
+
+ async function onOfflineLicenseChange(event) {
+ if (event.detail) {
+ const reader = new FileReader()
+ reader.readAsText(event.detail)
+ reader.onload = () => activateOfflineLicense(reader.result)
+ } else {
+ await deleteOfflineLicense()
}
}
@@ -73,29 +153,19 @@
}
}
- // deactivate the license key field if there is a license key set
- $: {
- if (licenseInfo?.licenseKey) {
- licenseKey = "**********************************************"
- licenseKeyType = "password"
- licenseKeyDisabled = true
- activateDisabled = true
- }
- }
-
- const setLicenseInfo = async () => {
- licenseInfo = await API.getLicenseInfo()
- }
-
onMount(async () => {
- await setLicenseInfo()
+ if ($admin.offlineMode) {
+ await getOfflineLicense()
+ } else {
+ await getLicenseKey()
+ }
})
{#if $auth.isAdmin}
@@ -112,38 +182,73 @@