0
Upload asset file
One script reply has been approved by the moderators Verified
Created by hugo697 40 days ago Viewed 5 times
0
Submitted by hugo697 Bun
Verified 40 days ago
1
//native
2
type Actimo = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Actimo,
8
	width: string | undefined,
9
	height: string | undefined,
10
	crop: string | undefined,
11
	x2: string | undefined,
12
	body: { files?: string[]; path?: string; youtube?: number }
13
) {
14
	const url = new URL(`https://actimo.com/api/v1/assets/`)
15

16
	for (const [k, v] of [
17
		['width', width],
18
		['height', height],
19
		['crop', crop],
20
		['x2', x2]
21
	]) {
22
		if (v !== undefined && v !== '' && k !== undefined) {
23
			url.searchParams.append(k, v)
24
		}
25
	}
26

27
	const formData = new FormData()
28

29
	for (const [k, v] of Object.entries(body)) {
30
		if (v !== undefined && v !== '') {
31
			formData.append(k, String(v))
32
		}
33
	}
34

35
	const response = await fetch(url, {
36
		method: 'POST',
37
		headers: {
38
			'api-key': auth.apiKey
39
		},
40
		body: formData
41
	})
42

43
	if (!response.ok) {
44
		const text = await response.text()
45
		throw new Error(`${response.status} ${text}`)
46
	}
47

48
	return await response.json()
49
}
50