UNPKG

pancake-client-sdk

Version:
132 lines 3.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MediaResource = void 0; const base_1 = require("./base"); class MediaResource extends base_1.BaseResource { /** * Get list of media files */ async list(params) { return this.client.get(this.getShopPath('/media'), params); } /** * Get media by ID */ async getById(mediaId) { return this.client.get(this.getShopPath(`/media/${mediaId}`)); } /** * Upload file */ async upload(data) { const formData = new FormData(); formData.append('file', data.file); if (data.folder_id) { formData.append('folder_id', data.folder_id); } if (data.tags) { formData.append('tags', JSON.stringify(data.tags)); } if (data.metadata) { formData.append('metadata', JSON.stringify(data.metadata)); } if (data.filename) { formData.append('filename', data.filename); } if (data.content_type) { formData.append('content_type', data.content_type); } return this.client.post(this.getShopPath('/media/upload'), formData); } /** * Delete media */ async delete(mediaId) { return this.client.delete(this.getShopPath(`/media/${mediaId}`)); } /** * Update media */ async update(mediaId, data) { return this.client.put(this.getShopPath(`/media/${mediaId}`), data); } /** * Process image */ async processImage(mediaId, options) { return this.client.post(this.getShopPath(`/media/${mediaId}/process`), options); } /** * List folders */ async listFolders() { return this.client.get(this.getShopPath('/media/folders')); } /** * Create folder */ async createFolder(data) { return this.client.post(this.getShopPath('/media/folders'), data); } /** * Update folder */ async updateFolder(folderId, data) { return this.client.put(this.getShopPath(`/media/folders/${folderId}`), data); } /** * Delete folder */ async deleteFolder(folderId, recursive) { return this.client.delete(this.getShopPath(`/media/folders/${folderId}`), { recursive }); } /** * Get media statistics */ async getStats() { return this.client.get(this.getShopPath('/media/stats')); } /** * Bulk operation on media files */ async bulkOperation(operation) { return this.client.post(this.getShopPath('/media/bulk'), operation); } /** * Get upload URL for direct upload */ async getUploadUrl(data) { return this.client.post(this.getShopPath('/media/get-upload-url'), data); } /** * Scan media for viruses/malware */ async scanMedia(mediaId) { return this.client.post(this.getShopPath(`/media/${mediaId}/scan`), {}); } /** * Generate thumbnail */ async generateThumbnail(mediaId, options) { return this.client.post(this.getShopPath(`/media/${mediaId}/thumbnail`), options || {}); } /** * Get media download URL */ async getDownloadUrl(mediaId, options) { return this.client.get(this.getShopPath(`/media/${mediaId}/download-url`), options); } /** * Search media */ async search(query, params) { return this.client.get(this.getShopPath('/media/search'), { ...params, query }); } } exports.MediaResource = MediaResource; //# sourceMappingURL=media.js.map