import { DriveFileData , DriveFileMetadataPayload , DriveItemData } from '../../types' ; import analyticsService from '../../../analytics/services/analytics.service' ; import errorService from '../../../core/services/error.service' ; import localStorageService from '../../../core/services/local-storage.service' ; import { DevicePlatform } from '../../../core/types' ; import i18n from '../../../i18n/services/i18n.service' ; import { UserSettings } from '../../../auth/types' ; import uploadFile from './uploadFile' ; import * as uuid from 'uuid' ; import { createStorageClient } from '../../../../factory/modules' ; import { StorageTypes } from '@internxt/sdk/dist/drive' ; export function updateMetaData ( fileId , metadata , bucketId ) { const storageClient = createStorageClient ( ) ; const payload = { fileId : fileId , metadata : metadata , bucketId : bucketId , destinationPath : uuid . v4 ( ) } ; return storageClient . updateFile ( payload ) . then ( ( ) => { const user = localStorageService . getUser ( ) as UserSettings ; analyticsService . trackFileRename ( { file_id : fileId , email : user . email , platform : DevicePlatform . Web , } ) ; } ) ; } export function deleteFile ( fileData ) { const storageClient = createStorageClient ( ) ; return storageClient . deleteFile ( { fileId : fileData . id , folderId : fileData . folderId } ) . then ( ( ) => { const user = localStorageService . getUser ( ) as UserSettings ; analyticsService . trackDeleteItem ( fileData as DriveItemData , { email : user . email , platform : DevicePlatform . Web , } ) ; } ) ; } export async function moveFile ( fileId , destination , bucketId ) { const storageClient = createStorageClient ( ) ; const payload = { fileId : fileId , destination : destination , bucketId : bucketId , destinationPath : uuid . v4 ( ) } ; return storageClient . moveFile ( payload ) . then ( response => { const user = localStorageService . getUser ( ) as UserSettings ; analyticsService . trackMoveItem ( 'file' , { file_id : response . item . id , email : user . email , platform : DevicePlatform . Web , } ) ; return response ; } ) . catch ( error => { const castedError = errorService . castError ( error ) ; if ( castedError . status ) { castedError . message = i18n . get ( `tasks.move-file.errors.${ castedError . status }` ) ; } throw castedError ; } ) ; } async function fetchRecents ( limit ) { const storageClient = createStorageClient ( ) ; return storageClient . getRecentFiles ( limit ) ; } const fileService = { updateMetaData , deleteFile , moveFile , fetchRecents , uploadFile , } ; export default fileService ;