Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 735fff7

Browse filesBrowse files
committed
2.4.2015032124 - 共有项目的图片上传
1 parent c0dacfc commit 735fff7
Copy full SHA for 735fff7

File tree

Expand file treeCollapse file tree

5 files changed

+70
-36
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+70
-36
lines changed
Open diff view settings
Collapse file

‎Coding_iOS/Coding_iOS-Info.plist‎

Copy file name to clipboardExpand all lines: Coding_iOS/Coding_iOS-Info.plist
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</dict>
3333
</array>
3434
<key>CFBundleVersion</key>
35-
<string>2.4.2015032021</string>
35+
<string>2.4.2015032124</string>
3636
<key>LSRequiresIPhoneOS</key>
3737
<true/>
3838
<key>NSLocationAlwaysUsageDescription</key>
Collapse file

‎Coding_iOS/Controllers/FileListViewController.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Controllers/FileListViewController.m
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerControlle
262262
}
263263
}
264264
for (NSString *fileName in needToUploads) {
265-
[self addUploadTaskWithFileName:fileName];
265+
[self uploadFileWithFileName:fileName];
266266
}
267267

268268
[self dismissViewControllerAnimated:YES completion:nil];
@@ -272,9 +272,9 @@ - (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePicker
272272
}
273273

274274
#pragma mark uploadTask
275-
- (void)addUploadTaskWithFileName:(NSString *)fileName{
275+
- (void)uploadFileWithFileName:(NSString *)fileName{
276276
Coding_FileManager *manager = [Coding_FileManager sharedManager];
277-
[manager addUploadTaskWithFileName:fileName];
277+
[manager addUploadTaskWithFileName:fileName projectIsPublic:_curProject.is_public.boolValue];
278278
[self configuploadFiles];
279279
}
280280

@@ -285,7 +285,7 @@ - (void)removeUploadTaskWithFileName:(NSString *)fileName{
285285
}
286286

287287
- (void)completionUploadWithResult:(id)responseObject error:(NSError *)error{
288-
if (!responseObject) {
288+
if (!responseObject || ![responseObject isKindOfClass:[ProjectFile class]]) {
289289
return;
290290
}
291291
ProjectFile *curFile = responseObject;
@@ -323,7 +323,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
323323
FileListUploadCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_FileListUpload forIndexPath:indexPath];
324324
cell.fileName = [self.uploadFiles objectAtIndex:indexPath.row];
325325
cell.reUploadBlock = ^(NSString *fileName){
326-
[weakSelf addUploadTaskWithFileName:fileName];
326+
[weakSelf uploadFileWithFileName:fileName];
327327
};
328328
cell.cancelUploadBlock = ^(NSString *fileName){
329329
[weakSelf removeUploadTaskWithFileName:fileName];
Collapse file

‎Coding_iOS/Util/Manager/Coding_FileManager.h‎

Copy file name to clipboardExpand all lines: Coding_iOS/Util/Manager/Coding_FileManager.h
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
//upload
3939
+ (BOOL)writeUploadDataWithName:(NSString *)fileName andAsset:(ALAsset *)asset;
4040
+ (BOOL)writeUploadDataWithName:(NSString *)fileName andImage:(UIImage *)image;
41+
+ (BOOL)deleteUploadDataWithName:(NSString *)fileName;
42+
4143
- (NSURL *)diskUploadUrlForFile:(NSString *)fileName;
4244
- (void)removeCUploadTaskForFile:(NSString *)fileName hasError:(BOOL)hasError;
4345
- (Coding_UploadTask *)cUploadTaskForFile:(NSString *)fileName;
44-
- (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName;
46+
- (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName projectIsPublic:(BOOL)is_public;
4547
- (NSArray *)uploadFilesInProject:(NSString *)project_id andFolder:(NSString *)folder_id;
4648
@end
4749

Collapse file

‎Coding_iOS/Util/Manager/Coding_FileManager.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Util/Manager/Coding_FileManager.m
+45-25Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,16 @@ + (BOOL)writeUploadDataWithName:(NSString *)fileName andImage:(UIImage *)image{
218218

219219
return [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath options:NSAtomicWrite error:nil];
220220
}
221-
- (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName{
221+
+ (BOOL)deleteUploadDataWithName:(NSString *)fileName{
222+
NSString *filePath = [[self uploadPath] stringByAppendingPathComponent:fileName];
223+
NSFileManager *fm = [NSFileManager defaultManager];
224+
if ([fm fileExistsAtPath:filePath]) {
225+
return [fm removeItemAtPath:fileName error:nil];
226+
}else{
227+
return YES;
228+
}
229+
}
230+
- (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName projectIsPublic:(BOOL)is_public{
222231
if (!fileName) {
223232
return nil;
224233
}
@@ -233,10 +242,15 @@ - (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName{
233242
NSString *filePath = [[[self class] uploadPath] stringByAppendingPathComponent:fileName];
234243
NSURL *filePathUrl = [NSURL fileURLWithPath:filePath];
235244

236-
NSURL *uploadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@api/project/%@/file/upload", kNetPath_Code_Base, project_id]];
245+
NSURL *uploadUrl;
246+
if (is_public) {
247+
uploadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@api/project/%@/upload_public_image", kNetPath_Code_Base, project_id]];
248+
}else{
249+
uploadUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@api/project/%@/file/upload", kNetPath_Code_Base, project_id]];
250+
}
237251

238252
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:uploadUrl.absoluteString parameters:@{@"dir": folder_id} constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
239-
[formData appendPartWithFileURL:filePathUrl name:@"file" fileName:name mimeType:@"image/jpeg, image/png, image/gif, image/tiff" error:nil];
253+
[formData appendPartWithFileURL:filePathUrl name:@"file" fileName:name mimeType:@"image/jpeg, image/png, image/gif" error:nil];
240254
} error:nil];
241255

242256
NSProgress *progress = nil;
@@ -245,33 +259,39 @@ - (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName{
245259
if (!error) {
246260
error = [manager handleResponse:responseObject];
247261
}
248-
249-
if (error) {
262+
response = response? response: [[NSURLResponse alloc] init];
263+
if (error){
250264
[manager showError:error];
251265
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationUploadCompled object:manager userInfo:@{@"response" : response,
252266
@"error" : error}];
253-
}else{
254-
NSString *block_project_id = [[[[response.URL.absoluteString componentsSeparatedByString:@"/project/"] lastObject] componentsSeparatedByString:@"/file/"] firstObject];
255-
267+
}else if (responseObject) {
268+
NSString *block_project_id = [[[[response.URL.absoluteString componentsSeparatedByString:@"/project/"] lastObject] componentsSeparatedByString:@"/"] firstObject];
256269
responseObject = [responseObject valueForKey:@"data"];
257-
ProjectFile *curFile = [NSObject objectOfClass:@"ProjectFile" fromJSON:responseObject];
258-
NSString *block_fileName = [NSString stringWithFormat:@"%@|||%@|||%@", block_project_id, curFile.parent_id.stringValue, curFile.name];
259-
NSString *block_filePath = [[[manager class] uploadPath] stringByAppendingPathComponent:block_fileName];
260270

261-
//移动文件到已下载
262-
NSString *diskFileName = [NSString stringWithFormat:@"%@|||%@|||%@|%@", curFile.name, block_project_id, curFile.storage_type, curFile.storage_key];
263-
NSString *diskFilePath = [[[manager class] downloadPath] stringByAppendingPathComponent:diskFileName];
264-
[[NSFileManager defaultManager] moveItemAtPath:block_filePath toPath:diskFilePath error:nil];
265-
[manager directoryDidChange:manager.docUploadWatcher];
266-
[manager directoryDidChange:manager.docDownloadWatcher];
267-
NSLog(@"upload_fileName------\n%@", block_fileName);
268-
269-
//移除任务
270-
[[Coding_FileManager sharedManager] removeCUploadTaskForFile:block_fileName hasError:(error != nil)];
271-
272-
//处理completionHandler
273-
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationUploadCompled object:manager userInfo:@{@"response" : response,
274-
@"data" : curFile}];
271+
if ([responseObject isKindOfClass:[NSString class]]) {
272+
//处理completionHandler
273+
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationUploadCompled object:manager userInfo:@{@"response" : response,
274+
@"data" : responseObject}];
275+
}else{
276+
ProjectFile *curFile = [NSObject objectOfClass:@"ProjectFile" fromJSON:responseObject];
277+
NSString *block_fileName = [NSString stringWithFormat:@"%@|||%@|||%@", block_project_id, curFile.parent_id.stringValue, curFile.name];
278+
NSString *block_filePath = [[[manager class] uploadPath] stringByAppendingPathComponent:block_fileName];
279+
280+
//移动文件到已下载
281+
NSString *diskFileName = [NSString stringWithFormat:@"%@|||%@|||%@|%@", curFile.name, block_project_id, curFile.storage_type, curFile.storage_key];
282+
NSString *diskFilePath = [[[manager class] downloadPath] stringByAppendingPathComponent:diskFileName];
283+
[[NSFileManager defaultManager] moveItemAtPath:block_filePath toPath:diskFilePath error:nil];
284+
[manager directoryDidChange:manager.docUploadWatcher];
285+
[manager directoryDidChange:manager.docDownloadWatcher];
286+
NSLog(@"upload_fileName------\n%@", block_fileName);
287+
288+
//移除任务
289+
[[Coding_FileManager sharedManager] removeCUploadTaskForFile:block_fileName hasError:(error != nil)];
290+
291+
//处理completionHandler
292+
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationUploadCompled object:manager userInfo:@{@"response" : response,
293+
@"data" : curFile}];
294+
}
275295
}
276296
}];
277297

Collapse file

‎Coding_iOS/Views/EaseMarkdownTextView.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Views/EaseMarkdownTextView.m
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ - (void)doUploadPhoto:(UIImage *)image{
279279
if ([Coding_FileManager writeUploadDataWithName:fileName andImage:image]) {
280280
[self hudTipWillShow:YES];
281281
self.uploadingPhotoName = originalFileName;
282-
Coding_UploadTask *uploadTask =[[Coding_FileManager sharedManager] addUploadTaskWithFileName:fileName];
282+
Coding_UploadTask *uploadTask =[[Coding_FileManager sharedManager] addUploadTaskWithFileName:fileName projectIsPublic:_curProject.is_public.boolValue];
283283
@weakify(self)
284284
[RACObserve(uploadTask, progress.fractionCompleted) subscribeNext:^(NSNumber *fractionCompleted) {
285285
@strongify(self);
@@ -299,9 +299,21 @@ - (void)completionUploadWithResult:(id)responseObject error:(NSError *)error{
299299
if (!responseObject) {
300300
return;
301301
}
302-
ProjectFile *curFile = responseObject;
303-
if ([curFile.name isEqualToString:self.uploadingPhotoName]) {
304-
NSString *photoLinkStr = [NSString stringWithFormat:[self needPreNewLine]? @"\n![图片](%@)\n": @"![图片](%@)\n", curFile.owner_preview];
302+
NSString *fileName = nil, *fileUrlStr = @"";
303+
if ([responseObject isKindOfClass:[NSString class]]) {
304+
fileUrlStr = responseObject;
305+
}else if ([responseObject isKindOfClass:[ProjectFile class]]){
306+
ProjectFile *curFile = responseObject;
307+
fileName = curFile.name;
308+
fileUrlStr = curFile.preview;
309+
}
310+
if (!fileName || [fileName isEqualToString:self.uploadingPhotoName]) {
311+
//移除文件(共有项目不能自动移除)
312+
NSString *fileName = [NSString stringWithFormat:@"%@|||%@|||%@", self.curProject.id.stringValue, @"0", self.uploadingPhotoName];
313+
[Coding_FileManager deleteUploadDataWithName:fileName];
314+
315+
//插入文字
316+
NSString *photoLinkStr = [NSString stringWithFormat:[self needPreNewLine]? @"\n![图片](%@)\n": @"![图片](%@)\n", fileUrlStr];
305317
[self insertText:photoLinkStr];
306318
[self becomeFirstResponder];
307319
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.