Giter VIP home page Giter VIP logo

plugin-filehost's Introduction

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 文件。

plugin-filehost's People

Contributors

mnixry avatar starhearthunt avatar yanyongyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

bakashigure

plugin-filehost's Issues

如何使用此插件呢

根据文档所述,我应该不需要进行任何操作,在shamrock下发送语音和图片都会遇到以下类似报错,而且确定插件正常加载无报错
Screenshot_20240102_133652_com.wujie.connect.jpg

载入时遇到错误

有可能是我没用nb install造成的,死活找不到包(换源也一样),我就直接下载压缩包解压后丢进bot的src/plugin下直接加载的,有没有办法解决呢qwq
Screenshot_20231211_232426.jpg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.