Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Menghuan1918 committed Aug 14, 2024
1 parent 0a3b7c2 commit f710f41
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ title: Update Log
icon: wrench
---

## V0.2.5

### ✨ Feature Changes

- Added built-in upload tool: S3

### 🔧 Bug Fixes

- MD Document Image Uploader could not handle relative path images.

### 🚀 Others

- Introduced Ruff in GitHub Action for code checking and code formatting.

## V0.2.4

### ✨ Feature changes
Expand Down
14 changes: 14 additions & 0 deletions src/zh/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ title: 更新日志
icon: wrench
---

## V0.2.5

### ✨ 功能变动

- 新增内置上传工具:S3

### 🔧 BUG 修复

- MD 文档图片上传工具无法处理相对路径图片的问题

### 🚀 其他

- 在 GitHub Action 中引入 Ruff 进行代码检查以及代码格式化检查

## V0.2.4

### ✨ 功能变动
Expand Down
69 changes: 67 additions & 2 deletions src/zh/guide/Tools/Upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: 内置上传工具
icon: upload
---

此工具需要您使用 ==0.2.4== 或更高版本。

`pdfdeal`内置了一些常见的储存服务的上传工具,当然您也可以自行编写一个上传的函数--这也非常简单。
Expand All @@ -12,6 +13,7 @@ icon: upload

- [自定义函数](#自定义函数)
- [阿里 OSS](#阿里云-oss)
- [S3 对象储存](#s3)

## 自定义函数

Expand Down Expand Up @@ -41,19 +43,32 @@ def upload_file(local_file_path, remote_file_path):
return ("This is a test",True)
```

如果您有好的新文件上传实现,欢迎提交 PR!
如果您有好的新文件上传实现,欢迎[提交 PR!](#更多)

## 阿里云 OSS

请首先导入函数并使用您的阿里云 ACCESS_KEY 进行初始化。

```python
from pdfdeal.FileTools.Img.Ali_OSS import Ali_OSS
```

`Ali_OSS`函数需要以下参数进行初始化:

- OSS_ACCESS_KEY_ID:您的阿里云 ACCESS_KEY ID
- OSS_ACCESS_KEY_SECRET:您的阿里云 ACCESS_KEY SECRET
- Endpoint:您的 OSS 服务 Endpoint
- Bucket:您的 OSS Bucket 名称

> [!warning]
> 首先您需要安装包`oss2`进行使用:`pip install -U oss2`
>
> 请确保您的 OSS 已经将权限设置为公开可读
![确保公开可读](../../../images/ali_oss.png)

示例:

```python
from pdfdeal.FileTools.Img.Ali_OSS import Ali_OSS
from pdfdeal.file_tools import md_replace_imgs
Expand All @@ -79,6 +94,56 @@ md_replace_imgs(
# )
```

## S3

请首先导入函数并使用您的S3验证密匙进行初始化。

```python
from pdfdeal.FileTools.Img.S3 import S3
```

`S3`函数需要以下参数进行初始化:
- S3_ACCESS_KEY_ID:您的S3 ACCESS_KEY ID
- S3_ACCESS_KEY_SECRET:您的S3 ACCESS_KEY SECRET
- Endpoint:您的S3服务Endpoint
- Bucket:您的S3 Bucket名称
- Customized_Domain:您的S3自定义域名,注意`{Customized_Domain}/{remote_file_path}`将作为最终的图片地址返回。请不要忘记为自定义域名添加`http://``https://`前缀。

> [!warning]
> 首先您需要安装包`oss2`进行使用:`pip install -U boto3`
>
> 请确保您的 S3 已经将权限设置为公开可读
示例:

```python
from pdfdeal.FileTools.Img.S3 import S3
from pdfdeal.file_tools import md_replace_imgs

ossupload = S3(
S3_ACCESS_KEY_ID=os.environ.get("S3_ACCESS_KEY_ID"),
S3_ACCESS_KEY_SECRET=os.environ.get("S3_ACCESS_KEY_SECRET"),
Endpoint=os.environ.get("S3_Endpoint"),
Bucket=os.environ.get("S3_Bucket"),
Customized_Domain=os.environ.get("S3_Customized_Domain"),
)

md_replace_imgs(
mdfile="Output/1706.03762-2024-08-11 17-06-35.md",
replace=ossupload,
threads=5,
)

# 或者您希望替换指定路径中所有MD文档的图片为S3地址
# mds_replace_imgs(
# path="Output",
# replace=ossupload,
# threads=5,
# )
```

## 更多...

正在赶来的路上 🥳
正在赶来的路上~

如您想提交一个关于文件上传的 PR,请首先 fork[项目](https://github.com/Menghuan1918/pdfdeal),随后在项目的`src/pdfdeal/FileTools/Img`文件夹中新建`.py`文件,您可以仿照文件夹中其他上出实现完成您的上传操作,最后发起 PR🥳

0 comments on commit f710f41

Please sign in to comment.