0
Get posts calendar
One script reply has been approved by the moderators Verified
Created by hugo697 223 days ago Viewed 13488 times
0
Submitted by hugo697 Bun
Verified 223 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
	postStatus:
10
		| 'ALL'
11
		| 'DRAFT'
12
		| 'PLANNED'
13
		| 'PUBLISHED'
14
		| 'IN_REVIEW'
15
		| 'MANUALLY_ACTIVATING'
16
		| 'TRANSLATION_IN_PROGRESS'
17
		| 'TRANSLATION_COMPLETED'
18
		| 'NON_PUBLISHED'
19
		| undefined,
20
	start: string | undefined,
21
	end: string | undefined,
22
	subtenantId: string | undefined,
23
	groupId: string | undefined,
24
	tagIds: string | undefined,
25
	topicIds: string | undefined,
26
	channels: string | undefined,
27
	adhookToken: string,
28
	Origin: string
29
) {
30
	const url = new URL(`https://app.adhook.io/v1/posts/calendar`)
31

32
	for (const [k, v] of [
33
		['filter', filter],
34
		['postStatus', postStatus],
35
		['start', start],
36
		['end', end],
37
		['subtenantId', subtenantId],
38
		['groupId', groupId],
39
		['tagIds', tagIds],
40
		['topicIds', topicIds],
41
		['channels', channels]
42
	]) {
43
		if (v !== undefined && v !== '' && k !== undefined) {
44
			url.searchParams.append(k, v)
45
		}
46
	}
47

48
	const response = await fetch(url, {
49
		method: 'GET',
50
		headers: {
51
			adhookToken: adhookToken,
52
			Authorization: `Bearer ${auth.token}`,
53
			Origin: Origin
54
		},
55
		body: undefined
56
	})
57

58
	if (!response.ok) {
59
		const text = await response.text()
60
		throw new Error(`${response.status} ${text}`)
61
	}
62

63
	return await response.json()
64
}
65