-
Notifications
You must be signed in to change notification settings - Fork 17
feat: Password protected public share #1922
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
base: main
Are you sure you want to change the base?
Changes from all commits
52b10a8
f980820
b73ad37
0d4f9ae
adaaec6
30af9f4
20b4e51
d6bd7eb
82a3ccf
b34550e
a10af0f
79a5918
54ecd11
94a2354
933ebc1
510ad78
a9b8f4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /* | ||
| * Infomaniak kDrive - Android | ||
| * Copyright (C) 2022-2025 Infomaniak Network SA | ||
| * Copyright (C) 2022-2026 Infomaniak Network SA | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
|
|
@@ -114,7 +114,7 @@ object ApiRoutes { | |
| //region File url | ||
| fun getDownloadFileUrl(file: File): String = with(file) { | ||
| val downloadUrl = if (isPublicShared()) { | ||
| downloadPublicShareFile(driveId, publicShareUuid, id) | ||
| downloadPublicShareFile(driveId, publicShareUuid, id, publicShareAuthToken) | ||
| } else { | ||
| downloadFile(file) | ||
| } | ||
|
|
@@ -124,25 +124,25 @@ object ApiRoutes { | |
|
|
||
| fun getThumbnailUrl(file: File) = with(file) { | ||
| when { | ||
| isPublicShared() -> getPublicShareFileThumbnail(driveId, publicShareUuid, id) | ||
| isPublicShared() -> getPublicShareFileThumbnail(driveId, publicShareUuid, id, publicShareAuthToken) | ||
| isTrashed() -> thumbnailTrashFile(file) | ||
| else -> thumbnailFile(file) | ||
| } | ||
| } | ||
|
|
||
| fun getImagePreviewUrl(file: File): String = with(file) { | ||
| val url = if (isPublicShared()) { | ||
| getPublicShareFilePreview(driveId, publicShareUuid, id) | ||
| getPublicShareFilePreview(driveId, publicShareUuid, id, publicShareAuthToken) | ||
| } else { | ||
| imagePreviewFile(file) | ||
| } | ||
|
|
||
| return "$url?width=2500&height=1500&quality=80" | ||
| return url.appendQuery("width=2500&height=1500&quality=80") | ||
| } | ||
|
|
||
| fun getOnlyOfficeUrl(file: File) = with(file) { | ||
| if (isPublicShared()) { | ||
| showPublicShareOfficeFile(driveId, publicShareUuid, id) | ||
| showPublicShareOfficeFile(driveId, publicShareUuid, id, publicShareAuthToken) | ||
| } else { | ||
| "$AUTOLOG_URL?url=${showOffice(file)}" | ||
| } | ||
|
|
@@ -313,38 +313,48 @@ object ApiRoutes { | |
|
|
||
| /** Public Share */ | ||
| //region Public share | ||
| fun getPublicShareInfo(driveId: Int, linkUuid: String) = "${getPublicShareUrlV2(driveId, linkUuid)}/init" | ||
| fun getPublicShareInfo(driveId: Int, linkUuid: String): String = "${getPublicShareUrlV2(driveId, linkUuid)}/init" | ||
|
|
||
| fun submitPublicSharePassword(driveId: Int, linkUuid: String) = "${getPublicShareUrlV2(driveId, linkUuid)}/auth" | ||
|
|
||
| fun getPublicShareRootFile(driveId: Int, linkUuid: String, fileId: Int): String { | ||
| return "$SHARE_URL_V3/$driveId/share/$linkUuid/files/$fileId?$sharedFileWithQuery" | ||
| } | ||
|
|
||
| fun getPublicShareChildrenFiles(driveId: Int, linkUuid: String, fileId: Int, sortType: SortType): String { | ||
| fun getPublicShareChildrenFiles( | ||
| driveId: Int, | ||
| linkUuid: String, | ||
| fileId: Int, | ||
| sortType: SortType, | ||
| authToken: String?, | ||
| ): String { | ||
| val orderQuery = "order_by=${sortType.orderBy}&order=${sortType.order}" | ||
| return "$SHARE_URL_V3/$driveId/share/$linkUuid/files/$fileId/files?$sharedFileWithQuery&$orderQuery" | ||
| val authParam = authToken?.let { "&sharelink_token=$it" } ?: "" | ||
| return "$SHARE_URL_V3/$driveId/share/$linkUuid/files/$fileId/files?$sharedFileWithQuery&$orderQuery$authParam" | ||
| } | ||
|
|
||
| fun getPublicShareFileCount(driveId: Int, linkUuid: String, fileId: Int): String { | ||
| return "${publicShareFile(driveId, linkUuid, fileId)}/count" | ||
| } | ||
|
|
||
| private fun getPublicShareFileThumbnail(driveId: Int, linkUuid: String, fileId: Int): String { | ||
| return "${publicShareFile(driveId, linkUuid, fileId)}/thumbnail" | ||
| private fun getPublicShareFileThumbnail(driveId: Int, linkUuid: String, fileId: Int, authToken: String? = null): String { | ||
| val authParam = authToken?.let { "?sharelink_token=$it" } ?: "" | ||
| return "${publicShareFile(driveId, linkUuid, fileId)}/thumbnail$authParam" | ||
| } | ||
|
|
||
| private fun getPublicShareFilePreview(driveId: Int, linkUuid: String, fileId: Int): String { | ||
| return "${publicShareFile(driveId, linkUuid, fileId)}/preview" | ||
| private fun getPublicShareFilePreview(driveId: Int, linkUuid: String, fileId: Int, authToken: String? = null): String { | ||
| val authParam = authToken?.let { "?sharelink_token=$it" } ?: "" | ||
| return "${publicShareFile(driveId, linkUuid, fileId)}/preview$authParam" | ||
| } | ||
|
|
||
| private fun downloadPublicShareFile(driveId: Int, linkUuid: String, fileId: Int): String { | ||
| return "${publicShareFile(driveId, linkUuid, fileId)}/download" | ||
| private fun downloadPublicShareFile(driveId: Int, linkUuid: String, fileId: Int, authToken: String? = null): String { | ||
| val authParam = authToken?.let { "?sharelink_token=$it" } ?: "" | ||
| return "${publicShareFile(driveId, linkUuid, fileId)}/download$authParam" | ||
| } | ||
|
|
||
| private fun showPublicShareOfficeFile(driveId: Int, linkUuid: String, fileId: Int): String { | ||
| // For now, this call fails because the back hasn't dev the conversion of office files to pdf for mobile | ||
| return "$SHARE_URL_V1/share/$driveId/$linkUuid/preview/text/$fileId" | ||
| private fun showPublicShareOfficeFile(driveId: Int, linkUuid: String, fileId: Int, authToken: String? = null): String { | ||
| val authParam = authToken?.let { "?sharelink_token=$it" } ?: "" | ||
| return "$SHARE_URL_V1/share/$driveId/$linkUuid/preview/text/$fileId$authParam" | ||
|
Comment on lines
+340
to
+357
|
||
| } | ||
|
|
||
| fun importPublicShareFiles(driveId: Int) = "${driveURLV2(driveId)}/imports/sharelink" | ||
|
|
@@ -353,8 +363,14 @@ object ApiRoutes { | |
| return "${getPublicShareUrlV2(driveId, linkUuid)}/archive" | ||
| } | ||
|
|
||
| fun downloadPublicShareArchive(driveId: Int, publicShareUuid: String, archiveUuid: String): String { | ||
| return "${buildPublicShareArchive(driveId, publicShareUuid)}/$archiveUuid/download" | ||
| fun downloadPublicShareArchive( | ||
| driveId: Int, | ||
| publicShareUuid: String, | ||
| archiveUuid: String, | ||
| authToken: String? = null, | ||
| ): String { | ||
| val authParam = authToken?.let { "?sharelink_token=$it" } ?: "" | ||
| return "${buildPublicShareArchive(driveId, publicShareUuid)}/$archiveUuid/download$authParam" | ||
| } | ||
|
|
||
| private fun publicShareFile(driveId: Int, linkUuid: String, fileId: Int): String { | ||
|
|
@@ -446,4 +462,9 @@ object ApiRoutes { | |
|
|
||
| private fun showOffice(file: File) = "${OFFICE_URL}/${file.driveId}/${file.id}" | ||
| //endregion | ||
|
|
||
| fun String.appendQuery(query: String): String { | ||
| val querySeparator = if (contains("?")) "&" else "?" | ||
| return this + querySeparator + query | ||
| } | ||
|
Comment on lines
+466
to
+469
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use Uri.Builder or buildUrl from ktor to manage all the case of ApiRoutes ? |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Infomaniak kDrive - Android | ||
| * Copyright (C) 2025-2026 Infomaniak Network SA | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.infomaniak.drive.data.api.publicshare | ||
|
|
||
| import android.os.Parcelable | ||
| import kotlinx.parcelize.Parcelize | ||
|
|
||
| @Parcelize | ||
| data class PublicShareToken( | ||
| val token: String = "", | ||
| ) : Parcelable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPublicShareChildrenFilesappendssharelink_tokendirectly into the URL without URL-encoding. If the token contains reserved characters, the resulting URL can be invalid or interpreted incorrectly. Prefer building the query viaappendQuery(...)(with proper encoding) or using anHttpUrlbuilder; also avoid appending when the token is blank.