diff --git a/README.md b/README.md index 3f4a495..1788cbf 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/api.html b/api.html new file mode 100644 index 0000000..06014bf --- /dev/null +++ b/api.html @@ -0,0 +1,492 @@ +
+
+
+

API

+
+
+
+ +
+
+
+
+

The Gofile system operates using accounts, files, and folders. With this API, you can manage an efficient file storage system. All files are organized within folders, and each folder is associated with an account. Every account has at least one root folder, which cannot be deleted.

+

If you upload a file without specifying any parameters, a guest account and a root folder will be created, and the file will be uploaded to a new folder within the root folder. If you wish to upload multiple files, you must first upload the initial file, then obtain the folderId from the response of the request. You can then upload the remaining files one at a time, specifying the folderId as a parameter.

+

Endpoints marked with the following icon require a premium account.

+
+
+
+
+
+
+

+ +

+
+
+

Returns the best server available to receive files.

+

+ Curl example
+

curl https://api.gofile.io/getServer
+

+

+ JavaScript example
+

+
                    
+fetch('https://api.gofile.io/getServer')
+  .then(response => response.json())
+  .then(data => {
+    if (data.status === 'ok') {
+      console.log(data.data.server)
+    }
+  })
+  .catch(error => console.error(error))
+                    
+                  
+

+ Response example
+

+
                    
+{
+  "status": "ok",
+  "data": {
+    "server": "store1"
+  }
+}
+                    
+                  
+
+
+
+
+

+ +

+
+
+

Upload one file on a specific server.
If you specify a folderId, the file will be added to this folder.

+ Parameters
+
    +
  • + requiredfile
    Must contain one file.
    If you want to upload multiple files, call uploadFile again and specify the folderId of the first file uploaded.
  • +
  • + optionaltoken
    The access token of an account. Can be retrieved from the profile page.
    If valid, the file will be added to this account.
    If undefined, a guest account will be created to receive the file.
  • +
  • + optionalfolderId
    The ID of a folder.
    If valid, the file will be added to this folder.
    If undefined, a new folder will be created to receive the file.
    When using the folderId, you must pass the account token.
  • +
+

+ Curl example
+

curl -F file=@someFile.txt https://store1.gofile.io/uploadFile
+

+

+ JavaScript example
+

+
                    
+const formData = new FormData();
+formData.append('file', fileInput.files[0]);
+fetch('https://store1.gofile.io/uploadFile', {
+    method: 'POST',
+    body: formData,
+  })
+  .then(response => response.json())
+  .then(data => {
+    if (data.status === 'ok') {
+      console.log(data.data)
+    }
+  })
+  .catch(error => console.error(error))
+                    
+                  
+

+ Response example
+

+
                    
+{
+  "status": "ok",
+  "data": {
+    "downloadPage": "https://gofile.io/d/Z19n9a",
+    "code": "Z19n9a",
+    "parentFolder": "3dbc2f87-4c1e-4a81-badc-af004e61a5b4",
+    "fileId": "4991e6d7-5217-46ae-af3d-c9174adae924",
+    "fileName": "example.mp4",
+    "md5": "10c918b1d01aea85864ee65d9e0c2305"
+  }
+}
+                    
+                  
+
+
+
+
+

+ +

+
+
+

Get a specific content details

+ Parameters
+
    +
  • + requiredcontentId
    The content ID.
  • +
  • + requiredtoken
    The access token of an account. Can be retrieved from the profile page.
  • +
+

+ Curl example
+

curl https://api.gofile.io/getContent?contentId=aefb20bd-1a19-4194-8c31-e750fbfcf0db&token=ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM
+

+

+ JavaScript example
+

+
                    
+fetch(`https://api.gofile.io/getContent?contentId=${contentId}&token=${token}`)
+  .then(response => response.json())
+  .then(data => {
+    if (data.status === 'ok') {
+      console.log(data.data)
+    }
+  })
+  .catch(error => console.error(error))
+                    
+                  
+

+ Response example
+

+
                    
+{
+  "status": "ok",
+  "data": {
+    "isOwner": true,
+    "id": "3dbc2f87-4c1e-4a81-badc-af004e61a5b4",
+    "type": "folder",
+    "name": "Z19n9a",
+    "parentFolder": "3241d27a-f7e1-4158-bc75-73d057eff5fa",
+    "code": "Z19n9a",
+    "createTime": 1648229689,
+    "public": true,
+    "childs": [
+      "4991e6d7-5217-46ae-af3d-c9174adae924"
+    ],
+    "totalDownloadCount": 0,
+    "totalSize": 9840497,
+    "contents": {
+      "4991e6d7-5217-46ae-af3d-c9174adae924": {
+        "id": "4991e6d7-5217-46ae-af3d-c9174adae924",
+        "type": "file",
+        "name": "example.mp4",
+        "parentFolder": "3dbc2f87-4c1e-4a81-badc-af004e61a5b4",
+        "createTime": 1648229689,
+        "size": 9840497,
+        "downloadCount": 0,
+        "md5": "10c918b1d01aea85864ee65d9e0c2305",
+        "mimetype": "video/mp4",
+        "serverChoosen": "store4",
+        "directLink": "https://store4.gofile.io/download/direct/4991e6d7-5217-46ae-af3d-c9174adae924/example.mp4",
+        "link": "https://store4.gofile.io/download/4991e6d7-5217-46ae-af3d-c9174adae924/example.mp4"
+      }
+    }
+  }
+}
+                    
+                    
+

+
+
+
+
+

+ +

+
+
+

Create a new folder

+ Parameters
+
    +
  • + requiredparentFolderId
    The parent folder ID.
  • +
  • + requiredfolderName
    The name of the created folder.
  • +
  • + requiredtoken
    The access token of an account. Can be retrieved from the profile page.
  • +
+

+ Curl example
+

curl https://api.gofile.io/createFolder -X PUT --data-raw 'parentFolderId=aefb20bd-1a19-4194-8c31-e750fbfcf0db&token=ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM&folderName=myFolder'
+

+

+ JavaScript example
+

+
                    
+fetch('https://api.gofile.io/createFolder', {
+  method: 'PUT',
+  headers: {
+    'Content-Type': 'application/json',
+  },
+  body: JSON.stringify({
+    parentFolderId: 'aefb20bd-1a19-4194-8c31-e750fbfcf0db',
+    token: 'ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM',
+    folderName: 'myFolder',
+  }),
+})
+.then(response => response.json())
+.then(data => {
+  if (data.status === 'ok') {
+    console.log('Folder created successfully')
+  }
+})
+.catch(error => console.error(error))
+                    
+                  
+

+ Response example
+

                      
+{
+  "status": "ok",
+  "data": {}
+}
+                      
+                    
+

+
+
+
+
+

+ +

+
+
+

Set an option on a content

+ Parameters
+
    +
  • + requiredtoken
    The access token of an account. Can be retrieved from the profile page.
  • +
  • + requiredcontentId
    The content ID.
  • +
  • + requiredoption
    Can be "public", "password", "description", "expire", "tags" or "directLink".
  • +
  • + requiredvalue
    The value of the option to be defined.
    For "public", can be "true" or "false". The contentId must be a folder.
    For "password", must be the password. The contentId must be a folder.
    For "description", must be the description. The contentId must be a folder.
    For "expire", must be the expiration date in the form of unix timestamp. The contentId must be a folder.
    For "tags", must be a comma seperated list of tags. The contentId must be a folder.
    For "directLink", can be "true" or "false". The contentId must be a file.
  • +
+

+ Curl example
+

curl https://api.gofile.io/setOption -X PUT --data-raw 'contentId=aefb20bd-1a19-4194-8c31-e750fbfcf0db&token=ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM&option=description&value=Test+description'
+

+

+ JavaScript example
+

+
                    
+fetch('https://api.gofile.io/setOption', {
+  method: 'PUT',
+  headers: {
+    'Content-Type': 'application/json',
+  },
+  body: JSON.stringify({
+    contentId: 'aefb20bd-1a19-4194-8c31-e750fbfcf0db',
+    token: 'ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM',
+    option: 'description',
+    value: 'Test description',
+  }),
+})
+.then(response => response.json())
+.then(data => {
+  if (data.status === 'ok') {
+    console.log(data.data)
+  }
+})
+.catch(error => console.error(error))
+                    
+                  
+

+ Response example
+

                      
+{
+  "status": "ok",
+  "data": {}
+}
+                      
+                    
+

+
+
+
+
+

+ +

+
+
+

Copy one or multiple contents to another folder

+ Parameters
+
    +
  • + requiredcontentsId
    Comma separated contentId to copy (files or folders)
  • +
  • + requiredfolderIdDest
    Destination folder ID
  • +
  • + requiredtoken
    The access token of an account. Can be retrieved from the profile page.
  • +
+

+ Curl example
+

curl 'https://api.gofile.io/copyContent' -X PUT --data-raw 'contentsId=74cdb7aa-c7e5-4451-5314-f14b4c48c4c1&folderIdDest=18c320d4-c123-4aad-82f5-5ceae39fca1c&token=01n3MXauGU6ZNt347nujBrayPF1hM3nJ'
+

+

+ JavaScript example
+

+
                    
+fetch('https://api.gofile.io/copyContent', {
+  method: 'PUT',
+  headers: {
+    'Content-Type': 'application/json',
+  },
+  body: JSON.stringify({
+    contentsId: '74cdb7aa-c7e5-4451-5314-f14b4c48c4c1',
+    folderIdDest: '18c320d4-c123-4aad-82f5-5ceae39fca1c',
+    token: '01n3MXauGU6ZNt347nujBrayPF1hM3nJ',
+  }),
+})
+.then(response => response.json())
+.then(data => {
+  if (data.status === 'ok') {
+    console.log(data.data)
+  }
+})
+.catch(error => console.error(error))
+                    
+                  
+

+ Response example
+

                      
+{
+  "status": "ok",
+  "data": {}
+}
+                      
+                    
+

+
+
+
+
+

+ +

+
+
+

Delete one or multiple files/folders

+ Parameters
+
    +
  • + requiredcontentsId
    Comma separated contentId to delete (files or folders)
  • +
  • + requiredtoken
    The access token of an account. Can be retrieved from the profile page.
  • +
+

+ Curl example
+

curl 'https://api.gofile.io/deleteContent' -X DELETE --data-raw 'contentsId=41c45aa2-4f81-424d-b943-81e854dbecfd%2C74bdb74f-c7e3-4968-8327-f14c4c48c4c6&token=ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM'
+

+

+ JavaScript example
+

+
                    
+fetch('https://api.gofile.io/deleteContent', {
+  method: 'DELETE',
+  headers: {
+    'Content-Type': 'application/json',
+  },
+  body: JSON.stringify({
+    contentsId: '41c45aa2-4f81-424d-b943-81e854dbecfd,74bdb74f-c7e3-4968-8327-f14c4c48c4c6',
+    token: 'ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM',
+  }),
+})
+.then(response => response.json())
+.then(data => {
+  if (data.status === 'ok') {
+    console.log(data.data)
+  }
+})
+.catch(error => console.error(error))
+                    
+                  
+

+ Response example
+

                      
+{
+  "status": "ok",
+  "data": {}
+}
+                      
+                    
+

+
+
+
+
+

+ +

+
+
+

Retrieving specific account information

+ Parameters +
    +
  • + requiredtoken
    The access token of an account. Can be retrieved from the profile page.
  • +
+

+ Curl example
+

curl https://api.gofile.io/getAccountDetails?token=ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM
+

+

+ JavaScript example
+

+
                    
+fetch(`https://api.gofile.io/getAccountDetails?token=ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM`)
+  .then(response => response.json())
+  .then(data => {
+    if (data.status === 'ok') {
+      console.log(data.data)
+    }
+  })
+  .catch(error => console.error(error))
+                    
+                  
+

+ Response example
+

                      
+{
+  "status": "ok",
+  "data": {
+    "token": "ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM",
+    "email": "email@domain.tld",
+    "tier": "standard",
+    "rootFolder": "2aecea58-84e6-420d-b2b9-68b4add8418d",
+    "foldersCount": 4,
+    "filesCount": 20,
+    "totalSize": 67653500,
+    "totalDownloadCount": 1
+  }
+}
+                      
+                    
+

+
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/examples/e2e/src/main/kotlin/dev/s7a/example/gofile/Main.kt b/examples/e2e/src/main/kotlin/dev/s7a/example/gofile/Main.kt index 8c29593..588a8e8 100644 --- a/examples/e2e/src/main/kotlin/dev/s7a/example/gofile/Main.kt +++ b/examples/e2e/src/main/kotlin/dev/s7a/example/gofile/Main.kt @@ -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 @@ -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() @@ -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") } diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileClient.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileClient.kt index c0fb51c..c1a1d9c 100644 --- a/src/commonMain/kotlin/dev/s7a/gofile/GofileClient.kt +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileClient.kt @@ -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]. @@ -22,7 +23,11 @@ class GofileClient(private val client: HttpClient) { fun setupClient(client: HttpClientConfig<*>) { client.run { install(ContentNegotiation) { - json() + json( + Json { + ignoreUnknownKeys = true + }, + ) } } } @@ -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 { - return request(GofileRequest.SetFolderOption(folderId, option, token)) + suspend fun setOption(folderId: String, option: GofileOption, token: String): Result { + return request(GofileRequest.SetOption(folderId, option, token)) } /** diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileGetAccountDetailsResponse.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileGetAccountDetailsResponse.kt index 3e1fcd9..89011ab 100644 --- a/src/commonMain/kotlin/dev/s7a/gofile/GofileGetAccountDetailsResponse.kt +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileGetAccountDetailsResponse.kt @@ -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 @@ -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 ) diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileFolderOption.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileOption.kt similarity index 51% rename from src/commonMain/kotlin/dev/s7a/gofile/GofileFolderOption.kt rename to src/commonMain/kotlin/dev/s7a/gofile/GofileOption.kt index 482e206..7a736e3 100644 --- a/src/commonMain/kotlin/dev/s7a/gofile/GofileFolderOption.kt +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileOption.kt @@ -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. */ @@ -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) : GofileFolderOption("tags") { + data class Tags(val values: List) : 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() + } } diff --git a/src/commonMain/kotlin/dev/s7a/gofile/GofileRequest.kt b/src/commonMain/kotlin/dev/s7a/gofile/GofileRequest.kt index 738e23c..1320896 100644 --- a/src/commonMain/kotlin/dev/s7a/gofile/GofileRequest.kt +++ b/src/commonMain/kotlin/dev/s7a/gofile/GofileRequest.kt @@ -71,10 +71,10 @@ internal sealed interface GofileRequest { Headers.build { append(HttpHeaders.ContentType, contentType) append(HttpHeaders.ContentDisposition, "filename=\"${fileName}\"") - } + }, ) - } - ) + }, + ), ) } @@ -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) - } - ) + }, + ), ) } } @@ -192,8 +192,8 @@ internal sealed interface GofileRequest { append("contentsId", contentsId.joinToString(",")) append("folderIdDest", folderIdDest) append("token", token) - } - ) + }, + ), ) } } @@ -215,8 +215,8 @@ internal sealed interface GofileRequest { Parameters.build { append("contentsId", contentsId.joinToString(",")) append("token", token) - } - ) + }, + ), ) } } diff --git a/src/commonTest/kotlin/ExampleDecodeTests.kt b/src/commonTest/kotlin/ExampleDecodeTests.kt new file mode 100644 index 0000000..64e9df9 --- /dev/null +++ b/src/commonTest/kotlin/ExampleDecodeTests.kt @@ -0,0 +1,181 @@ +import dev.s7a.gofile.GofileChildContent +import dev.s7a.gofile.GofileContent +import dev.s7a.gofile.GofileGetAccountDetailsResponse +import dev.s7a.gofile.GofileGetServerResponse +import dev.s7a.gofile.GofileResponse +import dev.s7a.gofile.GofileTier +import dev.s7a.gofile.GofileUploadFileResponse +import kotlinx.serialization.json.Json +import kotlin.test.Test +import kotlin.test.assertEquals + +/** + * Last update: 2023-04-20 + */ +class ExampleDecodeTests { + @Test + fun getServer() { + assertEquals( + GofileResponse.Ok( + GofileGetServerResponse( + server = "store1", + ), + ), + Json.decodeFromString( + GofileResponse.serializer(GofileGetServerResponse.serializer()), + """ + { + "status": "ok", + "data": { + "server": "store1" + } + } + """.trimIndent(), + ), + ) + } + + @Test + fun uploadFile() { + assertEquals( + GofileResponse.Ok( + GofileUploadFileResponse( + downloadPage = "https://gofile.io/d/Z19n9a", + code = "Z19n9a", + parentFolder = "3dbc2f87-4c1e-4a81-badc-af004e61a5b4", + fileId = "4991e6d7-5217-46ae-af3d-c9174adae924", + fileName = "example.mp4", + md5 = "10c918b1d01aea85864ee65d9e0c2305", + ), + ), + Json.decodeFromString( + GofileResponse.serializer(GofileUploadFileResponse.serializer()), + """ + { + "status": "ok", + "data": { + "downloadPage": "https://gofile.io/d/Z19n9a", + "code": "Z19n9a", + "parentFolder": "3dbc2f87-4c1e-4a81-badc-af004e61a5b4", + "fileId": "4991e6d7-5217-46ae-af3d-c9174adae924", + "fileName": "example.mp4", + "md5": "10c918b1d01aea85864ee65d9e0c2305" + } + } + """.trimIndent(), + ), + ) + } + + @Test + fun getContent() { + assertEquals( + GofileResponse.Ok( + GofileContent.Folder( + isOwner = true, + id = "3dbc2f87-4c1e-4a81-badc-af004e61a5b4", + name = "Z19n9a", + parentFolder = "3241d27a-f7e1-4158-bc75-73d057eff5fa", + code = "Z19n9a", + createTime = 1648229689, + public = true, + childs = listOf( + "4991e6d7-5217-46ae-af3d-c9174adae924", + ), + totalDownloadCount = 0, + totalSize = 9840497.0, + contents = mapOf( + "4991e6d7-5217-46ae-af3d-c9174adae924" to GofileChildContent.File( + id = "4991e6d7-5217-46ae-af3d-c9174adae924", + name = "example.mp4", + parentFolder = "3dbc2f87-4c1e-4a81-badc-af004e61a5b4", + createTime = 1648229689, + size = 9840497.0, + downloadCount = 0, + md5 = "10c918b1d01aea85864ee65d9e0c2305", + mimetype = "video/mp4", + serverChoosen = "store4", + directLink = "https://store4.gofile.io/download/direct/4991e6d7-5217-46ae-af3d-c9174adae924/example.mp4", + link = "https://store4.gofile.io/download/4991e6d7-5217-46ae-af3d-c9174adae924/example.mp4", + ), + ), + ), + ), + Json.decodeFromString( + GofileResponse.serializer(GofileContent.serializer()), + """ + { + "status": "ok", + "data": { + "isOwner": true, + "id": "3dbc2f87-4c1e-4a81-badc-af004e61a5b4", + "type": "folder", + "name": "Z19n9a", + "parentFolder": "3241d27a-f7e1-4158-bc75-73d057eff5fa", + "code": "Z19n9a", + "createTime": 1648229689, + "public": true, + "childs": [ + "4991e6d7-5217-46ae-af3d-c9174adae924" + ], + "totalDownloadCount": 0, + "totalSize": 9840497, + "contents": { + "4991e6d7-5217-46ae-af3d-c9174adae924": { + "id": "4991e6d7-5217-46ae-af3d-c9174adae924", + "type": "file", + "name": "example.mp4", + "parentFolder": "3dbc2f87-4c1e-4a81-badc-af004e61a5b4", + "createTime": 1648229689, + "size": 9840497, + "downloadCount": 0, + "md5": "10c918b1d01aea85864ee65d9e0c2305", + "mimetype": "video/mp4", + "serverChoosen": "store4", + "directLink": "https://store4.gofile.io/download/direct/4991e6d7-5217-46ae-af3d-c9174adae924/example.mp4", + "link": "https://store4.gofile.io/download/4991e6d7-5217-46ae-af3d-c9174adae924/example.mp4" + } + } + } + } + """.trimIndent(), + ), + ) + } + + @Test + fun getAccountDetails() { + assertEquals( + GofileResponse.Ok( + GofileGetAccountDetailsResponse( + token = "ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM", + email = "email@domain.tld", + tier = GofileTier.Standard, + rootFolder = "2aecea58-84e6-420d-b2b9-68b4add8418d", + foldersCount = 4, + filesCount = 20, + totalSize = 67653500.0, + totalDownloadCount = 1, + ), + ), + Json.decodeFromString( + GofileResponse.serializer(GofileGetAccountDetailsResponse.serializer()), + """ + { + "status": "ok", + "data": { + "token": "ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM", + "email": "email@domain.tld", + "tier": "standard", + "rootFolder": "2aecea58-84e6-420d-b2b9-68b4add8418d", + "foldersCount": 4, + "filesCount": 20, + "totalSize": 67653500, + "totalDownloadCount": 1 + } + } + """.trimIndent(), + ), + ) + } +} diff --git a/src/commonTest/kotlin/ResponseTypeTests.kt b/src/commonTest/kotlin/ResponseTypeTests.kt index 3e14612..8215d34 100644 --- a/src/commonTest/kotlin/ResponseTypeTests.kt +++ b/src/commonTest/kotlin/ResponseTypeTests.kt @@ -1,5 +1,6 @@ import dev.s7a.gofile.GofileGetServerResponse import dev.s7a.gofile.GofileResponse +import dev.s7a.gofile.GofileUploadFileResponse import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @@ -15,7 +16,7 @@ class ResponseTypeTests { """ {"status":"ok","data":{"server":"_server"}} """.trimIndent(), - Json.encodeToString>(GofileResponse.Ok(GofileGetServerResponse("_server"))) + Json.encodeToString>(GofileResponse.Ok(GofileGetServerResponse("_server"))), ) } @@ -25,7 +26,7 @@ class ResponseTypeTests { """ {"status":"_status"} """.trimIndent(), - Json.encodeToString>(GofileResponse.Error("_status")) + Json.encodeToString>(GofileResponse.Error("_status")), ) } @@ -35,7 +36,7 @@ class ResponseTypeTests { """ {"status":"_status","data":{"a":"1","b":"2"}} """.trimIndent(), - Json.encodeToString>(GofileResponse.Error("_status", JsonObject(mapOf("a" to JsonPrimitive("1"), "b" to JsonPrimitive("2"))))) + Json.encodeToString>(GofileResponse.Error("_status", JsonObject(mapOf("a" to JsonPrimitive("1"), "b" to JsonPrimitive("2"))))), ) } @@ -47,7 +48,7 @@ class ResponseTypeTests { {"status":"ok","data":{"server":"_server"}} """.trimIndent().let { Json.decodeFromString>(it) - } + }, ) } @@ -59,7 +60,7 @@ class ResponseTypeTests { {"status":"_status"} """.trimIndent().let { Json.decodeFromString>(it) - } + }, ) } @@ -71,7 +72,7 @@ class ResponseTypeTests { {"status":"_status","data":{}} """.trimIndent().let { Json.decodeFromString>(it) - } + }, ) } @@ -83,7 +84,7 @@ class ResponseTypeTests { {"status":"_status","data":{"a":"1","b":"2"}} """.trimIndent().let { Json.decodeFromString>(it) - } + }, ) } } diff --git a/src/commonTest/kotlin/Tests.kt b/src/commonTest/kotlin/Tests.kt index ea181bf..6c930d5 100644 --- a/src/commonTest/kotlin/Tests.kt +++ b/src/commonTest/kotlin/Tests.kt @@ -1,5 +1,5 @@ import dev.s7a.gofile.GofileClient -import dev.s7a.gofile.GofileFolderOption +import dev.s7a.gofile.GofileOption import dev.s7a.gofile.GofileStatusException import io.ktor.client.engine.mock.MockEngine import io.ktor.client.engine.mock.respond @@ -187,7 +187,7 @@ class Tests { } @Test - fun setFolderOption_should_be_successful() { + fun setOption_should_be_successful() { runTest { val mockEngine = MockEngine { respond( @@ -201,28 +201,30 @@ class Tests { headers = headersOf(HttpHeaders.ContentType, "application/json") ) } - assertTrue(GofileClient(mockEngine).setFolderOption("aefb20bd-1a19-4194-8c31-e750fbfcf0db", GofileFolderOption.Description("Test+description"), "ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM").isSuccess) + assertTrue(GofileClient(mockEngine).setOption("aefb20bd-1a19-4194-8c31-e750fbfcf0db", GofileOption.Description("Test+description"), "ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM").isSuccess) } } @Test - fun setFolderOption_can_handle_error() { + fun setOption_can_handle_error() { runTest { val mockEngine = MockEngine { respondError(HttpStatusCode.InternalServerError) } - assertFalse(GofileClient(mockEngine).setFolderOption("aefb20bd-1a19-4194-8c31-e750fbfcf0db", GofileFolderOption.Description("Test+description"), "ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM").isSuccess) + assertFalse(GofileClient(mockEngine).setOption("aefb20bd-1a19-4194-8c31-e750fbfcf0db", GofileOption.Description("Test+description"), "ivlW1ZSGn2Y4AoADbCHUjllj2cO9m3WM").isSuccess) } } @Test - fun assert_GofileFolderOption() { - assertEquals("true", GofileFolderOption.Public(true).value) - assertEquals("false", GofileFolderOption.Public(false).value) - assertEquals("pass", GofileFolderOption.Password("pass").value) - assertEquals("abc", GofileFolderOption.Description("abc").value) - assertEquals("1659636061790", GofileFolderOption.Expire(1659636061790).value) - assertEquals("abc,def", GofileFolderOption.Tags("abc", "def").value) + fun assert_GofileOption() { + assertEquals("true", GofileOption.Public(true).value) + assertEquals("false", GofileOption.Public(false).value) + assertEquals("pass", GofileOption.Password("pass").value) + assertEquals("abc", GofileOption.Description("abc").value) + assertEquals("1659636061790", GofileOption.Expire(1659636061790).value) + assertEquals("abc,def", GofileOption.Tags("abc", "def").value) + assertEquals("true", GofileOption.DirectLink(true).value) + assertEquals("false", GofileOption.DirectLink(false).value) } @Test