UNPKG

@blue-impact-engine/blue-impact-engine-client

Version:
63 lines 2.37 kB
export class MediaService { constructor(httpClient) { this.httpClient = httpClient; } /** * Get all media items */ async getAll() { const response = await this.httpClient.get('/api/media'); if (response.data && typeof response.data === 'object' && 'docs' in response.data) { return response.data; } return { docs: [], totalDocs: 0, limit: 10, totalPages: 1, page: 1, pagingCounter: 1, hasPrevPage: false, hasNextPage: false, prevPage: null, nextPage: null }; } /** * Get a specific media item by ID */ async getById(id) { return this.httpClient.get(`/api/media/${id}`); } /** * Get media items with pagination */ async getWithPagination(page = 1, limit = 10) { const response = await this.httpClient.get(`/api/media?page=${page}&limit=${limit}`); if (response.data && typeof response.data === 'object' && 'docs' in response.data) { return response.data; } return { docs: [], totalDocs: 0, limit: 10, totalPages: 1, page: 1, pagingCounter: 1, hasPrevPage: false, hasNextPage: false, prevPage: null, nextPage: null }; } /** * Get media items by tag */ async getByTag(tag) { const response = await this.httpClient.get(`/api/media?tags=${tag}`); if (response.data && typeof response.data === 'object' && 'docs' in response.data) { return response.data; } return { docs: [], totalDocs: 0, limit: 10, totalPages: 1, page: 1, pagingCounter: 1, hasPrevPage: false, hasNextPage: false, prevPage: null, nextPage: null }; } /** * Get the full URL for a media item */ getMediaUrl(mediaItem) { if (mediaItem.url?.startsWith('http')) { return mediaItem.url; } // Construct full URL using the base URL from the client config const config = this.httpClient.getConfig(); return `${config.baseUrl}${mediaItem.url || ''}`; } /** * Get the thumbnail URL for a media item */ getThumbnailUrl(mediaItem) { if (mediaItem.thumbnailURL?.startsWith('http')) { return mediaItem.thumbnailURL; } // If no thumbnail, use the main image return this.getMediaUrl(mediaItem); } } //# sourceMappingURL=MediaService.js.map