Skip to content

Commit

Permalink
Merge pull request #860 from Infomaniak/refactorDriveUrl
Browse files Browse the repository at this point in the history
Refactor drive url
  • Loading branch information
JorisBodin authored Jul 29, 2022
2 parents 808d707 + e6c581a commit bcd25a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
buildConfigField 'String', 'CLIENT_ID', '"9473D73C-C20F-4971-9E10-D957C563FA68"'
buildConfigField 'String', 'DRIVE_API', '"https://api.drive.infomaniak.com/drive/"'
buildConfigField 'String', 'DRIVE_API_V1', '"https://api.drive.infomaniak.com/drive/"'
buildConfigField 'String', 'DRIVE_API_V2', '"https://api.drive.infomaniak.com/2/drive/"'
buildConfigField 'String', 'MATOMO_URL', '"https://analytics.infomaniak.com/matomo.php"'
buildConfigField 'String', 'OFFICE_URL', '"https://drive.infomaniak.com/app/office/"'
Expand Down Expand Up @@ -67,7 +67,7 @@ android {
fdroid { dimension 'distribution' }
preprod {
dimension 'distribution'
buildConfigField 'String', 'DRIVE_API', '"https://drive.preprod.dev.infomaniak.ch/drive/"'
buildConfigField 'String', 'DRIVE_API_V1', '"https://drive.preprod.dev.infomaniak.ch/drive/"'
buildConfigField 'String', 'DRIVE_API_V2', '"https://drive.preprod.dev.infomaniak.ch/2/drive/"'
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/infomaniak/drive/ApplicationMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import coil.disk.DiskCache
import coil.memory.MemoryCache
import com.facebook.stetho.Stetho
import com.facebook.stetho.okhttp3.StethoInterceptor
import com.infomaniak.drive.BuildConfig.DRIVE_API
import com.infomaniak.drive.BuildConfig.DRIVE_API_V2
import com.infomaniak.drive.GeniusScanUtils.initGeniusScanSdk
import com.infomaniak.drive.data.documentprovider.CloudStorageProvider.Companion.initRealm
import com.infomaniak.drive.data.models.UiSettings
Expand Down Expand Up @@ -137,7 +137,7 @@ class ApplicationMain : Application(), ImageLoaderFactory {
OkHttpClient.Builder().apply {
addInterceptor(Interceptor { chain ->
var request = chain.request()
if (request.url.toString().contains(DRIVE_API) || request.url.toString().contains(INFOMANIAK_API)) {
if (request.url.toString().contains(DRIVE_API_V2) || request.url.toString().contains(INFOMANIAK_API)) {
request = request.newBuilder().headers(HttpUtils.getHeaders()).removeHeader("Cache-Control").build()
}
chain.proceed(request)
Expand Down
48 changes: 23 additions & 25 deletions app/src/main/java/com/infomaniak/drive/data/api/ApiRoutes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,24 @@ object ApiRoutes {

private fun orderQuery(order: SortType) = "order_for[${order.orderBy}]=${order.order}&order_by=${order.orderBy}"

private fun v2URL(driveId: Int) = "${DRIVE_API_V2}${driveId}"
private fun driveURL(driveId: Int) = "${DRIVE_API_V2}${driveId}"

private fun fileURL(driveId: Int) = "${v2URL(driveId)}/files"
private fun filesURL(driveId: Int) = "${driveURL(driveId)}/files"

fun fileURL(file: File) = fileURL(file.driveId, file.id)
private fun fileURL(driveId: Int, fileId: FileId) = "${filesURL(driveId)}/${fileId}"

private fun fileURL(driveId: Int, fileId: FileId) = "${fileURL(driveId)}/${fileId}"
fun fileURL(file: File) = fileURL(file.driveId, file.id)

fun trashURL(file: File) = "${v2URL(file.driveId)}/trash/${file.id}"
fun trashURL(file: File) = "${driveURL(file.driveId)}/trash/${file.id}"

/** V1 */
//region V1
fun getAllDrivesData() = "${DRIVE_API}init?with=drives,users,teams,ips,categories"
fun getAllDrivesData() = "${DRIVE_API_V1}init?with=drives,users,teams,ips,categories"
//endregion

/** Archive */
//region Archive
fun buildArchive(driveId: Int): String = "${fileURL(driveId)}/archives"

fun getUUIDArchiveFiles(driveId: Int): String = "${DRIVE_API}$driveId/file/archive"
fun buildArchive(driveId: Int): String = "${filesURL(driveId)}/archives"

fun downloadArchiveFiles(driveId: Int, uuid: String): String = "${buildArchive(driveId)}/$uuid"
//endregion
Expand All @@ -59,7 +57,7 @@ object ApiRoutes {
//region Access/Invitation
fun accessUrl(file: File) = "${fileURL(file)}/access"

fun fileInvitationAccess(file: File, invitationId: Int) = "${v2URL(file.driveId)}/files/invitations/$invitationId"
fun fileInvitationAccess(file: File, invitationId: Int) = "${driveURL(file.driveId)}/files/invitations/$invitationId"

fun getFileShare(file: File) = "${accessUrl(file)}?with=user"

Expand All @@ -74,7 +72,7 @@ object ApiRoutes {

/** Action */
//region Action
fun undoAction(driveId: Int) = "${v2URL(driveId)}/cancel"
fun undoAction(driveId: Int) = "${driveURL(driveId)}/cancel"
//endregion

/** Activities */
Expand All @@ -86,12 +84,12 @@ object ApiRoutes {
"&actions[]=comment_create"

fun getLastActivities(driveId: Int) =
"${fileURL(driveId)}/activities?$activitiesWithQuery,user&depth=unlimited&$activitiesActions"
"${filesURL(driveId)}/activities?$activitiesWithQuery,user&depth=unlimited&$activitiesActions"

fun getFileActivities(file: File) = "${fileURL(file)}/activities"

fun getFileActivities(driveId: Int, fileIds: String, fromDate: Long) =
"${fileURL(driveId)}/activities/batch?$activitiesWithQuery&file_ids=$fileIds&from_date=$fromDate" +
"${filesURL(driveId)}/activities/batch?$activitiesWithQuery&file_ids=$fileIds&from_date=$fromDate" +
"&actions[]=file_rename" +
"&actions[]=file_update"

Expand All @@ -101,13 +99,13 @@ object ApiRoutes {
/** Category */
//region Category

fun categories(driveId: Int) = "${v2URL(driveId)}/categories"
fun categories(driveId: Int) = "${driveURL(driveId)}/categories"

fun category(driveId: Int, categoryId: Int) = "${categories(driveId)}/$categoryId"

fun fileCategory(file: File, categoryId: Int) = "${fileURL(file)}/categories/$categoryId"

fun fileCategory(driveId: Int, categoryId: Int) = "${fileURL(driveId)}/categories/$categoryId"
fun fileCategory(driveId: Int, categoryId: Int) = "${filesURL(driveId)}/categories/$categoryId"
//endregion

/** Comment */
Expand All @@ -132,7 +130,7 @@ object ApiRoutes {

/** Favorite */
//region Favorite
fun getFavoriteFiles(driveId: Int, order: SortType) = "${fileURL(driveId)}/favorites?$fileWithQuery&${orderQuery(order)}"
fun getFavoriteFiles(driveId: Int, order: SortType) = "${filesURL(driveId)}/favorites?$fileWithQuery&${orderQuery(order)}"

fun favorite(file: File) = "${fileURL(file)}/favorite"
//endregion
Expand Down Expand Up @@ -173,7 +171,7 @@ object ApiRoutes {

/** Search */
//region Search
fun searchFiles(driveId: Int, sortType: SortType) = "${fileURL(driveId)}/search?$fileWithQuery&${orderQuery(sortType)}"
fun searchFiles(driveId: Int, sortType: SortType) = "${filesURL(driveId)}/search?$fileWithQuery&${orderQuery(sortType)}"
//endregion

/** Share link */
Expand All @@ -183,9 +181,9 @@ object ApiRoutes {

/** Trash */
//region Trash
fun driveTrash(driveId: Int, order: SortType) = "${v2URL(driveId)}/trash?${orderQuery(order)}&$fileWithQuery"
fun driveTrash(driveId: Int, order: SortType) = "${driveURL(driveId)}/trash?${orderQuery(order)}&$fileWithQuery"

fun emptyTrash(driveId: Int) = "${v2URL(driveId)}/trash"
fun emptyTrash(driveId: Int) = "${driveURL(driveId)}/trash"

fun trashedFile(file: File) = "${trashURL(file)}?$fileExtraWithQuery"

Expand All @@ -198,7 +196,7 @@ object ApiRoutes {

/** Upload */
//region Upload
private fun uploadSessionUrl(driveId: Int) = "${v2URL(driveId)}/upload/session"
private fun uploadSessionUrl(driveId: Int) = "${driveURL(driveId)}/upload/session"

fun getSession(driveId: Int, uploadToken: String) = "${uploadSessionUrl(driveId)}/$uploadToken"

Expand All @@ -208,19 +206,19 @@ object ApiRoutes {

fun closeSession(driveId: Int, uploadToken: String) = "${uploadSessionUrl(driveId)}/$uploadToken/finish"

fun uploadFile(driveId: Int, folderId: Int) = "${DRIVE_API}$driveId/file/$folderId/upload"
fun uploadFile(driveId: Int, folderId: Int) = "${DRIVE_API_V1}$driveId/file/$folderId/upload"
//endregion

/** Root Directory */
//region Root Directory
fun bulkAction(driveId: Int) = "${fileURL(driveId)}/bulk"
fun bulkAction(driveId: Int) = "${filesURL(driveId)}/bulk"

fun getLastModifiedFiles(driveId: Int) = "${fileURL(driveId)}/last_modified?$fileWithQuery"
fun getLastModifiedFiles(driveId: Int) = "${filesURL(driveId)}/last_modified?$fileWithQuery"

fun createTeamFolder(driveId: Int) = "${fileURL(driveId)}/team_directory?$fileWithQuery"
fun createTeamFolder(driveId: Int) = "${filesURL(driveId)}/team_directory?$fileWithQuery"

fun getMySharedFiles(driveId: Int, sortType: SortType) =
"${fileURL(driveId)}/my_shared?${orderQuery(sortType)}&$fileWithQuery,users"
"${filesURL(driveId)}/my_shared?${orderQuery(sortType)}&$fileWithQuery,users"
//endregion

/** Others */
Expand Down

0 comments on commit bcd25a3

Please sign in to comment.