fshstorage 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 maxeepy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: fshstorage
3
+ Version: 1.0.0
4
+ Summary: FshStorage API Wrapper written in Python
5
+ Author: maxie
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://codeberg.org/maxeepy/fshstorage-wrapper
8
+ Project-URL: Issues, https://codeberg.org/maxeepy/fshstorage-wrapper/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: requests>=2.30
20
+ Requires-Dist: fshlink
21
+ Dynamic: license-file
22
+
23
+ # fshstorage
24
+
25
+ ## Examples
26
+
27
+ ### Logging in and getting a list of files
28
+
29
+ ```py
30
+ from fshstorage import FshStorageWrapper
31
+
32
+ fsh = FshStorageWrapper("token")
33
+ print(fsh.list_files()) # Returns a dictionary of file_name: FshStoragePartailFile's
34
+
35
+ ```
36
+
37
+ ### Downloading a file
38
+
39
+ ```py
40
+ file1 = api.download_file("name.png")
41
+ print(file1) # Returns a FshStorageFile
42
+
43
+ # ------
44
+
45
+ list_of_files = api.files()
46
+
47
+ file2 = list_of_files["name.png"]
48
+ print(list_of_files["name.png"]) # Returns a FshStoragePartialFile
49
+
50
+ file2 = file2.download()
51
+ print(file2) # Returns a FshFile
52
+ ```
53
+
54
+ ### Sharing a file
55
+
56
+ ```py
57
+ file1.share() # Returns a https://link.fsh.plus/... (FshShortenedLink object)
58
+ api.share_file("name.png") # Returns a https://link.fsh.plus/... (FshShortenedLink object)
59
+ ```
60
+
61
+ ### Saving a file
62
+
63
+ ```py
64
+ file1.save() # Defaults to the name attribute in file1 (will download to your current working directory)
65
+ file2.save("name.png") # Saves the file to the specified path/name
66
+ ```
67
+
68
+ ### Deleting a file
69
+
70
+ ```py
71
+ api.delete_file("name.png")
72
+ ```
73
+
74
+ ### Renaming a file
75
+
76
+ ```py
77
+ api.rename_file("name.png", "waaaaaa.png")
78
+ ```
@@ -0,0 +1,56 @@
1
+ # fshstorage
2
+
3
+ ## Examples
4
+
5
+ ### Logging in and getting a list of files
6
+
7
+ ```py
8
+ from fshstorage import FshStorageWrapper
9
+
10
+ fsh = FshStorageWrapper("token")
11
+ print(fsh.list_files()) # Returns a dictionary of file_name: FshStoragePartailFile's
12
+
13
+ ```
14
+
15
+ ### Downloading a file
16
+
17
+ ```py
18
+ file1 = api.download_file("name.png")
19
+ print(file1) # Returns a FshStorageFile
20
+
21
+ # ------
22
+
23
+ list_of_files = api.files()
24
+
25
+ file2 = list_of_files["name.png"]
26
+ print(list_of_files["name.png"]) # Returns a FshStoragePartialFile
27
+
28
+ file2 = file2.download()
29
+ print(file2) # Returns a FshFile
30
+ ```
31
+
32
+ ### Sharing a file
33
+
34
+ ```py
35
+ file1.share() # Returns a https://link.fsh.plus/... (FshShortenedLink object)
36
+ api.share_file("name.png") # Returns a https://link.fsh.plus/... (FshShortenedLink object)
37
+ ```
38
+
39
+ ### Saving a file
40
+
41
+ ```py
42
+ file1.save() # Defaults to the name attribute in file1 (will download to your current working directory)
43
+ file2.save("name.png") # Saves the file to the specified path/name
44
+ ```
45
+
46
+ ### Deleting a file
47
+
48
+ ```py
49
+ api.delete_file("name.png")
50
+ ```
51
+
52
+ ### Renaming a file
53
+
54
+ ```py
55
+ api.rename_file("name.png", "waaaaaa.png")
56
+ ```
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 77.0.3", "requests >= 2.30", "fshlink"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "fshstorage"
7
+ authors = [
8
+ { name = "maxie" }
9
+ ]
10
+ description = "FshStorage API Wrapper written in Python"
11
+ readme = "README.md"
12
+ requires-python = ">=3.10"
13
+ dependencies = [
14
+ "requests >= 2.30",
15
+ "fshlink"
16
+ ]
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Operating System :: OS Independent"
25
+ ]
26
+ license = "MIT"
27
+ license-files = ["LICEN[CS]E*"]
28
+ dynamic = ["version"]
29
+
30
+ [project.urls]
31
+ Homepage = "https://codeberg.org/maxeepy/fshstorage-wrapper"
32
+ Issues = "https://codeberg.org/maxeepy/fshstorage-wrapper/issues"
33
+
34
+ [tool.setuptools.dynamic]
35
+ version = { attr = "fshstorage.__version__" }
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .fshstorage import *
2
+
3
+ __version__ = "1.0.0"
@@ -0,0 +1,3 @@
1
+ KB = 1024 * 1024
2
+ MB = 1024 * KB
3
+ CHUNK_SIZE = 2 * MB
@@ -0,0 +1,148 @@
1
+ import requests
2
+ from fshlink import FshShortenedLink
3
+ from .constants import CHUNK_SIZE, MB, KB
4
+ from contextlib import ExitStack
5
+ from mimetypes import guess_type
6
+ from pathlib import Path
7
+ from io import IOBase, BytesIO
8
+ from typing import Union
9
+
10
+ class FileSize:
11
+ def __init__(self, size: int):
12
+ self.raw = size
13
+ self.human = self.raw / KB
14
+ self.limit = 10 * MB
15
+ self.human_limit = 10
16
+
17
+ def __str__(self):
18
+ return f"{round(self.human, 2)}MB/{self.human_limit}MB"
19
+
20
+ def __repr__(self):
21
+ raw = self.raw
22
+ human = self.human
23
+ limit = self.limit
24
+ return f"FileSize({raw=}, {human=}, {limit=})"
25
+
26
+ class FshStoragePartialFile:
27
+ def __init__(self, name: str, type: str, size: int, message: str, chunkSize: int, _base_url: str, _session: requests.Session):
28
+ self.name = name
29
+ self.mimetype = type
30
+ self.size = FileSize(size)
31
+ self.message_id = message
32
+ self._chunk_size = chunkSize
33
+ self._base_url = _base_url
34
+ self._session = _session
35
+
36
+ def download(self) -> "FshStorageFile":
37
+ url = f"{self._base_url}/download"
38
+ response = self._session.get(url, params = {"m": self.message_id})
39
+ if not response.ok:
40
+ raise Exception(response.status_code)
41
+ chunks = []
42
+ for chunk in response.iter_content(CHUNK_SIZE):
43
+ chunks.append(chunk)
44
+ return FshStorageFile(b"".join(chunks), self.name, self.mimetype, self.size)
45
+
46
+ def share(self) -> FshShortenedLink:
47
+ url = f"{self._base_url}/share"
48
+ response = self._session.post(url, params = {"m": self.message_id})
49
+ return FshShortenedLink(response.json()["link"])
50
+
51
+ def __str__(self):
52
+ return f"{self._base_url}/download?m={self.message_id}"
53
+
54
+ def __repr__(self):
55
+ name = self.name
56
+ mimetype = self.mimetype
57
+ size = self.size
58
+ message = self.message_id
59
+ return f"FshStoragePartialFile({name=}, {mimetype=}, {size=}, {message=})"
60
+
61
+ class FshStorageFile(BytesIO):
62
+ def __init__(self, file: Union[IOBase, str, bytes], name: str, type: str = None, size: Union[int, FileSize] = None):
63
+ super().__init__(file)
64
+ self.name = name
65
+ self.mimetype = type
66
+ if type is None:
67
+ self.mimetype = guess_type(self.name)[0] or "application/octet-stream"
68
+
69
+ self.size = size if isinstance(size, FileSize) else FileSize(size)
70
+
71
+ def save(self, path: Union[str, Path]) -> None:
72
+ with open(path, "wb") as f:
73
+ f.write(self.read())
74
+
75
+ def __str__(self):
76
+ return self.name
77
+
78
+ def __repr__(self):
79
+ name = self.name
80
+ mimetype = self.mimetype
81
+ size = self.size
82
+ return f"FshStorageFile({name=}, {mimetype=}, {size=})"
83
+
84
+ def __del__(self):
85
+ self.close()
86
+
87
+ class FshStorageDictionary(dict):
88
+ def __init__(self, data, _session: requests.Session, _base_url: str = "https://storage.fsh.plus"):
89
+ super().__init__({item["name"]: FshStoragePartialFile(**item, _base_url=_base_url, _session=_session) for item in data})
90
+
91
+ class FshStorageWrapper:
92
+ def __init__(self, fsh_storage_token: str, *, base_url: str = "https://storage.fsh.plus"):
93
+ self.token = fsh_storage_token
94
+ self._session = requests.Session()
95
+ self._session.headers = {"Cookie": f"FshAccountToken={self.token}"}
96
+ self.base_url = base_url
97
+ self._base_url = base_url + "/api"
98
+ self.file_list = self.list_files()
99
+
100
+ def list_files(self) -> FshStorageDictionary:
101
+ url = f"{self._base_url}/files"
102
+ response = self._session.get(url)
103
+ return FshStorageDictionary(response.json(), _session = self._session, _base_url = self._base_url)
104
+
105
+ def upload_file(self, name: str, file: Union[str, FshStorageFile]) -> requests.Response:
106
+ stack = ExitStack()
107
+ file_mime = None
108
+ if isinstance(file, str):
109
+ file = Path(file)
110
+ file_mime = guess_type(file.name)[0]
111
+ elif isinstance(file, FshStorageFile):
112
+ file_mime = file.mimetype
113
+ else:
114
+ raise ValueError("file is not str or FshStorageFile")
115
+
116
+ url = f"{self._base_url}/upload"
117
+ response = self._session.post(url, params = {"name": name if name not in self.file_list else f"New {name}", "type": file_mime}, data = file if not isinstance(file, Path) else stack.enter_context(file.open("rb")), headers = {"Content-Type": "application/octet-stream"})
118
+ self.file_list = self.list_files()
119
+ return response
120
+
121
+ def overwrite_file(self, name: str, file: IOBase) -> requests.Response:
122
+ self.delete_file(name)
123
+ return self.upload_file(name, file)
124
+
125
+ def rename_file(self, name: str, new_name: str) -> requests.Response:
126
+ url = f"{self._base_url}/rename"
127
+ response = self._session.post(url, params = {"m": self.file_list[name].message_id, "name": new_name})
128
+ self.file_list = self.list_files()
129
+ return response
130
+
131
+ def share_file(self, name: str) -> FshShortenedLink:
132
+ return self.file_list[name].share()
133
+
134
+ def download_file(self, name: str) -> FshStorageFile:
135
+ return self.file_list[name].download()
136
+
137
+ def delete_file(self, name: str):
138
+ url = f"{self._base_url}/delete"
139
+ response = self._session.post(url, params = {"m": self.file_list[name].message_id})
140
+ self.file_list = self.list_files()
141
+ return response
142
+
143
+ def __str__(self):
144
+ base_url = self.base_url
145
+ return f"FshStorageWrapper(token=..., {base_url=})"
146
+
147
+ def __repr__(self):
148
+ return self.__str__()
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: fshstorage
3
+ Version: 1.0.0
4
+ Summary: FshStorage API Wrapper written in Python
5
+ Author: maxie
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://codeberg.org/maxeepy/fshstorage-wrapper
8
+ Project-URL: Issues, https://codeberg.org/maxeepy/fshstorage-wrapper/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: requests>=2.30
20
+ Requires-Dist: fshlink
21
+ Dynamic: license-file
22
+
23
+ # fshstorage
24
+
25
+ ## Examples
26
+
27
+ ### Logging in and getting a list of files
28
+
29
+ ```py
30
+ from fshstorage import FshStorageWrapper
31
+
32
+ fsh = FshStorageWrapper("token")
33
+ print(fsh.list_files()) # Returns a dictionary of file_name: FshStoragePartailFile's
34
+
35
+ ```
36
+
37
+ ### Downloading a file
38
+
39
+ ```py
40
+ file1 = api.download_file("name.png")
41
+ print(file1) # Returns a FshStorageFile
42
+
43
+ # ------
44
+
45
+ list_of_files = api.files()
46
+
47
+ file2 = list_of_files["name.png"]
48
+ print(list_of_files["name.png"]) # Returns a FshStoragePartialFile
49
+
50
+ file2 = file2.download()
51
+ print(file2) # Returns a FshFile
52
+ ```
53
+
54
+ ### Sharing a file
55
+
56
+ ```py
57
+ file1.share() # Returns a https://link.fsh.plus/... (FshShortenedLink object)
58
+ api.share_file("name.png") # Returns a https://link.fsh.plus/... (FshShortenedLink object)
59
+ ```
60
+
61
+ ### Saving a file
62
+
63
+ ```py
64
+ file1.save() # Defaults to the name attribute in file1 (will download to your current working directory)
65
+ file2.save("name.png") # Saves the file to the specified path/name
66
+ ```
67
+
68
+ ### Deleting a file
69
+
70
+ ```py
71
+ api.delete_file("name.png")
72
+ ```
73
+
74
+ ### Renaming a file
75
+
76
+ ```py
77
+ api.rename_file("name.png", "waaaaaa.png")
78
+ ```
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/fshstorage/__init__.py
5
+ src/fshstorage/constants.py
6
+ src/fshstorage/fshstorage.py
7
+ src/fshstorage.egg-info/PKG-INFO
8
+ src/fshstorage.egg-info/SOURCES.txt
9
+ src/fshstorage.egg-info/dependency_links.txt
10
+ src/fshstorage.egg-info/requires.txt
11
+ src/fshstorage.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ requests>=2.30
2
+ fshlink
@@ -0,0 +1 @@
1
+ fshstorage