fiuai-s3 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl
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.
Potentially problematic release.
This version of fiuai-s3 might be problematic. Click here for more details.
- fiuai_s3/__init__.py +3 -2
- fiuai_s3/minio/minio_storage.py +19 -3
- fiuai_s3/object_storage.py +8 -2
- fiuai_s3/type.py +13 -1
- {fiuai_s3-0.3.0.dist-info → fiuai_s3-0.3.2.dist-info}/METADATA +52 -2
- fiuai_s3-0.3.2.dist-info/RECORD +11 -0
- fiuai_s3-0.3.0.dist-info/RECORD +0 -11
- {fiuai_s3-0.3.0.dist-info → fiuai_s3-0.3.2.dist-info}/WHEEL +0 -0
- {fiuai_s3-0.3.0.dist-info → fiuai_s3-0.3.2.dist-info}/licenses/LICENSE +0 -0
fiuai_s3/__init__.py
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
# Copyright (c) 2025 FiuAI
|
|
7
7
|
|
|
8
8
|
from .object_storage import ObjectStorage, ObjectStorageFactory, StorageConfig
|
|
9
|
+
from .type import DocFileObject, DocSourceFrom, DocFileType
|
|
9
10
|
|
|
10
|
-
__version__ = "0.
|
|
11
|
-
__all__ = ["ObjectStorage", "ObjectStorageFactory", "StorageConfig"]
|
|
11
|
+
__version__ = "0.3.2"
|
|
12
|
+
__all__ = ["ObjectStorage", "ObjectStorageFactory", "StorageConfig", "DocFileObject", "DocSourceFrom", "DocFileType"]
|
fiuai_s3/minio/minio_storage.py
CHANGED
|
@@ -12,7 +12,7 @@ from minio import Minio
|
|
|
12
12
|
from minio.error import S3Error
|
|
13
13
|
from minio.commonconfig import Tags
|
|
14
14
|
from ..object_storage import ObjectStorage, StorageConfig
|
|
15
|
-
from ..type import DocFileObject, DocFileType
|
|
15
|
+
from ..type import DocFileObject, DocFileType, DocSourceFrom
|
|
16
16
|
|
|
17
17
|
logger = logging.getLogger(__name__)
|
|
18
18
|
|
|
@@ -163,14 +163,30 @@ class MinioStorage(ObjectStorage):
|
|
|
163
163
|
raise ValueError("auth_tenant_id、auth_company_id、doc_id 不能为空")
|
|
164
164
|
return f"{tenant_id}/{company_id}/{docid}/{filename}"
|
|
165
165
|
|
|
166
|
-
def upload_doc_file(self,
|
|
166
|
+
def upload_doc_file(self,
|
|
167
|
+
filename: str,
|
|
168
|
+
data: bytes,
|
|
169
|
+
doc_source_from: Optional[DocSourceFrom],
|
|
170
|
+
doc_file_type: Optional[DocFileType],
|
|
171
|
+
tags: Optional[Dict[str, str]] = None,
|
|
172
|
+
auth_tenant_id: Optional[str] = None,
|
|
173
|
+
auth_company_id: Optional[str] = None,
|
|
174
|
+
doc_id: Optional[str] = None) -> bool:
|
|
175
|
+
"""
|
|
176
|
+
上传单据文件,自动拼接存储路径并打tag
|
|
177
|
+
"""
|
|
167
178
|
try:
|
|
179
|
+
|
|
168
180
|
object_key = self._build_doc_path(filename, auth_tenant_id, auth_company_id, doc_id)
|
|
169
|
-
print(f"tags is {tags}")
|
|
170
181
|
# 将tags转换为Tags对象
|
|
171
182
|
tags_obj = Tags()
|
|
172
183
|
for k, v in tags.items():
|
|
173
184
|
tags_obj[k] = v
|
|
185
|
+
|
|
186
|
+
if doc_source_from:
|
|
187
|
+
tags_obj["doc_source_from"] = doc_source_from.value
|
|
188
|
+
if doc_file_type:
|
|
189
|
+
tags_obj["doc_file_type"] = doc_file_type.value
|
|
174
190
|
|
|
175
191
|
self.client.put_object(
|
|
176
192
|
bucket_name=self.bucket_name,
|
fiuai_s3/object_storage.py
CHANGED
|
@@ -10,7 +10,7 @@ from typing import Optional, List, Dict, Any
|
|
|
10
10
|
from pydantic import BaseModel, Field, ConfigDict
|
|
11
11
|
import logging
|
|
12
12
|
from uuid import uuid4
|
|
13
|
-
from .
|
|
13
|
+
from .type import DocFileObject, DocSourceFrom, DocFileType
|
|
14
14
|
|
|
15
15
|
logger = logging.getLogger(__name__)
|
|
16
16
|
|
|
@@ -97,7 +97,13 @@ class ObjectStorage(ABC):
|
|
|
97
97
|
pass
|
|
98
98
|
|
|
99
99
|
@abstractmethod
|
|
100
|
-
def upload_doc_file(self,
|
|
100
|
+
def upload_doc_file(self,
|
|
101
|
+
filename: str,
|
|
102
|
+
data: bytes,
|
|
103
|
+
doc_source_from: Optional[DocSourceFrom],
|
|
104
|
+
doc_file_type: Optional[DocFileType],
|
|
105
|
+
tags: Optional[Dict[str, str]] = None,
|
|
106
|
+
auth_tenant_id: Optional[str] = None, auth_company_id: Optional[str] = None, doc_id: Optional[str] = None) -> bool:
|
|
101
107
|
"""
|
|
102
108
|
上传单据文件,自动拼接存储路径并打tag
|
|
103
109
|
Args:
|
fiuai_s3/type.py
CHANGED
|
@@ -11,7 +11,7 @@ from typing import Optional, Dict
|
|
|
11
11
|
|
|
12
12
|
class DocFileType(Enum):
|
|
13
13
|
"""
|
|
14
|
-
|
|
14
|
+
文档文件类型, 避免某些场景不规范的文件名
|
|
15
15
|
"""
|
|
16
16
|
PDF = "pdf"
|
|
17
17
|
OFD = "ofd"
|
|
@@ -22,6 +22,18 @@ class DocFileType(Enum):
|
|
|
22
22
|
IMAGE = "image"
|
|
23
23
|
AUDIO = "audio"
|
|
24
24
|
ARCHIVE = "archive"
|
|
25
|
+
OTHER = "other"
|
|
26
|
+
|
|
27
|
+
class DocSourceFrom(Enum):
|
|
28
|
+
"""
|
|
29
|
+
文档来源, 避免某些场景同类文件混淆,比如有2个xml文件,一个用户上传,一个ai生成
|
|
30
|
+
"""
|
|
31
|
+
USER = "user"
|
|
32
|
+
AI = "ai"
|
|
33
|
+
INTEGRATION = "integration"
|
|
34
|
+
ETAX = "etax"
|
|
35
|
+
BANK = "bank"
|
|
36
|
+
OTHER = "other"
|
|
25
37
|
|
|
26
38
|
class DocFileObject(BaseModel):
|
|
27
39
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fiuai-s3
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: 一个支持阿里云OSS和MinIO的对象存储抽象包
|
|
5
5
|
Project-URL: Homepage, https://github.com/fiuai-sz/fiuai-s3
|
|
6
6
|
Project-URL: Repository, https://github.com/fiuai-sz/fiuai-s3.git
|
|
@@ -322,6 +322,52 @@ S3_Client.upload_doc_file(
|
|
|
322
322
|
)
|
|
323
323
|
```
|
|
324
324
|
|
|
325
|
+
为了规范文件, 文档类型的文件上传请按规范进行打标
|
|
326
|
+
```python
|
|
327
|
+
class DocFileType(Enum):
|
|
328
|
+
"""
|
|
329
|
+
文档文件类型, 避免某些场景不规范的文件名
|
|
330
|
+
"""
|
|
331
|
+
PDF = "pdf"
|
|
332
|
+
OFD = "ofd"
|
|
333
|
+
XML = "xml"
|
|
334
|
+
DOCTYPE = "doctype"
|
|
335
|
+
TABLE = "table"
|
|
336
|
+
TEXT = "text"
|
|
337
|
+
IMAGE = "image"
|
|
338
|
+
AUDIO = "audio"
|
|
339
|
+
ARCHIVE = "archive"
|
|
340
|
+
OTHER = "other"
|
|
341
|
+
```
|
|
342
|
+
```python
|
|
343
|
+
class DocSourceFrom(Enum):
|
|
344
|
+
"""
|
|
345
|
+
文档来源, 避免某些场景同类文件混淆,比如有2个xml文件,一个用户上传,一个ai生成
|
|
346
|
+
"""
|
|
347
|
+
USER = "user"
|
|
348
|
+
AI = "ai"
|
|
349
|
+
INTEGRATION = "integration"
|
|
350
|
+
ETAX = "etax"
|
|
351
|
+
BANK = "bank"
|
|
352
|
+
OTHER = "other"
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
上传时标注
|
|
356
|
+
```python
|
|
357
|
+
c = ObjectStorageFactory.get_instance()
|
|
358
|
+
c.upload_doc_file(
|
|
359
|
+
filename="test.txt",
|
|
360
|
+
data=b"test",
|
|
361
|
+
doc_source_from=DocSourceFrom.USER,
|
|
362
|
+
doc_file_type=DocFileType.XML,
|
|
363
|
+
tags={"name": "hilton", "age": "10"},
|
|
364
|
+
auth_tenant_id="t1",
|
|
365
|
+
auth_company_id="c1",
|
|
366
|
+
doc_id="id111",
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
|
|
325
371
|
#### 下载单据文件
|
|
326
372
|
```python
|
|
327
373
|
data = S3_Client.download_doc_file(
|
|
@@ -376,4 +422,8 @@ MIT License
|
|
|
376
422
|
|
|
377
423
|
## 贡献
|
|
378
424
|
|
|
379
|
-
欢迎提交 Issue 和 Pull Request!
|
|
425
|
+
欢迎提交 Issue 和 Pull Request!
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
# 发布
|
|
429
|
+
uv publish --username __token__ --password your-pypi-token-here
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
fiuai_s3/__init__.py,sha256=PhRotxS_rfqOgdDkci63ToVqhtDi4uSC3-3aJTNebWo,421
|
|
2
|
+
fiuai_s3/object_storage.py,sha256=idhKF4BFoP_ZPHY3PzlzHxVecrv1EnnBYyJ3QjGHiDE,8812
|
|
3
|
+
fiuai_s3/type.py,sha256=-UBL0gVyMDC-4WRKNKyAupAE7s04TCOiFbM-YQPxh_Y,945
|
|
4
|
+
fiuai_s3/alicloud/__init__.py,sha256=mmrCrFp5DzRF5fViJDq7_LpsqCViwTPXOPz4qoaSscI,218
|
|
5
|
+
fiuai_s3/alicloud/alicloud_storage.py,sha256=d24AFYDs7RsTsfL9IiVOxYlGyLzsaUa_WUYD5VPLP4s,6035
|
|
6
|
+
fiuai_s3/minio/__init__.py,sha256=hOmpUkTq8TPgYOxfeOMcWq1_YsJ2r8Zf9VTX3w_v1Lk,209
|
|
7
|
+
fiuai_s3/minio/minio_storage.py,sha256=xsEt70WEo5X7RRLjIno4uXsoGbuATvwtv_wnQ2QSFBY,9021
|
|
8
|
+
fiuai_s3-0.3.2.dist-info/METADATA,sha256=ltEia0FzulOArPzwYgy2_d4CfsM0_eCD2hM9W02HiRA,18727
|
|
9
|
+
fiuai_s3-0.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
fiuai_s3-0.3.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
11
|
+
fiuai_s3-0.3.2.dist-info/RECORD,,
|
fiuai_s3-0.3.0.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
fiuai_s3/__init__.py,sha256=SZNl4Ohwf19PLyjRjIASpzhg3rvutd1WbLpblz_8G3s,312
|
|
2
|
-
fiuai_s3/object_storage.py,sha256=K_g2i3ohbT3BIJW-ZB5IbwYHtPuQMF4ZTwEoKR3WKr4,8561
|
|
3
|
-
fiuai_s3/type.py,sha256=3LdjA9wO9IKKfKONLuI0SQ9FVSablhDnRphJqpDosRQ,608
|
|
4
|
-
fiuai_s3/alicloud/__init__.py,sha256=mmrCrFp5DzRF5fViJDq7_LpsqCViwTPXOPz4qoaSscI,218
|
|
5
|
-
fiuai_s3/alicloud/alicloud_storage.py,sha256=d24AFYDs7RsTsfL9IiVOxYlGyLzsaUa_WUYD5VPLP4s,6035
|
|
6
|
-
fiuai_s3/minio/__init__.py,sha256=hOmpUkTq8TPgYOxfeOMcWq1_YsJ2r8Zf9VTX3w_v1Lk,209
|
|
7
|
-
fiuai_s3/minio/minio_storage.py,sha256=SU743Nr7w8HMran-xkccEoeecSNKYySVNCGjo462-Lk,8476
|
|
8
|
-
fiuai_s3-0.3.0.dist-info/METADATA,sha256=WEEnAxbTp6ogOVIE8r41u7WwwYcAZ3KcEW0iq4FDUr4,17609
|
|
9
|
-
fiuai_s3-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
-
fiuai_s3-0.3.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
11
|
-
fiuai_s3-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|