type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Create watermark profiles via basic upload
* Creates watermark profiles using a single `HTTP POST multipart/form-data` request.
*/
export async function main(
auth: Cloudflare,
account_identifier: string,
body: {
file: string;
name?: string;
opacity?: number;
padding?: number;
position?: string;
scale?: number;
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/stream/watermarks`
);
const formData = new FormData();
for (const [k, v] of Object.entries(body)) {
if (v !== undefined && v !== "") {
formData.append(k, String(v));
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: formData,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 337 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Create watermark profiles via basic upload
* Creates watermark profiles using a single `HTTP POST multipart/form-data` request.
*/
export async function main(auth: Cloudflare, account_identifier: string) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/stream/watermarks`
);
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 447 days ago