UNPKG

tav-media

Version:

Cross platform media editing framework

72 lines (71 loc) 2.93 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { FileSystem } from "../io/file-system"; import { tav } from "../tav"; /** * License Authorization result. * @category Engine */ export var OAuthErrorCode; (function (OAuthErrorCode) { /** * The license is invalid. */ OAuthErrorCode[OAuthErrorCode["OK"] = 0] = "OK"; /** * Invalid license file */ OAuthErrorCode[OAuthErrorCode["ERROR_INVALID_PARAMETER"] = -1] = "ERROR_INVALID_PARAMETER"; /** * The license is not for this app id */ OAuthErrorCode[OAuthErrorCode["ERROR_INVALID_APP_ID"] = -2] = "ERROR_INVALID_APP_ID"; /** * The license is not for this site */ OAuthErrorCode[OAuthErrorCode["ERROR_INVALID_PACKAGE_NAME"] = -3] = "ERROR_INVALID_PACKAGE_NAME"; /** * The license is expired */ OAuthErrorCode[OAuthErrorCode["ERROR_INVALID_TIME"] = -4] = "ERROR_INVALID_TIME"; /** * Invalid license file */ OAuthErrorCode[OAuthErrorCode["ERROR_DECRYPT_FAILED"] = -5] = "ERROR_DECRYPT_FAILED"; })(OAuthErrorCode || (OAuthErrorCode = {})); ; const OAuthErrorMessages = { [-1 /* OAuthErrorCode.ERROR_INVALID_PARAMETER */]: "Invalid license file", [-2 /* OAuthErrorCode.ERROR_INVALID_APP_ID */]: "The license is not for this app id", [-3 /* OAuthErrorCode.ERROR_INVALID_PACKAGE_NAME */]: "The license is not for this site", [-4 /* OAuthErrorCode.ERROR_INVALID_TIME */]: "The license is expired", [-5 /* OAuthErrorCode.ERROR_DECRYPT_FAILED */]: "Invalid license file" }; /** * Utils to setup license */ export class TAVLicense { static Auth(licenseDataOrUrl, appId, key) { return __awaiter(this, void 0, void 0, function* () { const licensePath = 'tav-media-web.license'; if (typeof (licenseDataOrUrl) === 'string') { yield FileSystem.download(licensePath, licenseDataOrUrl); } else { FileSystem.writeFile(licensePath, licenseDataOrUrl); } const result = tav.TAVLicense.Auth(licensePath, appId, key); if (result !== 0 /* OAuthErrorCode.OK */ && OAuthErrorMessages[result]) { console.warn(OAuthErrorMessages[result]); } return result; }); } }