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AAI,CAAA;QAC1C,OAAO,qBAAqB,KAAK,WAAW,IAAI,cAAc,OAAO,GAAG,CAAA;IAC1E,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,QAAgB,EAAE,KAAa;QACvD,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACvF,OAAO,SAAS,iBAAiB,EAAE,CAAA;IACrC,CAAC;CACF;AAnED,gDAmEC","sourcesContent":["import { Arch, InvalidConfigurationError, isEmptyOrSpaces, log } from \"builder-util\"\nimport { httpExecutor } from \"builder-util/out/nodeHttpExecutor\"\nimport { ClientRequest, RequestOptions } from \"http\"\nimport { HttpPublisher, PublishContext } from \"electron-publish\"\nimport { BitbucketOptions } from \"builder-util-runtime/out/publishOptions\"\nimport { configureRequestOptions, HttpExecutor } from \"builder-util-runtime\"\nimport * as FormData from \"form-data\"\nimport { readFile } from \"fs-extra\"\n\nexport class BitbucketPublisher extends HttpPublisher {\n readonly providerName = \"bitbucket\"\n readonly hostname = \"api.bitbucket.org\"\n\n private readonly info: BitbucketOptions\n private readonly auth: string\n private readonly basePath: string\n\n constructor(context: PublishContext, info: BitbucketOptions) {\n super(context)\n\n const token = info.token || process.env.BITBUCKET_TOKEN || null\n const username = info.username || process.env.BITBUCKET_USERNAME || null\n\n if (isEmptyOrSpaces(token)) {\n throw new InvalidConfigurationError(`Bitbucket token is not set using env \"BITBUCKET_TOKEN\" (see https://www.electron.build/configuration/publish#BitbucketOptions)`)\n }\n\n if (isEmptyOrSpaces(username)) {\n log.warn('No Bitbucket username provided via \"BITBUCKET_USERNAME\". Defaulting to use repo owner.')\n }\n\n this.info = info\n this.auth = BitbucketPublisher.convertAppPassword(username ?? this.info.owner, token)\n this.basePath = `/2.0/repositories/${this.info.owner}/${this.info.slug}/downloads`\n }\n\n protected doUpload(\n fileName: string,\n _arch: Arch,\n _dataLength: number,\n _requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void,\n file: string\n ): Promise<any> {\n return HttpExecutor.retryOnServerError(async () => {\n const fileContent = await readFile(file)\n const form = new FormData()\n form.append(\"files\", fileContent, fileName)\n const upload: RequestOptions = {\n hostname: this.hostname,\n path: this.basePath,\n headers: form.getHeaders(),\n timeout: this.info.timeout || undefined,\n }\n await httpExecutor.doApiRequest(configureRequestOptions(upload, this.auth, \"POST\"), this.context.cancellationToken, it => form.pipe(it))\n return fileName\n })\n }\n\n async deleteRelease(filename: string): Promise<void> {\n const req: RequestOptions = {\n hostname: this.hostname,\n path: `${this.basePath}/${filename}`,\n timeout: this.info.timeout || undefined,\n }\n await httpExecutor.request(configureRequestOptions(req, this.auth, \"DELETE\"), this.context.cancellationToken)\n }\n\n toString() {\n const { owner, slug, channel } = this.info\n return `Bitbucket (owner: ${owner}, slug: ${slug}, channel: ${channel})`\n }\n\n static convertAppPassword(username: string, token: string) {\n const base64encodedData = Buffer.from(`${username}:${token.trim()}`).toString(\"base64\")\n return `Basic ${base64encodedData}`\n }\n}\n"]}
\No newline at end of file