Skip to content

Commit

Permalink
Add option to insert non-standard ports into links
Browse files Browse the repository at this point in the history
* If the server's outward-facing port (the configured port) is something
  else and you don't have access to port 80 or 443 or whatever, the new
  checkbox will enable putting that port in the URL
  • Loading branch information
moshee committed Mar 30, 2014
1 parent 31bac53 commit 6f1dfc9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
38 changes: 29 additions & 9 deletions Airlift/ALPreferenceViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<customView id="1">
<rect key="frame" x="0.0" y="0.0" width="365" height="182"/>
<rect key="frame" x="0.0" y="0.0" width="365" height="198"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ggP-Aq-0oM">
<rect key="frame" x="64" y="130" width="47" height="17"/>
<rect key="frame" x="64" y="146" width="47" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Server:" id="i7z-fG-cBL">
<font key="font" metaFont="system"/>
Expand All @@ -29,7 +29,7 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="IrO-Bt-Luf">
<rect key="frame" x="117" y="127" width="148" height="22"/>
<rect key="frame" x="117" y="143" width="148" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="http://i.example.com" drawsBackground="YES" usesSingleLineMode="YES" id="sv7-GC-m2h">
<font key="font" metaFont="system"/>
Expand All @@ -42,7 +42,7 @@
</connections>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ej2-Fs-xjo">
<rect key="frame" x="273" y="127" width="50" height="22"/>
<rect key="frame" x="273" y="143" width="50" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="60606" drawsBackground="YES" id="2i8-jE-EMk">
<font key="font" metaFont="system"/>
Expand All @@ -54,7 +54,7 @@
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HFk-rw-0Qd">
<rect key="frame" x="45" y="98" width="66" height="17"/>
<rect key="frame" x="45" y="114" width="66" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Password:" id="Yml-l7-3BU">
<font key="font" metaFont="system"/>
Expand All @@ -63,7 +63,7 @@
</textFieldCell>
</textField>
<secureTextField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9di-Da-EKP">
<rect key="frame" x="117" y="95" width="206" height="22"/>
<rect key="frame" x="117" y="111" width="206" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesSingleLineMode="YES" id="GrU-Ba-SrX">
<font key="font" metaFont="system"/>
Expand All @@ -79,7 +79,7 @@
</connections>
</secureTextField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7O1-f7-34V">
<rect key="frame" x="265" y="130" width="9" height="17"/>
<rect key="frame" x="265" y="146" width="9" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title=":" id="aqc-Hx-Djq">
<font key="font" metaFont="system"/>
Expand All @@ -88,9 +88,9 @@
</textFieldCell>
</textField>
<button toolTip="Example: uploading &quot;image.jpg&quot; would return &quot;http://i.example.com/f9G2.jpg&quot; instead of &quot;http://i.example.com/f9G2&quot;" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jx1-BW-FBZ">
<rect key="frame" x="28" y="60" width="308" height="20"/>
<rect key="frame" x="169" y="80" width="161" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Append filename extension to returned URLs" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="5GV-RM-QLJ">
<buttonCell key="cell" type="check" title="Filename extensions" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="5GV-RM-QLJ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
Expand All @@ -110,6 +110,26 @@
<binding destination="-2" name="value" keyPath="versionString" id="K0I-vR-zda"/>
</connections>
</textField>
<button toolTip="If the server is on a nonstandard port for its scheme (not 80 for http and not 443 for https), put that port in the URL" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uij-Hd-4qt">
<rect key="frame" x="169" y="58" width="161" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Non-standard ports" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="PBp-AH-IkQ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="2eN-FZ-YlG" name="value" keyPath="values.shouldInsertPort" id="utv-sZ-rqY"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="dck-zr-B3C">
<rect key="frame" x="35" y="81" width="130" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Add to copied links:" id="Pvl-TO-vT5">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</customView>
<userDefaultsController representsSharedInstance="YES" id="2eN-FZ-YlG"/>
Expand Down
19 changes: 17 additions & 2 deletions Airlift/ALUploadHistoryItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,23 @@ - (void)copyLink {
url = [url stringByAppendingPathExtension:ext];
}

NSString* linkableURL =
[NSString stringWithFormat:@"%@://%@", [originalURL scheme], url];
NSString* scheme = [originalURL scheme];
int port = [[originalURL port] intValue];

NSString* linkableURL = [NSString stringWithFormat:@"%@://%@", scheme, url];
BOOL shouldInsertPort =
[[NSUserDefaults standardUserDefaults] boolForKey:@"shouldInsertPort"];

if (shouldInsertPort
&& !(([scheme isEqualToString:@"http"] && port == 80)
|| ([scheme isEqualToString:@"https"] && port == 443))) {
NSLog(@"got a nonstandard port %d, gonna try to wedge it into the link",
port);
NSURL* parsedURL = [NSURL URLWithString:linkableURL];
linkableURL =
[NSString stringWithFormat:@"%@://%@:%d%@", scheme,
[parsedURL host], port, [parsedURL path]];
}

NSString* errMsg = [self copyString:linkableURL];
if (errMsg != nil) {
Expand Down
8 changes: 5 additions & 3 deletions Airlift/ALUploadManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,11 @@ - (void)URLSession:(NSURLSession*)session
}

if (responseCode != 201) {
NSString* subtitle = [NSString
stringWithFormat:@"server returned error: %@ (status %d)",
[jsonResponse valueForKey:@"Err"], responseCode];
NSString* errString = [jsonResponse valueForKey:@"Err"];
NSString* subtitle =
[NSString stringWithFormat:@"server returned error: %@ (status %d)",
errString, responseCode];
NSLog(@"Server error: %@ (status %d)", errString, responseCode);
[appDelegate showNotificationOfType:ALNotificationUploadAborted
title:@"Error uploading"
subtitle:subtitle
Expand Down

0 comments on commit 6f1dfc9

Please sign in to comment.