Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup: Lots of fixes, refactoring and documentation #887

Merged
merged 18 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d0597f6
fix(backup): Upload could crash when response body undefined
zatteo Jul 27, 2023
826d3c5
fix(backup): Stop backup only if quota exceeded and not if file too l…
zatteo Jul 27, 2023
a17d491
refactor(backup): Create an upload service distinct from Media model
zatteo Jul 27, 2023
fe5822f
feat(backup): Create backups in /Photos instead of /
zatteo Jul 28, 2023
d332981
fix(backup): Set backup as to do on new start after killing app
zatteo Jul 27, 2023
b5d3084
feat(backup): Disable album management on Android
zatteo Jul 28, 2023
ce52f19
fix(backup): Stop considering trashed files as backuped when restoring
zatteo Jul 28, 2023
82ba33b
fix(backup): Fix restoring when media at backup root path
zatteo Jul 28, 2023
2a1d096
fix(backup): Try to fix "stream was reset: CANCEL" error
zatteo Jul 28, 2023
84c256b
fix(backup): Allow users to rename is backup folder
zatteo Jul 28, 2023
a187a28
feat(backup): Send modification date when uploading
zatteo Jul 28, 2023
1d9348e
feat(backup): Duplicate file and append a number when upload conflict
zatteo Jul 28, 2023
9b50fba
docs(backup): Add schema about backup
zatteo Jul 28, 2023
321c68d
Revert "fix(backup): Try to fix "stream was reset: CANCEL" error"
Crash-- Jul 31, 2023
d7ba638
fix: Add Size to upload URL
Crash-- Jul 31, 2023
c4aa505
chore: Add a task to generate the dependancies graph
Crash-- Aug 1, 2023
d0cfea6
fix: Use okhttp5.0.0-alpha.1 for react-native-background-upload
Crash-- Aug 1, 2023
f7cf0f8
fix: Better check for Upload error type in `uploadMedias()`
Ldoppea Aug 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/@types/cozy-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ declare module 'cozy-client' {
) => Promise<{ included: { attributes: unknown }[] }>
createDirectoryByPath: (path: string) => Promise<FileCollectionGetResult>
ensureDirectoryExists: (path: string) => Promise<string>
getDirectoryOrCreate: (
name: string,
parentDirectory: object
) => Promise<FileCollectionGetResult>
createFileMetadata: (metadata: object) => Promise<{ data: { id: string } }>
addReferencesTo: (references: object, dirs: object[]) => Promise<void>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
59 changes: 58 additions & 1 deletion src/app/domain/backup/services/manageRemoteBackupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ import { IOCozyFile } from 'cozy-client/types/types'
const DOCTYPE_APPS = 'io.cozy.apps'
const DOCTYPE_FILES = 'io.cozy.files'
const BACKUP_REF = `io.cozy.apps/photos/mobile`
const PHOTOS_REF = `io.cozy.apps/photos`

interface Folder {
_id: string
attributes: {
name: string
path: string
}
}

interface BackupFolder {
_id: string
Expand Down Expand Up @@ -119,17 +128,65 @@ const createRemoteBackupFolderWithConflictStrategy = async (
}
}

export const getOrCreatePhotosMagicFolder = async (
Crash-- marked this conversation as resolved.
Show resolved Hide resolved
client: CozyClient
): Promise<Folder> => {
const { included } = await client.collection(DOCTYPE_FILES).findReferencedBy({
_type: DOCTYPE_APPS,
_id: PHOTOS_REF
})

let photosMagicFolders = included as Folder[]

photosMagicFolders = photosMagicFolders.filter(
folder => !isInTrash(folder.attributes.path)
)

if (photosMagicFolders.length > 0) {
return photosMagicFolders[0]
}

const { data: newPhotosMagicFolder } = await client
.collection(DOCTYPE_FILES)
.createDirectoryByPath('/Photos')
Crash-- marked this conversation as resolved.
Show resolved Hide resolved

await client.collection(DOCTYPE_FILES).addReferencesTo(
{
_id: PHOTOS_REF,
_type: DOCTYPE_APPS
},
[
{
_id: newPhotosMagicFolder._id
}
]
)

return {
_id: newPhotosMagicFolder._id,
attributes: {
name: newPhotosMagicFolder.name,
path: newPhotosMagicFolder.path
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi ne pas retourner tout newPhotosMagicFolder? 🤔

}

export const createRemoteBackupFolder = async (
client: CozyClient
): Promise<RemoteBackupConfig> => {
const deviceName = await getDeviceName()
const deviceId = await getDeviceId()

const photosMagicFolder = await getOrCreatePhotosMagicFolder(client)

const {
data: { _id: backupRootId }
} = await client
.collection(DOCTYPE_FILES)
.createDirectoryByPath(t('services.backup.backupRootPath'))
.getDirectoryOrCreate(
t('services.backup.backupRootName'),
photosMagicFolder
)

const backupFolderAttributes = {
type: 'directory',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"services": {
"backup": {
"backupRootPath": "/Mobile backup",
"backupRootName": "Mobile backup",
"notifications": {
"onProgressTitle": "Uploading",
"onProgressMessage": "{{filename}} is being uploaded",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"services": {
"backup": {
"backupRootPath": "/Copiado desde mi móvil",
"backupRootName": "Copiado desde mi móvil",
"errors": {
"fileNotFound": "Archivo no encontrado",
"fileNotSupported": "Archivo no compatible con la copia de seguridad",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"services": {
"backup": {
"backupRootPath": "/Sauvegardé depuis mon mobile",
"backupRootName": "Sauvegardé depuis mon mobile",
"notifications": {
"onProgressTitle": "Envoi en cours",
"onProgressMessage": "{{filename}} est en cours de sauvegarde",
Expand Down