diff --git a/docs/web-api.yaml b/docs/web-api.yaml index 3c465b68..a6c79e53 100644 --- a/docs/web-api.yaml +++ b/docs/web-api.yaml @@ -37,6 +37,8 @@ tags: description: Game Mods management - name: users description: Users management + - name: file manager + description: File management servers: - url: "{gameap-host}" @@ -143,6 +145,13 @@ paths: /api/gdaemon_tasks/{gdaemon_task}/output: $ref: './web-api/paths/gdaemon_tasks_id_output.yaml' + /file-manager/{server}/content: + $ref: './web-api/paths/file_manager_content.yaml' + + /file-manager/{server}/upload: + $ref: './web-api/paths/file_manager_upload.yaml' + + components: schemas: User: diff --git a/docs/web-api/paths/file_manager_content.yaml b/docs/web-api/paths/file_manager_content.yaml new file mode 100644 index 00000000..16ef1d37 --- /dev/null +++ b/docs/web-api/paths/file_manager_content.yaml @@ -0,0 +1,214 @@ +get: + summary: Get Files + tags: + - 'file manager' + description: Returns a list of files and directories in the specified directory. + parameters: + - in: path + name: server + required: true + description: The server ID. + schema: + type: integer + - in: query + name: disk + required: true + description: The disk name. + schema: + type: string + - in: query + name: path + description: The path to the directory. If not specified, the root directory will be used. + schema: + type: string + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + properties: + status: + type: string + example: success + message: + type: string + nullable: true + example: null + directories: + type: array + items: + type: object + properties: + path: + type: string + example: path/to/logs + timestamp: + type: integer + example: 1723147777 + type: + type: string + example: dir + dirname: + type: string + example: "" + basename: + type: string + example: logs + files: + type: array + items: + type: object + properties: + path: + type: string + example: path/to/ops.json + timestamp: + type: integer + example: 1723147780 + type: + type: string + example: file + visibility: + type: string + example: public + size: + type: integer + example: 2 + dirname: + type: string + example: "" + basename: + type: string + example: ops.json + extension: + type: string + example: json + filename: + type: string + example: ops + 4XX: + description: OK + content: + application/json: + schema: + type: object + properties: + errors: + type: object + message: + type: string + 5XX: + description: OK + content: + application/json: + schema: + type: object + x-codeSamples: + - lang: 'cURL' + label: 'CLI' + source: | + curl --request GET \ + --url 'https://demo.gameap.com/file-manager/1/content?disk=server&path=logs' \ + --header "Accept: application/json" \ + --header 'Content-Type: application/json: ' \ + --header 'Authorization: Bearer YOUR_API_KEY' + - lang: 'PHP' + source: | + $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => [ + 'Content-Type: application/json', + 'Authorization: Bearer ' . $apiKey, + ], + ]); + + $response = curl_exec($curl); + + curl_close($curl); + + $result = json_decode($response, true); + print_r($result); + - lang: 'GO' + source: | + package main + + import ( + "fmt" + "io" + "net/http" + "os" + ) + + func main() { + url := "https://demo.gameap.com/file-manager/1/content?disk=server&path=logs" + apiKey := "YOUR_API_KEY" + + client := &http.Client{} + + req, err := http.NewRequest("GET", url, nil) + if err != nil { + fmt.Println(err) + return + } + + req.Header.Add("Accept", "application/json") + req.Header.Add("Content-Type", "application/json") + req.Header.Add("Authorization", "Bearer "+apiKey) + + resp, err := client.Do(req) + if err != nil { + fmt.Println(err) + return + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + fmt.Println(err) + return + } + + fmt.Println(string(body)) + } + - lang: "NodeJS" + source: | + const request = require('request'); + + const url = 'https://demo.gameap.com/file-manager/1/content?disk=server&path=logs'; + const apiKey = 'YOUR_API_KEY'; + + const headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + apiKey + }; + + request.get({ + url: url, + headers: headers + }, (error, response, body) => { + if (error) { + console.log(error); + } else { + console.log(body); + } + }); \ No newline at end of file diff --git a/docs/web-api/paths/file_manager_upload.yaml b/docs/web-api/paths/file_manager_upload.yaml new file mode 100644 index 00000000..96cf797d --- /dev/null +++ b/docs/web-api/paths/file_manager_upload.yaml @@ -0,0 +1,216 @@ +post: + summary: Upload Files + tags: + - 'file manager' + requestBody: + required: true + content: + multipart/form-data: + schema: + type: object + properties: + disk: + type: string + example: server + path: + type: string + example: "" + overwrite: + type: integer + example: 0 + files: + type: array + items: + type: string + format: binary + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + properties: + status: + type: string + example: success + message: + type: string + example: All files uploaded! + x-codeSamples: + - lang: 'cURL' + label: 'CLI' + source: | + curl -X POST "https://demo.gameap.com/file-manager/1/upload" \ + --header "Accept: application/json" \ + --header 'Authorization: Bearer YOUR_API_KEY' + --header "Content-Type: multipart/form-data" \ + --form "disk=server" \ + --form "path=some/path/to/directory" \ + --form "overwrite=0" \ + --form "files=@/path/to/your/file1.txt" \ + --form "files=@/path/to/your/file2.jpg" + + - lang: 'PHP' + source: | + 'server', + 'path' => 'path/to/directory', + 'overwrite' => 0, + 'files' => $fileFields + ]; + + curl_setopt_array($curl, [ + CURLOPT_URL => $url, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $postFields, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => [ + 'Content-Type: multipart/form-data', + 'Authorization: Bearer ' . $apiKey, + ], + ]); + + $response = curl_exec($curl); + + // Check for errors + if (curl_errno($ch)) { + echo 'Error:' . curl_error($ch); + } else { + $responseData = json_decode($response, true); + print_r($responseData); + } + + curl_close($curl); + + - lang: 'GO' + source: | + package main + + import ( + "bytes" + "fmt" + "io" + "mime/multipart" + "net/http" + "os" + "path/filepath" + ) + + func main() { + // Replace with the actual URL endpoint + url := "https://demo.gameap.com/file-manager/1/upload" + apiKey := "YOUR_API_KEY" + + // Prepare the files to be uploaded + files := []string{"path/to/your/file1.txt", "path/to/your/file2.jpg"} + + // Create a buffer to write our multipart form + var requestBody bytes.Buffer + writer := multipart.NewWriter(&requestBody) + + // Add fields + writer.WriteField("disk", "server") + writer.WriteField("path", "some/path/to/directory") + writer.WriteField("overwrite", "0") + + // Add files + for _, filePath := range files { + file, err := os.Open(filePath) + if err != nil { + fmt.Println("Error opening file:", err) + return + } + defer file.Close() + + part, err := writer.CreateFormFile("files", filepath.Base(file.Name())) + if err != nil { + fmt.Println("Error creating form file:", err) + return + } + + _, err = io.Copy(part, file) + if err != nil { + fmt.Println("Error copying file:", err) + return + } + } + + // Close the writer to finalize the multipart form + writer.Close() + + // Create a new HTTP request + req, err := http.NewRequest("POST", url, &requestBody) + if err != nil { + fmt.Println("Error creating request:", err) + return + } + + req.Header.Add("Accept", "application/json") + req.Header.Set("Content-Type", writer.FormDataContentType()) + req.Header.Add("Authorization", "Bearer "+apiKey) + + + // Perform the request + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + fmt.Println("Error performing request:", err) + return + } + defer resp.Body.Close() + + // Read and print the response + respBody, err := io.ReadAll(resp.Body) + if err != nil { + fmt.Println("Error reading response:", err) + return + } + + fmt.Println("Response:", string(respBody)) + } + + - lang: "NodeJS" + source: | + const fs = require('fs'); + const request = require('request'); + + const url = 'https://demo.gameap.com/file-manager/1/upload'; + const apiKey = 'YOUR_API_KEY'; + + const formData = { + disk: 'server', + path: 'some/path/to/directory', + overwrite: '0', + files: [ + fs.createReadStream('/path/to/your/file1.txt'), + fs.createReadStream('/path/to/your/file2.jpg') + ] + }; + + request.post({ url: url, formData: formData }, function (err, httpResponse, body) { + if (err) { + return console.error('Upload failed:', err); + } + console.log('Upload successful! Server responded with:', body); + }); \ No newline at end of file diff --git a/docs/web-api/paths/servers_id_query.yaml b/docs/web-api/paths/servers_id_query.yaml index 3194bbe7..4d1781b7 100644 --- a/docs/web-api/paths/servers_id_query.yaml +++ b/docs/web-api/paths/servers_id_query.yaml @@ -96,10 +96,10 @@ get: package main import ( - "fmt" - "io" - "net/http" - "os" + "fmt" + "io" + "net/http" + "os" ) func main() {