@apillon/sdk
Version:
▶◀ Apillon SDK for NodeJS ▶◀
82 lines • 2.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.File = void 0;
const apillon_1 = require("../../lib/apillon");
const apillon_api_1 = require("../../lib/apillon-api");
const apillon_logger_1 = require("../../lib/apillon-logger");
const storage_1 = require("../../types/storage");
class File extends apillon_1.ApillonModel {
/**
* Constructor which should only be called via StorageBucket class.
* @param bucketUuid Unique identifier of the file's bucket.
* @param directoryUuid Unique identifier of the file's directory.
* @param fileUuid Unique identifier of the file.
* @param data Data to populate the directory with.
*/
constructor(bucketUuid, directoryUuid, fileUuid, data) {
super(fileUuid);
/**
* Unique identifier of the file's bucket.
*/
this.bucketUuid = null;
/**
* Unique identifier of the directory in which the file resides.
*/
this.directoryUuid = null;
/**
* File name.
*/
this.name = null;
/**
* File unique IPFS content identifier.
*/
this.CID = null;
/**
* File upload status.
*/
this.status = null;
/**
* Type of content.
*/
this.type = storage_1.StorageContentType.FILE;
/**
* Link on IPFS gateway.
*/
this.link = null;
/**
* Full path to file.
*/
this.path = null;
this.bucketUuid = bucketUuid;
this.directoryUuid = directoryUuid;
this.API_PREFIX = `/storage/buckets/${bucketUuid}/files/${fileUuid}`;
this.status = data === null || data === void 0 ? void 0 : data.fileStatus;
this.populate(data);
}
/**
* Gets file details.
* @returns File instance
*/
async get() {
const data = await apillon_api_1.ApillonApi.get(this.API_PREFIX);
this.status = data.fileStatus;
return this.populate(data);
}
/**
* Deletes a file from the bucket.
*/
async delete() {
await apillon_api_1.ApillonApi.delete(this.API_PREFIX);
apillon_logger_1.ApillonLogger.log('File deleted successfully');
}
serializeFilter(key, value) {
const serialized = super.serializeFilter(key, value);
const enums = {
status: storage_1.FileStatus[value],
type: storage_1.StorageContentType[value],
};
return Object.keys(enums).includes(key) ? enums[key] : serialized;
}
}
exports.File = File;
//# sourceMappingURL=file.js.map