Skip to content

Commit

Permalink
fix problems after edited the file.
Browse files Browse the repository at this point in the history
  • Loading branch information
henry9610 committed Oct 29, 2024
1 parent cdb84a7 commit 0184a3f
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 343 deletions.
66 changes: 0 additions & 66 deletions Pod/Classes/SeafConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -950,29 +950,6 @@ - (void)handleStarredData:(id)JSON
_starredFiles = stars;
}

//befor 2.9.27 old api for get starred files
//- (void)getStarredFiles:(void (^)(NSHTTPURLResponse *response, id JSON))success
// failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure
//{
// [self sendRequest:API_URL"/starredfiles/"
// success:
// ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
// @synchronized(self) {
// Debug("Succeeded to get starred files ...\n");
// [self handleStarredData:JSON];
// NSData *data = [Utils JSONEncode:JSON];
// [self setValue:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] forKey:KEY_STARREDFILES entityName:ENTITY_OBJECT];
// if (success)
// success (response, JSON);
// }
// }
// failure:
// ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON, NSError *error) {
// if (failure)
// failure (response, error);
// }];
//}

- (void)getStarredFiles:(void (^)(NSHTTPURLResponse *response, id JSON))success
failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure
{
Expand Down Expand Up @@ -1057,42 +1034,6 @@ - (BOOL)setStarred:(BOOL)starred repo:(NSString *)repo path:(NSString *)path
return YES;
}

//before 2.9.27 old api for set starred file
//- (BOOL)setStarred:(BOOL)starred repo:(NSString *)repo path:(NSString *)path
//{
// NSString *key = [NSString stringWithFormat:@"%@-%@", repo, path];
// if (starred) {
// [_starredFiles addObject:key];
// NSString *form = [NSString stringWithFormat:@"repo_id=%@&p=%@", repo, [path escapedUrl]];
// NSString *url = [NSString stringWithFormat:API_URL"/starredfiles/"];
//// NSString *url = [NSString stringWithFormat:API_URL_V21"/starredfiles/"];
//
// [self sendPost:url form:form
// success:
// ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
// Debug("Succeeded to star file %@, %@\n", repo, path);
// }
// failure:
// ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON, NSError *error) {
// Warning("Failed to star file %@, %@\n", repo, path);
// }];
// } else {
// [_starredFiles removeObject:key];
// NSString *url = [NSString stringWithFormat:API_URL"/starredfiles/?repo_id=%@&p=%@", repo, path.escapedUrl];
// [self sendDelete:url
// success:
// ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
// Debug("Succeeded to unstar file %@, %@\n", repo, path);
// }
// failure:
// ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON, NSError *error) {
// Warning("Failed to unstar file %@, %@\n", repo, path);
// }];
// }
//
// return YES;
//}

- (SeafRepo *)getRepo:(NSString *)repo
{
return [self.rootFolder getRepo:repo];
Expand Down Expand Up @@ -1211,12 +1152,6 @@ - (void)resetUploadedPhotos
[self.photoBackup resetUploadedPhotos];
}

//not used
//- (void)firstTimeSyncUpdateSyncedPhotos:(SeafDir *)uploaddir
//{
// [self setFirstTimeSync:false];
//}

- (void)checkPhotos:(BOOL)force
{
[self.photoBackup checkPhotos:force];
Expand Down Expand Up @@ -1532,7 +1467,6 @@ - (void)clearAccountCache
[SeafStorage.sharedObject clearCache];
[_cacheProvider clearAllCacheInAccount:self.accountIdentifier];
[SeafAvatar clearCache];
[[NSNotificationCenter defaultCenter] postNotificationName:@"clearCache" object:nil];
[self clearUploadCache];
// CLear old versiond data
NSString *attrsFile = [[SeafStorage.sharedObject rootPath] stringByAppendingPathComponent:@"uploadfiles.plist"];
Expand Down
33 changes: 25 additions & 8 deletions Pod/Classes/SeafDataTaskManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ - (id)init
_accountQueueDict = [NSMutableDictionary new];
_finishBlock = nil;
[self startTimer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cacheCleared:) name:@"clearCache" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
return self;
Expand Down Expand Up @@ -98,7 +97,7 @@ - (void)cancelAutoSyncTasks:(SeafConnection *)conn
NSMutableArray *arr = [[NSMutableArray alloc] init];
@synchronized (accountQueue.uploadQueue.allTasks) {
for (SeafUploadFile *ufile in accountQueue.uploadQueue.allTasks) {
if (ufile.autoSync && ufile.udir->connection == conn) {
if (ufile.uploadFileAutoSync && ufile.udir->connection == conn) {
[arr addObject:ufile];
}
}
Expand All @@ -118,7 +117,7 @@ - (void)cancelAutoSyncVideoTasks:(SeafConnection *)conn
NSMutableArray *arr = [[NSMutableArray alloc] init];
@synchronized (accountQueue.uploadQueue.allTasks) {
for (SeafUploadFile *ufile in accountQueue.uploadQueue.allTasks) {
if (ufile.autoSync && ufile.udir->connection == conn && !ufile.isImageFile) {
if (ufile.uploadFileAutoSync && ufile.udir->connection == conn && !ufile.isImageFile) {
[arr addObject:ufile];
}
}
Expand All @@ -143,7 +142,7 @@ - (void)cancelAllUploadTasks:(SeafConnection * _Nonnull)conn
{
SeafAccountTaskQueue *accountQueue = [self getAccountQueueWithIndentifier:conn.accountIdentifier];
[accountQueue.uploadQueue clearTasks];
[self removeAccountUploadTaskFromStorage:conn.accountIdentifier];
[self removeAccountUploadTaskFromStorage:conn.accountIdentifier];//remove the current account all uploadFile info from storage
}

- (void)noException:(void (^)(void))block
Expand Down Expand Up @@ -231,9 +230,6 @@ - (SeafAccountTaskQueue *)accountQueueForConnection:(SeafConnection *)connection
return [self getAccountQueueWithIndentifier:connection.accountIdentifier];
}

- (void)cacheCleared:(NSNotification*)notification {
}

/**
* Saves information about an upload file task to persistent storage.
* @param ufile The upload file whose information is to be saved.
Expand Down Expand Up @@ -333,6 +329,13 @@ - (NSMutableDictionary*)convertTaskToDict:(id)task {
[Utils dict:dict setObject:ufile.udir.path forKey:@"path"];
[Utils dict:dict setObject:ufile.udir.perm forKey:@"perm"];
[Utils dict:dict setObject:ufile.udir.mime forKey:@"mime"];
if (ufile.isEditedFile) {
[Utils dict:dict setObject:[NSNumber numberWithBool:ufile.isEditedFile] forKey:@"isEditedFile"];
[Utils dict:dict setObject:ufile.editedFilePath forKey:@"editedFilePath"];
[Utils dict:dict setObject:ufile.editedFileRepoId forKey:@"editedFileRepoId"];
[Utils dict:dict setObject:ufile.editedFileOid forKey:@"editedFileOid"];
}

[Utils dict:dict setObject:[NSNumber numberWithBool:ufile.isUploaded] forKey:@"uploaded"];
}
return dict;
Expand Down Expand Up @@ -375,6 +378,19 @@ - (void)startLastTimeUnfinshTaskWithConnection:(SeafConnection *)conn {
ufile.overwrite = [[dict objectForKey:@"overwrite"] boolValue];
SeafDir *udir = [[SeafDir alloc] initWithConnection:conn oid:[dict objectForKey:@"oid"] repoId:[dict objectForKey:@"repoId"] perm:[dict objectForKey:@"perm"] name:[dict objectForKey:@"name"] path:[dict objectForKey:@"path"] mime:[dict objectForKey:@"mime"]];
ufile.udir = udir;

NSNumber *isEditedFileNumber = [dict objectForKey:@"isEditedFile"];
BOOL isEditedUploadFile = NO;
if (isEditedFileNumber != nil && [isEditedFileNumber isKindOfClass:[NSNumber class]]) {
isEditedUploadFile = [isEditedFileNumber boolValue];
}

if (isEditedUploadFile) {
ufile.isEditedFile = YES;
ufile.editedFilePath = [dict objectForKey:@"editedFilePath"];
ufile.editedFileRepoId = [dict objectForKey:@"editedFileRepoId"];
ufile.editedFileOid = [dict objectForKey:@"editedFileOid"];
}
[self addUploadTask:ufile];
}
if (toDelete.count > 0) {
Expand Down Expand Up @@ -405,7 +421,8 @@ - (NSArray *)getUploadTasksInDir:(SeafDir *)dir {
SeafAccountTaskQueue *accountQueue = [self getAccountQueueWithIndentifier:dir->connection.accountIdentifier];
NSMutableArray *filesInDir = [NSMutableArray new];
for (SeafUploadFile *ufile in accountQueue.uploadQueue.allTasks) {
if ([ufile.udir.repoId isEqualToString: dir.repoId] && [ufile.udir.path isEqualToString: dir.path]) {
//Check if the uploaded file belongs to the current folder.
if (!ufile.isEditedFile && [ufile.udir.repoId isEqualToString: dir.repoId] && [ufile.udir.path isEqualToString: dir.path]) {
[filesInDir addObject:ufile];
}
}
Expand Down
6 changes: 3 additions & 3 deletions Pod/Classes/SeafDir.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
path:(NSString *)aPath
mime:(NSString *)aMime;

@property (readonly, copy) NSArray *allItems;
@property (readonly, copy) NSArray *items;
@property (readonly) NSArray *uploadFiles;
@property (readonly, copy) NSArray *allItems;//All items displayed in the current directory
@property (readonly, copy) NSArray *items;//All items from server,after modified by - (void)updateItems:(NSMutableArray *)items
@property (readonly) NSArray *uploadFiles;// equal to uploadItems
@property (readonly) BOOL editable;
@property (nonatomic, copy) NSString *perm;
//@property (assign, nonatomic) BOOL encrypted;///< Indicates whether the repository is encrypted.
Expand Down
22 changes: 20 additions & 2 deletions Pod/Classes/SeafDir.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

@interface SeafDir ()
@property NSObject *uploadLock;
@property (readonly, nonatomic) NSMutableArray *uploadItems;
@property (readonly, nonatomic) NSMutableArray *uploadItems;//Files being uploaded in the current directory.

@end

Expand Down Expand Up @@ -123,6 +123,10 @@ - (BOOL)handleData:(NSString *)oid data:(id)JSON
Warning("Invalid response type: %@, %@", NSStringFromClass([JSON class]), JSON);
return false;
}

//check if has edited file not uploaded before.
SeafAccountTaskQueue *accountQueue = [SeafDataTaskManager.sharedObject accountQueueForConnection:self->connection];
NSArray *allUpLoadTasks = accountQueue.uploadQueue.allTasks;

NSMutableArray *newItems = [NSMutableArray array];
for (NSDictionary *itemInfo in JSON) {
Expand All @@ -148,6 +152,20 @@ - (BOOL)handleData:(NSString *)oid data:(id)JSON
NSString *oid = [Utils getNewOidFromMtime:[mtimeNumber longLongValue] repoId:self.repoId path:path];

newItem.oid = oid;

if (allUpLoadTasks.count > 0) {//if have uploadTask
for (SeafUploadFile *file in allUpLoadTasks) {
//check and set uploadFile to SeafFile
if ((file.editedFileOid != nil) && [file.editedFileOid isEqualToString:oid]) {
SeafFile *fileItem = (SeafFile *)newItem;
fileItem.ufile = file;
[fileItem setMpath:file.lpath];
fileItem.ufile.delegate = fileItem;
newItem = fileItem;
}
}
}

} else if ([type isEqual:@"dir"]) {
newItem = [[SeafDir alloc] initWithConnection:connection oid:[itemInfo objectForKey:@"id"] repoId:self.repoId perm:[itemInfo objectForKey:@"permission"] name:name path:path];
}
Expand Down Expand Up @@ -471,7 +489,7 @@ - (void)addUploadFile:(SeafUploadFile *)file
[self.uploadItems addObject:file];
}
_allItems = nil;
if (!file.autoSync) [self.delegate download:self complete:true];
if (!file.uploadFileAutoSync) [self.delegate download:self complete:true];
}

- (void)removeUploadItem:(SeafUploadFile *)ufile
Expand Down
1 change: 1 addition & 0 deletions Pod/Classes/SeafFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typedef void (^SeafThumbCompleteBlock)(BOOL ret);
@property (copy, nonatomic) NSString * _Nullable thumbnailURLStr;//image thumbnail Url String
@property (nonatomic, assign) NSInteger thumbFailedCount;//download thumb failure count
@property (nonatomic, copy) NSURLSessionDownloadTask * _Nullable thumbtask;
@property (strong, nonatomic) SeafUploadFile * _Nullable ufile;

/**
* Checks if the file is currently being downloaded.
Expand Down
Loading

0 comments on commit 0184a3f

Please sign in to comment.