-
Notifications
You must be signed in to change notification settings - Fork 10
/
LogoScrape.ts
40 lines (38 loc) 路 1.37 KB
/
LogoScrape.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
import { Helpers } from './Helpers';
import { ImageSearch } from './ImageSearch';
export class LogoScrape {
public static async getLogo(url: string | string[]): Promise<any> {
if (typeof url !== 'string') {
return Promise.all(
url.map((urlItem: string) => {
if (!Helpers.validUrl(urlItem)) {
throw new Error(`No valid url found (${urlItem})`);
}
return ImageSearch.findImages(urlItem);
})
);
} else {
if (!Helpers.validUrl(url)) {
throw new Error(`No valid url found (${url})`);
}
return ImageSearch.findImages(url);
}
}
public static async getLogos(url: string | string[]): Promise<any> {
if (typeof url !== 'string') {
return Promise.all(
url.map((urlItem: string) => {
if (!Helpers.validUrl(urlItem)) {
throw new Error(`No valid url found (${urlItem})`);
}
return ImageSearch.findImages(urlItem, true);
})
);
} else {
if (!Helpers.validUrl(url)) {
throw new Error(`No valid url found (${url})`);
}
return ImageSearch.findImages(url, true);
}
}
}