-
Notifications
You must be signed in to change notification settings - Fork 1
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
Small improvements for Android backup + custom behavior when quota exceeded #882
Changes from all commits
9537817
4f0d74e
40b501c
8c65e1e
fe55860
cbc786c
d6243e6
762373e
4309cf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
diff --git a/node_modules/react-native-background-upload/android/src/main/java/com/vydia/RNUploader/GlobalRequestObserverDelegate.kt b/node_modules/react-native-background-upload/android/src/main/java/com/vydia/RNUploader/GlobalRequestObserverDelegate.kt | ||
index c89d495..5da9d14 100644 | ||
--- a/node_modules/react-native-background-upload/android/src/main/java/com/vydia/RNUploader/GlobalRequestObserverDelegate.kt | ||
+++ b/node_modules/react-native-background-upload/android/src/main/java/com/vydia/RNUploader/GlobalRequestObserverDelegate.kt | ||
@@ -9,6 +9,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEm | ||
import net.gotev.uploadservice.data.UploadInfo | ||
import net.gotev.uploadservice.network.ServerResponse | ||
import net.gotev.uploadservice.observer.request.RequestObserverDelegate | ||
+import net.gotev.uploadservice.exceptions.UploadError | ||
|
||
class GlobalRequestObserverDelegate(reactContext: ReactApplicationContext) : RequestObserverDelegate { | ||
private val TAG = "UploadReceiver" | ||
@@ -28,6 +29,10 @@ class GlobalRequestObserverDelegate(reactContext: ReactApplicationContext) : Req | ||
// Make sure we do not try to call getMessage() on a null object | ||
if (exception != null) { | ||
params.putString("error", exception.message) | ||
+ if (exception is UploadError) { | ||
+ params.putInt("responseCode", exception.serverResponse.code) | ||
+ params.putString("responseBody", String(exception.serverResponse.body, Charsets.US_ASCII)) | ||
+ } | ||
} else { | ||
params.putString("error", "Unknown exception") | ||
} | ||
diff --git a/node_modules/react-native-background-upload/index.d.ts b/node_modules/react-native-background-upload/index.d.ts | ||
index 8b2a07c..80cff93 100644 | ||
--- a/node_modules/react-native-background-upload/index.d.ts | ||
+++ b/node_modules/react-native-background-upload/index.d.ts | ||
@@ -11,6 +11,8 @@ declare module "react-native-background-upload" { | ||
|
||
export interface ErrorData extends EventData { | ||
error: string | ||
+ responseCode: number | ||
+ responseBody: string | ||
} | ||
|
||
export interface CompletedData extends EventData { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export class BackupError extends Error { | ||
statusCode: number | undefined | ||
|
||
constructor(message: string, statusCode: number | undefined) { | ||
const stringifiedMessage = JSON.stringify({ | ||
message, | ||
statusCode | ||
}) | ||
|
||
super(stringifiedMessage) | ||
this.name = 'BackupError' | ||
this.statusCode = statusCode | ||
} | ||
} | ||
|
||
export const STACK_ERRORS_INTERRUPTING_BACKUP = [ | ||
413 // quota exceeded | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not true all the time. You can have a 413 error when the file is too big (5 GB) for our storage service (swift). If you want to handle that correctly, see desktop: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be done later, not a blocker ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did not know about this! I will update with this new PR : https://github.com/cozy/cozy-stack/pull/4069/files |
||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
getPathExtension, | ||
getPathWithoutExtension, | ||
getPathWithoutFilename | ||
} from '/app/domain/backup/helpers' | ||
|
||
describe('file helper', () => { | ||
describe('getPathExtension', () => { | ||
it.each([ | ||
['IMG_001.heic', 'heic'], | ||
['/Folder/IMG_001.heic', 'heic'], | ||
['IMG_001.heic.mov', 'mov'] | ||
])('with %p should return %p', (path, result) => { | ||
expect(getPathExtension(path)).toBe(result) | ||
}) | ||
}) | ||
|
||
describe('getPathWithoutExtension', () => { | ||
it.each([ | ||
['IMG_001.heic', 'IMG_001'], | ||
['/Folder/IMG_001.heic', '/Folder/IMG_001'], | ||
['IMG_001.heic.mov', 'IMG_001.heic'] | ||
])('with %p should return %p', (path, result) => { | ||
expect(getPathWithoutExtension(path)).toBe(result) | ||
}) | ||
}) | ||
|
||
describe('getPathWithoutFilename', () => { | ||
it.each([ | ||
['IMG_001.heic', ''], | ||
['/Folder/IMG_001.heic', '/Folder'], | ||
['/Folder/Directory/IMG_001.heic', '/Folder/Directory'] | ||
])('with %p should return %p', (path, result) => { | ||
expect(getPathWithoutFilename(path)).toBe(result) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const getPathExtension = (path: string): string => { | ||
return path.substring(path.lastIndexOf('.') + 1) | ||
} | ||
|
||
export const getPathWithoutExtension = (path: string): string => { | ||
return path.substring(0, path.lastIndexOf('.')) | ||
} | ||
|
||
export const getPathWithoutFilename = (path: string): string => { | ||
return path.substring(0, path.lastIndexOf('/')) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from '/app/domain/backup/helpers/error' | ||
export * from '/app/domain/backup/helpers/file' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { getVideoPathFromLivePhoto } from '/app/domain/backup/services/uploadMedia.ios' | ||
|
||
describe('uploadMedia.ios', () => { | ||
describe('getVideoPathFromLivePhoto', () => { | ||
it.each([ | ||
['IMG_001.HEIC', 'IMG_001.MOV'], | ||
['FullSizeRender.heic', 'FullSizeRender.mov'], | ||
['/Folder/IMG_001.HEIC', '/Folder/IMG_001.MOV'], | ||
['/Folder/FullSizeRender.heic', '/Folder/FullSizeRender.mov'] | ||
])('with %p should return %p', (path, result) => { | ||
expect(getVideoPathFromLivePhoto(path)).toBe(result) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,24 @@ import RNFileSystem from 'react-native-fs' | |
|
||
import { getMimeType } from '/app/domain/backup/services/getMedias' | ||
import { Media, UploadMediaResult } from '/app/domain/backup/models/Media' | ||
import { | ||
getPathExtension, | ||
getPathWithoutExtension | ||
} from '/app/domain/backup/helpers' | ||
import { t } from '/locales/i18n' | ||
|
||
import CozyClient, { StackErrors, IOCozyFile } from 'cozy-client' | ||
|
||
const getVideoPathFromLivePhoto = (photoPath: string): string => { | ||
return photoPath.substring(0, photoPath.lastIndexOf('.')) + '.MOV' | ||
export const getVideoPathFromLivePhoto = (photoPath: string): string => { | ||
const extension = getPathExtension(photoPath) | ||
|
||
if (extension === extension.toUpperCase()) { | ||
// Path is something like IMG_001.MOV | ||
return getPathWithoutExtension(photoPath) + '.MOV' | ||
} else { | ||
// When Live Photo has been modified, path is something like FullSizeRender.mov | ||
return getPathWithoutExtension(photoPath) + '.mov' | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seriously? 😮💨 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... One day we will update react-native-camera-roll to handle this correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really? New version of camera-roll handle that? Why can't we upgrade? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No no I wanted to say "we will make a PR to add the feature directly on react-native-camera-roll" |
||
} | ||
|
||
const getRealFilepath = async (media: Media): Promise<string> => { | ||
|
@@ -17,7 +30,7 @@ const getRealFilepath = async (media: Media): Promise<string> => { | |
let filepath = data.node.image.filepath | ||
|
||
if (filepath === null) { | ||
throw new Error('Impossible to get a real filepath') | ||
throw new Error(t('services.backup.errors.fileNotFound')) | ||
} | ||
|
||
filepath = filepath.replace('file://', '') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you create an upstream PR? can you link it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in the commit Vydia/react-native-background-upload#337