Skip to content

Commit 0979467

Browse files
committed
文件资源的跳转
1 parent e0a2854 commit 0979467

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

Coding_iOS/Controllers/FileViewController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313

1414
@interface FileViewController : BaseViewController
1515
@property (strong, nonatomic) ProjectFile *curFile;
16+
- (void)requestFileData;
1617
@end

Coding_iOS/Controllers/RootControllers/BaseViewController.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "ProjectCommitsViewController.h"
2828
#import "MRPRDetailViewController.h"
2929
#import "CommitFilesViewController.h"
30+
#import "FileViewController.h"
3031

3132
#import "UnReadManager.h"
3233

@@ -154,6 +155,7 @@ + (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr analyseMethod:(An
154155
NSString *ppRegexStr = @"/u/([^/]+)/pp/([0-9]+)$";
155156
NSString *topicRegexStr = @"/u/([^/]+)/p/([^/]+)/topic/(\\d+)";
156157
NSString *taskRegexStr = @"/u/([^/]+)/p/([^/]+)/task/(\\d+)";
158+
NSString *fileRegexStr = @"/u/([^/]+)/p/([^/]+)/attachment/([^/]+)/preview/(\\d+)";
157159
NSString *gitMRPRCommitRegexStr = @"/u/([^/]+)/p/([^/]+)/git/(merge|pull|commit)/([^/#]+)";
158160
NSString *conversionRegexStr = @"/user/messages/history/([^/]+)$";
159161
NSString *projectRegexStr = @"/u/([^/]+)/p/([^/]+)";
@@ -249,7 +251,24 @@ + (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr analyseMethod:(An
249251
};
250252
analyseVC = vc;
251253
}
252-
254+
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:fileRegexStr]).count > 0){
255+
NSString *user_global_key = matchedCaptures[1];
256+
NSString *project_name = matchedCaptures[2];
257+
NSString *fileId = matchedCaptures[4];
258+
if ([presentingVC isKindOfClass:[FileViewController class]]) {
259+
FileViewController *vc = (FileViewController *)presentingVC;
260+
if (vc.curFile.file_id.integerValue == fileId.integerValue) {
261+
[vc requestFileData];
262+
analyseVCIsNew = NO;
263+
analyseVC = vc;
264+
}
265+
}
266+
if (!analyseVC) {
267+
FileViewController *vc = [FileViewController new];
268+
ProjectFile *curFile = [[ProjectFile alloc] initWithFileId:@(fileId.integerValue) inProject:project_name ofUser:user_global_key];
269+
vc.curFile = curFile;
270+
analyseVC = vc;
271+
}
253272
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:conversionRegexStr]).count > 0) {
254273
//私信
255274
NSString *user_global_key = matchedCaptures[1];

Coding_iOS/Models/ProjectFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef NS_ENUM(NSInteger, DownloadState){
2727
@property (readwrite, nonatomic, strong) NSString *diskFileName;
2828

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

3132
- (BOOL)isEmpty;
3233

Coding_iOS/Models/ProjectFile.m

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#import "ProjectFile.h"
1010
#import "Coding_FileManager.h"
1111

12+
@interface ProjectFile ()
13+
@property (strong, nonatomic) NSString *project_name, *project_owner_name;
14+
@end
15+
1216
@implementation ProjectFile
1317

1418
+(ProjectFile *)fileWithFileId:(NSNumber *)fileId andProjectId:(NSNumber *)project_id{
@@ -17,6 +21,27 @@ +(ProjectFile *)fileWithFileId:(NSNumber *)fileId andProjectId:(NSNumber *)proje
1721
file.project_id = project_id;
1822
return file;
1923
}
24+
25+
- (instancetype)initWithFileId:(NSNumber *)fileId inProject:(NSString *)project_name ofUser:(NSString *)project_owner_name{
26+
self = [super init];
27+
if (self) {
28+
_file_id = fileId;
29+
_project_id = nil;
30+
_project_name = project_name;
31+
_project_owner_name = project_owner_name;
32+
}
33+
return self;
34+
}
35+
36+
- (void)setOwner_preview:(NSString *)owner_preview{
37+
_owner_preview = owner_preview;
38+
if (!_project_id && owner_preview.length > 0) {
39+
NSString *project_id;
40+
project_id = [[[[owner_preview componentsSeparatedByString:@"project/"] lastObject] componentsSeparatedByString:@"/"] firstObject];
41+
_project_id = @(project_id.integerValue);
42+
}
43+
}
44+
2045
- (BOOL)isEmpty{
2146
return !(self.storage_key && self.storage_key.length > 0);
2247
}
@@ -142,7 +167,15 @@ - (NSDictionary *)toMoveToParams{
142167
}
143168

144169
- (NSString *)toDetailPath{
145-
return [NSString stringWithFormat:@"api/project/%@/files/%@/view", _project_id.stringValue, _file_id.stringValue];
170+
NSString *path;
171+
if (!_project_id) {
172+
path = [NSString stringWithFormat:@"api/user/%@/project/%@/files/%@/view", _project_owner_name, _project_name, _file_id.stringValue];
173+
}else{
174+
path = [NSString stringWithFormat:@"api/project/%@/files/%@/view", _project_id.stringValue, _file_id.stringValue];
175+
}
176+
return path;
146177
}
178+
179+
147180
@end
148181

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,9 @@ - (void)request_FileDetail:(ProjectFile *)file andBlock:(void (^)(id data, NSErr
755755
id resultData = [data valueForKeyPath:@"data"];
756756
resultData = [resultData valueForKeyPath:@"file"];
757757
ProjectFile *detailFile = [NSObject objectOfClass:@"ProjectFile" fromJSON:resultData];
758-
detailFile.project_id = file.project_id;
758+
if (file.project_id) {
759+
detailFile.project_id = file.project_id;
760+
}
759761
block(detailFile, nil);
760762
}else{
761763
block(nil, error);

Coding_iOS/Views/FileDownloadView.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ - (void)clickedByUser{
246246
break;
247247
}
248248
}else{//新建下载
249-
249+
if (!self.file.project_id) {
250+
[self showHudTipStr:@"下载失败~"];
251+
return;
252+
}
250253
__weak typeof(self) weakSelf = self;
251254
Coding_DownloadTask *cDownloadTask = [manager addDownloadTaskForFile:self.file completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
252255
if (error) {

0 commit comments

Comments
 (0)