From f37b8626257e49dd6cddc6e39cf83f0a820dce85 Mon Sep 17 00:00:00 2001 From: Walker Aldridge Date: Tue, 20 Aug 2024 08:09:22 -0500 Subject: [PATCH] Update bucket api paths, remove wild anys in models, fix readme --- README.md | 4 ++-- pyproject.toml | 2 +- src/waifuvault/waifumodels.py | 18 +++++++++--------- src/waifuvault/waifuvault.py | 4 ++-- tests/test_waifuvault.py | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 11b3c55..9d19995 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ To Upload a file, use the `upload_file` function. This function takes the follow |-------------------|--------------------|-----------------------------------------------------------------|----------------|----------------------------------| | `target` | `string or buffer` | The target to upload can be a buffer, URL or filename | true | URL or file path | | `target_name` | `string` | The filename of the target if it is a buffer | true if buffer | Filename with extension | -| `bucket_token` | 'string' | Token for a bucket to upload the file into | false | Create bucket gives token | +| `bucket_token` | `string` | Token for a bucket to upload the file into | false | Create bucket gives token | | `expires` | `string` | A string containing a number and a unit (1d = 1day) | false | Valid units are `m`, `h` and `d` | | `hideFilename` | `boolean` | 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 | | @@ -206,7 +206,7 @@ Deleting a bucket will delete the bucket and all the files it contains. > **IMPORTANT:** All contained files will be **DELETED** along with the Bucket! -To delete a bucket, you must call the `deleteBucket` function with the following options as parameters: +To delete a bucket, you must call the `delete_bucket` function with the following options as parameters: | Option | Type | Description | Required | Extra info | |-------------|-----------|-----------------------------------|----------|-------------------| diff --git a/pyproject.toml b/pyproject.toml index 0d4809f..4af930a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "waifuvault" -version = "1.4.2" +version = "1.4.3" authors = [ { name="Walker Aldridge", email="walker@waifuvault.moe" }, ] diff --git a/src/waifuvault/waifumodels.py b/src/waifuvault/waifumodels.py index 84e5e9b..5dd23ff 100644 --- a/src/waifuvault/waifumodels.py +++ b/src/waifuvault/waifumodels.py @@ -31,8 +31,15 @@ def build_parameters(self): return parameters +class FileOptions: + def __init__(self, hide_filename: bool = False, one_time_download: bool = False, protected: bool = False): + self.hideFilename = hide_filename + self.oneTimeDownload = one_time_download + self.protected = protected + + class FileResponse: - def __init__(self, token: str = None, url: str = None, retention_period: any = None, bucket: str = None, options: any = None): + def __init__(self, token: str = None, url: str = None, retention_period: any = None, bucket: str = None, options: FileOptions = None): self.token = token self.url = url self.retentionPeriod = retention_period @@ -40,14 +47,7 @@ def __init__(self, token: str = None, url: str = None, retention_period: any = N self.options = options -class FileOptions: - def __init__(self, hide_filename: bool = False, one_time_download: bool = False, protected: bool = False): - self.hideFilename = hide_filename - self.oneTimeDownload = one_time_download - self.protected = protected - - class BucketResponse: - def __init__(self, token: str = None, files: any = None): + def __init__(self, token: str = None, files: list[FileResponse] = None): self.token = token self.files = files diff --git a/src/waifuvault/waifuvault.py b/src/waifuvault/waifuvault.py index 2c93578..86e2dee 100644 --- a/src/waifuvault/waifuvault.py +++ b/src/waifuvault/waifuvault.py @@ -12,7 +12,7 @@ # Create Bucket def create_bucket(): - url = f"{__base_url__}/bucket/createBucket" + url = f"{__base_url__}/bucket/create" response = requests.get(url) __check_error(response, False) return __bucket_to_obj(json.loads(response.text)) @@ -28,7 +28,7 @@ def delete_bucket(token: str): # Get Bucket def get_bucket(token: str): - url = f"{__base_url__}/bucket" + url = f"{__base_url__}/bucket/get" data = {"bucket_token": token} response = requests.post(url, json=data) __check_error(response, False) diff --git a/tests/test_waifuvault.py b/tests/test_waifuvault.py index e33f4b3..0e469c9 100644 --- a/tests/test_waifuvault.py +++ b/tests/test_waifuvault.py @@ -245,7 +245,7 @@ def test_create_bucket(mocker): bucket = waifuvault.create_bucket() # Then - mock_create.assert_called_once_with('https://waifuvault.moe/rest/bucket/createBucket') + mock_create.assert_called_once_with('https://waifuvault.moe/rest/bucket/create') assert (bucket.token == "test-bucket"), "Create Bucket did not return bucket" @@ -259,7 +259,7 @@ def test_get_bucket(mocker): bucket = waifuvault.get_bucket("test-bucket") # Then - mock_get.assert_called_once_with('https://waifuvault.moe/rest/bucket', json={'bucket_token': 'test-bucket'}) + mock_get.assert_called_once_with('https://waifuvault.moe/rest/bucket/get', json={'bucket_token': 'test-bucket'}) assert (bucket.token == "test-bucket"), "Get Bucket did not return bucket"