import { aes } from '@internxt/lib' ; import httpService from '../../core/services/http.service' ; import { Device , DeviceBackup } from '../types' ; const backupsService = { async getAllDevices ( ) { const devices = await httpService . get < Device [ ] > ( '/api/backup/device' ) ; return devices . filter ( ( device ) => device . id ) ; } , async getAllBackups ( mac ) { const backups = await httpService . get < DeviceBackup [ ] > ( `/api/backup/${ mac }` ) ; return backups . map ( ( backup ) => { const path = aes . decrypt ( backup . path , `${ process . env . REACT_APP_CRYPTO_SECRET2 }-${ backup . bucket }` ) ; const name = path . split ( /[/\\]/ ) . pop ( ) as string ; return { ... backup , path , name , } ; } ) ; } , async deleteBackup ( backup ) { await httpService . delete < void > ( `/api/backup/${ backup . id }` ) ; } , async deleteDevice ( device ) { await httpService . delete < void > ( `/api/backup/device/${ device . id }` ) ; } , } ; export default backupsService ;