0
Search pages
One script reply has been approved by the moderators Verified
Created by hugo697 16 days ago Viewed 1456 times
0
Submitted by hugo697 Bun
Verified 16 days ago
1
//native
2
type Adhook = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Adhook,
8
	q: string | undefined,
9
	adhookToken: string,
10
	Origin: string
11
) {
12
	const url = new URL(`https://app.adhook.io/v1/promotions/facebook/pages/search`)
13

14
	for (const [k, v] of [['q', q]]) {
15
		if (v !== undefined && v !== '' && k !== undefined) {
16
			url.searchParams.append(k, v)
17
		}
18
	}
19

20
	const response = await fetch(url, {
21
		method: 'GET',
22
		headers: {
23
			adhookToken: adhookToken,
24
			Authorization: `Bearer ${auth.token}`,
25
			Origin: Origin
26
		},
27
		body: undefined
28
	})
29

30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34

35
	return await response.json()
36
}
37