UNPKG

cloudapp-dl

Version:

CloudApp/Zight API client and CLI. Use as a CLI tool to download videos or as a programmatic library to interact with the Zight API.

214 lines (171 loc) 5.26 kB
/** * CommonJS wrapper for cloudapp-dl * * This allows the package to be used with require(): * const { ZightClient } = require('cloudapp-dl'); */ let _module = null; /** * Dynamically import the ESM module * @returns {Promise<Object>} */ async function loadModule() { if (!_module) { _module = await import('./index.js'); } return _module; } // Export a promise-based loader for the full module module.exports.load = loadModule; // Export ZightClient as a class that wraps the async import class ZightClientCJS { constructor(options = {}) { this._options = options; this._client = null; this._initPromise = this._init(); } async _init() { const mod = await loadModule(); this._client = new mod.ZightClient(this._options); return this._client; } async _ensureClient() { if (!this._client) { await this._initPromise; } return this._client; } // Proxy all methods to the underlying client get isAuthenticated() { return this._client?.isAuthenticated ?? false; } get sessionId() { return this._client?.sessionId ?? null; } get sessionExpiry() { return this._client?.sessionExpiry ?? null; } get userId() { return this._client?.userId ?? null; } get userName() { return this._client?.userName ?? null; } async login() { const client = await this._ensureClient(); return client.login(); } setSession(sessionId, sessionExpiry = null) { if (this._client) { this._client.setSession(sessionId, sessionExpiry); } } logout() { if (this._client) { this._client.logout(); } } async getAccountDetails() { const client = await this._ensureClient(); return client.getAccountDetails(); } async getOrganization(orgId = null) { const client = await this._ensureClient(); return client.getOrganization(orgId); } async getDrops(options = {}) { const client = await this._ensureClient(); return client.getDrops(options); } async getDrop(dropId) { const client = await this._ensureClient(); return client.getDrop(dropId); } async getItem(itemId) { const client = await this._ensureClient(); return client.getItem(itemId); } async searchDrops(query, options = {}) { const client = await this._ensureClient(); return client.searchDrops(query, options); } async getItemsFromDashboard(options = {}) { const client = await this._ensureClient(); return client.getItemsFromDashboard(options); } async getAllItems(options = {}) { const client = await this._ensureClient(); return client.getAllItems(options); } async getCollections(options = {}) { const client = await this._ensureClient(); return client.getCollections(options); } async getAllCollections() { const client = await this._ensureClient(); return client.getAllCollections(); } async createVideoRequest(options) { const client = await this._ensureClient(); return client.createVideoRequest(options); } async getVideoRequests(options = {}) { const client = await this._ensureClient(); return client.getVideoRequests(options); } async getVideoRequest(requestId) { const client = await this._ensureClient(); return client.getVideoRequest(requestId); } async updateVideoRequest(requestId, options) { const client = await this._ensureClient(); return client.updateVideoRequest(requestId, options); } async deleteVideoRequest(requestId) { const client = await this._ensureClient(); return client.deleteVideoRequest(requestId); } async uploadFile(filePath, onProgress = null) { const client = await this._ensureClient(); return client.uploadFile(filePath, onProgress); } async createUploadRequest(filename, fileSize, contentType) { const client = await this._ensureClient(); return client.createUploadRequest(filename, fileSize, contentType); } async confirmUploadComplete(slug, s3Key, checksum) { const client = await this._ensureClient(); return client.confirmUploadComplete(slug, s3Key, checksum); } async deleteItem(itemId, permanent = false) { const client = await this._ensureClient(); return client.deleteItem(itemId, permanent); } async restoreItem(itemId) { const client = await this._ensureClient(); return client.restoreItem(itemId); } async getTrashItems() { const client = await this._ensureClient(); return client.getTrashItems(); } async emptyTrash(onProgress = null) { const client = await this._ensureClient(); return client.emptyTrash(onProgress); } async getNotifications(options = {}) { const client = await this._ensureClient(); return client.getNotifications(options); } async markNotificationViewed(notificationId) { const client = await this._ensureClient(); return client.markNotificationViewed(notificationId); } async markAllNotificationsViewed(onProgress = null) { const client = await this._ensureClient(); return client.markAllNotificationsViewed(onProgress); } } module.exports.ZightClient = ZightClientCJS; // Also export a helper to get the full ESM module module.exports.getModule = loadModule;