camoufox-js 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/__main__.js CHANGED
File without changes
package/dist/pkgman.d.ts CHANGED
@@ -26,7 +26,9 @@ export declare class GitHubDownloader {
26
26
  constructor(githubRepo: string);
27
27
  checkAsset(asset: any): any;
28
28
  missingAssetError(): void;
29
- getAsset(): Promise<any>;
29
+ getAsset({ retries }?: {
30
+ retries: number;
31
+ }): Promise<any>;
30
32
  }
31
33
  export declare class CamoufoxFetcher extends GitHubDownloader {
32
34
  arch: string;
@@ -53,7 +55,9 @@ export declare function installedVerStr(): string;
53
55
  export declare function camoufoxPath(downloadIfMissing?: boolean): PathLike;
54
56
  export declare function getPath(file: string): string;
55
57
  export declare function launchPath(): string;
56
- export declare function webdl(url: string, desc?: string, bar?: boolean, buffer?: Writable | null): Promise<Buffer>;
58
+ export declare function webdl(url: string, desc?: string, bar?: boolean, buffer?: Writable | null, { retries }?: {
59
+ retries: number;
60
+ }): Promise<Buffer>;
57
61
  export declare function unzip(zipFile: Buffer, extractPath: string, desc?: string, bar?: boolean): Promise<void>;
58
62
  export declare function loadYaml(file: string): {
59
63
  [key: string]: any;
package/dist/pkgman.js CHANGED
@@ -7,6 +7,7 @@ import { CamoufoxNotInstalled, FileNotFoundError, MissingRelease, UnsupportedArc
7
7
  import AdmZip from 'adm-zip';
8
8
  import * as yaml from 'js-yaml';
9
9
  import ProgressBar from 'progress';
10
+ import { setTimeout } from 'timers/promises';
10
11
  const ARCH_MAP = {
11
12
  'x64': 'x86_64',
12
13
  'ia32': 'i686',
@@ -97,12 +98,25 @@ export class GitHubDownloader {
97
98
  missingAssetError() {
98
99
  throw new MissingRelease(`Could not find a release asset in ${this.githubRepo}.`);
99
100
  }
100
- async getAsset() {
101
- const resp = await fetch(this.apiUrl);
102
- if (!resp.ok) {
103
- throw new Error(`Failed to fetch releases from ${this.apiUrl}`);
101
+ async getAsset({ retries } = { retries: 5 }) {
102
+ let attempts = 0;
103
+ let response;
104
+ while (attempts < retries) {
105
+ try {
106
+ response = await fetch(this.apiUrl);
107
+ if (response.ok)
108
+ break;
109
+ }
110
+ catch (e) {
111
+ console.error(e, `retrying (${attempts + 1}/${retries})...`);
112
+ await setTimeout(5e3);
113
+ }
114
+ attempts++;
104
115
  }
105
- const releases = await resp.json();
116
+ if (!response || !response.ok) {
117
+ throw new Error(`Failed to fetch releases from ${this.apiUrl} after ${retries} attempts`);
118
+ }
119
+ const releases = await response.json();
106
120
  for (const release of releases) {
107
121
  for (const asset of release.assets) {
108
122
  const data = this.checkAsset(asset);
@@ -270,10 +284,23 @@ export function launchPath() {
270
284
  }
271
285
  return launchPath;
272
286
  }
273
- export async function webdl(url, desc = '', bar = true, buffer = null) {
274
- const response = await fetch(url);
275
- if (!response.ok) {
276
- throw new Error(`Failed to download file from ${url}`);
287
+ export async function webdl(url, desc = '', bar = true, buffer = null, { retries } = { retries: 5 }) {
288
+ let attempts = 0;
289
+ let response;
290
+ while (attempts < retries) {
291
+ try {
292
+ response = await fetch(url);
293
+ if (response.ok)
294
+ break;
295
+ }
296
+ catch (e) {
297
+ console.error(e, `retrying (${attempts + 1}/${retries})...`);
298
+ await setTimeout(5e3);
299
+ }
300
+ attempts++;
301
+ }
302
+ if (!response || !response.ok) {
303
+ throw new Error(`Failed to download from ${url} after ${retries} attempts`);
277
304
  }
278
305
  const totalSize = parseInt(response.headers.get('content-length') || '0', 10);
279
306
  const progressBar = bar ? new ProgressBar(`${desc} [:bar] :percent :etas`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camoufox-js",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {