Files

24 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2026-10-29 11:57:29 +01:00
// Generated, do not edit. sha256:446976735f7157c5e0705294189119a2714fb95130e9b9374ed76421fa83e2f5
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { CONFIG } from '../../shared/config.js';
import { parseLicense, verifySignature, coversVersion, appVersion } from '../license.mjs';
import { installDir } from '../portfolios.mjs';
import { fail } from '../../shared/app-error.js';
export async function installLicense(text) {
let parsed;
try {
parsed = parseLicense(String(text ?? ''));
} catch (err) {
fail('license.installUnreadable', { reason: err.message }, `This is not a valid licence file: ${err.message}`);
}
if (!verifySignature(parsed)) {
fail('license.installBadSignature', null, 'The signature does not belong to this licence, or it was not issued for this app.');
}
writeFileSync(join(installDir(), CONFIG.LICENSE.FILE_NAME), `${JSON.stringify(parsed, null, 2)}\n`);
const version = appVersion();
return { license: parsed.license, version, covers: coversVersion(parsed.license, version) };
}