Skip to main content

nonebot-plugin-filehost

NoneBot2 的 HTTP 静态文件托管插件,为跨机文件传输提供解决方案

PyPI PyPI - Python Version

GitHub issues GitHub stars GitHub forks GitHub license


优势

  • 跨机器, 跨网络支持, 只要反向 WebSocket 可以正常连接, 它就可以使用
  • 使用临时文件作为中转, 内存占用低
    • 临时文件会尝试采用硬链接方式创建, 快速且可靠
    • 临时文件在程序退出时会自动删除, 不会永久占用空间
  • 自动检测访问来源生成资源 URL, 无需手动配置

开始使用

安装插件

请使用 NoneBot CLI 进行安装:

nb plugin install nonebot-plugin-filehost

进行配置

本插件支持以下配置项

  • FILEHOST_HOST_OVERRIDE:用于覆盖自动检测的访问来源, 例如 http://example.com:8080/, 在反向 WebSocket 连接 Host 和公网 Host 不一致时使用

  • FILEHOST_LINK_FILE:使用文件系统链接代替文件复制, 可以提升临时文件创建速度

    • 默认为True,同时支持bool和int类型
      • 当为bool时, 无条件启用链接
      • 当为int时, 当文件字节数大于或等于该数时启用链接, 低于时使用复制
  • FILEHOST_LINK_TYPE

    • 指定使用的链接类型, 有hard和soft两个可选值
      • hard: 建立硬链接
      • symbolic: 建立软链接
    • 默认为hard
  • FILEHOST_TMP_DIR:临时文件存放目录, 默认为操作系统的临时目录

在代码中使用

托管已有文件:

from pathlib import Path
from nonebot_plugin_filehost import FileHost

url = await FileHost(Path("/path/to/your/file")).to_url()

托管 bytes 或者 BytesIO:

from nonebot_plugin_filehost import FileHost

url = await FileHost(some_bytes).to_url()

使用同步代码:

url = FileHost().to_url_sync()

TODO

  • 支持自定义文件服务访问路径
  • 支持对 URL 进行读取,进行中转

开源许可

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.

本项目使用 MIT 开源许可证进行许可, 详细信息请参阅 LICENSE 文件。

Metadata

Release files for nonebot-plugin-filehost 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-plugin-filehost 1.1.1
File Size Uploaded
nonebot_plugin_filehost-1.1.1.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-filehost 1.1.1
File Interpreter ABI Platform
nonebot_plugin_filehost-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.5 kB

Release files / nonebot_plugin_filehost-1.1.1.tar.gz

Download URL nonebot_plugin_filehost-1.1.1.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
47d677a04321ccc57d4368cb447cc857b964d40b5e09fcdf4ec6a0ac7110b7c4
BLAKE2b-256 checksum
How to use checksums
c6929eec2789ca2b5fb4519acb476d056bd778a1bc4a3d7fc028ab719dc5d11e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.12.4 CPython/3.11.7

Release files / nonebot_plugin_filehost-1.1.1-py3-none-any.whl

Download URL nonebot_plugin_filehost-1.1.1-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e77a1eb6de1b15aad1f4fa05566fbf05e07822ffcfe3def11a48a84cbb17e022
BLAKE2b-256 checksum
How to use checksums
65d0ebdf825493bfcf2ca3cc79521e536034424503684a33d98e6cbf84dd9e5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.12.4 CPython/3.11.7

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page