- Accept a single pasted/uploaded combined licence key (base64+gzip of licence+activation key), auto-detected in either paste mode, alongside the legacy two-field format - Warn and block applying a key generated for the wrong protocol before it ever reaches the backend - Decode both the legacy positional features string and a new named features object, so already-issued keys keep working unchanged - Show a live "Key Details" preview (validity, users, site IDs, enabled features) as a key is typed, pasted, or uploaded - Fix cypress test setup broken by the paste-format default change, and an unreliable FileReader-based base64 conversion in the test helpers
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import * as base64Converter from 'base64-arraybuffer'
|
|
|
|
export const base64ToArrayBuffer = (base64: string) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
const dataUrl = 'data:application/octet-binary;base64,' + base64
|
|
|
|
fetch(dataUrl)
|
|
.then((res) => res.arrayBuffer())
|
|
.then((buffer) => {
|
|
resolve(new Uint8Array(buffer))
|
|
})
|
|
.catch((err) => {
|
|
reject(err)
|
|
})
|
|
})
|
|
}
|
|
|
|
// Blob + FileReader.readAsDataURL (a natural alternative here) is
|
|
// unreliable in the Cypress runner's iframe - onload/onerror can simply
|
|
// never fire, leaving the promise permanently unsettled (a silent hang,
|
|
// surfacing only as Mocha's "done() was never invoked" 30s later with no
|
|
// clue why). base64-arraybuffer's encode() is synchronous and
|
|
// dependency-free - no browser API involved, so this class of hang isn't
|
|
// possible - and it's the same library the app itself uses for this exact
|
|
// conversion.
|
|
export const arrayBufferToBase64 = (
|
|
arrayBuffer: ArrayBuffer
|
|
): Promise<string> => {
|
|
return Promise.resolve(base64Converter.encode(arrayBuffer))
|
|
}
|