diff --git a/package.json b/package.json index ff3a8f7..3372bbf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dathost", - "version": "0.0.8", + "version": "0.0.9", "description": "TypeScript wrapper for Dathost's API", "main": "src/index.ts", "files": [ diff --git a/src/http.ts b/src/http.ts index 2c7579f..36849ac 100644 --- a/src/http.ts +++ b/src/http.ts @@ -28,24 +28,21 @@ export default class HTTP { ) } - public async get(url: string, raw = false): Promise { - if (raw) { - return await this.request.get(url, { responseType: 'blob' }) - } - return await this.request.get(url) + public async get(url: string, config: AxiosRequestConfig = {}): Promise { + return await this.request.get(url, config) } - public async delete(url: string): Promise { - return await this.request.delete(url) + public async delete(url: string, config: AxiosRequestConfig = {}): Promise { + return await this.request.delete(url, config) } - public async post(url: string, data?: URLSearchParams | FormData): Promise { + public async post(url: string, data?: URLSearchParams | FormData, config: AxiosRequestConfig = {}): Promise { if (data instanceof FormData) - return await this.request.post(url, data, {headers: {'Content-Type': 'multipart/form-data'}}) - return await this.request.post(url, data) + return await this.request.post(url, data, {headers: {'Content-Type': 'multipart/form-data'}, ...config}) + return await this.request.post(url, data, config) } - public async put(url: string, data: URLSearchParams): Promise { - return await this.request.put(url, data) + public async put(url: string, data: URLSearchParams, config: AxiosRequestConfig = {}): Promise { + return await this.request.put(url, data, config) } } diff --git a/src/server/file.ts b/src/server/file.ts index 2490f4a..d4c02cc 100644 --- a/src/server/file.ts +++ b/src/server/file.ts @@ -1,3 +1,5 @@ +import { AxiosRequestConfig } from 'axios' + import HTTP from '../http' import FormData from '../helpers/formData' @@ -36,13 +38,17 @@ export default class File { await this.http.put(this.url, payload) } - public async download(asText = false): Promise { - return await this.http.get(`${this.url}?as_text=${asText.toString()}`, !asText) + public async download(asText = false, config: AxiosRequestConfig = {}): Promise { + if (!asText) { + config.responseType = 'blob' + } + + return await this.http.get(`${this.url}?as_text=${asText.toString()}`, config) } - public async upload(data: Blob): Promise { + public async upload(data: Blob, config: AxiosRequestConfig = {}): Promise { const payload = new FormData() payload.append('file', data) - await this.http.post(`https://upload.dathost.net/api/0.1/game-servers/${this.serverId}/files/${this.path}`, payload) + await this.http.post(`https://upload.dathost.net/api/0.1/game-servers/${this.serverId}/files/${this.path}`, payload, config) } }