Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
feat: Support api-version: 2023-04-20
Browse files Browse the repository at this point in the history
  • Loading branch information
sya-ri committed Nov 10, 2023
1 parent df99681 commit 7e98115
Show file tree
Hide file tree
Showing 10 changed files with 748 additions and 62 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ A kotlin wrapper for the [Gofile.io](https://gofile.io) API.
- [x] JVM
- [x] JS
- [x] Native
- Supports all endpoints.
- Supports all endpoints. (API Version: 2023-04-20)
- [x] getServer
- [x] uploadFile
- [x] getContent
- [x] createFolder
- [x] setFolderOption
- [x] setOption
- [x] copyContent
- [x] deleteContent
- [x] getAccountDetails
Expand Down
492 changes: 492 additions & 0 deletions api.html

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions examples/e2e/src/main/kotlin/dev/s7a/example/gofile/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package dev.s7a.example.gofile

import dev.s7a.gofile.GofileClient
import dev.s7a.gofile.GofileFolderOption
import dev.s7a.gofile.GofileOption
import dev.s7a.gofile.GofileTier
import dev.s7a.gofile.uploadFile
import java.util.Calendar
Expand All @@ -23,10 +23,10 @@ suspend fun main() {
println("accountDetails: $accountDetails")
val createFolder = client.createFolder(uploadFile.parentFolder, "new-folder", token).getOrThrow()
println("createFolder: $createFolder")
client.setFolderOption(createFolder.id, GofileFolderOption.Description("description"), token).getOrThrow()
client.setFolderOption(createFolder.id, GofileFolderOption.Expire(Calendar.getInstance().apply { add(Calendar.DAY_OF_MONTH, 1) }.toInstant().epochSecond), token).getOrThrow()
client.setFolderOption(createFolder.id, GofileFolderOption.Password("password"), token).getOrThrow()
client.setFolderOption(createFolder.id, GofileFolderOption.Tags("t", "a", "g", "s"), token).getOrThrow()
client.setOption(createFolder.id, GofileOption.Description("description"), token).getOrThrow()
client.setOption(createFolder.id, GofileOption.Expire(Calendar.getInstance().apply { add(Calendar.DAY_OF_MONTH, 1) }.toInstant().epochSecond), token).getOrThrow()
client.setOption(createFolder.id, GofileOption.Password("password"), token).getOrThrow()
client.setOption(createFolder.id, GofileOption.Tags("t", "a", "g", "s"), token).getOrThrow()
if (accountDetails.tier == GofileTier.Donor) {
client.copyContent(uploadFile.fileId, createFolder.id, token).getOrThrow()
val getContentFile = client.getContent(uploadFile.fileId, token).getOrThrow()
Expand All @@ -36,4 +36,6 @@ suspend fun main() {
}
val deleteContent = client.deleteContent(uploadFile.fileId, token).getOrThrow()
println("deleteContent: $deleteContent")
val deleteFolder = client.deleteContent(createFolder.id, token).getOrThrow()
println("deleteFolder: $deleteFolder")
}
13 changes: 9 additions & 4 deletions src/commonMain/kotlin/dev/s7a/gofile/GofileClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.ktor.client.engine.HttpClientEngineFactory
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.request
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.json.Json

/**
* Gofile.io client that uses a pre-setup [HttpClient].
Expand All @@ -22,7 +23,11 @@ class GofileClient(private val client: HttpClient) {
fun setupClient(client: HttpClientConfig<*>) {
client.run {
install(ContentNegotiation) {
json()
json(
Json {
ignoreUnknownKeys = true
},
)
}
}
}
Expand Down Expand Up @@ -124,14 +129,14 @@ class GofileClient(private val client: HttpClient) {
/**
* Set an option on a folder.
*
* `https://api.gofile.io/setFolderOption`
* `https://api.gofile.io/setOption`
*
* @param folderId The folder ID.
* @param option The option.
* @param token The access token of an account. Can be retrieved from the profile page.
*/
suspend fun setFolderOption(folderId: String, option: GofileFolderOption, token: String): Result<Unit> {
return request(GofileRequest.SetFolderOption(folderId, option, token))
suspend fun setOption(folderId: String, option: GofileOption, token: String): Result<Unit> {
return request(GofileRequest.SetOption(folderId, option, token))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import kotlinx.serialization.Serializable
* @property tierAmount Dollars paid monthly.
* @property rootFolder The root folder id.
* @property filesCount A number of files.
* @property filesCountLimit Limit of [filesCount].
* @property foldersCount
* @property totalSize A size of all files.
* @property totalSizeLimit Limit of [totalSize].
* @property total30DDLTraffic DDL traffic increases when someone downloads your content through a direct link. It is counted for the last 30 days. Downloads from the website are unlimited.
* @property total30DDLTrafficLimit Limit of [total30DDLTraffic].
* @property totalDownloadCount
* @see GofileClient.getAccountDetails
*/
@Serializable
Expand All @@ -26,9 +24,7 @@ data class GofileGetAccountDetailsResponse(
val tierAmount: Int? = null,
val rootFolder: String,
val filesCount: Int,
val filesCountLimit: Int?,
val foldersCount: Int? = null,
val totalSize: Double,
val totalSizeLimit: Double?,
val total30DDLTraffic: Double,
val total30DDLTrafficLimit: Double?
val totalDownloadCount: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package dev.s7a.gofile
/**
* The value of the option to be defined.
*
* @property name Can be "public", "password", "description", "expire" or "tags".
* @property name Can be "public", "password", "description", "expire", "tags" or "directLink".
*/
sealed class GofileFolderOption(val name: String) {
sealed class GofileOption(val name: String) {
/**
* The option value.
*/
Expand All @@ -14,33 +14,40 @@ sealed class GofileFolderOption(val name: String) {
/**
* Whether anyone can access it.
*/
data class Public(val isPublic: Boolean) : GofileFolderOption("public") {
data class Public(val isPublic: Boolean) : GofileOption("public") {
override val value = isPublic.toString()
}

/**
* Password is required for access.
*/
data class Password(override val value: String) : GofileFolderOption("password")
data class Password(override val value: String) : GofileOption("password")

/**
* Description.
*/
data class Description(override val value: String) : GofileFolderOption("description")
data class Description(override val value: String) : GofileOption("description")

/**
* Expiration date in the form of unix timestamp.
*/
data class Expire(val timestamp: Long) : GofileFolderOption("expire") {
data class Expire(val timestamp: Long) : GofileOption("expire") {
override val value = timestamp.toString()
}

/**
* Tags.
*/
data class Tags(val values: List<String>) : GofileFolderOption("tags") {
data class Tags(val values: List<String>) : GofileOption("tags") {
constructor(vararg value: String) : this(value.toList())

override val value = values.joinToString(",")
}

/**
* The contentId must be a file.
*/
data class DirectLink(val directLink: Boolean) : GofileOption("directLink") {
override val value = directLink.toString()
}
}
34 changes: 17 additions & 17 deletions src/commonMain/kotlin/dev/s7a/gofile/GofileRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ internal sealed interface GofileRequest {
Headers.build {
append(HttpHeaders.ContentType, contentType)
append(HttpHeaders.ContentDisposition, "filename=\"${fileName}\"")
}
},
)
}
)
},
),
)
}

Expand Down Expand Up @@ -141,34 +141,34 @@ internal sealed interface GofileRequest {
append("parentFolderId", parentFolderId)
append("folderName", folderName)
append("token", token)
}
)
},
),
)
}
}

/**
* Set an option on a folder.
* Set an option.
*
* `https://api.gofile.io/setFolderOption`
* `https://api.gofile.io/setOption`
*
* @property folderId The folder ID.
* @property contentId The content ID.
* @property option The option.
* @property token The access token of an account. Can be retrieved from the profile page.
*/
data class SetFolderOption(val folderId: String, val option: GofileFolderOption, val token: String) : GofileRequest {
data class SetOption(val contentId: String, val option: GofileOption, val token: String) : GofileRequest {
override val method = HttpMethod.Put
override val urlString = "https://api.gofile.io/setFolderOption"
override val urlString = "https://api.gofile.io/setOption"
override fun buildAction(builder: HttpRequestBuilder) {
builder.setBody(
FormDataContent(
Parameters.build {
append("folderId", folderId)
append("contentId", contentId)
append("option", option.name)
append("value", option.value)
append("token", token)
}
)
},
),
)
}
}
Expand All @@ -192,8 +192,8 @@ internal sealed interface GofileRequest {
append("contentsId", contentsId.joinToString(","))
append("folderIdDest", folderIdDest)
append("token", token)
}
)
},
),
)
}
}
Expand All @@ -215,8 +215,8 @@ internal sealed interface GofileRequest {
Parameters.build {
append("contentsId", contentsId.joinToString(","))
append("token", token)
}
)
},
),
)
}
}
Expand Down
Loading

0 comments on commit 7e98115

Please sign in to comment.