clodynix
Version:
Clodynix is a modern, efficient, and developer-friendly CDN package offering seamless content delivery with an intuitive dashboard and comprehensive documentation. Simplify your content delivery with Clodynix's powerful and scalable platform.
216 lines (213 loc) • 6.26 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
Clodynix: () => clodynix_default
});
module.exports = __toCommonJS(index_exports);
// src/functions/clodynix.ts
var import_axios = __toESM(require("axios"));
var Clodynix = class {
apiKey;
origin;
secret;
constructor({
apiKey,
origin,
secret
}) {
this.apiKey = apiKey;
this.origin = origin;
this.secret = secret;
}
getAuthToken() {
return this.apiKey;
}
getOriginLink() {
return this.origin;
}
getSecret() {
return this.secret;
}
async checkFileInfo(fileId, token) {
try {
const res = await import_axios.default.get(`${this.getOriginLink()}/v2/file/info/client`, {
headers: {
Authorization: this.getAuthToken(),
Secret: this.getSecret()
},
data: { fileId, token }
});
if (res.status !== 200) throw new Error(res.data);
return res.data.data;
} catch (error) {
throw new Error(error.message);
}
}
async registerFile(token) {
try {
const res = await import_axios.default.post(
`${this.getOriginLink()}/v2/file/register`,
{ token },
{
headers: {
Authorization: this.getAuthToken(),
Secret: this.getSecret()
}
}
);
if (res.status !== 200) throw new Error(res.data);
return res.data.data;
} catch (error) {
throw new Error(error.message);
}
}
async uploadByLink(link) {
try {
const res = await import_axios.default.put(
`${this.getOriginLink()}/v2/file/upload/link`,
{ link },
{
headers: {
Authorization: this.getAuthToken(),
Secret: this.getSecret()
}
}
);
if (res.status !== 200) throw new Error(res.data);
return res.data.data;
} catch (error) {
throw new Error(error.message);
}
}
async createUploadToken(totalChunks, fileData) {
try {
const res = await import_axios.default.post(
`${this.getOriginLink()}/v2/file/upload/token/create`,
{ totalChunks, fileData },
{
headers: {
Authorization: this.getAuthToken(),
Secret: this.getSecret()
}
}
);
if (res.status !== 200) throw new Error(res.data);
return res.data.data;
} catch (error) {
throw new Error(error.message);
}
}
async deleteFile(fileId) {
try {
const res = await import_axios.default.delete(`${this.getOriginLink()}/v2/file/delete`, {
headers: {
Authorization: this.getAuthToken(),
Secret: this.getSecret()
},
data: { fileId }
});
if (res.status !== 200) throw new Error(res.data);
return res.data.data;
} catch (error) {
throw new Error(error.message);
}
}
async generateLink(fileId) {
try {
const res = await import_axios.default.post(
`${this.getOriginLink()}/v2/link/single/create`,
{ fileId },
{
headers: {
Authorization: this.getAuthToken(),
Secret: this.getSecret()
}
}
);
if (res.status !== 200) throw new Error(res.data);
return res.data.data;
} catch (error) {
throw new Error(error.message);
}
}
async generateLinksBatch(fileIds) {
try {
const res = await import_axios.default.post(
`${this.getOriginLink()}/v2/link/batch/create`,
{ fileIds },
{
headers: {
Authorization: this.getAuthToken(),
Secret: this.getSecret()
}
}
);
if (res.status !== 200) throw new Error(res.data);
return res.data.data;
} catch (error) {
throw new Error(error.message);
}
}
async uploadDirect(formdata) {
try {
const file = formdata.get("file");
const fileBuffer = await file.arrayBuffer();
const blob = new Blob([fileBuffer]);
const form = new FormData();
const fileData = {
name: file.name.split(".").shift() || "",
extention: file.name.split(".").pop() || "",
size: file.size
};
form.append("fileData", JSON.stringify(fileData));
form.append("file", blob);
const res = await import_axios.default.put(
`${this.getOriginLink()}/v2/file/upload/direct`,
form,
{
headers: {
Authorization: this.getAuthToken(),
Secret: this.getSecret()
}
}
);
if (res.status !== 200) throw new Error(res.data);
return res.data.data;
} catch (error) {
throw new Error(error.message);
}
}
};
var clodynix_default = Clodynix;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Clodynix
});