0
Create media item from recording
One script reply has been approved by the moderators Verified
Created by hugo697 2 days ago Viewed 0 times
0
Submitted by hugo697 Bun
Verified 2 days ago
1
//native
2
type Actimo = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Actimo,
8
	body: {
9
		files?: { audio?: string; video?: string }
10
		path?: string
11
		youtube?: number
12
	}
13
) {
14
	const url = new URL(`https://actimo.com/api/v1/media/record`)
15

16
	const formData = new FormData()
17

18
	for (const [k, v] of Object.entries(body)) {
19
		if (v !== undefined && v !== '') {
20
			formData.append(k, String(v))
21
		}
22
	}
23

24
	const response = await fetch(url, {
25
		method: 'POST',
26
		headers: {
27
			'api-key': auth.apiKey
28
		},
29
		body: formData
30
	})
31

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

37
	return await response.json()
38
}
39