FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Models/ProjectFile.m at master · dxinba/Coding-iOS · GitHub
dxinba
/
Coding-iOS
Public
forked from
coding/Coding-iOS
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Models
/
ProjectFile.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
208 lines (180 loc) · 6.92 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Models
/
ProjectFile.m
Copy path
File metadata and controls
executable file
·
208 lines (180 loc) · 6.92 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//
//
ProjectFile.m
//
Coding_iOS
//
//
Created by Ease on 14/11/13.
//
Copyright (c) 2014年 Coding. All rights reserved.
//
#
import
"
ProjectFile.h
"
#
import
"
Coding_FileManager.h
"
@interface
ProjectFile
()
@property
(
strong
,
nonatomic
,
readwrite
)
NSString
*diskFileName;
@end
@implementation
ProjectFile
-(
id
)
copyWithZone
:
(
NSZone
*)
zone
{
ProjectFile *file = [[[
self
class
]
allocWithZone:
zone]
init
];
file.
project_owner_name
= [_project_owner_name
copy
];
file.
project_name
= [_project_name
copy
];
file.
diskFileName
= [_diskFileName
copy
];
file.
owner
= [_owner
copy
];
file.
share
= [FileShare
instanceWithUrl:
_share.url];
file.
title
= [_title
copy
];
file.
storage_type
= [_storage_type
copy
];
file.
storage_key
= [_storage_key
copy
];
file.
preview
= [_preview
copy
];
file.
owner_preview
= [_owner_preview
copy
];
file.
fileType
= [_fileType
copy
];
file.
name
= [_name
copy
];
file.
number
= [_number
copy
];
file.
project_id
= [_project_id
copy
];
file.
size
= [_size
copy
];
file.
current_user_role_id
= [_current_user_role_id
copy
];
file.
type
= [_type
copy
];
file.
parent_id
= [_parent_id
copy
];
file.
owner_id
= [_owner_id
copy
];
file.
file_id
= [
self
.file_id
copy
];
file.
created_at
= [_created_at
copy
];
file.
updated_at
= [_updated_at
copy
];
file.
id
=[_id
copy
];
file.
path
=[_path
copy
];
return
file;
}
+(ProjectFile *)
fileWithFileId
:
(
NSNumber
*)
fileId
andProjectId
:
(
NSNumber
*)
project_id
{
ProjectFile *file = [[ProjectFile
alloc
]
init
];
file.
file_id
= fileId;
file.
project_id
= project_id;
return
file;
}
+ (
instancetype
)
sharedFolderInProject
:
(
NSString
*)
project_name
ofUser
:
(
NSString
*)
project_owner_name
{
ProjectFile *file = [[
self
alloc
]
initWithFileId:
@(-
1
)
inProject:
project_name
ofUser:
project_owner_name];
file.
type
= @
0
;
//
文件夹类型
return
file;
}
- (
instancetype
)
initWithFileId
:
(
NSNumber
*)
fileId
inProject
:
(
NSString
*)
project_name
ofUser
:
(
NSString
*)
project_owner_name
{
self = [
super
init
];
if
(self) {
self.
file_id
= fileId;
_project_id =
nil
;
_project_name = project_name;
_project_owner_name = project_owner_name;
}
return
self;
}
- (
void
)
setOwner_preview
:
(
NSString
*)
owner_preview
{
_owner_preview = owner_preview;
if
(!_project_id && owner_preview.
length
>
0
) {
NSString
*project_id;
project_id = [[[[owner_preview
componentsSeparatedByString:
@"
project/
"
]
lastObject
]
componentsSeparatedByString:
@"
/
"
]
firstObject
];
_project_id = @(project_id.
integerValue
);
}
}
- (
NSNumber
*)
file_id
{
return
_file_id ?: _id;
}
- (
void
)
setCount
:
(
NSNumber
*)
count
{
_count = @(
MAX
(
0
, count.
integerValue
));
}
- (
BOOL
)
isDefaultFolder
{
return
_file_id && _file_id.
integerValue
==
0
;
}
- (
BOOL
)
isSharedFolder
{
return
_file_id && _file_id.
integerValue
== -
1
;
}
- (
BOOL
)
isEmpty
{
return
!(self.
storage_key
&& self.
storage_key
.
length
>
0
);
}
- (DownloadState)
downloadState
{
DownloadState state = DownloadStateDefault;
if
([
self
diskFileUrl
]) {
state = DownloadStateDownloaded;
}
else
{
Coding_DownloadTask *cDownloadTask = [
self
cDownloadTask
];
if
(cDownloadTask) {
if
(cDownloadTask.
task
.
state
==
NSURLSessionTaskStateRunning
) {
state = DownloadStateDownloading;
}
else
if
(cDownloadTask.
task
.
state
==
NSURLSessionTaskStateSuspended
) {
state = DownloadStatePausing;
}
else
{
[Coding_FileManager
cancelCDownloadTaskForKey:
self
.storage_key];
}
}
}
return
state;
}
- (
NSString
*)
owner_name
{
return
_owner_name ?: _owner.
name
;
}
- (
NSString
*)
downloadPath
{
NSString
*path = [
NSString
stringWithFormat:
@"
%@
api/project/
%@
/files/
%@
/download
"
, [
NSObject
baseURLStr
], _project_id.stringValue,
self
.file_id.stringValue];
return
path;
}
- (
NSString
*)
diskFileName
{
if
(!_diskFileName) {
_diskFileName = [
NSString
stringWithFormat:
@"
%@
|||
%@
|||
%@
|
%@
"
, _name, _project_id.stringValue, _storage_type,
self
.storage_key_for_disk];
}
return
_diskFileName;
}
- (
NSString
*)
storage_key_for_disk
{
NSArray
*fileNameCom = [_name
componentsSeparatedByString:
@"
.
"
];
NSMutableArray
*storage_keyCom = [_storage_key
componentsSeparatedByString:
@"
.
"
].
mutableCopy
;
if
(fileNameCom.
count
>
1
&& storage_keyCom.
count
>
0
&& ![fileNameCom.lastObject
isEqualToString:
storage_keyCom.lastObject]) {
//
_storage_key 后缀名与 fileNameCom 后缀名不同的情况
[storage_keyCom
addObject:
fileNameCom.lastObject];
return
[storage_keyCom
componentsJoinedByString:
@"
.
"
];
}
else
if
(_storage_key.
length
>
0
){
return
[_storage_key
componentsSeparatedByString:
@"
/
"
].
lastObject
;
//
'group0/M00/00/01/fwAAAVsHsvqAOY8rABzvMF5h1Ck652.JPG'..诡异的前半截数据
}
else
{
//
说是以后,可能迁移到腾讯云,_storage_key 字段可能不保
return
[
NSString
stringWithFormat:
@"
%@
_
%@
.
%@
"
, _project_id, _file_id, fileNameCom.lastObject];
}
}
- (Coding_DownloadTask *)
cDownloadTask
{
return
[Coding_FileManager
cDownloadTaskForKey:
_storage_key];
}
- (
NSURL
*)
diskFileUrl
{
return
[Coding_FileManager
diskDownloadUrlForKey:
self
.storage_key] ?: [Coding_FileManager
diskDownloadUrlForKey:
self
.storage_key_for_disk];
}
- (
NSString
*)
toDeletePath
{
return
[
NSString
stringWithFormat:
@"
api/project/
%@
/file/delete
"
, _project_id.stringValue];
}
- (
NSDictionary
*)
toDeleteParams
{
return
@{
@"
fileIds
"
: @[
self
.file_id.stringValue]};
}
- (
NSDictionary
*)
toMoveToParams
{
return
@{
@"
fileId
"
: @[
self
.file_id.stringValue]};
}
- (
NSString
*)
toDetailPath
{
NSString
*path;
if
(!_project_id) {
path = [
NSString
stringWithFormat:
@"
api/user/
%@
/project/
%@
/files/
%@
/view
"
, _project_owner_name, _project_name, _file_id.stringValue];
}
else
{
path = [
NSString
stringWithFormat:
@"
api/project/
%@
/files/
%@
/view
"
, _project_id.stringValue, _file_id.stringValue];
}
return
path;
}
- (
NSString
*)
toActivityListPath
{
return
[
NSString
stringWithFormat:
@"
api/project/
%@
/file/
%@
/activities
"
, _project_id.stringValue,
self
.file_id.stringValue];
}
- (
NSString
*)
toHistoryListPath
{
return
[
NSString
stringWithFormat:
@"
api/project/
%@
/files/
%@
/histories
"
, _project_id.stringValue,
self
.file_id.stringValue];
}
- (
NSDictionary
*)
toShareParams
{
return
@{
@"
projectId
"
: _project_id,
@"
resourceId
"
: self.
file_id
,
@"
resourceType
"
: @
0
,
@"
accessType
"
: @
0
};
}
- (
NSString
*)
toFolderFilesPath
{
if
(self.
isSharedFolder
) {
return
[
NSString
stringWithFormat:
@"
api/user/
%@
/project/
%@
/folder/shared_files
"
, _project_owner_name, _project_name];
}
else
{
return
[
NSString
stringWithFormat:
@"
api/user/
%@
/project/
%@
/folder/
%@
/all
"
, _project_owner_name, _project_name,
self
.file_id];
}
}
- (
NSDictionary
*)
toFolderFilesParams
{
return
@{
@"
height
"
:
@"
90
"
,
@"
width
"
:
@"
90
"
,
@"
page
"
:
@"
1
"
,
@"
pageSize
"
:
@"
500
"
};
}
@end
Back
|
FazBrowse Home
|
New Git URL