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kB,KAAK,MAAL,CAAY,IAAZ,IAAoB,KAAK,MAAL,CAAY,KAAK,YAAY,KAAK,MAAL,CAAY,KAAK,eAAe,KAAK,MAAL,CAAY,WAAW,iBAAiB,KAAK,MAAL,CAAY,IAAI,cAAc,KAAK,OAAO,GAA5L;AACD;;AArGgD,C","sourcesContent":["import { Arch, InvalidConfigurationError, isEmptyOrSpaces, isTokenCharValid, log, toLinuxArchString } from \"builder-util\"\nimport { BintrayOptions, configureRequestOptions, HttpError } from \"builder-util-runtime\"\nimport { BintrayClient, Version } from \"builder-util-runtime/out/bintray\"\nimport { httpExecutor } from \"builder-util/out/nodeHttpExecutor\"\nimport { ClientRequest, RequestOptions } from \"http\"\nimport { Lazy } from \"lazy-val\"\nimport { HttpPublisher, PublishContext, PublishOptions } from \"electron-publish\"\n\nexport class BintrayPublisher extends HttpPublisher {\n private readonly _versionPromise = new Lazy(() => this.init())\n\n private readonly client: BintrayClient\n\n readonly providerName = \"Bintray\"\n\n constructor(context: PublishContext, info: BintrayOptions, private readonly version: string, private readonly options: PublishOptions = {}) {\n super(context)\n\n let token = info.token\n if (isEmptyOrSpaces(token)) {\n token = process.env.BT_TOKEN\n if (isEmptyOrSpaces(token)) {\n throw new InvalidConfigurationError(`Bintray token is not set, neither programmatically, nor using env \"BT_TOKEN\" (see https://www.electron.build/configuration/publish#bintrayoptions)`)\n }\n\n token = token.trim()\n\n if (!isTokenCharValid(token)) {\n throw new InvalidConfigurationError(`Bintray token (${JSON.stringify(token)}) contains invalid characters, please check env \"BT_TOKEN\"`)\n }\n }\n\n this.client = new BintrayClient(info, httpExecutor, this.context.cancellationToken, token)\n }\n\n private async init(): Promise {\n try {\n return await this.client.getVersion(this.version)\n }\n catch (e) {\n if (e instanceof HttpError && e.statusCode === 404) {\n if (this.options.publish !== \"onTagOrDraft\") {\n log.info({version: this.version}, \"version doesn't exist, creating one\")\n return await this.client.createVersion(this.version)\n }\n else {\n log.warn({reason: \"version doesn't exist\", version: this.version}, \"skipped publishing\")\n }\n }\n\n throw e\n }\n }\n\n protected async doUpload(fileName: string, arch: Arch, dataLength: number, requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void) {\n const version = await this._versionPromise.value\n if (version == null) {\n log.warn({file: fileName, reason: \"version doesn't exist and is not created\", version: this.version}, \"skipped publishing\")\n return\n }\n\n const options: RequestOptions = {\n hostname: \"api.bintray.com\",\n path: `/content/${this.client.owner}/${this.client.repo}/${this.client.packageName}/${encodeURI(`${version.name}/${fileName}`)}`,\n method: \"PUT\",\n headers: {\n \"Content-Length\": dataLength,\n \"X-Bintray-Override\": \"1\",\n \"X-Bintray-Publish\": \"1\",\n \"X-Bintray-Debian-Architecture\": toLinuxArchString(arch, \"deb\")\n }\n }\n\n if (this.client.distribution != null) {\n options.headers!![\"X-Bintray-Debian-Distribution\"] = this.client.distribution\n }\n\n if (this.client.component != null) {\n options.headers!![\"X-Bintray-Debian-Component\"] = this.client.component\n }\n\n for (let attemptNumber = 0; ; attemptNumber++) {\n try {\n return await httpExecutor.doApiRequest(configureRequestOptions(options, this.client.auth), this.context.cancellationToken, requestProcessor)\n }\n catch (e) {\n if (attemptNumber < 3 && ((e instanceof HttpError && e.statusCode === 502) || e.code === \"EPIPE\")) {\n continue\n }\n\n throw e\n }\n }\n }\n\n //noinspection JSUnusedGlobalSymbols\n async deleteRelease(isForce = false): Promise {\n if (!isForce && !this._versionPromise.hasValue) {\n return\n }\n\n const version = (await this._versionPromise.value)\n if (version != null) {\n await this.client.deleteVersion(version.name)\n }\n }\n\n toString() {\n return `Bintray (user: ${this.client.user || this.client.owner}, owner: ${this.client.owner}, package: ${this.client.packageName}, repository: ${this.client.repo}, version: ${this.version})`\n }\n}"],"sourceRoot":""}