UNPKG

dood-stream-client

Version:

๐Ÿš€ A feature-rich client for the DoodStream API with caching, logging, and error handling

114 lines (113 loc) โ€ข 3.19 kB
import { ErrorFactory } from "../errors/error-factory"; /** * ๐Ÿ”— Remote Upload-related API functionality */ export class RemoteUploadApi { /** * Create a new Remote Upload API instance * * @param client - HTTP client */ constructor(client) { this.client = client; } /** * ๐Ÿ”— Add a remote upload link * * @param params - Remote upload parameters * @returns Promise with remote upload response */ async addLink(params) { if (!params.url) { throw ErrorFactory.createValidationError("URL is required for remote upload"); } return this.client.get("/upload/url", params); } /** * ๐Ÿ“‹ Get remote upload list & status * * @returns Promise with remote upload list response */ async getList() { return this.client.get("/urlupload/list"); } /** * ๐Ÿ” Get status of a specific remote upload * * @param params - Remote upload status parameters * @returns Promise with remote upload list response */ async getStatus(params) { if (!params.file_code) { throw ErrorFactory.createValidationError("File code is required to check remote upload status"); } return this.client.get("/urlupload/status", params); } /** * ๐Ÿ”ข Get remote upload slots info * * @returns Promise with remote upload slots response */ async getSlots() { return this.client.get("/urlupload/slots"); } /** * ๐Ÿ”„ Restart all error uploads * * @returns Promise with base response */ async restartErrors() { return this.client.get("/urlupload/actions", { restart_errors: true, }); } /** * ๐Ÿงน Clear all error uploads * * @returns Promise with base response */ async clearErrors() { return this.client.get("/urlupload/actions", { clear_errors: true, }); } /** * ๐Ÿงน Clear all uploads * * @returns Promise with base response */ async clearAll() { return this.client.get("/urlupload/actions", { clear_all: true, }); } /** * ๐Ÿ—‘๏ธ Delete a specific transfer * * @param fileCode - File code to delete * @returns Promise with base response */ async deleteTransfer(fileCode) { if (!fileCode) { throw ErrorFactory.createValidationError("File code is required to delete a transfer"); } return this.client.get("/urlupload/actions", { delete_code: fileCode, }); } /** * ๐Ÿ› ๏ธ Perform custom remote upload actions * * @param params - Remote upload actions parameters * @returns Promise with base response */ async performActions(params) { if (!params.restart_errors && !params.clear_errors && !params.clear_all && !params.delete_code) { throw ErrorFactory.createValidationError("At least one action parameter must be specified"); } return this.client.get("/urlupload/actions", params); } }