Skip to content

Commit

Permalink
feat: manage download on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
vhu-axelor committed Feb 7, 2025
1 parent 8a6b551 commit 8d05e6f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,10 @@ PODS:
- RCT-Folly (= 2022.05.16.00)
- React-Core
- React-RCTImage
- RNShare (12.0.3):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- RNStaticSafeAreaInsets (2.2.0):
- React-Core
- RNSVG (14.0.0):
Expand Down Expand Up @@ -1267,6 +1271,7 @@ DEPENDENCIES:
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNReanimated (from `../node_modules/react-native-reanimated`)
- RNScreens (from `../node_modules/react-native-screens`)
- RNShare (from `../node_modules/react-native-share`)
- RNStaticSafeAreaInsets (from `../node_modules/react-native-static-safe-area-insets`)
- RNSVG (from `../node_modules/react-native-svg`)
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
Expand Down Expand Up @@ -1419,6 +1424,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-reanimated"
RNScreens:
:path: "../node_modules/react-native-screens"
RNShare:
:path: "../node_modules/react-native-share"
RNStaticSafeAreaInsets:
:path: "../node_modules/react-native-static-safe-area-insets"
RNSVG:
Expand Down Expand Up @@ -1508,6 +1515,7 @@ SPEC CHECKSUMS:
RNGestureHandler: 1155b1898ceddefeebf77792927360d44fe11e77
RNReanimated: 8a4d86eb951a4a99d8e86266dc71d7735c0c30a9
RNScreens: 29418ceffb585b8f0ebd363de304288c3dce8323
RNShare: 1bdc6605a311cd16363450faf740b6b531b496c1
RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8
RNSVG: 255767813dac22db1ec2062c8b7e7b856d4e5ae6
RNVectorIcons: 73ab573085f65a572d3b6233e68996d4707fd505
Expand Down
4 changes: 4 additions & 0 deletions jest/setup-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,7 @@ jest.mock('react-native-vision-camera', () => {
});

jest.mock('@react-native-community/slider', () => 'RNSlider');

jest.mock('react-native-share', () => ({
turboModuleRegistry: jest.fn(),
}));
1 change: 1 addition & 0 deletions packages/core/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
"Base_StoragePermissionDetails": "This app needs access to your storage to download files.",
"Base_ErrorOnDownload": "Something went wrong while downloading the file.",
"Base_FileDownload": "Download complete, file saved to your download folder.",
"Base_FileDownloadiOS": "Download complete, file saved.",
"Base_DownloadPermissionDenied": "The application does not have the necessary permissions to download the file.",
"Base_SliceAction_FetchFilesDetails": "fetch file details",
"Base_SliceAction_FetchMetaModule": "fetch meta modules",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
"Base_StoragePermissionDetails": "L'application a besoin d'avoir accès à votre stockage pour télécharger des fichiers.",
"Base_ErrorOnDownload": "Il y a eu un problème lors du téléchargement du fichier.",
"Base_FileDownload": "Téléchargement complété, document sauvegardé dans votre dossier téléchargements.",
"Base_FileDownloadiOS": "Téléchargement complété, document sauvegardé.",
"Base_DownloadPermissionDenied": "L'application ne possède pas les permissions nécessaires au téléchargement du fichier.",
"Base_SliceAction_FetchFilesDetails": "récupération des détails du fichier",
"Base_SliceAction_FetchMetaModule": "récupération des modules",
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/tools/FileDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const downloadFileOnPhone = async (
}/content/download`
: `${authentification.baseUrl}ws/dms/download/${file.id}`;

const downloadPath = `${fs.dirs.LegacyDownloadDir}/${file.fileName}`;
const downloadPath = `${Platform.OS === 'ios' ? fs.dirs.DocumentDir : fs.dirs.LegacyDownloadDir}/${file.fileName}`;

config({
fileCache: true,
Expand All @@ -104,10 +104,10 @@ export const downloadFileOnPhone = async (
.fetch('GET', downloadUrl, {
Cookie: `CSRF-TOKEN=${authentification.token}; ${authentification.jsessionId}`,
})
.then(res => {
.then(async res => {
if (Platform.OS === 'ios') {
Share.open({
url: res.path(),
await Share.open({
url: 'file://' + res.path(),
saveToFiles: true,
}).catch(console.error);
}
Expand All @@ -116,7 +116,9 @@ export const downloadFileOnPhone = async (
type: 'success',
position: 'bottom',
text1: I18n.t('Base_Success'),
text2: I18n.t('Base_FileDownload'),
text2: I18n.t(
Platform.OS === 'ios' ? 'Base_FileDownloadiOS' : 'Base_FileDownload',
),
});
})
.catch(() => {
Expand Down

0 comments on commit 8d05e6f

Please sign in to comment.