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
JavaScript
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);
}
}