1 | |
2 | type Shutterstock = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List sound effects licenses |
7 | * This endpoint lists existing licenses. |
8 | */ |
9 | export async function main( |
10 | auth: Shutterstock, |
11 | sfx_id: string | undefined, |
12 | license: string | undefined, |
13 | page: string | undefined, |
14 | per_page: string | undefined, |
15 | sort: "newest" | "oldest" | undefined, |
16 | username: string | undefined, |
17 | start_date: string | undefined, |
18 | end_date: string | undefined, |
19 | license_id: string | undefined, |
20 | download_availability: |
21 | | "all" |
22 | | "downloadable" |
23 | | "non_downloadable" |
24 | | undefined, |
25 | team_history: string | undefined, |
26 | ) { |
27 | const url = new URL(`https://api.shutterstock.com/v2/sfx/licenses`); |
28 | for (const [k, v] of [ |
29 | ["sfx_id", sfx_id], |
30 | ["license", license], |
31 | ["page", page], |
32 | ["per_page", per_page], |
33 | ["sort", sort], |
34 | ["username", username], |
35 | ["start_date", start_date], |
36 | ["end_date", end_date], |
37 | ["license_id", license_id], |
38 | ["download_availability", download_availability], |
39 | ["team_history", team_history], |
40 | ]) { |
41 | if (v !== undefined && v !== "" && k !== undefined) { |
42 | url.searchParams.append(k, v); |
43 | } |
44 | } |
45 | const response = await fetch(url, { |
46 | method: "GET", |
47 | headers: { |
48 | Authorization: "Bearer " + auth.token, |
49 | }, |
50 | body: undefined, |
51 | }); |
52 | if (!response.ok) { |
53 | const text = await response.text(); |
54 | throw new Error(`${response.status} ${text}`); |
55 | } |
56 | return await response.json(); |
57 | } |
58 |
|