Skip to content

Commit

Permalink
feat(backup): Count number of deduplicated medias and return it to fr…
Browse files Browse the repository at this point in the history
…ont end

It can be strange for the user to see that the number of medias to
backup is not the same as the number of medias really uploaded in his backup folder.
So we specify that x medias have been deduplicated and return it to front end.
  • Loading branch information
zatteo committed Jan 10, 2024
1 parent 2f382cf commit c0e4f70
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app/domain/backup/hooks/useInitBackup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const useInitBackup = (): void => {
backupConfig.currentBackup.mediasToBackup.length,
totalMediasToBackupCount:
backupConfig.currentBackup.totalMediasToBackupCount,
deduplicatedMediaCount:
backupConfig.currentBackup.deduplicatedMediaCount,
message: t('services.backup.errors.appKilled')
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/domain/backup/models/Backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface LastBackup {
message?: string
backedUpMediaCount: number
totalMediasToBackupCount: number
deduplicatedMediaCount: number
}

/**
Expand All @@ -34,6 +35,7 @@ export interface LocalBackupConfig {
status: BackupStatus
mediasToBackup: Media[]
totalMediasToBackupCount: number
deduplicatedMediaCount: number
}
lastBackup?: LastBackup
}
Expand Down
6 changes: 6 additions & 0 deletions src/app/domain/backup/services/manageBackup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export const startBackup = async (
postUploadLocalBackupConfig.currentBackup.mediasToBackup.length,
totalMediasToBackupCount:
postUploadLocalBackupConfig.currentBackup.totalMediasToBackupCount,
deduplicatedMediaCount:
postUploadLocalBackupConfig.currentBackup.deduplicatedMediaCount,
message
})

Expand Down Expand Up @@ -151,6 +153,8 @@ export const startBackup = async (
postUploadLocalBackupConfig.currentBackup.mediasToBackup.length,
totalMediasToBackupCount:
postUploadLocalBackupConfig.currentBackup.totalMediasToBackupCount,
deduplicatedMediaCount:
postUploadLocalBackupConfig.currentBackup.deduplicatedMediaCount,
message: e.textMessage
})
} else {
Expand All @@ -161,6 +165,8 @@ export const startBackup = async (
postUploadLocalBackupConfig.currentBackup.mediasToBackup.length,
totalMediasToBackupCount:
postUploadLocalBackupConfig.currentBackup.totalMediasToBackupCount,
deduplicatedMediaCount:
postUploadLocalBackupConfig.currentBackup.deduplicatedMediaCount,
message: t('services.backup.errors.unknownIssue')
})
}
Expand Down
7 changes: 6 additions & 1 deletion src/app/domain/backup/services/manageLocalBackupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const INITIAL_BACKUP_CONFIG: LocalBackupConfig = {
currentBackup: {
status: 'to_do',
mediasToBackup: [],
totalMediasToBackupCount: 0
totalMediasToBackupCount: 0,
deduplicatedMediaCount: 0
}
}

Expand Down Expand Up @@ -189,6 +190,9 @@ export const setMediaAsBackupedBecauseDeduplicated = async (
mediaToBackup => !isSameMedia(mediaToBackup, media)
)

localBackupConfig.currentBackup.deduplicatedMediaCount =
localBackupConfig.currentBackup.deduplicatedMediaCount + 1

await setLocalBackupConfig(client, localBackupConfig)

log.debug(`✅ ${media.name} set as backuped because deduplicated`)
Expand Down Expand Up @@ -272,6 +276,7 @@ export const setBackupAsReady = async (
localBackupConfig.currentBackup.mediasToBackup.length
}

localBackupConfig.currentBackup.deduplicatedMediaCount = 0
localBackupConfig.currentBackup.status = 'ready'

await setLocalBackupConfig(client, localBackupConfig)
Expand Down

0 comments on commit c0e4f70

Please sign in to comment.