npm i @jvddavid/cloudflare-images
import CloudFlareImages from '@jvddavid/cloudflare-images';
const cloudflare = new CloudFlareImages({
accountId: 'account_id', // mandatory
token: 'token'
// OR
email: 'email',
key: 'key'
});
const { success, errors, messages, result } = await cloudflare.listImages({
page: 1,
perPage: 1000,
});
// example of result
const result = {
images: [
{
id: "aiofaosu7-13515135-jhsduy8173",
filename: "demo.jpg",
meta: { demo: "demo" },
requireSignedURLs: false,
uploaded: "2014-01-02T02:20:00.123Z",
variants: ["..."], // url of variants
},
],
};
const { success, errors, messages, result } = await cloudflare.listImagesV2({
perPage: 1000,
sortOrder: null,
continuationToken: null,
});
// example of result
const result = {
images: [
{
id: "aiofaosu7-13515135-jhsduy8173",
filename: "demo.jpg",
meta: { demo: "demo" },
requireSignedURLs: false,
uploaded: "2014-01-02T02:20:00.123Z",
variants: ["..."], // url of variants
},
],
continuation_token: "aispfahoshfao-asfibasi-safusaui",
};
const { success, errors, messages, result } = await cloudflare.stats();
// example of result
const result = {
count: {
allowed: 100000,
current: 15,
},
};
const { success, errors, messages, result } = await cloudflare.imageDetails(
"image_id"
);
// example of result
const result = {
id: "aiofaosu7-13515135-jhsduy8173",
filename: "demo.jpg",
meta: { demo: "demo" },
requireSignedURLs: false,
uploaded: "2014-01-02T02:20:00.123Z",
variants: ["..."], // url of variants
};
const { success, errors, messages, result } = await cloudflare.image(
"image_id"
);
// example of result
const result = "base64image"; // or null
const { success, errors, messages, result } = await cloudflare.uploadImage({
name: "image_name",
image: "image_base64" /* string or Buffer or Blob */,
metadata: { key: "value" },
requireSignedURLs: false,
});
// example result
const result = {
id: "aiofaosu7-13515135-jhsduy8173",
filename: "demo.jpg",
meta: { demo: "demo" },
requireSignedURLs: false,
uploaded: "2014-01-02T02:20:00.123Z",
variants: ["..."], // url of variants
};
const { success, errors, messages, result } = await cloudflare.uploadImageURL({
imageURL: "https://example.com/image.png",
metadata: { key: "value" },
requireSignedURLs: false,
});
// example result
const result = {
id: "aiofaosu7-13515135-jhsduy8173",
filename: "demo.jpg",
meta: { demo: "demo" },
requireSignedURLs: false,
uploaded: "2014-01-02T02:20:00.123Z",
variants: ["..."], // url of variants
};
const { success, errors, messages, result } = await cloudflare.updateImage({
imageId: "image_id",
metadata: { key: "value" },
requireSignedURLs: false,
});
// example result
const result = {
id: "aiofaosu7-13515135-jhsduy8173",
filename: "demo.jpg",
meta: { demo: "demo" },
requireSignedURLs: false,
uploaded: "2014-01-02T02:20:00.123Z",
variants: ["..."], // url of variants
};
const { success, errors, messages, result } = await cloudflare.deleteImage(
"image_id"
);
// result is empty
const success = true;
const { success, errors, messages, result } =
await cloudflare.directUploadUrlV2({
expiry: new Date(Date.now() + 1000 * 60 * 60 * 1),
metadata: { key: "value" },
requireSignedURLs: false,
});
// example of result
const result = {
id: "7gaf8asg8vba97vga-avba78fa",
uploadURL: "...",
};
const { success, errors, messages, result } =
await cloudflare.listSigningKeys();
// example of result
const result = {
keys: [
{
name: "default",
value: "...",
},
],
};
const { success, errors, messages, result } = await cloudflare.listVariants();
// example of result
const result = {
variants: {
hero: {
id: "hero",
neverRequireSignedURLs: true,
options: {
fit: "scale-down",
height: 768,
metadata: "none",
width: 1366,
},
},
},
};
const { success, errors, messages, result } = await cloudflare.variantDetails(
"variant_id"
);
// example of result
const result = {
id: "hero",
neverRequireSignedURLs: true,
options: {
fit: "scale-down",
height: 768,
metadata: "none",
width: 1366,
},
};
const { success, errors, messages, result } = await cloudflare.createVariant({
name: "variant_name",
options: { width: 100, height: 100, fit: "contain", metadata: "none" },
});
// example of result
const result = {
id: "hero",
neverRequireSignedURLs: true,
options: {
fit: "scale-down",
height: 768,
metadata: "none",
width: 1366,
},
};
const { success, errors, messages, result } = await cloudflare.updateVariant({
id: "variant_id",
options: { width: 100, height: 100, fit: "contain", metadata: "none" },
neverRequireSignedURLs: false,
});
// example of result
const result = {
id: "hero",
neverRequireSignedURLs: true,
options: {
fit: "scale-down",
height: 768,
metadata: "none",
width: 1366,
},
};
const { success, errors, messages, result } = await cloudflare.deleteVariant(
"variant_id"
);
// result is empty
const success = true;