Skip to content

Commit ea85d03

Browse files
committed
文件 - storage_key 后缀与真实文件后缀不一致的 bugfix
1 parent ff78b27 commit ea85d03

File tree

9 files changed

+36
-15
lines changed

9 files changed

+36
-15
lines changed

Coding_iOS/Controllers/FileVersionsViewController.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ - (void)doRemarkFileVersion:(FileVersion *)curVersion withRemarkStr:(NSString *)
187187
- (void)deleteFileVersion:(FileVersion *)curVersion{
188188
__weak typeof(self) weakSelf = self;
189189

190-
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:curVersion.storage_key];
190+
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:curVersion.storage_key_for_disk];
191191
Coding_DownloadTask *cDownloadTask = [Coding_FileManager cDownloadTaskForKey:curVersion.storage_key];
192192
UIActionSheet *actionSheet;
193193

@@ -234,7 +234,7 @@ - (void)doDeleteFileVersion:(FileVersion *)curVersion fromDisk:(BOOL)fromDisk{
234234
[Coding_FileManager cancelCDownloadTaskForKey:curVersion.storage_key];
235235
}
236236
// 删除本地文件
237-
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:curVersion.storage_key];
237+
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:curVersion.storage_key_for_disk];
238238
NSString *filePath = fileUrl.path;
239239
NSFileManager *fm = [NSFileManager defaultManager];
240240
if ([fm fileExistsAtPath:filePath]) {

Coding_iOS/Models/FileVersion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@property (strong, nonatomic) NSDate *created_at;
1616
@property (readwrite, nonatomic, strong) User *owner;
1717

18-
@property (strong, nonatomic, readonly) NSString *diskFileName;
18+
@property (strong, nonatomic, readonly) NSString *diskFileName, *storage_key_for_disk;
1919

2020
- (NSString *)downloadPath;
2121

Coding_iOS/Models/FileVersion.m

+14-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,22 @@ @interface FileVersion ()
1616
@implementation FileVersion
1717
- (NSString *)diskFileName{
1818
if (!_diskFileName) {
19-
_diskFileName = [NSString stringWithFormat:@"%@|||%@|||%@|%@", _name, _project_id.stringValue, _storage_type, _storage_key];
19+
_diskFileName = [NSString stringWithFormat:@"%@|||%@|||%@|%@", _name, _project_id.stringValue, _storage_type, self.storage_key_for_disk];
2020
}
2121
return _diskFileName;
2222
}
23+
24+
- (NSString *)storage_key_for_disk{
25+
NSArray *fileNameCom = [_name componentsSeparatedByString:@"."];
26+
NSMutableArray *storage_keyCom = [_storage_key componentsSeparatedByString:@"."].mutableCopy;
27+
if (fileNameCom.count > 1 && storage_keyCom.count > 0 && ![fileNameCom.lastObject isEqualToString:storage_keyCom.lastObject]) {
28+
[storage_keyCom addObject:fileNameCom.lastObject];
29+
return [storage_keyCom componentsJoinedByString:@"."];
30+
}else{
31+
return _storage_key;
32+
}
33+
}
34+
2335
- (NSString *)downloadPath{
2436
return [NSString stringWithFormat:@"%@api/project/%@/files/histories/%@/download", [NSObject baseURLStr], _project_id, _history_id];
2537
}
@@ -54,6 +66,6 @@ - (Coding_DownloadTask *)cDownloadTask{
5466
return [Coding_FileManager cDownloadTaskForKey:_storage_key];
5567
}
5668
- (NSURL *)hasBeenDownload{
57-
return [Coding_FileManager diskDownloadUrlForKey:_storage_key];
69+
return [Coding_FileManager diskDownloadUrlForKey:self.storage_key_for_disk];
5870
}
5971
@end

Coding_iOS/Models/ProjectFile.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef NS_ENUM(NSInteger, DownloadState){
2626
@property (readwrite, nonatomic, strong) NSString *name, *fileType, *owner_preview, *preview, *storage_key, *storage_type, *title, *path;
2727
@property (readwrite, nonatomic, strong) User *owner;
2828
@property (readwrite, nonatomic, strong) FileShare *share, *share_ea;
29-
@property (strong, nonatomic, readonly) NSString *diskFileName;
29+
@property (strong, nonatomic, readonly) NSString *diskFileName, *storage_key_for_disk;
3030

3131
+ (ProjectFile *)fileWithFileId:(NSNumber *)fileId andProjectId:(NSNumber *)project_id;
3232
- (instancetype)initWithFileId:(NSNumber *)fileId inProject:(NSString *)project_name ofUser:(NSString *)project_owner_name;

Coding_iOS/Models/ProjectFile.m

+13-2
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,27 @@ - (NSString *)downloadPath{
102102

103103
- (NSString *)diskFileName{
104104
if (!_diskFileName) {
105-
_diskFileName = [NSString stringWithFormat:@"%@|||%@|||%@|%@", _name, _project_id.stringValue, _storage_type, _storage_key];
105+
_diskFileName = [NSString stringWithFormat:@"%@|||%@|||%@|%@", _name, _project_id.stringValue, _storage_type, self.storage_key_for_disk];
106106
}
107107
return _diskFileName;
108108
}
109109

110+
- (NSString *)storage_key_for_disk{
111+
NSArray *fileNameCom = [_name componentsSeparatedByString:@"."];
112+
NSMutableArray *storage_keyCom = [_storage_key componentsSeparatedByString:@"."].mutableCopy;
113+
if (fileNameCom.count > 1 && storage_keyCom.count > 0 && ![fileNameCom.lastObject isEqualToString:storage_keyCom.lastObject]) {
114+
[storage_keyCom addObject:fileNameCom.lastObject];
115+
return [storage_keyCom componentsJoinedByString:@"."];
116+
}else{
117+
return _storage_key;
118+
}
119+
}
120+
110121
- (Coding_DownloadTask *)cDownloadTask{
111122
return [Coding_FileManager cDownloadTaskForKey:_storage_key];
112123
}
113124
- (NSURL *)hasBeenDownload{
114-
return [Coding_FileManager diskDownloadUrlForKey:_storage_key];
125+
return [Coding_FileManager diskDownloadUrlForKey:self.storage_key_for_disk];
115126
}
116127

117128
- (NSString *)toDeletePath{

Coding_iOS/Util/Manager/Coding_FileManager.m

+2-4
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ - (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName projectIsP
261261
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationUploadCompled object:manager userInfo:@{@"response" : response,
262262
@"error" : error}];
263263
}else if (responseObject) {
264-
NSString *block_project_id = [[[[response.URL.absoluteString componentsSeparatedByString:@"/project/"] lastObject] componentsSeparatedByString:@"/"] firstObject];
265264
responseObject = [responseObject valueForKey:@"data"];
266265

267266
if ([responseObject isKindOfClass:[NSString class]]) {
@@ -270,12 +269,11 @@ - (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName projectIsP
270269
@"data" : responseObject}];
271270
}else{
272271
ProjectFile *curFile = [NSObject objectOfClass:@"ProjectFile" fromJSON:responseObject];
273-
NSString *block_fileName = [NSString stringWithFormat:@"%@|||%@|||%@", block_project_id, curFile.parent_id.stringValue, curFile.name];
272+
NSString *block_fileName = [NSString stringWithFormat:@"%@|||%@|||%@", curFile.project_id.stringValue, curFile.parent_id.stringValue, curFile.name];
274273
NSString *block_filePath = [[[manager class] uploadPath] stringByAppendingPathComponent:block_fileName];
275274

276275
//移动文件到已下载
277-
NSString *diskFileName = [NSString stringWithFormat:@"%@|||%@|||%@|%@", curFile.name, block_project_id, curFile.storage_type, curFile.storage_key];
278-
NSString *diskFilePath = [[[manager class] downloadPath] stringByAppendingPathComponent:diskFileName];
276+
NSString *diskFilePath = [[[manager class] downloadPath] stringByAppendingPathComponent:curFile.diskFileName];
279277
[[NSFileManager defaultManager] moveItemAtPath:block_filePath toPath:diskFilePath error:nil];
280278
[manager directoryDidChange:manager.docUploadWatcher];
281279
[manager directoryDidChange:manager.docDownloadWatcher];

Coding_iOS/Views/Cell/FileListFileCell.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ - (void)setFile:(ProjectFile *)file{
142142

143143
- (void)clickedByUser{
144144
Coding_FileManager *manager = [Coding_FileManager sharedManager];
145-
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:_file.storage_key];
145+
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:_file.storage_key_for_disk];
146146
if (fileUrl) {//已经下载到本地了
147147
if (_showDiskFileBlock) {
148148
_showDiskFileBlock(fileUrl, _file);

Coding_iOS/Views/Cell/FileVersionCell.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ - (void)changeToState:(DownloadState)state{
164164

165165
- (void)clickedByUser{
166166
Coding_FileManager *manager = [Coding_FileManager sharedManager];
167-
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:_curVersion.storage_key];
167+
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:_curVersion.storage_key_for_disk];
168168
if (fileUrl) {//已经下载到本地了
169169
if (_showDiskFileBlock) {
170170
_showDiskFileBlock(fileUrl, _curVersion);

Coding_iOS/Views/FileDownloadView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ - (NSString *)fileType{
6767
return [self.curData valueForKey:@"fileType"];
6868
}
6969
- (NSString *)storage_key{
70-
return [self.curData valueForKey:@"storage_key"];
70+
return [self.curData valueForKey:@"storage_key_for_disk"];
7171
}
7272
- (NSString *)name{
7373
if (_version) {

0 commit comments

Comments
 (0)