import ApiClient from './ApiClient'; import { mapFileUploadResponse } from './FileUploadUtils'; import { mapLocationACLResponse } from './LocationClient'; import { mapResourceProfileResponse } from './ResourceClient'; import * as L from './types/Library'; import urls from './urls'; export const mapPresentationDataResponse = ( p: L.LibraryPresentationDataResponse, ): L.LibraryPresentationData => ({ applicationThumbnailUrl: p.application_thumbnail_url, thumbnailUrl: p.thumbnail_url, applicationIconUrl: p.application_icon_url, fileUploads: p.file_uploads ? p.file_uploads.map(mapFileUploadResponse) : null, }); export const mapContentResponse = (c: L.ContentResponse): L.Content => ({ id: c.id, name: c.name, resourceType: c.resource_type, resourceId: c.resource_id, lastActivityAt: c.last_activity_at, updatedAt: c.updated_at, createdAt: c.created_at, ownedBy: mapResourceProfileResponse(c.owned_by), acl: c.acl?.map((item) => mapLocationACLResponse(item)) || [], presentationData: mapPresentationDataResponse(c.presentation_data), }); export default class LibraryClient { async getLibrary(this: ApiClient, query?: string): Promise { const res = await this.requestProtected< L.GetLibraryRequest, L.GetLibraryResponse >({ method: 'GET', url: urls.library(query), }); return { total: res.total, data: res.data.map(mapContentResponse), folderPath: res.folder_path, }; } }