Support full URL in X-Object-Public header
authorMiltiadis Vasilakis <mvasilak@gmail.com>
Tue, 25 Jun 2013 15:13:13 +0000 (18:13 +0300)
committerMiltiadis Vasilakis <mvasilak@gmail.com>
Tue, 25 Jun 2013 15:13:13 +0000 (18:13 +0300)
When X-Object-Public has a valid URL use it as
it is, instead of adding the public link url
prefix.

Classes/StorageObjectViewController.m

index 98c353d..eae8d08 100755 (executable)
@@ -190,6 +190,22 @@ Delete Object
 
 #pragma mark - Internal
 
+- (NSURL *)publicLinkURL {
+    if ([self.object.publicURI hasPrefix:@"https://"]) {
+        return [NSURL URLWithString:[NSString stringWithFormat:@"https://%@",
+                                     [NSString encodeToPercentEscape:[self.object.publicURI substringFromIndex:8]
+                                                  charactersToEncode:@"!*'();:@&=+$,?%#[]"]]];
+    } else if ([self.object.publicURI hasPrefix:@"http://"]) {
+        return [NSURL URLWithString:[NSString stringWithFormat:@"http://%@",
+                                     [NSString encodeToPercentEscape:[self.object.publicURI substringFromIndex:7]
+                                                  charactersToEncode:@"!*'();:@&=+$,?%#[]"]]];
+    } else {
+        return [account.provider.publicLinkURLPrefix URLByAppendingPathComponent:
+                [NSString encodeToPercentEscape:[self.object.publicURI substringFromIndex:1]
+                             charactersToEncode:@"!*'();:@&=+$,?%#[]"]];
+    }
+}
+
 - (void)objectIsPublicSwitchChanged:(id)sender {
     NSString *activityMessage = [NSString stringWithFormat:@"Enabling public link.."];
     self.oldPublicURI = object.publicURI;
@@ -450,14 +466,11 @@ Delete Object
                                             CGSizeMake(221.0, 9000.0))
                              lineBreakMode:UILineBreakModeCharacterWrap].height;
     } else if ((indexPath.section == publicLinkSection) && (indexPath.row == 1)) {
-        NSURL *publicLinkURL = [account.provider.publicLinkURLPrefix URLByAppendingPathComponent:
-                                [NSString encodeToPercentEscape:[self.object.publicURI substringFromIndex:1]
-                                             charactersToEncode:@"!*'();:@&=+$,?%#[]"]];
-        result = 30.0 + [[publicLinkURL description] sizeWithFont:[UIFont systemFontOfSize:18.0]
-                                                constrainedToSize:(([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ?
-                                                                   CGSizeMake(596.0, 9000.0) :
-                                                                   CGSizeMake(280.0, 9000.0))
-                                                    lineBreakMode:UILineBreakModeCharacterWrap].height;
+        result = 30.0 + [[[self publicLinkURL] description] sizeWithFont:[UIFont systemFontOfSize:18.0]
+                                                       constrainedToSize:(([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ?
+                                                                          CGSizeMake(596.0, 9000.0) :
+                                                                          CGSizeMake(280.0, 9000.0))
+                                                           lineBreakMode:UILineBreakModeCharacterWrap].height;
     }
     return MAX(aTableView.rowHeight, result);
 }
@@ -475,9 +488,7 @@ Delete Object
         cell.textView.backgroundColor = [UIColor clearColor];
         cell.textView.font = [UIFont systemFontOfSize:15.0];
         cell.textView.dataDetectorTypes = UIDataDetectorTypeLink;
-        cell.textView.text = [[account.provider.publicLinkURLPrefix URLByAppendingPathComponent:
-                               [NSString encodeToPercentEscape:[self.object.publicURI substringFromIndex:1]
-                                            charactersToEncode:@"!*'();:@&=+$,?%#[]"]] description];
+        cell.textView.text = [[self publicLinkURL] description];
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
         cell.accessoryView = UITableViewCellAccessoryNone;
         return cell;