Skip to content

Commit

Permalink
Merge pull request #11 from waifuvault/support-new-feature
Browse files Browse the repository at this point in the history
support new feature and structure
VictoriqueMoe authored Apr 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents cfd3bdb + dbe3892 commit df6f7e9
Showing 5 changed files with 36 additions and 15 deletions.
8 changes: 6 additions & 2 deletions pkg/mod/waifu_response.go
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 12 additions & 0 deletions pkg/mod/waifu_response_options.go
Original file line number Diff line number Diff line change
@@ -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"`
}
3 changes: 3 additions & 0 deletions pkg/mod/waifu_vault_put_opts.go
Original file line number Diff line number Diff line change
@@ -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"`
}
7 changes: 4 additions & 3 deletions pkg/waifu_vault_api.go
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 11 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit df6f7e9

Please sign in to comment.