Commit c80742633f
c80742633f51e79d18d7cea71514ef16c96bc60b
parent: 6bf594654d
Unsigned
Alicia Sykes <alicia@omg.lol> · 2024-02-29 21:08 UTC
Write interfaces and fetch logic for fetching github stats, privacy policy info, and website metrics for each service
Layout: unified · split
web/src/utils/fetch-privacy-policy.ts
added
+61
| @@ -0,0 +1,61 @@ |
| |
1 | |
| |
2 | export const fetchTosdrPrivacy = async (serviceId: string): Promise<PrivacyPolicyResponse | null> => { |
| |
3 | const endpoint = `https://api.tosdr.org/service/v2?id=${serviceId}`; |
| |
4 | try { |
| |
5 | return await fetch(endpoint).then((res) => res.json()); |
| |
6 | } catch (error) { |
| |
7 | console.error('Error fetching privacy policy data:', error); |
| |
8 | return null; |
| |
9 | } |
| |
10 | }; |
| |
11 | |
| |
12 | interface Document { |
| |
13 | id: number; |
| |
14 | name: string; |
| |
15 | url: string; |
| |
16 | updated_at: string; |
| |
17 | created_at: string; |
| |
18 | } |
| |
19 | |
| |
20 | interface Case { |
| |
21 | id: number; |
| |
22 | weight: number; |
| |
23 | title: string; |
| |
24 | description: string; |
| |
25 | updated_at: string; |
| |
26 | created_at: string; |
| |
27 | topic_id: number; |
| |
28 | classification: string; |
| |
29 | } |
| |
30 | |
| |
31 | interface Point { |
| |
32 | id: number; |
| |
33 | title: string; |
| |
34 | source: string; |
| |
35 | status: string; |
| |
36 | analysis: string; |
| |
37 | case: Case; |
| |
38 | document_id: number | null; |
| |
39 | updated_at: string; |
| |
40 | created_at: string; |
| |
41 | } |
| |
42 | |
| |
43 | interface Params { |
| |
44 | id: number; |
| |
45 | is_comprehensively_reviewed: boolean; |
| |
46 | name: string; |
| |
47 | updated_at: string; |
| |
48 | created_at: string; |
| |
49 | slug: string; |
| |
50 | rating: string; |
| |
51 | urls: string[]; |
| |
52 | image: string; |
| |
53 | documents: Document[]; |
| |
54 | points: Point[]; |
| |
55 | } |
| |
56 | |
| |
57 | export interface PrivacyPolicyResponse { |
| |
58 | error: number; |
| |
59 | message: string; |
| |
60 | parameters: Params; |
| |
61 | } |
web/src/utils/fetch-repo-info.ts
added
+68
| @@ -0,0 +1,68 @@ |
| |
1 | |
| |
2 | |
| |
3 | |
| |
4 | export const fetchGitHubStats = async (github: string): Promise<GitHubStatsResponse | null> => { |
| |
5 | const endpoint = `https://repo-info.as93.workers.dev/${github}`; |
| |
6 | try { |
| |
7 | return await fetch(endpoint).then((res) => res.json()); |
| |
8 | } catch (error) { |
| |
9 | console.error('Error fetching GitHub stats:', error); |
| |
10 | return null; |
| |
11 | } |
| |
12 | }; |
| |
13 | |
| |
14 | // fetch(`https://repo-info.as93.workers.dev/${github}`).then((res) => res.json()); |
| |
15 | |
| |
16 | export interface GitHubStatsResponse { |
| |
17 | info: { |
| |
18 | ownerUsername: string; |
| |
19 | ownerAvatar: string; |
| |
20 | description: string; |
| |
21 | url: string; |
| |
22 | homepage: string; |
| |
23 | language: string; |
| |
24 | topics: string[]; |
| |
25 | license: string; |
| |
26 | isFork: boolean; |
| |
27 | isArchived: boolean; |
| |
28 | createdAt: string; |
| |
29 | updatedAt: string; |
| |
30 | size: number; |
| |
31 | scarCount: number; |
| |
32 | forksCount: number; |
| |
33 | watchersCount: number; |
| |
34 | }; |
| |
35 | languages: { |
| |
36 | [key: string]: number; |
| |
37 | }; |
| |
38 | updates: Array<{ |
| |
39 | type: string; |
| |
40 | actor: { |
| |
41 | username: string; |
| |
42 | avatar: string; |
| |
43 | }; |
| |
44 | repo: string; |
| |
45 | action: string; |
| |
46 | createdAt: string; |
| |
47 | number?: number; |
| |
48 | }>; |
| |
49 | versions: Array<{ |
| |
50 | name: string; |
| |
51 | commit: string; |
| |
52 | zipball: string; |
| |
53 | tarball: string; |
| |
54 | }>; |
| |
55 | contributors: Array<{ |
| |
56 | username: string; |
| |
57 | avatar: string; |
| |
58 | contributions: number; |
| |
59 | }>; |
| |
60 | commits: Array<{ |
| |
61 | sha: string; |
| |
62 | authorName: string; |
| |
63 | authorDate: string; |
| |
64 | message: string; |
| |
65 | authorUsername: string; |
| |
66 | authorAvatar: string; |
| |
67 | }>; |
| |
68 | } |
web/src/utils/fetch-website-info.ts
added
+146
| @@ -0,0 +1,146 @@ |
| |
1 | |
| |
2 | export const fetchWebsiteInfo = async (url: string): Promise<WebsiteData | null> => { |
| |
3 | const endpoint = `https://site-info-fetch.as93.workers.dev/?url=${url}`; |
| |
4 | try { |
| |
5 | return await fetch(endpoint).then((res) => res.json()); |
| |
6 | } catch (error) { |
| |
7 | console.error('Error fetching website info:', error); |
| |
8 | return null; |
| |
9 | } |
| |
10 | }; |
| |
11 | |
| |
12 | interface DNSRecord { |
| |
13 | target: string; |
| |
14 | ip: string; |
| |
15 | country_code: string; |
| |
16 | country_name: string; |
| |
17 | isp: string; |
| |
18 | } |
| |
19 | |
| |
20 | interface DNSRecords { |
| |
21 | ns: { |
| |
22 | records: DNSRecord[]; |
| |
23 | }; |
| |
24 | mx: { |
| |
25 | records: DNSRecord[]; |
| |
26 | }; |
| |
27 | } |
| |
28 | |
| |
29 | interface Engine { |
| |
30 | name: string; |
| |
31 | reference: string; |
| |
32 | detected: boolean; |
| |
33 | } |
| |
34 | |
| |
35 | interface DomainBlacklist { |
| |
36 | engines: Engine[]; |
| |
37 | detections: number; |
| |
38 | } |
| |
39 | |
| |
40 | interface FileType { |
| |
41 | signature: string; |
| |
42 | extension: string; |
| |
43 | headers: string; |
| |
44 | } |
| |
45 | |
| |
46 | interface GeoLocation { |
| |
47 | countries: string[]; |
| |
48 | } |
| |
49 | |
| |
50 | interface HtmlForms { |
| |
51 | number_of_total_forms: number; |
| |
52 | number_of_total_input_fields: number; |
| |
53 | two_text_inputs_in_a_form: boolean; |
| |
54 | credit_card_field_present: boolean; |
| |
55 | password_field_present: boolean; |
| |
56 | email_field_present: boolean; |
| |
57 | } |
| |
58 | |
| |
59 | interface Redirection { |
| |
60 | found: boolean; |
| |
61 | external: boolean; |
| |
62 | url: string; |
| |
63 | redirects: any[]; |
| |
64 | } |
| |
65 | |
| |
66 | interface ResponseHeaders { |
| |
67 | code: number; |
| |
68 | status: string; |
| |
69 | date: string; |
| |
70 | last_modified: string; |
| |
71 | etag: string; |
| |
72 | accept_ranges: string; |
| |
73 | vary: string; |
| |
74 | content_encoding: string; |
| |
75 | cache_control: string; |
| |
76 | content_length: string; |
| |
77 | content_type: string; |
| |
78 | age: string; |
| |
79 | content_security_policy_report_only: string; |
| |
80 | strict_transport_security: string; |
| |
81 | public_key_pins_report_only: string; |
| |
82 | x_frame_options: string; |
| |
83 | x_content_type_options: string; |
| |
84 | x_xss_protection: string; |
| |
85 | referrer_policy: string; |
| |
86 | x_permitted_cross_domain_policies: string; |
| |
87 | onion_location: string; |
| |
88 | } |
| |
89 | |
| |
90 | interface RiskScore { |
| |
91 | result: number; |
| |
92 | } |
| |
93 | |
| |
94 | interface SecurityChecks { |
| |
95 | [key: string]: boolean | string; |
| |
96 | } |
| |
97 | |
| |
98 | interface ServerDetails { |
| |
99 | ip: string; |
| |
100 | hostname: string; |
| |
101 | continent_code: string; |
| |
102 | continent_name: string; |
| |
103 | country_code: string; |
| |
104 | country_name: string; |
| |
105 | region_name: string; |
| |
106 | city_name: string; |
| |
107 | latitude: number; |
| |
108 | longitude: number; |
| |
109 | isp: string; |
| |
110 | asn: string; |
| |
111 | } |
| |
112 | |
| |
113 | interface SiteCategory { |
| |
114 | [key: string]: boolean; |
| |
115 | } |
| |
116 | |
| |
117 | interface UrlParts { |
| |
118 | scheme: string; |
| |
119 | host: string; |
| |
120 | host_nowww: string; |
| |
121 | port: null | number; |
| |
122 | path: null | string; |
| |
123 | query: null | string; |
| |
124 | } |
| |
125 | |
| |
126 | interface WebPage { |
| |
127 | title: string; |
| |
128 | description: string; |
| |
129 | keywords: string; |
| |
130 | } |
| |
131 | |
| |
132 | export interface WebsiteData { |
| |
133 | dns_records: DNSRecords; |
| |
134 | domain_blacklist: DomainBlacklist; |
| |
135 | file_type: FileType; |
| |
136 | geo_location: GeoLocation; |
| |
137 | html_forms: HtmlForms; |
| |
138 | redirection: Redirection; |
| |
139 | response_headers: ResponseHeaders; |
| |
140 | risk_score: RiskScore; |
| |
141 | security_checks: SecurityChecks; |
| |
142 | server_details: ServerDetails; |
| |
143 | site_category: SiteCategory; |
| |
144 | url_parts: UrlParts; |
| |
145 | web_page: WebPage; |
| |
146 | } |