A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: fix image filename in picker
Ammar Ahmed152794ccd044
diff --git a/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsx b/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsxindex 58ee9c38c..2a7c8afcc 100644--- a/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsx+++ b/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsx@@ -17,7 +17,13 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/import React, { useState } from "react";-import { Image, ScrollView, TouchableOpacity, View } from "react-native";+import {+ Image,+ Platform,+ ScrollView,+ TouchableOpacity,+ View+} from "react-native";import { Image as ImageType } from "react-native-image-crop-picker";import { useThemeColors } from "../../../../../../packages/theme/dist";import { presentSheet } from "../../../services/event-manager";@@ -65,7 +71,7 @@ export default function AttachImage({<TouchableOpacity key={item.filename} activeOpacity={0.9}><Imagesource={{- uri: item.sourceURL || item.path+ uri: Platform.OS === "ios" ? item.sourceURL : item.path}}style={{width: 100,diff --git a/apps/mobile/app/screens/editor/tiptap/picker.ts b/apps/mobile/app/screens/editor/tiptap/picker.tsindex 517bd1caf..52a67cb12 100644--- a/apps/mobile/app/screens/editor/tiptap/picker.ts+++ b/apps/mobile/app/screens/editor/tiptap/picker.ts@@ -41,6 +41,7 @@ import { FILE_SIZE_LIMIT, IMAGE_SIZE_LIMIT } from "../../../utils/constants";import { eCloseSheet } from "../../../utils/events";import { useTabStore } from "./use-tab-store";import { editorController, editorState } from "./utils";+import { basename } from "pathe";const showEncryptionSheet = (file: DocumentPickerResponse) => {presentSheet({@@ -265,6 +266,7 @@ const handleImageResponse = async (response: Image[],options: PickerOptions) => {+ console.log(response, "result-file-picker");const result = await AttachImage.present(response, options.context);if (!result) return;const compress = result.compress;@@ -300,7 +302,12 @@ const handleImageResponse = async (type: "url"});- const fileName = image.filename || "image";+ const fileName = image.sourceURL+ ? basename(image.sourceURL)+ : image.filename || "image";++ console.log("attaching image...", fileName);+console.log("attaching file...");if (!(await attachFile(uri, hash, image.mime, fileName, options))) return;diff --git a/apps/mobile/patches/react-native-image-crop-picker+0.40.2.patch b/apps/mobile/patches/react-native-image-crop-picker+0.40.2.patchnew file mode 100644index 000000000..e410f3010--- /dev/null+++ b/apps/mobile/patches/react-native-image-crop-picker+0.40.2.patch@@ -0,0 +1,12 @@+diff --git a/node_modules/react-native-image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/PickerModule.java b/node_modules/react-native-image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/PickerModule.java+index 5de0845..1b158d8 100644+--- a/node_modules/react-native-image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/PickerModule.java++++ b/node_modules/react-native-image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/PickerModule.java+@@ -692,6 +692,7 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi+ image.putString("mime", options.outMimeType);+ image.putInt("size", (int) new File(compressedImagePath).length());+ image.putString("modificationDate", String.valueOf(modificationDate));++ image.putString("sourceURL", path);++ if (includeBase64) {+ image.putString("data", getBase64StringFromFile(compressedImagePath));diff --git a/apps/mobile/patches/react-native-image-picker+4.1.2.patch b/apps/mobile/patches/react-native-image-picker+4.1.2.patchdeleted file mode 100644index a16bcee38..000000000--- a/apps/mobile/patches/react-native-image-picker+4.1.2.patch+++ /dev/null@@ -1,169 +0,0 @@-diff --git a/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/Utils.java b/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/Utils.java-index 8e59033..c87febe 100644---- a/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/Utils.java-+++ b/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/Utils.java-@@ -1,6 +1,7 @@- package com.imagepicker;-- import android.Manifest;-+import android.annotation.SuppressLint;- import android.app.Activity;- import android.content.ClipData;- import android.content.ContentResolver;-@@ -21,6 +22,7 @@ import android.provider.OpenableColumns;- import android.util.Base64;- import android.webkit.MimeTypeMap;--+import androidx.annotation.NonNull;- import androidx.core.app.ActivityCompat;- import androidx.core.content.FileProvider;- import androidx.exifinterface.media.ExifInterface;-@@ -36,6 +38,7 @@ import java.io.FileNotFoundException;- import java.io.IOException;- import java.io.InputStream;- import java.io.OutputStream;-+import java.net.URI;- import java.util.ArrayList;- import java.util.Arrays;- import java.util.Collections;-@@ -266,7 +269,9 @@ public class Utils {- MediaMetadataRetriever m = new MediaMetadataRetriever();- m.setDataSource(context, uri);- int duration = Math.round(Float.parseFloat(m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION))) / 1000;-- m.release();-+ try {-+ m.release();-+ } catch(Exception e) {}- return duration;- }--@@ -383,7 +388,7 @@ public class Utils {- return fileUris;- }--- static ReadableMap getImageResponseMap(Uri uri, Options options, Context context) {-+ static WritableMap getImageResponseMap(Uri uri, Options options, Context context) {- String fileName = uri.getLastPathSegment();- int[] dimensions = getImageDimensions(uri, context);--@@ -418,13 +423,16 @@ public class Utils {-- for(int i = 0; i < fileUris.size(); ++i) {- Uri uri = fileUris.get(i);-+ String fileName = getNameFromURI(context,uri);-- if (isImageType(uri, context)) {- if (uri.getScheme().contains("content")) {- uri = getAppSpecificStorageUri(uri, context);- }- uri = resizeImage(uri, context, options);-- assets.pushMap(getImageResponseMap(uri, options, context));-+ WritableMap resMap = getImageResponseMap(uri, options, context);-+ resMap.putString("originalFileName",fileName);-+ assets.pushMap(resMap);- } else if (isVideoType(uri, context)) {- assets.pushMap(getVideoResponseMap(uri, context));- } else {-@@ -438,6 +446,32 @@ public class Utils {- return response;- }--+ /**-+ * Return file name from Uri given.-+ * @param context the context, cannot be null.-+ * @param uri uri request for file name, cannot be null-+ * @return the corresponding display name for file defined in uri or null if error occurs.-+ */-+ @SuppressLint("Range")-+ static String getNameFromURI(@NonNull Context context, @NonNull Uri uri) {-+ String result = null;-+ Cursor c = null;-+ try {-+ c = context.getContentResolver().query(uri, null, null, null, null);-+ c.moveToFirst();-+ result = c.getString(c.getColumnIndex(OpenableColumns.DISPLAY_NAME));-+ }-+ catch (Exception e){-+ // error occurs-+ }-+ finally {-+ if(c != null){-+ c.close();-+ }-+ }-+ return result;-+ }-+- static ReadableMap getErrorMap(String errCode, String errMsg) {- WritableMap map = Arguments.createMap();- map.putString("errorCode", errCode);-diff --git a/node_modules/react-native-image-picker/ios/ImagePickerManager.m b/node_modules/react-native-image-picker/ios/ImagePickerManager.m-index b634ffb..18b8950 100644---- a/node_modules/react-native-image-picker/ios/ImagePickerManager.m-+++ b/node_modules/react-native-image-picker/ios/ImagePickerManager.m-@@ -96,6 +96,39 @@ - (void) showPickerViewController:(UIViewController *)picker- });- }--+-(NSString *)cachesDirectoryName-+{-+ static NSString *cachePath = nil;-+ if(!cachePath) {-+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);-+ cachePath = [paths objectAtIndex:0];-+ }-+-+ return cachePath;-+}-+-+///-+/// Builds paths for identifiers in the cache directory-+///-+-(NSString *)pathForName:(NSString *)name-+{-+ NSString *cachePath = [self cachesDirectoryName];-+ NSString *path = [cachePath stringByAppendingPathComponent:name];-+ return path;-+}-+-+#pragma mark - NSData Cache methods-+-+///-+/// Saves the given data to the cache directory-+///-+-(NSString *)saveToCacheDirectory:(NSData *)data withName:(NSString *)name-+{-+ NSString *path = [self pathForName:name];-+ [data writeToFile:path atomically:YES];-+ return path;-+}-+- #pragma mark - Helpers-- -(NSMutableDictionary *)mapImageToAsset:(UIImage *)image data:(NSData *)data {-@@ -121,22 +154,14 @@ -(NSMutableDictionary *)mapImageToAsset:(UIImage *)image data:(NSData *)data {- asset[@"type"] = [@"image/" stringByAppendingString:fileType];-- NSString *fileName = [self getImageFileName:fileType];-- NSString *path = [[NSTemporaryDirectory() stringByStandardizingPath] stringByAppendingPathComponent:fileName];-- [data writeToFile:path atomically:YES];-+ NSString *path = [self saveToCacheDirectory:data withName:fileName];-- if ([self.options[@"includeBase64"] boolValue]) {- asset[@"base64"] = [data base64EncodedStringWithOptions:0];- }--- NSURL *fileURL = [NSURL fileURLWithPath:path];-- asset[@"uri"] = [fileURL absoluteString];---- NSNumber *fileSizeValue = nil;-- NSError *fileSizeError = nil;-- [fileURL getResourceValue:&fileSizeValue forKey:NSURLFileSizeKey error:&fileSizeError];-- if (fileSizeValue){-- asset[@"fileSize"] = fileSizeValue;-- }-+ asset[@"uri"] = path;-+ asset[@"fileSize"] = [NSNumber numberWithInteger:[data length]];-- asset[@"fileName"] = fileName;- asset[@"width"] = @(image.size.width);