diff --git a/pkg/mod/waifu_response.go b/pkg/mod/waifu_response.go index eb98d59..0e3fe34 100644 --- a/pkg/mod/waifu_response.go +++ b/pkg/mod/waifu_response.go @@ -2,12 +2,16 @@ package mod // WaifuResponse is the response from the api for files and uploads type WaifuResponse[T string | int] struct { + // Token for the uploaded file Token string `json:"token"` + // URL to the uploaded file URL string `json:"url"` - // Protected is if this file is protected-protected/encrypted - Protected bool `json:"protected"` + + // Options The options for this upload + Options WaifuResponseOptions `json:"options"` + // RetentionPeriod is a string or a number that represents // when the file will expire, if called with `format` true, then // this will be a string like "332 days 7 hours 18 minutes 8 seconds" diff --git a/pkg/mod/waifu_response_options.go b/pkg/mod/waifu_response_options.go new file mode 100644 index 0000000..90b7479 --- /dev/null +++ b/pkg/mod/waifu_response_options.go @@ -0,0 +1,12 @@ +package mod + +type WaifuResponseOptions struct { + // HideFilename If the filename is hidden + HideFilename bool `json:"hideFilename"` + + // OneTimeDownload If this file will be deleted when it is accessed + OneTimeDownload bool `json:"oneTimeDownload"` + + // Protected is if this file is protected-protected/encrypted + Protected bool `json:"protected"` +} diff --git a/pkg/mod/waifu_vault_put_opts.go b/pkg/mod/waifu_vault_put_opts.go index 6cf2e97..2ef7cc0 100644 --- a/pkg/mod/waifu_vault_put_opts.go +++ b/pkg/mod/waifu_vault_put_opts.go @@ -26,4 +26,7 @@ type WaifuvaultPutOpts struct { // The filename if `Bytes` is used FileName string + + // If this is true, then the file will be deleted as soon as it is accessed + OneTimeDownload bool `json:"oneTimeDownload"` } diff --git a/pkg/waifu_vault_api.go b/pkg/waifu_vault_api.go index 8c9b50f..7596cc0 100644 --- a/pkg/waifu_vault_api.go +++ b/pkg/waifu_vault_api.go @@ -70,9 +70,10 @@ func (re *api) UploadFile(ctx context.Context, options mod.WaifuvaultPutOpts) (* } uploadUrl := getUrl(map[string]any{ - "expires": options.Expires, - "hide_filename": options.HideFilename, - "password": options.Password, + "expires": options.Expires, + "hide_filename": options.HideFilename, + "password": options.Password, + "one_time_download": options.OneTimeDownload, }, "") r, err := re.createRequest(ctx, http.MethodPut, uploadUrl, &body, writer) diff --git a/readme.md b/readme.md index cdd2929..fbfac39 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# waifuvault-node-api +# waifuvault-go-api This contains the official API bindings for uploading, deleting and obtaining files with [waifuvault.moe](https://waifuvault.moe/). Contains a full up-to-date API for interacting with the service @@ -51,15 +51,16 @@ func main() { To Upload a file, use the `UploadFile` function. This function takes the following options as struct: -| Option | Type | Description | Required | Extra info | -|----------------|------------|---------------------------------------------------------------------------|------------------------------------------------|-----------------------------------------------------------------------------------| -| `File` | `*os.File` | The file to upload. This is an *os.File | true only if `Url` or `Bytes` is not supplied | If `Url` or `Bytes` is supplied, this prop can't be set | -| `Url` | `string` | The URL to a file that exists on the internet | true only if `File` or `Bytes` is not supplied | If `File` or `Bytes` is supplied, this prop can't be set | -| `Bytes` | `*[]byte` | The raw Bytes to of the file to upload. | true only if `File` or `Url` is not supplied | If `File` or `Url` is supplied, this prop can't be set and `FileName` MUST be set | -| `Expires` | `string` | A string containing a number and a unit (1d = 1day) | false | Valid units are `m`, `h` and `d` | -| `HideFilename` | `bool` | If true, then the uploaded filename won't appear in the URL | false | Defaults to `false` | -| `Password` | `string` | If set, then the uploaded file will be encrypted | false | | -| `FileName` | `string` | Only used if `Bytes` is set, this will be the filename used in the upload | true only if `Bytes` is set | | +| Option | Type | Description | Required | Extra info | +|-------------------|------------|---------------------------------------------------------------------------|------------------------------------------------|-----------------------------------------------------------------------------------| +| `File` | `*os.File` | The file to upload. This is an *os.File | true only if `Url` or `Bytes` is not supplied | If `Url` or `Bytes` is supplied, this prop can't be set | +| `Url` | `string` | The URL to a file that exists on the internet | true only if `File` or `Bytes` is not supplied | If `File` or `Bytes` is supplied, this prop can't be set | +| `Bytes` | `*[]byte` | The raw Bytes to of the file to upload. | true only if `File` or `Url` is not supplied | If `File` or `Url` is supplied, this prop can't be set and `FileName` MUST be set | +| `Expires` | `string` | A string containing a number and a unit (1d = 1day) | false | Valid units are `m`, `h` and `d` | +| `HideFilename` | `bool` | If true, then the uploaded filename won't appear in the URL | false | Defaults to `false` | +| `Password` | `string` | If set, then the uploaded file will be encrypted | false | | +| `FileName` | `string` | Only used if `Bytes` is set, this will be the filename used in the upload | true only if `Bytes` is set | | +| `OneTimeDownload` | `bool` | if supplied, the file will be deleted as soon as it is accessed | false | | Using a URL: