-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
206 lines (198 loc) · 6.98 KB
/
index.ts
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
export * from './src/screen';
export * from './src/rerouter';
export * from './src/struct';
export * from './src/utils';
export const version = 1;
declare global {
type RGB = { r: number; g: number; b: number };
type XYRGB = { x: number; y: number; r: number; g: number; b: number };
type Image = any;
function getStoragePath(): string;
function sendEvent(event: string, content: string): void;
function execute(command: string): string;
function sleep(during: number): void;
function getImageSize(img: Image): { width: number; height: number };
function getImageColor(img: Image, x: number, y: number): RGB;
function identityColorScore(hex1: string, hex2: string): number;
function isSameColor(hex1: string, hex2: string, threshold: number): boolean;
function getScreenSize(): { width: number; height: number };
function getScreenshot(): Image;
function getScreenshotModify(
cropX: number,
cropY: number,
cropWidth: number,
cropHeight: number,
resizeWidth: number,
resizeHeight: number,
quality: number
): Image;
function releaseImage(img: Image): void;
function getIdentityScore(source: Image, target: Image): number;
function cropImage(img: Image, x: number, y: number, w: number, h: number): any;
function findImage(sourceImg: Image, targetImg: Image): { score: number; x: number; y: number };
function findImages(
sourceImg: Image,
targetImg: Image,
scoreLimit: number,
resultCountLimit: number,
withoutOverlap: boolean
): { [idx: string]: { score: number; x: number; y: number } };
function resizeImage(img: Image, w: number, h: number): any;
function saveImage(img: Image, path: string): void;
function openImage(path: string): Image;
function drawCircle(img: Image, x: number, y: number, radius: number, r: number, g: number, b: number, a: number): void;
function tap(x: number, y: number, during: number): void;
function tapDown(x: number, y: number, during: number): void;
function tapDown(x: number, y: number, during: number, id: number): void;
function tapUp(x: number, y: number, during: number): void;
function tapUp(x: number, y: number, during: number, id: number): void;
function moveTo(x: number, y: number, during: number): void;
function moveTo(x: number, y: number, during: number, id: number): void;
function swipe(x1: number, y1: number, x2: number, y2: number): void;
function keycode(label: string, during: number): void;
function typing(words: string, during: number): void;
function readFile(path: string): string | undefined;
// opencv apis
function clone(sourceImg: Image): Image;
enum SmoothType {
CV_BLUR_NO_SCALE = 0,
CV_BLUR = 1,
CV_GAUSSIAN = 2,
CV_MEDIAN = 3,
CV_BILATERAL = 4,
}
function smooth(sourceImg: Image, smoothType: SmoothType, size: number): Image;
enum ConvertColorCode {
CV_BGR2HSV = 40,
CV_BGR2HLS = 52,
}
function convertColor(sourceImg: Image, code: ConvertColorCode): Image;
function bgrToGray(sourceImg: Image): void;
function absDiff(sourceImg: Image, targetImg: Image): Image;
enum ThresholdCode {
CV_THRES_BINARY = 0,
}
function threshold(sourceImg: Image, thr: number, maxThr: number, code: ThresholdCode): void;
function eroid(sourceImg: Image, width: number, height: number, x: number, y: number): void;
function dilate(sourceImg: Image, width: number, height: number, x: number, y: number): void;
function inRange(sourceImg: Image, minB: number, minG: number, minR: number, minA: number, maxB: number, maxG: number, maxR: number, maxA: number): Image;
function outRange(sourceImg: Image, minB: number, minG: number, minR: number, minA: number, maxB: number, maxG: number, maxR: number, maxA: number): Image;
function cloneWithMask(sourceImg: Image, mask: Image): Image;
enum HoughMethod {
CV_HOUGH_GRADIENT = 3,
}
function houghCircles(
sourceImg: Image,
method: HoughMethod,
dp: number,
minDist: number,
p1: number,
p2: number,
minR: number,
maxR: number
): { [i: string]: { x: number; y: number; r: number } };
function getBase64FromImage(image: Image): string;
function getImageFromBase64(string: string): Image;
function httpClient(method: string, url: string, body: string, headers: { [key: string]: string }): string;
function getUserPlan(): string | undefined;
var s3UploadFile: (
filepath: string,
objectName: string,
contentType: string,
endpoint: string,
bucket: string,
keyId: string,
accessKey: string,
token: string,
ssl: boolean,
// fake optional parameters
retry?: number,
retryInterval?: number
) => number | string;
var s3DownloadFile: (
filepath: string,
objectName: string,
endpoint: string,
bucket: string,
keyId: string,
accessKey: string,
token: string,
ssl: boolean,
// fake optional parameters
retry?: number,
retryInterval?: number
) => true | string;
function targz(targetPath: string, sourcePath: string): string | 'success';
function untargz(sourcePath: string): string | 'success';
function xDecodeHex(hexedString: string): string | undefined;
var writeFile: (path: string, content: string) => number;
}
if (typeof writeFile === 'function') {
const writeFileTmp = writeFile;
writeFile = (path: string, content: string): number => {
const rtn = writeFileTmp(path, content);
execute(`chmod 777 ${path}`);
return rtn;
};
} else {
console.log('writeFile is not defined');
}
if (typeof s3UploadFile === 'function') {
const s3UploadFileTmp = s3UploadFile;
s3UploadFile = (
filepath: string,
objectName: string,
contentType: string,
endpoint: string,
bucket: string,
keyId: string,
accessKey: string,
token: string,
ssl: boolean,
retry: number = 3,
retryInterval: number = 10_000
): number | string => {
let sizeOrErrorMsg: number | string = '';
for (let r = 0; r < retry; r++) {
if (r > 0) {
sleep(retryInterval);
}
sizeOrErrorMsg = s3UploadFileTmp(filepath, objectName, contentType, endpoint, bucket, keyId, accessKey, token, ssl);
if (typeof sizeOrErrorMsg === 'number') {
break;
}
}
return sizeOrErrorMsg;
};
}
if (typeof s3DownloadFile === 'function') {
const s3DownloadFileTmp = s3DownloadFile;
s3DownloadFile = (
filepath: string,
objectName: string,
endpoint: string,
bucket: string,
keyId: string,
accessKey: string,
token: string,
ssl: boolean,
retry: number = 3,
retryInterval: number = 10_000
): true | string => {
const fileNotExistedMsg = 'The specified key does not exist.';
let successOrErrorMsg: true | string = '';
for (let r = 0; r < retry; r++) {
if (r > 0) {
sleep(retryInterval);
}
successOrErrorMsg = s3DownloadFileTmp(filepath, objectName, endpoint, bucket, keyId, accessKey, token, ssl);
if (successOrErrorMsg === true) {
break;
}
if (successOrErrorMsg === fileNotExistedMsg) {
break;
}
}
return successOrErrorMsg;
};
}