360 Secure SkillHub
360 安全技能中心

filebed-delivery

将本地文件上传到自建 filebed 服务并返回公开下载链接,支持密码、有效期与访问次数限制,也可查询、撤销链接。依赖本地服务、密钥和反向代理;文档对优先发送附件还是链接存在矛盾。

分类:自动化
sunshinejnjn
sunshinejnjn
热度 1.36
最近更新 2026-10-28 05:42:27

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add sunshinejnjn/filebed-delivery
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
name
filebed-delivery
version
1.0.1
description
Deliver files to the user by uploading them to the local filebed service and returning a public download URL. Use whenever the user wants to hand a file over via a link instead of sending the file as a Telegram/WhatsApp attachment (attachments keep failing on those platforms). The agent runs the bundled script `filebed.py add <path>` — all server interaction (reading the bearer secret, auth, timeouts, error decoding) happens inside the script, which prints one JSON object; on success send the `url` field to the user.
id
filebed-delivery
tags
["filebed","delivery","telegram","whatsapp"]

Filebed Delivery

Send a file to a user through a link instead of a raw attachment.

Why: Telegram and WhatsApp attachments frequently fail (size limits, proxy drops, "file is about to expire", media-type rejections). Uploading to the local filebed service and handing the user a URL is far more reliable and the URL can be password protected / self-destruct / expire.

The local service is a Flask app bound to 0.0.0.0:23284 on the host. X-Forwarded-* from the host nginx makes the public URL https://filebed.dupetrc.qiyi.us:31585/v/<token>.

When to use

  • The user said "send me this file" / "give me a link to X" / "it won't send".
  • A file is large or a type a media proxy rejected (image / audio / video / archive / doc).
  • You already have a local path and want to hand the user a shareable URL.

Trust / scope rules

  • This is an INTERNAL, trusted action (reading/writing local files, calling a localhost API). Do this without asking permission.
  • NEVER send the bearer secret anywhere. The secret is the server's authentication token, not something the user needs and not a link content. The script reads it itself — never print, paste, or cat the secret file.
  • Treat the returned URL as public: anyone with the link can download unless the file is password-protected. When the file is sensitive, use --password.
  • Do not upload paths the user did not give you.

How to use (the script does everything)

Call the bundled script (filebed.py, next to this SKILL.md) and read the JSON it prints. Do not curl the API yourself and do not read the secret file — the script owns all of that. All of the client's settings — the API base, the secret source path, the bearer token, the default link ttl/limits, and timeouts — are loaded automatically from filebed-config.json (next to this SKILL.md). The agent never needs to set any env var; just call the script and read the returned JSON.

python3 filebed.py add <absolute-path>

Optional flags:

flag meaning default
--ttl-days N link validity in days (sliding: resets on each access) 100
--max-accesses N self-destruct after N downloads -1 = never
--password P require this password to download none
--expires-seconds N absolute expiry, seconds (ignored if --ttl-days set) -

Policy defaults: 100-day link, no self-destruct. Pass --password for sensitive content; pass --max-accesses 1 for a one-time link.

The script prints exactly one JSON object on stdout:

Success ("ok": true, exit code 0) — take the url, that is all the user needs:

{
  "ok": true,
  "status": "created",
  "token": "Q68ODU…aHTO",
  "size": 40,
  "size_human": "40 bytes",
  "ttl_days": 100.0,
  "max_accesses": -1,
  "direct_send_recommended": true,
  "url": "https://filebed.dupetrc.qiyi.us:31585/v/Q68ODU…aHTO"
}

size is the raw byte count; size_human is the same value in human-readable form (40 bytes / 1.5 KB / 2.4 MB / 1.2 GB) — quote size_human when telling the user how big the file is.

If direct_send_recommended is true (file ≤ 3 MiB by default, see the threshold in filebed-config.json), the preferred delivery is to send the file as a normal Telegram/WhatsApp attachment — the filebed URL is only a fallback. When the flag is absent, or the file is larger than the threshold, the URL is the primary (and only) thing to hand to the user.

Failure ("ok": false, exit code 1) — relay error to the user, fix the cause, retry:

{"ok": false, "error": "file not found: /tmp/x.pdf", "hint": "pass a path to an existing regular file on this host"}

Common failure causes: the path does not exist / is not a regular file; the filebed service is down (hint shows how to check the systemd unit); the bearer secret file is missing or wrong (HTTP 401).

Other subcommands (only when the user asks about an existing link):

python3 filebed.py status <token>    # inspect a link (expiry, access count, ...)
python3 filebed.py delete <token>    # revoke a link immediately
python3 filebed.py health            # check the service is up

API endpoints (reference only — the script wraps all of these)

All local, http://127.0.0.1:23284; every /api/v1/* call needs the bearer token from /home/jnjn/filebed/.secret. filebed.py reads that file at call time, so the agent never handles the secret or builds raw requests.

  • POST /api/v1/add — create a link. Fields: path (required), password, ttl_days (default 100, sliding), max_accesses (default -1 = never), expires_seconds (ignored when ttl_days is set).
  • GET /api/v1/status/<token> — link state: active, valid, expired, file_exists, access_count, last_access, last_remote_ip, ttl_days, max_accesses.
  • GET /api/v1/list — all links (admin only).
  • POST /api/v1/delete/<token> — revoke a link immediately.

Delivery flow (agent → user)

  1. Do not run a separate existence check (ls, test -f, …) first. The script already validates the path (os.path.isfile) and returns a clean error JSON if the file is missing or is not a regular file — see below. Just call add; if the file is genuinely absent, the script tells you.
  2. Run filebed.py add <path> with the right flags (defaults: 100 days, no self-destruct; add --password for sensitive content, --max-accesses when the user asked for a limited link).
  3. Read the result:
    • ok: false → relay the error/hint to the user and fix the cause before retrying (wrong/missing path, service down, bad secret).
    • ok: true + direct_send_recommended: true → send the file as the primary delivery; keep the url from the JSON ready as a fallback.
    • ok: true without that flag (or the file is > the threshold) → the url is the delivery.
  4. Send the user what actually works: the attachment when direct_send_recommended is true, otherwise the url. Do not paste the token, the local path, or the bearer secret.

Formatting the URL to the user

  • Put the URL on its own line so it renders as a clickable link.
  • Do not wrap it in Markdown that strips it; plain text is fine on Telegram.
  • Optionally add one line describing what it is and any expiry/limits.

Example reply:

Link to the file (opens in browser, no attachment needed):
https://filebed.dupetrc.qiyi.us:31585/v/Q68ODUmmetrjE1Q8se1sMHmgwhAyAmhYpNpoaHTO

It self-destructs after 3 downloads.

For password-protected links, add a short instruction and deliver the password separately:

Link: https://filebed.dupetrc.qiyi.us:31585/v/Q68ODUmmetrjE1Q8se1sMHmgwhAyAmhYpNpoaHTO
Password: hunter2   (sent right after)

Safety / edge cases

  • file not found error → tell the user the path was missing or wrong; do not hand a link and then fail silently.
  • A link can be revoked (filebed.py delete <token>) or auto-expire (ttl / max_accesses / expires). If the user reports the link is dead, run filebed.py status <token> to see which condition fired, then revoke and re-create if needed.
  • When the file is deleted on disk, the link returns HTTP 410 with a "file is no longer available" page and invalidates itself; surface a clear message rather than a raw error.
  • Large files stream fine, but the service is single-host and local — the public reachability comes from the host nginx reverse proxy on 31585. If the user can't open it, check the host nginx path, not the Flask app.

Maintenance notes (do not ship to the user)

  • Service is a systemd user unit filebed.service, unit file ~/.config/systemd/user/filebed.service, secret + env in /home/jnjn/filebed/.env (mode 600) and /home/jnjn/filebed/.secret.
  • filebed.py loads its settings from filebed-config.json at startup: api_base, secret_file, bearer_secret (fallback; the secret file is preferred at call time), default link policy (default_ttl_days=100, default_max_accesses=-1), and request timeouts. It is set to mode 600 and holds a live bearer token — treat it like a password (do not ship/commit).
  • The live secret itself is still read live from secret_file (/home/jnjn/filebed/.secret, mode 600); the config only carries a fallback. Override anything at runtime via env FILEBED_API, FILEBED_SECRET_FILE, FILEBED_SECRET, or FILEBED_CONFIG=<path> when debugging on another host.
  • Logs: journalctl --user -u filebed.service -n 20 --no-pager.
  • Restart: systemctl --user restart filebed.service.
  • Test end-to-end with the scripts in /home/jnjn/filebed/run_*.sh (single-instance, auto-cleanup on exit — do not leak extra servers; the previous OOM was caused by stacking servers that outlived their shell).