marinofaggiana 4 年 前
コミット
bfa65cb3d4

+ 3 - 15
iOSClient/AutoUpload/NCAutoUpload.m

@@ -404,15 +404,9 @@
         tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView == %@", appDelegate.activeAccount, serverUrl, fileName]];
         if (!metadata) {
         
-            tableMetadata *metadataForUpload = [tableMetadata new];
+            tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:[[NSUUID UUID] UUIDString] serverUrl:serverUrl url:@"" contentType:@""];
             
-            metadataForUpload.account = appDelegate.activeAccount;
             metadataForUpload.assetLocalIdentifier = asset.localIdentifier;
-            metadataForUpload.date = [NSDate new];
-            metadataForUpload.ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrl fileNameView:fileName directory:false];
-            metadataForUpload.fileName = fileName;
-            metadataForUpload.fileNameView = fileName;
-            metadataForUpload.serverUrl = serverUrl;
             metadataForUpload.session = session;
             metadataForUpload.sessionSelector = selector;
             metadataForUpload.size = [[NCUtility sharedInstance] getFileSizeWithAsset:asset];
@@ -422,7 +416,7 @@
             if ((asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive || asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive+PHAssetMediaSubtypePhotoHDR) && CCUtility.getLivePhoto) {
                 
                 NSString *fileNameMove = [NSString stringWithFormat:@"%@.mov", fileName.stringByDeletingPathExtension];
-                NSString *ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrl fileNameView:fileNameMove directory:false];
+                NSString *ocId = [[NSUUID UUID] UUIDString];
                 NSString *filePath = [CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileNameMove];
                 
                 dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
@@ -431,14 +425,8 @@
                     if (url != nil) {
                         unsigned long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:url.path error:nil] fileSize];
                         
-                        tableMetadata *metadataMOVForUpload = [tableMetadata new];
+                        tableMetadata *metadataMOVForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileNameMove ocId:ocId serverUrl:serverUrl url:@"" contentType:@""];
                         
-                        metadataMOVForUpload.account = appDelegate.activeAccount;
-                        metadataMOVForUpload.date = [NSDate new];
-                        metadataMOVForUpload.ocId = ocId;
-                        metadataMOVForUpload.fileName = fileNameMove;
-                        metadataMOVForUpload.fileNameView = fileNameMove;
-                        metadataMOVForUpload.serverUrl = serverUrl;
                         metadataMOVForUpload.session = session;
                         metadataMOVForUpload.sessionSelector = selector;
                         metadataMOVForUpload.size = fileSize;

+ 6 - 17
iOSClient/Main/CCMain.m

@@ -863,21 +863,15 @@
             
             NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
             NSString *fileName =  [url lastPathComponent];
-            NSString *ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrl fileNameView:fileName directory:false];
+            NSString *ocId = [[NSUUID UUID] UUIDString];
             NSData *data = [NSData dataWithContentsOfURL:newURL];
             
             if (data && error == nil) {
                 
                 if ([data writeToFile:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName] options:NSDataWritingAtomic error:&error]) {
                     
-                    tableMetadata *metadataForUpload = [tableMetadata new];
+                    tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:ocId serverUrl:serverUrl url:@"" contentType:@""];
                     
-                    metadataForUpload.account = appDelegate.activeAccount;
-                    metadataForUpload.date = [NSDate new];
-                    metadataForUpload.ocId = ocId;
-                    metadataForUpload.fileName = fileName;
-                    metadataForUpload.fileNameView = fileName;
-                    metadataForUpload.serverUrl = serverUrl;
                     metadataForUpload.session = k_upload_session;
                     metadataForUpload.sessionSelector = selectorUploadFile;
                     metadataForUpload.size = data.length;
@@ -2147,18 +2141,13 @@
             if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
                 
                 NSString *fileName = [[NCUtility sharedInstance] createFileName:metadata.fileNameView serverUrl:self.serverUrl account:appDelegate.activeAccount];
-                NSString *ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:self.serverUrl fileNameView:fileName directory:false];
+                NSString *ocId = [[NSUUID UUID] UUIDString];
                 
                 [CCUtility copyFileAtPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView] toPath:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName]];
                     
-                tableMetadata *metadataForUpload = [tableMetadata new];
-                        
-                metadataForUpload.account = appDelegate.activeAccount;
-                metadataForUpload.date = [NSDate new];
-                metadataForUpload.ocId = ocId;
-                metadataForUpload.fileName = fileName;
-                metadataForUpload.fileNameView = fileName;
-                metadataForUpload.serverUrl = self.serverUrl;
+                // Prepare record metadata
+                tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:ocId serverUrl:self.serverUrl url:@"" contentType:@""];
+            
                 metadataForUpload.session = k_upload_session;
                 metadataForUpload.sessionSelector = selectorUploadFile;
                 metadataForUpload.size = metadata.size;

+ 3 - 5
iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift

@@ -170,8 +170,7 @@ extension NCCreateFormUploadConflictDelegate {
                 let fileNameMOV = (metadata.fileNameView as NSString).deletingPathExtension + ".mov"
                 
                 let newFileName = NCUtility.sharedInstance.createFileName(metadata.fileNameView, serverUrl: metadata.serverUrl, account: metadata.account)
-                let ocId = CCUtility.createMetadataID(fromAccount: metadata.account, serverUrl: metadata.serverUrl, fileNameView: newFileName, directory: false)!
-                metadata.ocId = ocId
+                metadata.ocId = UUID().uuidString
                 metadata.fileName = newFileName
                 metadata.fileNameView = newFileName
                 
@@ -184,12 +183,11 @@ extension NCCreateFormUploadConflictDelegate {
                         let oldPath = CCUtility.getDirectoryProviderStorageOcId(metadataMOV.ocId, fileNameView: metadataMOV.fileNameView)
                         let newFileNameMOV = (newFileName as NSString).deletingPathExtension + ".mov"
                         
-                        let ocId = CCUtility.createMetadataID(fromAccount: metadataMOV.account, serverUrl: metadataMOV.serverUrl, fileNameView: newFileNameMOV, directory: false)!
-                        metadataMOV.ocId = ocId
+                        metadataMOV.ocId = UUID().uuidString
                         metadataMOV.fileName = newFileNameMOV
                         metadataMOV.fileNameView = newFileNameMOV
                         
-                        let newPath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: newFileNameMOV)
+                        let newPath = CCUtility.getDirectoryProviderStorageOcId(metadataMOV.ocId, fileNameView: newFileNameMOV)
                         CCUtility.moveFile(atPath: oldPath, toPath: newPath)
                         
                         break

+ 1 - 2
iOSClient/Main/Create cloud/NCCreateFormUploadFileText.swift

@@ -202,8 +202,7 @@ class NCCreateFormUploadFileText: XLFormViewController, NCSelectDelegate {
             self.present(alertController, animated: true, completion:nil)
             
         } else {
-            let ocId = CCUtility.createMetadataID(fromAccount: appDelegate.activeAccount, serverUrl: self.serverUrl, fileNameView: fileNameSave, directory: false)!
-            dismissAndUpload(fileNameSave, ocId: ocId, serverUrl: serverUrl)
+            dismissAndUpload(fileNameSave, ocId: UUID().uuidString, serverUrl: serverUrl)
         }
     }
     

+ 1 - 3
iOSClient/Main/Create cloud/NCCreateFormUploadScanDocument.swift

@@ -408,9 +408,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
         }
         
         //Create metadata for upload
-        let ocId = CCUtility.createMetadataID(fromAccount: self.appDelegate.activeAccount, serverUrl: serverUrl, fileNameView: fileNameSave, directory: false)!
-        
-        let metadataForUpload = NCManageDatabase.sharedInstance.createMetadata(account: appDelegate.activeAccount, fileName: fileNameSave, ocId: ocId, serverUrl: serverUrl, url: appDelegate.activeUrl, contentType: "")
+        let metadataForUpload = NCManageDatabase.sharedInstance.createMetadata(account: appDelegate.activeAccount, fileName: fileNameSave, ocId: UUID().uuidString, serverUrl: serverUrl, url: appDelegate.activeUrl, contentType: "")
         
         metadataForUpload.session = k_upload_session
         metadataForUpload.sessionSelector = selectorUploadFile

+ 2 - 8
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift

@@ -231,15 +231,9 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
             } else {
                 fileNameSave = (name as! NSString).deletingPathExtension + ".m4a"
             }
+                        
+            let metadataForUpload = NCManageDatabase.sharedInstance.createMetadata(account: self.appDelegate.activeAccount, fileName: fileNameSave, ocId: UUID().uuidString, serverUrl: self.serverUrl, url: "", contentType: "")
             
-            let metadataForUpload = tableMetadata()
-            
-            metadataForUpload.account = self.appDelegate.activeAccount
-            metadataForUpload.date = NSDate()
-            metadataForUpload.ocId = CCUtility.createMetadataID(fromAccount: self.appDelegate.activeAccount, serverUrl: self.serverUrl, fileNameView: fileNameSave, directory: false)
-            metadataForUpload.fileName = fileNameSave
-            metadataForUpload.fileNameView = fileNameSave
-            metadataForUpload.serverUrl = self.serverUrl
             metadataForUpload.session = k_upload_session
             metadataForUpload.sessionSelector = selectorUploadFile
             metadataForUpload.status = Int(k_metadataStatusWaitUpload)

+ 4 - 0
iOSClient/Networking/CCNetworking.m

@@ -654,11 +654,15 @@
         }
         
         // if new file upload create a new encrypted filename
+        fileNameIdentifier = [CCUtility generateRandomIdentifier];
+        
+        /*
         if ([metadata.ocId isEqualToString:[CCUtility createMetadataIDFromAccount:metadata.account serverUrl:metadata.serverUrl fileNameView:metadata.fileNameView directory:false]]) {
             fileNameIdentifier = [CCUtility generateRandomIdentifier];
         } else {
             fileNameIdentifier = metadata.fileName;
         }
+        */
         
         if ([[NCEndToEndEncryption sharedManager] encryptFileName:metadata.fileNameView fileNameIdentifier:fileNameIdentifier directory:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId] key:&key initializationVector:&initializationVector authenticationTag:&authenticationTag]) {
             

+ 2 - 8
iOSClient/UploadFromOtherUpp/CCUploadFromOtherUpp.m

@@ -170,14 +170,8 @@
 {
     NSString *fileName = [[NCUtility sharedInstance] createFileName:self.fileNameTextfield.text serverUrl:serverUrlLocal account:appDelegate.activeAccount];
     
-    tableMetadata *metadataForUpload = [tableMetadata new];
-    
-    metadataForUpload.account = appDelegate.activeAccount;
-    metadataForUpload.date = [NSDate new];
-    metadataForUpload.ocId = [CCUtility createMetadataIDFromAccount:appDelegate.activeAccount serverUrl:serverUrlLocal fileNameView:fileName directory:false];
-    metadataForUpload.fileName = fileName;
-    metadataForUpload.fileNameView = fileName;
-    metadataForUpload.serverUrl = serverUrlLocal;
+    tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.activeAccount fileName:fileName ocId:[[NSUUID UUID] UUIDString] serverUrl:serverUrlLocal url:@"" contentType:@""];
+    
     metadataForUpload.session = k_upload_session;
     metadataForUpload.sessionSelector = selectorUploadFile;
     metadataForUpload.status = k_metadataStatusWaitUpload;

+ 2 - 6
iOSClient/Utility/CCUtility.h

@@ -251,17 +251,13 @@
 
 + (void)extractImageVideoFromAssetLocalIdentifierForUpload:(tableMetadata *)metadata assetLocalIdentifier:(NSString *)assetLocalIdentifier completion:(void(^)(tableMetadata *metadataForUpload, NSURL *url))completion;
 
++ (NSString *)convertOcIdToFileId:(NSString *)ocId;
+
 // ===== E2E Encrypted =====
 
 + (NSString *)generateRandomIdentifier;
 + (BOOL)isFolderEncrypted:(NSString *)serverUrl e2eEncrypted:(BOOL)e2eEncrypted account:(NSString *)account;
 
-// ===== CCMetadata =====
-
-+ (NSString *)createMetadataIDFromAccount:(NSString *)account serverUrl:(NSString *)serverUrl fileNameView:(NSString *)fileNameView directory:(BOOL)directory;
-
-+ (NSString *)convertOcIdToFileId:(NSString *)ocId;
-
 // ===== Third parts =====
 
 + (NSString *)stringValueForKey:(id)key conDictionary:(NSDictionary *)dictionary;

+ 10 - 37
iOSClient/Utility/CCUtility.m

@@ -1493,9 +1493,8 @@
                     metadata.fileName = [fileNameJPEG stringByAppendingString:@".jpg"];
                     metadata.fileNameView = metadata.fileName;
                     
-                    // Change Metadata with new ocId, fileName, fileNameView
+                    // Change Metadata with new fileName, fileNameView
                     [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
-                    metadata.ocId = [CCUtility createMetadataIDFromAccount:metadata.account serverUrl:metadata.serverUrl fileNameView:metadata.fileNameView directory:false];
                 }
             }
             
@@ -1597,6 +1596,15 @@
     }
 }
 
++ (NSString *)convertOcIdToFileId:(NSString *)ocId
+{
+    NSArray *components = [ocId componentsSeparatedByString:@"oc"];
+    NSInteger numFileId = [components.firstObject intValue];
+    NSString *fileId = [@(numFileId) stringValue];
+    
+    return fileId;
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== E2E Encrypted =====
 #pragma --------------------------------------------------------------------------------------------
@@ -1631,41 +1639,6 @@
     }
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== CCMetadata =====
-#pragma --------------------------------------------------------------------------------------------
-
-+ (NSString *)createMetadataIDFromAccount:(NSString *)account serverUrl:(NSString *)serverUrl fileNameView:(NSString *)fileNameView directory:(BOOL)directory
-{
-    NSArray *arrayForbiddenCharacters = [NSArray arrayWithObjects:@"\\",@"<",@">",@":",@"\"",@"|",@"?",@"*",@"/", nil];
-    
-    for (NSString *currentCharacter in arrayForbiddenCharacters) {
-        account = [account stringByReplacingOccurrencesOfString:currentCharacter withString:@""];
-    }
-    
-    for (NSString *currentCharacter in arrayForbiddenCharacters) {
-        serverUrl = [serverUrl stringByReplacingOccurrencesOfString:currentCharacter withString:@""];
-    }
-    
-    NSString *uniqueID = [[account stringByAppendingString:serverUrl] lowercaseString];
-    NSString *metadataID =  [[uniqueID stringByAppendingString:fileNameView] lowercaseString];
-    
-    if (directory) {
-        return [metadataID stringByAppendingString:@"-dir"];
-    }
-    
-    return metadataID;
-}
-
-+ (NSString *)convertOcIdToFileId:(NSString *)ocId
-{
-    NSArray *components = [ocId componentsSeparatedByString:@"oc"];
-    NSInteger numFileId = [components.firstObject intValue];
-    NSString *fileId = [@(numFileId) stringValue];
-    
-    return fileId;
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Third parts =====
 #pragma --------------------------------------------------------------------------------------------