83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import type { Cloudly } from '../cloudly.classes.cloudly.js';
|
|
import * as plugins from '../cloudly.plugins.js';
|
|
|
|
import { Image } from './classes.image.js';
|
|
|
|
export class ImageManager {
|
|
cloudlyRef: Cloudly;
|
|
get db() {
|
|
return this.cloudlyRef.mongodbConnector.smartdataDb;
|
|
}
|
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
|
|
|
public CImage = plugins.smartdata.setDefaultManagerForDoc(this, Image);
|
|
|
|
smartbucketInstance: plugins.smartbucket.SmartBucket;
|
|
|
|
constructor(cloudlyRefArg: Cloudly) {
|
|
this.cloudlyRef = cloudlyRefArg;
|
|
|
|
this.cloudlyRef.typedrouter.addTypedRouter(this.typedrouter);
|
|
this.typedrouter.addTypedHandler(
|
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.image.IRequest_GetAllImages>(
|
|
'getAllImages',
|
|
async (requestArg) => {
|
|
const images = await this.CImage.getInstances({});
|
|
return {
|
|
images: await Promise.all(
|
|
images.map((image) => {
|
|
return image.createSavableObject();
|
|
})
|
|
),
|
|
};
|
|
}
|
|
)
|
|
);
|
|
|
|
this.typedrouter.addTypedHandler(
|
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.image.IRequest_CreateImage>(
|
|
'createImage',
|
|
async (reqArg) => {
|
|
const image = await this.CImage.create({
|
|
name: reqArg.name,
|
|
});
|
|
return {
|
|
image: await image.createSavableObject(),
|
|
};
|
|
}
|
|
)
|
|
);
|
|
|
|
this.typedrouter.addTypedHandler(
|
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.image.IRequest_DownloadImage>(
|
|
'pullImage',
|
|
async (reqArg) => {
|
|
const image = await this.CImage.getInstance({
|
|
data: {
|
|
name: reqArg.name,
|
|
}
|
|
});
|
|
const imageVersion =
|
|
}
|
|
)
|
|
);
|
|
}
|
|
|
|
public async start() {
|
|
const s3Descriptor: plugins.tsclass.storage.IS3Descriptor =
|
|
await this.cloudlyRef.config.appData.waitForAndGetKey('s3Descriptor');
|
|
console.log(this.cloudlyRef.config.data.s3Descriptor);
|
|
this.smartbucketInstance = new plugins.smartbucket.SmartBucket(
|
|
this.cloudlyRef.config.data.s3Descriptor
|
|
);
|
|
const bucket = await this.smartbucketInstance.getBucketByName('cloudly-test');
|
|
await bucket.fastStore('test/test.txt', 'hello');
|
|
}
|
|
|
|
public async createImage(nameArg: string) {
|
|
const newImage = await this.CImage.create({
|
|
name: nameArg,
|
|
});
|
|
}
|
|
}
|