mirror of
https://github.com/immich-app/immich.git
synced 2026-04-18 00:21:55 -04:00
31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import { PUBLIC_IMMICH_BUY_HOST, PUBLIC_IMMICH_PAY_HOST } from '$env/static/public';
|
|
import type { ImmichProduct } from '$lib/constants';
|
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
|
import { serverConfigManager } from '$lib/managers/server-config-manager.svelte';
|
|
import { setServerLicense, setUserLicense, type LicenseResponseDto } from '@immich/sdk';
|
|
|
|
export const activateProduct = async (licenseKey: string, activationKey: string): Promise<LicenseResponseDto> => {
|
|
// TODO is this needed?
|
|
await authManager.load();
|
|
|
|
const isServerActivation = authManager.user.isAdmin && licenseKey.search('IMSV') !== -1;
|
|
const licenseKeyDto = { licenseKey, activationKey };
|
|
// Send server key to user activation if user is not admin
|
|
return isServerActivation ? setServerLicense({ licenseKeyDto }) : setUserLicense({ licenseKeyDto });
|
|
};
|
|
|
|
export const getActivationKey = async (licenseKey: string): Promise<string> => {
|
|
const response = await fetch(new URL(`/api/v1/activate/${licenseKey}`, PUBLIC_IMMICH_PAY_HOST).href);
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch activation key');
|
|
}
|
|
return response.text();
|
|
};
|
|
|
|
export const getLicenseLink = (license: ImmichProduct) => {
|
|
const url = new URL('/', PUBLIC_IMMICH_BUY_HOST);
|
|
url.searchParams.append('productId', license);
|
|
url.searchParams.append('instanceUrl', serverConfigManager.value.externalDomain || globalThis.origin);
|
|
return url.href;
|
|
};
|