1+ import type { Id } from '../id.js' ;
12import { Image } from '../image.js' ;
23import { uploadImage } from '../ipfs.js' ;
34import type { CreateResult , Op } from '../types.js' ;
@@ -7,11 +8,13 @@ type CreateImageParams =
78 blob : Blob ;
89 name ?: string ;
910 description ?: string ;
11+ id ?: Id ;
1012 }
1113 | {
1214 url : string ;
1315 name ?: string ;
1416 description ?: string ;
17+ id ?: Id ;
1518 } ;
1619
1720/**
@@ -25,22 +28,24 @@ type CreateImageParams =
2528 * url: 'https://example.com/image.png',
2629 * name: 'name of the image', // optional
2730 * description: 'description of the image', // optional
31+ * id: imageId, // optional and will be generated if not provided
2832 * });
2933 *
3034 * const { id, ops } = createImage({
3135 * blob: new Blob(…),
3236 * name: 'name of the image', // optional
3337 * description: 'description of the image', // optional
38+ * id: imageId, // optional and will be generated if not provided
3439 * });
3540 * ```
3641 * @param params – {@link CreateImageParams}
3742 * @returns – {@link CreateResult}
3843 * @throws Will throw an IpfsUploadError if the image cannot be uploaded to IPFS
3944 */
40- export const createImage = async ( { name, description, ...params } : CreateImageParams ) : Promise < CreateResult > => {
45+ export const createImage = async ( { name, description, id : providedId , ...params } : CreateImageParams ) : Promise < CreateResult > => {
4146 const ops : Array < Op > = [ ] ;
4247 const { cid, dimensions } = await uploadImage ( params ) ;
43- const { id, ops : imageOps } = Image . make ( { cid, dimensions } ) ;
48+ const { id, ops : imageOps } = Image . make ( { cid, dimensions, id : providedId } ) ;
4449 ops . push ( ...imageOps ) ;
4550 ops . push ( ...createDefaultProperties ( { entityId : id , name, description } ) ) ;
4651
0 commit comments