Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cloudflare/internal/images.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ interface ImageListOptions {
creator?: string;
}

interface ImageSignedUrlOptions {
variant: string;
expiresIn?: number;
keyName?: string;
}

interface ImageList {
images: ImageMetadata[];
cursor?: string;
Expand All @@ -166,6 +172,14 @@ interface ImageHandle {
*/
bytes(): Promise<ReadableStream<Uint8Array> | null>;

/**
* Generate a signed delivery URL for this hosted image.
* @param options Signing configuration
* @returns A signed image delivery URL
* @throws {@link ImagesError} if signing fails
*/
signedUrl(options: ImageSignedUrlOptions): Promise<string>;

/**
* Update hosted image metadata
* @param options Properties to update
Expand Down
17 changes: 17 additions & 0 deletions src/cloudflare/internal/test/images/images-api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,23 @@ export const test_images_getImage_not_found = {
},
};

export const test_images_signed_url = {
/**
* @param {unknown} _
* @param {Env} env
*/
async test(_, env) {
const url = await env.images.hosted
.image('test-image-id')
.signedUrl({ variant: 'private' });

assert.equal(
url,
'https://imagedelivery.example/test-image-id/private?sig=mock-signature'
);
},
};

// UPLOAD
export const test_images_upload_with_options = {
/**
Expand Down
4 changes: 4 additions & 0 deletions src/cloudflare/internal/test/images/images-upstream-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class ImageHandleMock extends RpcTarget {
return new Blob([mockData]).stream();
}

async signedUrl(options) {
return `https://imagedelivery.example/${this.#imageId}/${options.variant}?sig=mock-signature`;
}

/**
* @param {ImageUpdateOptions} body
* @returns {Promise<ImageMetadata>}
Expand Down
14 changes: 14 additions & 0 deletions types/defines/images.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ interface ImageListOptions {
creator?: string;
}

interface ImageSignedUrlOptions {
variant: string;
expiresIn?: number;
keyName?: string;
}

interface ImageList {
images: ImageMetadata[];
cursor?: string;
Expand All @@ -163,6 +169,14 @@ interface ImageHandle {
*/
bytes(): Promise<ReadableStream<Uint8Array> | null>;

/**
* Generate a signed delivery URL for this hosted image.
* @param options Signing configuration
* @returns A signed image delivery URL
* @throws {@link ImagesError} if signing fails
*/
signedUrl(options: ImageSignedUrlOptions): Promise<string>;

/**
* Update hosted image metadata
* @param options Properties to update
Expand Down
12 changes: 12 additions & 0 deletions types/generated-snapshot/experimental/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14696,6 +14696,11 @@ interface ImageListOptions {
sortOrder?: "asc" | "desc";
creator?: string;
}
interface ImageSignedUrlOptions {
variant: string;
expiresIn?: number;
keyName?: string;
}
interface ImageList {
images: ImageMetadata[];
cursor?: string;
Expand All @@ -14712,6 +14717,13 @@ interface ImageHandle {
* @returns ReadableStream of image bytes, or null if not found
*/
bytes(): Promise<ReadableStream<Uint8Array> | null>;
/**
* Generate a signed delivery URL for this hosted image.
* @param options Signing configuration
* @returns A signed image delivery URL
* @throws {@link ImagesError} if signing fails
*/
signedUrl(options: ImageSignedUrlOptions): Promise<string>;
/**
* Update hosted image metadata
* @param options Properties to update
Expand Down
12 changes: 12 additions & 0 deletions types/generated-snapshot/experimental/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14719,6 +14719,11 @@ export interface ImageListOptions {
sortOrder?: "asc" | "desc";
creator?: string;
}
export interface ImageSignedUrlOptions {
variant: string;
expiresIn?: number;
keyName?: string;
}
export interface ImageList {
images: ImageMetadata[];
cursor?: string;
Expand All @@ -14735,6 +14740,13 @@ export interface ImageHandle {
* @returns ReadableStream of image bytes, or null if not found
*/
bytes(): Promise<ReadableStream<Uint8Array> | null>;
/**
* Generate a signed delivery URL for this hosted image.
* @param options Signing configuration
* @returns A signed image delivery URL
* @throws {@link ImagesError} if signing fails
*/
signedUrl(options: ImageSignedUrlOptions): Promise<string>;
/**
* Update hosted image metadata
* @param options Properties to update
Expand Down
12 changes: 12 additions & 0 deletions types/generated-snapshot/latest/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14048,6 +14048,11 @@ interface ImageListOptions {
sortOrder?: "asc" | "desc";
creator?: string;
}
interface ImageSignedUrlOptions {
variant: string;
expiresIn?: number;
keyName?: string;
}
interface ImageList {
images: ImageMetadata[];
cursor?: string;
Expand All @@ -14064,6 +14069,13 @@ interface ImageHandle {
* @returns ReadableStream of image bytes, or null if not found
*/
bytes(): Promise<ReadableStream<Uint8Array> | null>;
/**
* Generate a signed delivery URL for this hosted image.
* @param options Signing configuration
* @returns A signed image delivery URL
* @throws {@link ImagesError} if signing fails
*/
signedUrl(options: ImageSignedUrlOptions): Promise<string>;
/**
* Update hosted image metadata
* @param options Properties to update
Expand Down
12 changes: 12 additions & 0 deletions types/generated-snapshot/latest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14071,6 +14071,11 @@ export interface ImageListOptions {
sortOrder?: "asc" | "desc";
creator?: string;
}
export interface ImageSignedUrlOptions {
variant: string;
expiresIn?: number;
keyName?: string;
}
export interface ImageList {
images: ImageMetadata[];
cursor?: string;
Expand All @@ -14087,6 +14092,13 @@ export interface ImageHandle {
* @returns ReadableStream of image bytes, or null if not found
*/
bytes(): Promise<ReadableStream<Uint8Array> | null>;
/**
* Generate a signed delivery URL for this hosted image.
* @param options Signing configuration
* @returns A signed image delivery URL
* @throws {@link ImagesError} if signing fails
*/
signedUrl(options: ImageSignedUrlOptions): Promise<string>;
/**
* Update hosted image metadata
* @param options Properties to update
Expand Down
Loading