Skip to main content

Effortless static file hosting plugin for NoneBot2.

Project description

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,同时支持boolint类型
      • 当为bool时, 无条件启用链接
      • 当为int时, 当文件字节数大于或等于该数时启用链接, 低于时使用复制
  • FILEHOST_LINK_TYPE

    • 指定使用的链接类型, 有hardsoft两个可选值
      • 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 文件。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_filehost-1.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

nonebot_plugin_filehost-1.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_plugin_filehost-1.1.1.tar.gz.

File metadata

File hashes

Hashes for nonebot_plugin_filehost-1.1.1.tar.gz
Algorithm Hash digest
SHA256 47d677a04321ccc57d4368cb447cc857b964d40b5e09fcdf4ec6a0ac7110b7c4
MD5 2b1e1176e852b2da67d07c7975235535
BLAKE2b-256 c6929eec2789ca2b5fb4519acb476d056bd778a1bc4a3d7fc028ab719dc5d11e

See more details on using hashes here.

File details

Details for the file nonebot_plugin_filehost-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nonebot_plugin_filehost-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e77a1eb6de1b15aad1f4fa05566fbf05e07822ffcfe3def11a48a84cbb17e022
MD5 6ff068ef9d6449a871ff88274ee0238f
BLAKE2b-256 65d0ebdf825493bfcf2ca3cc79521e536034424503684a33d98e6cbf84dd9e5c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page