From 56754002bfc11437bb14f76b09341968da83c80b Mon Sep 17 00:00:00 2001 From: maxiaoping <634115572@qq.com> Date: Mon, 6 Jan 2020 18:03:33 +0800 Subject: [PATCH] ServerUpdate (#846) * Server update * update * URLEncoded * amend URLEncoded --- app/build.gradle | 4 ++-- .../java/com/seafile/seadroid2/SeafConnection.java | 6 +++--- .../java/com/seafile/seadroid2/util/Utils.java | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5685e0001..ef7133510 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId 'com.seafile.seadroid2' minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 98 - versionName "2.2.23" + versionCode 99 + versionName "2.2.24" multiDexEnabled true resValue "string", "authorities", applicationId + '.cameraupload.provider' resValue "string", "account_type", "com.seafile.seadroid2.account.api2" diff --git a/app/src/main/java/com/seafile/seadroid2/SeafConnection.java b/app/src/main/java/com/seafile/seadroid2/SeafConnection.java index a484cc64b..cfec33eb8 100644 --- a/app/src/main/java/com/seafile/seadroid2/SeafConnection.java +++ b/app/src/main/java/com/seafile/seadroid2/SeafConnection.java @@ -776,13 +776,13 @@ public boolean setPassword(String repoID, String passwd) throws SeafException { return false; } - private String getUploadLink(String repoID, boolean update) throws SeafException { + private String getUploadLink(String repoID, boolean update, String dir) throws SeafException { try { String apiPath; if (update) { apiPath = "api2/repos/" + repoID + "/update-link/"; } else { - apiPath = "api2/repos/" + repoID + "/upload-link/"; + apiPath = "api2/repos/" + repoID + "/upload-link/?p=" + Utils.toURLEncoded(dir); } HttpRequest req; req = prepareApiGetRequest(apiPath); @@ -879,7 +879,7 @@ private String commitUpload(String link, List blkIds, String dir, String */ public String uploadFile(String repoID, String dir, String filePath, ProgressMonitor monitor, boolean update) throws SeafException, IOException { - String url = getUploadLink(repoID, update); + String url = getUploadLink(repoID, update, dir); return uploadFileCommon(url, repoID, dir, filePath, monitor, update); } diff --git a/app/src/main/java/com/seafile/seadroid2/util/Utils.java b/app/src/main/java/com/seafile/seadroid2/util/Utils.java index 47a3db0f4..96850f15f 100644 --- a/app/src/main/java/com/seafile/seadroid2/util/Utils.java +++ b/app/src/main/java/com/seafile/seadroid2/util/Utils.java @@ -63,6 +63,7 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLEncoder; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; @@ -931,4 +932,17 @@ public static String getUploadStateShow(Context context) { } return results; } + + public static String toURLEncoded(String paramString) { + if (paramString == null || paramString.equals("")) { + return ""; + } + try { + String str = new String(paramString.getBytes(), "UTF-8"); + str = URLEncoder.encode(str, "UTF-8"); + return str; + } catch (Exception localException) { + } + return ""; + } }