GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dgit/src/request.ts at master · JohnApache/dgit

Expand file tree

/

request.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
110 lines (93 loc) · 2.82 KB
/

request.ts

Copy path

File metadata and controls

110 lines (93 loc) · 2.82 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import fs from 'fs';
import { DgitGlobalOption, DgitLifeCycle } from './type';
import { AddExtraRandomQs } from './cmd/utils';
import { createLogger } from './log';
import request, { UrlOptions, CoreOptions } from 'request';
type RequestOption = UrlOptions & CoreOptions;
const REQUEST_RETRY_DELAY = 1500;
const DEFAULT_MAX_RETRY_COUNT = 5;
const requestGet = (
options: RequestOption,
maxRetryCount: number,
hooks?: DgitLifeCycle,
): void => {
const {
onSuccess, onError, onFinish, onRetry,
} = hooks || {};
request.get(options, (err, _, body) => {
if (err) {
if (maxRetryCount < 1) {
onError && onError(err);
onFinish && onFinish();
return;
}
setTimeout(() => {
onRetry && onRetry();
requestGet(options, maxRetryCount - 1, hooks);
}, REQUEST_RETRY_DELAY);
return;
}
onSuccess && onSuccess(body);
onFinish && onFinish();
});
};
export const requestGetPromise = (
options: RequestOption,
dgitOptions: DgitGlobalOption,
hooks?: DgitLifeCycle,
): Promise<any> => new Promise((resolve, reject) => {
const { maxRetryCount = DEFAULT_MAX_RETRY_COUNT } = dgitOptions;
const {
onSuccess, onError, onFinish, onRetry,
} = hooks || {};
const newHooks: DgitLifeCycle = {
onSuccess (data: any) {
resolve(data);
onSuccess && onSuccess(data);
},
onError (err: any) {
reject(err);
onError && onError(err);
},
onFinish,
onRetry,
};
requestGet(options, maxRetryCount, newHooks);
});
export const requestOnStream = (
url: string,
ws: fs.WriteStream,
dgitOptions: DgitGlobalOption,
hooks?: DgitLifeCycle,
) => {
const { maxRetryCount = DEFAULT_MAX_RETRY_COUNT } = dgitOptions;
const logger = createLogger(dgitOptions);
const {
onSuccess, onError, onFinish, onRetry,
} = hooks || {};
const fn = (retryCount: number): void => {
const downloadUrl = AddExtraRandomQs(url);
logger(` dowloading from ${ downloadUrl }...`);
request(encodeURI(downloadUrl))
.on('error', err => {
if (retryCount <= 0) {
onError && onError(err);
onFinish && onFinish();
return;
}
setTimeout(() => {
onRetry && onRetry();
fn(retryCount - 1);
}, REQUEST_RETRY_DELAY);
})
.pipe(ws);
};
ws.on('finish', () => {
onSuccess && onSuccess();
onFinish && onFinish();
});
ws.on('error', () => {
logger(` ${ url }, write stream failed.`);
});
fn(maxRetryCount);
};
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.