type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Change variants setting
* Variant support enables caching variants of images with certain file extensions in addition to the original. This only applies when the origin server sends the 'Vary: Accept' response header. If the origin server sends 'Vary: Accept' but does not serve the variant requested, the response will not be cached. This will be indicated with BYPASS cache status in the response headers.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
body: {
value: {
avif?: unknown[];
bmp?: unknown[];
gif?: unknown[];
jp2?: unknown[];
jpeg?: unknown[];
jpg?: unknown[];
jpg2?: unknown[];
png?: unknown[];
tif?: unknown[];
tiff?: unknown[];
webp?: unknown[];
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/cache/variants`
);
const response = await fetch(url, {
method: "PATCH",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Change variants setting
* Variant support enables caching variants of images with certain file extensions in addition to the original. This only applies when the origin server sends the 'Vary: Accept' response header. If the origin server sends 'Vary: Accept' but does not serve the variant requested, the response will not be cached. This will be indicated with BYPASS cache status in the response headers.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
body: {
value: {
avif?: unknown[];
bmp?: unknown[];
gif?: unknown[];
jp2?: unknown[];
jpeg?: unknown[];
jpg?: unknown[];
jpg2?: unknown[];
png?: unknown[];
tif?: unknown[];
tiff?: unknown[];
webp?: unknown[];
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/cache/variants`
);
const response = await fetch(url, {
method: "PATCH",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 920 days ago