Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed missing URL for Upload and Download #772

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions app/src/main/java/com/seafile/seadroid2/SeafConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,18 @@ public Pair<String, String> getDownloadLink(String repoID, String path ,boolean
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);

String result = new String(req.bytes(), "UTF-8");
String fileID = req.header("oid");
result = result.replace("\"", ""); // remove quotation marks

// Fix missing URL
if (!result.startsWith("http")) {
result = account.server + result;
result = result.replaceAll("(?<!(http:|https:))[//]+", "/"); // remove double slashes
}

// should return "\"http://gonggeng.org:8082/...\"" or "\"https://gonggeng.org:8082/...\"
if (result.startsWith("\"http") && fileID != null) {
String url = result.substring(1, result.length() - 1);
return new Pair<String, String>(url, fileID);
String fileID = req.header("oid");
// should return "http://gonggeng.org:8082/..." or "https://gonggeng.org:8082/..."
if (fileID != null) {
return new Pair<String, String>(result, fileID);
} else {
throw SeafException.illFormatException;
}
Expand Down Expand Up @@ -780,12 +786,16 @@ private String getUploadLink(String repoID, boolean update) throws SeafException
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);

String result = new String(req.bytes(), "UTF-8");
// should return "\"http://gonggeng.org:8082/...\"" or "\"https://gonggeng.org:8082/...\"
if (result.startsWith("\"http")) {
// remove the starting and trailing quote
return result.substring(1, result.length() - 1);
} else
throw SeafException.unknownException;
result = result.replace("\"", ""); // remove quotation marks

// Fix missing URL
if (!result.startsWith("http")) {
result = account.server + result;
result = result.replaceAll("(?<!(http:|https:))[//]+", "/"); // remove double slashes
}

// should return "http://gonggeng.org:8082/..." or "https://gonggeng.org:8082/..."
return result;
} catch (SeafException e) {
Log.d(DEBUG_TAG, e.getCode() + e.getMessage());
throw e;
Expand Down