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

6
export async function main(
7
	auth: Adhook,
8
	filter: string | undefined,
9
	skip: string | undefined,
10
	limit: string | undefined,
11
	start: string | undefined,
12
	end: string | undefined,
13
	subtenantId: string | undefined,
14
	groupId: string | undefined,
15
	tagIds: string | undefined,
16
	topicIds: string | undefined,
17
	channels: string | undefined,
18
	postStatus:
19
		| 'ALL'
20
		| 'DRAFT'
21
		| 'PLANNED'
22
		| 'PUBLISHED'
23
		| 'IN_REVIEW'
24
		| 'MANUALLY_ACTIVATING'
25
		| 'TRANSLATION_IN_PROGRESS'
26
		| 'TRANSLATION_COMPLETED'
27
		| 'NON_PUBLISHED'
28
		| undefined,
29
	orderKey: string | undefined,
30
	reverseOrder: string | undefined,
31
	Origin: string
32
) {
33
	const url = new URL(`https://app.adhook.io/v1/posts`)
34

35
	for (const [k, v] of [
36
		['filter', filter],
37
		['skip', skip],
38
		['limit', limit],
39
		['start', start],
40
		['end', end],
41
		['subtenantId', subtenantId],
42
		['groupId', groupId],
43
		['tagIds', tagIds],
44
		['topicIds', topicIds],
45
		['channels', channels],
46
		['postStatus', postStatus],
47
		['orderKey', orderKey],
48
		['reverseOrder', reverseOrder]
49
	]) {
50
		if (v !== undefined && v !== '' && k !== undefined) {
51
			url.searchParams.append(k, v)
52
		}
53
	}
54

55
	const response = await fetch(url, {
56
		method: 'GET',
57
		headers: {
58
			Authorization: `Bearer ${auth.token}`,
59
			Origin: Origin
60
		},
61
		body: undefined
62
	})
63

64
	if (!response.ok) {
65
		const text = await response.text()
66
		throw new Error(`${response.status} ${text}`)
67
	}
68

69
	return await response.json()
70
}
71