0

Fetch Files

by
Published Nov 5, 2024

Fetches Files.

Script motimate Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Motimate = {
3
	token: string
4
}
5

6
export async function main(auth: Motimate, filter_created_at_lteq_: string | undefined) {
7
	const url = new URL(`https://motimateapp.com/public_api/files`)
8

9
	for (const [k, v] of [['filter[created_at_lteq]', filter_created_at_lteq_]]) {
10
		if (v !== undefined && v !== '' && k !== undefined) {
11
			url.searchParams.append(k, v)
12
		}
13
	}
14

15
	const response = await fetch(url, {
16
		method: 'GET',
17
		headers: {
18
			Authorization: 'Bearer ' + auth.token
19
		}
20
	})
21

22
	if (!response.ok) {
23
		const text = await response.text()
24
		throw new Error(`${response.status} ${text}`)
25
	}
26

27
	return await response.json()
28
}
29