0
List videos
One script reply has been approved by the moderators Verified

Lists up to 1000 videos from a single request. For a specific range, refer to the optional parameters.

Created by hugo697 151 days ago Viewed 3716 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 151 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * List videos
8
 * Lists up to 1000 videos from a single request. For a specific range, refer to the optional parameters.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  account_identifier: string,
13
  status:
14
    | "pendingupload"
15
    | "downloading"
16
    | "queued"
17
    | "inprogress"
18
    | "ready"
19
    | "error"
20
    | undefined,
21
  creator: string | undefined,
22
  type: string | undefined,
23
  asc: string | undefined,
24
  search: string | undefined,
25
  start: string | undefined,
26
  end: string | undefined,
27
  include_counts: string | undefined
28
) {
29
  const url = new URL(
30
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/stream`
31
  );
32
  for (const [k, v] of [
33
    ["status", status],
34
    ["creator", creator],
35
    ["type", type],
36
    ["asc", asc],
37
    ["search", search],
38
    ["start", start],
39
    ["end", end],
40
    ["include_counts", include_counts],
41
  ]) {
42
    if (v !== undefined && v !== "") {
43
      url.searchParams.append(k, v);
44
    }
45
  }
46
  const response = await fetch(url, {
47
    method: "GET",
48
    headers: {
49
      "X-AUTH-EMAIL": auth.email,
50
      "X-AUTH-KEY": auth.key,
51
      Authorization: "Bearer " + auth.token,
52
    },
53
    body: undefined,
54
  });
55
  if (!response.ok) {
56
    const text = await response.text();
57
    throw new Error(`${response.status} ${text}`);
58
  }
59
  return await response.json();
60
}
61