2024-06-05 12:13:03 +00:00
|
|
|
import type { CloudlyApiClient } from './classes.cloudlyapiclient.js';
|
2024-04-20 10:21:41 +00:00
|
|
|
import * as plugins from './plugins.js';
|
|
|
|
|
2024-06-02 19:39:31 +00:00
|
|
|
export class Image implements plugins.servezoneInterfaces.data.IImage {
|
2024-06-05 12:13:03 +00:00
|
|
|
public static async getImages(cloudlyClientRef: CloudlyApiClient) {
|
2024-06-02 19:39:31 +00:00
|
|
|
const getAllImagesTR = cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_GetAllImages>(
|
|
|
|
'getAllImages'
|
|
|
|
);
|
|
|
|
const response = await getAllImagesTR.fire({
|
2024-08-25 12:29:26 +00:00
|
|
|
identity: cloudlyClientRef.identity,
|
2024-06-02 19:39:31 +00:00
|
|
|
});
|
|
|
|
const resultImages: Image[] = [];
|
|
|
|
for (const image of response.images) {
|
|
|
|
const newImage = new Image(cloudlyClientRef);
|
|
|
|
Object.assign(newImage, image);
|
|
|
|
resultImages.push(newImage);
|
|
|
|
}
|
|
|
|
return resultImages;
|
2024-06-01 03:48:57 +00:00
|
|
|
}
|
2024-06-02 19:39:31 +00:00
|
|
|
|
2024-11-18 18:52:15 +00:00
|
|
|
public static async getImageById(cloudlyClientRef: CloudlyApiClient, imageIdArg: string) {
|
|
|
|
const getImageByIdTR = cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_GetImage>(
|
|
|
|
'getImage'
|
|
|
|
);
|
|
|
|
const response = await getImageByIdTR.fire({
|
|
|
|
identity: cloudlyClientRef.identity,
|
|
|
|
imageId: imageIdArg,
|
|
|
|
});
|
|
|
|
const newImage = new Image(cloudlyClientRef);
|
|
|
|
Object.assign(newImage, response.image);
|
|
|
|
return newImage;
|
|
|
|
}
|
|
|
|
|
2024-08-25 12:29:26 +00:00
|
|
|
/**
|
|
|
|
* creates a new image
|
|
|
|
*/
|
|
|
|
public static async createImage(cloudlyClientRef: CloudlyApiClient, imageDataArg: Partial<plugins.servezoneInterfaces.data.IImage['data']>) {
|
|
|
|
const createImageTR = cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_CreateImage>(
|
|
|
|
'createImage'
|
|
|
|
);
|
|
|
|
const response = await createImageTR.fire({
|
|
|
|
identity: cloudlyClientRef.identity,
|
|
|
|
name: imageDataArg.name,
|
|
|
|
description: imageDataArg.description,
|
|
|
|
});
|
|
|
|
const newImage = new Image(cloudlyClientRef);
|
|
|
|
Object.assign(newImage, response.image);
|
|
|
|
return newImage;
|
|
|
|
}
|
|
|
|
|
2024-06-02 19:39:31 +00:00
|
|
|
// INSTANCE
|
2024-06-05 12:13:03 +00:00
|
|
|
cloudlyClientRef: CloudlyApiClient;
|
2024-06-02 19:39:31 +00:00
|
|
|
|
|
|
|
id: plugins.servezoneInterfaces.data.IImage['id'];
|
|
|
|
data: plugins.servezoneInterfaces.data.IImage['data'];
|
|
|
|
|
2024-06-05 12:13:03 +00:00
|
|
|
constructor(cloudlyClientRef: CloudlyApiClient) {
|
2024-06-02 19:39:31 +00:00
|
|
|
this.cloudlyClientRef = cloudlyClientRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* updates the image data
|
|
|
|
*/
|
|
|
|
public async update() {
|
2024-10-16 12:35:38 +00:00
|
|
|
const getVersionsTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_GetImage>(
|
|
|
|
'getImage'
|
2024-06-02 19:39:31 +00:00
|
|
|
);
|
|
|
|
const response = await getVersionsTR.fire({
|
2024-08-25 12:29:26 +00:00
|
|
|
identity: this.cloudlyClientRef.identity,
|
2024-06-02 19:39:31 +00:00
|
|
|
imageId: this.id,
|
|
|
|
});
|
|
|
|
Object.assign(this, response.image);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pushes a new version of the image
|
|
|
|
* @param imageVersion
|
|
|
|
* @param imageReadableArg
|
|
|
|
*/
|
|
|
|
public async pushImageVersion(imageVersion: string, imageReadableArg: ReadableStream<Uint8Array>): Promise<void> {
|
|
|
|
const done = plugins.smartpromise.defer();
|
2024-10-16 12:35:38 +00:00
|
|
|
const pushImageTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_PushImageVersion>(
|
2024-06-02 19:39:31 +00:00
|
|
|
'pushImageVersion'
|
|
|
|
);
|
|
|
|
const virtualStream = new plugins.typedrequest.VirtualStream();
|
2024-10-16 12:35:38 +00:00
|
|
|
const response = await pushImageTR.fire({
|
2024-08-25 12:29:26 +00:00
|
|
|
identity: this.cloudlyClientRef.identity,
|
2024-06-02 19:39:31 +00:00
|
|
|
imageId: this.id,
|
|
|
|
versionString: '',
|
|
|
|
imageStream: virtualStream,
|
|
|
|
});
|
|
|
|
await virtualStream.readFromWebstream(imageReadableArg);
|
|
|
|
await this.update();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pulls a version of the image
|
|
|
|
*/
|
|
|
|
public async pullImageVersion(versionStringArg: string): Promise<ReadableStream<Uint8Array>> {
|
|
|
|
const pullImageTR = this.cloudlyClientRef.typedsocketClient.createTypedRequest<plugins.servezoneInterfaces.requests.image.IRequest_PullImageVersion>(
|
|
|
|
'pullImageVersion'
|
|
|
|
);
|
|
|
|
const response = await pullImageTR.fire({
|
2024-08-25 12:29:26 +00:00
|
|
|
identity: this.cloudlyClientRef.identity,
|
2024-06-02 19:39:31 +00:00
|
|
|
imageId: this.id,
|
|
|
|
versionString: versionStringArg,
|
|
|
|
});
|
|
|
|
const imageStream = response.imageStream;
|
|
|
|
const webduplexStream = new plugins.webstream.WebDuplexStream({});
|
|
|
|
imageStream.writeToWebstream(webduplexStream.writable);
|
|
|
|
return webduplexStream.readable;
|
|
|
|
};
|
|
|
|
}
|