@apillon/sdk
Version:
▶◀ Apillon SDK for NodeJS ▶◀
74 lines • 3.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Storage = void 0;
const apillon_1 = require("../../lib/apillon");
const apillon_api_1 = require("../../lib/apillon-api");
const common_1 = require("../../lib/common");
const storage_bucket_1 = require("./storage-bucket");
class Storage extends apillon_1.ApillonModule {
constructor() {
super(...arguments);
/**
* API url for storage.
*/
this.API_PREFIX = '/storage';
}
/**
* Creates a new storage bucket.
* @param data Data for creating the bucket.
* @returns A StorageBucket instance.
*/
async createBucket(data) {
const response = await apillon_api_1.ApillonApi.post(`${this.API_PREFIX}/buckets`, data);
return new storage_bucket_1.StorageBucket(response.bucketUuid, response);
}
/**
* Lists all buckets.
* @param {IApillonPagination} params Filter for listing collections.
* @returns Array of StorageBucket objects.
*/
async listBuckets(params) {
const url = (0, common_1.constructUrlWithQueryParams)(`${this.API_PREFIX}/buckets`, params);
const data = await apillon_api_1.ApillonApi.get(url);
return Object.assign(Object.assign({}, data), { items: data.items.map((bucket) => new storage_bucket_1.StorageBucket(bucket.bucketUuid, bucket)) });
}
/**
* @param uuid Unique bucket identifier.
* @returns An empty instance of StorageBucket.
*/
bucket(uuid) {
return new storage_bucket_1.StorageBucket(uuid);
}
/**
* Gets overall storage info for a project - available and used storage and bandwidth
* @returns {Promise<StorageInfo>}
*/
async getInfo() {
return await apillon_api_1.ApillonApi.get(`${this.API_PREFIX}/info`);
}
/**
* Gets basic data of an IPFS cluster used by the project.
*
* IPFS clusters contain multiple IPFS nodes but expose a single gateway for accessing content via CID or IPNS.
*
* Apillon clusters (gateways) are not publicly accessible
* @note Each project has its own secret for generating tokens to access content on the IPFS gateway.
* @returns {Promise<IpfsClusterInfo>}
*/
async getIpfsClusterInfo() {
return await apillon_api_1.ApillonApi.get(`${this.API_PREFIX}/ipfs-cluster-info`);
}
/**
* Apillon IPFS gateways are private and can only be accessible with a token.
* @docs [Generate an IPFS link](https://wiki.apillon.io/build/2-storage-api.html#get-or-generate-link-for-ipfs)
* @param {string} cid The CID or IPNS address of the fie
* @param {string} type The type of the link to generate based on the gateway. Can be 'ipfs' or 'ipns'.
* @returns {Promise<string>} The IPFS link where the requested content can be accessed.
*/
async generateIpfsLink(cid, type = 'ipfs') {
const { link } = await apillon_api_1.ApillonApi.get(`${this.API_PREFIX}/link-on-ipfs/${cid}?type=${type}`);
return link;
}
}
exports.Storage = Storage;
//# sourceMappingURL=storage.js.map