Commit 214f9b44 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update UrlHelper.kt

parent 7141a9a0
...@@ -8,7 +8,8 @@ object UrlHelper { ...@@ -8,7 +8,8 @@ object UrlHelper {
* @param uri The URI. * @param uri The URI.
* @return The URI whit no scheme (HTTP or HTTPS) * @return The URI whit no scheme (HTTP or HTTPS)
*/ */
fun removeUriScheme(uri: String) = uri.replace("http://", "").replace("https://", "") fun removeUriScheme(uri: String) =
uri.replace("http://", "").replace("https://", "")
/** /**
* Returns the hostname with the security protocol (scheme) HTTPS. * Returns the hostname with the security protocol (scheme) HTTPS.
...@@ -17,7 +18,7 @@ object UrlHelper { ...@@ -17,7 +18,7 @@ object UrlHelper {
* @return The hostname with the security protocol (scheme) HTTPS. * @return The hostname with the security protocol (scheme) HTTPS.
*/ */
fun getSafeHostname(hostname: String): String = fun getSafeHostname(hostname: String): String =
"https://" + hostname.replace("http://", "").replace("https://", "") "https://" + removeUriScheme(hostname)
/** /**
* Returns an URL with no spaces and inverted slashes. * Returns an URL with no spaces and inverted slashes.
...@@ -25,17 +26,17 @@ object UrlHelper { ...@@ -25,17 +26,17 @@ object UrlHelper {
* @param url The URL. * @param url The URL.
* @return The URL with no spaces and inverted slashes. * @return The URL with no spaces and inverted slashes.
*/ */
fun getUrl(url: String) = fun getSafeUrl(url: String) =
url.replace(" ", "%20").replace("\\", "") url.replace(" ", "%20").replace("\\", "")
/** /**
* Returns an URL for a file. * Returns an attachment link.
* *
* @param path The path to the file. * @param hostname The hostname.
* @param userId The user ID. * @param fileId The file ID.
* @param token The token. * @param fileName The file name.
* @return The URL for a file * @return The attachment link.
*/ */
fun getUrlForFile(path: String, userId: String, token: String): String = fun getAttachmentLink(hostname: String, fileId: String, fileName: String): String =
"https://" + removeUriScheme(getUrl(path)) + "?rc_uid=$userId" + "&rc_token=$token" getSafeHostname(hostname) + "/file-upload/" + fileId + "/" + fileName
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment