Lightweight intranet workbench for sharing files, code, and reports
Pure Zig 0.17.1 single binary · Zero C dependencies · Zero CDN · Strict CSP · Inline line & text review comments
Quick Start · Key Features · Shortcuts · Deployment · HTTP API
English · 简体中文
Important
zshare is designed for controlled intranets: no login, no upload token, and no site-wide share listing. Anyone who can reach the service and knows the full link can view and comment. Do not upload secrets, tokens, or sensitive credentials.
| Scenario | Capabilities |
|---|---|
| Home Workbench | Online paste for Markdown / code / plain text / HTML (auto-detects format, Ctrl/⌘ + Enter to publish) and full-page drag-and-drop upload for single files or .zip / .tar / .tar.gz archives |
| Warm Paper & Dark Theme | Warm-paper reading surface by default with one-key toggle to warm charcoal dark mode (t), unified concentric radii, and distraction-free typography |
| Markdown Reports | Client-side sanitized rendering with marked + DOMPurify; supports GFM tables, task lists, footnotes, admonitions, syntax highlighting with copy buttons, table of contents outline, wide view, font size controls, presentation mode, and image lightbox |
| Source Code Preview | Built-in highlight.js (including Zig, Dockerfile, and more) with a seamless line-number gutter, Wrap toggle, Copy code, and drag-select or Shift + Click to generate #L10-L25 anchor links |
| CSV / TSV Tables | Full RFC 4180 parsing with sticky headers and row numbers, click-to-sort (numeric/text), live filtering (/), cell wrapping toggle, one-click copy as TSV, chunked loading for large tables, and Preview / Source switching |
| Image Workbench | Supports PNG / JPEG / GIF / SVG / WebP / AVIF / ICO / BMP, automatically displays dimensions and file size, with checkerboard / paper / dark backgrounds and Fit / 100% zoom |
| Directories & HTML Reports | Directory view supports instant filtering (/) and inline README.md rendering; fullscreen immersive HTML preview with same-share relative assets loaded normally under a sandboxed CSP |
| Inline Comments & Collaboration | Google Docs-like experience: highlight text or multiple code lines to anchor a comment on the right; viewers see comments vertically aligned while uncommented pages stay centered; the HTML report comment drawer defaults to semi-transparent and becomes solid on hover; supports replies, resolve/reopen, author deletion verification, and local nickname persistence |
docker run -d --name zshare --read-only \
-p 127.0.0.1:18080:8080 \
-e ZSHARE_URL=http://127.0.0.1:18080 \
-v zshare-data:/data \
ghcr.io/glassyiris/zshare:latestOpen http://127.0.0.1:18080/. ZSHARE_URL is the address clients use, including any non-default port. Behind a TLS proxy, set it to the public HTTPS origin and preserve the original Host. For the mapping above, proxy to http://127.0.0.1:18080. Do not expose this unauthenticated service to the Internet: -p 18080:8080 publishes on all host interfaces by default, and peers on the same Docker network can reach the backend directly.
The image runs as 65532:65532. Reuse the named volume to retain shares and comments; if using a bind mount, make it writable by that container user.
Only pushing a new v* Git tag builds and publishes the linux/amd64 and linux/arm64 images. The image tag matches the Git tag: v0.0.1.beta.1 publishes only :v0.0.1.beta.1; a stable tag such as v1.2.3 also updates :latest. Before the first stable tag, use a published prerelease tag or build locally with docker build -t zshare:local . and substitute zshare:local above.
Only requires Zig 0.17.1, with zero system C dynamic library dependencies and no pkg-config. During the build, pinned versions of marked, DOMPurify, and highlight.js are automatically fetched and embedded into a single binary.
# 1. Build and test
zig build -Doptimize=ReleaseSafe
zig build test
# 2. Start the server (listens on 127.0.0.1:8080 by default)
./zig-out/bin/zshare serve
# 3. Open http://localhost:8080/ in a browser, or publish via CLI
./zig-out/bin/zshare publish --name 'Inspection Report' ./report.md
./zig-out/bin/zshare publish --name 'Interactive Report' --entry index.html ./dist
./zig-out/bin/zshare publish --name 'Archive Report' ./report.zipCross-compile for intranet Linux (zero external dynamic library dependencies):
zig build -Dtarget=x86_64-linux-musl -Doptimize=ReleaseSafeTip
When distributing the binary, you can include the third-party open-source license files located under zig-out/share/licenses/zshare/.
- On success, stdout outputs a single line of JSON:
urlis the share directory, andentry_urlis the entry file. - Default entry priority: explicit
--entry→ rootindex.html→ rootREADME.md→ the sole file → share directory (if an explicit entry does not exist, the entire upload fails). - On-disk layout is
YYYY-MM-DD/UUID/<share-name>/<relative-path>(date uses server UTC). Expiration markers (.expires:at) and comment logs (.comments:v1.jsonl) are stored in the same UUID directory and automatically removed during expiration cleanup.
| Key | Action |
|---|---|
[ / b |
Expand or collapse the file sidebar |
m |
Open or close the comments panel (press m after selecting text/lines to add a comment directly) |
t |
Toggle warm paper / warm charcoal dark theme |
w |
Toggle wide mode (Markdown) or word wrap (code) |
f |
Enter / exit Markdown presentation mode |
c |
Copy the current share link |
/ |
Quick filter in directory view / CSV table |
Shift + Click |
Select a line range and generate an anchor in code view |
? / Esc |
Open the shortcuts panel / close the active overlay |
zshare/
├── build.zig # Zig build script embedding web/ and pinned third-party static assets
├── build.zig.zon # Dependency manifest and hash pinning
├── src/ # Pure Zig backend
│ ├── main.zig # CLI entry point (serve / publish)
│ ├── server.zig # HTTP routing, uploads, static assets, and comments API
│ ├── view.zig # View layer entry, static assets, and CSP response dispatch
│ ├── view/ # View submodules (types / html / directory / page)
│ ├── comments.zig # Append-only JSONL comment store, ownership hash checks, and state folding
│ ├── upload.zig # Pure Zig streaming extraction (zip / tar / tar.gz) and path validation
│ ├── retention.zig # Expiration parsing and periodic background cleanup
│ ├── paths.zig # Path safety validation and URL encoding/decoding
│ └── protocol.zig # Request headers, MIME detection, and Origin parsing
└── web/ # Frontend static assets (zero frameworks, no build step)
├── icon.svg # Brand vector icon and favicon
├── pages/ # Home workbench (paste.html)
├── styles/ # Warm paper / warm charcoal dark stylesheet (view.css)
└── scripts/ # Theme, viewer interactions, comment engine, and paste/upload scripts
- Preview limits: Markdown and text source previews are capped at
2 MiB(files over256 KiBor containing overly long lines fall back to plain text; files over10,000lines omit line numbers). Downloads (?download=1) always return the raw bytes. - Sandboxing & CSP: Fullscreen HTML previews are streamed as-is, while external CDNs, cross-origin APIs, form submissions, and top-level navigation are restricted by a sandboxed CSP. Markdown only allows same-share relative images and
data:URIs; external images are blocked. Browser sandboxing is not a network firewall—do not treat untrusted HTML as safe executable code. - Archive safety: Automatically extracts
.zip(Store / Deflate),.tar,.tar.gz, and.tgz(single gzip member) without recursively extracting nested archives, and rejects symlinks, special files, path traversal, and duplicate entries. Single uploads are capped at128 MiB; extraction is capped at512 MiBand10,000entries; relative paths may be at most32levels deep and1,023UTF-8 bytes. - Comment auth & polling: On first use, the browser automatically generates a local secret and sends it via
X-Zshare-Client-Secret; the server persists only its SHA-256 hash to verify author deletions. Nicknames are stored in browserlocalStorageand reused across shares. While the panel is open, updates are polled incrementally via?since=<seq>(returns204with exponential backoff when unchanged).
| Environment Variable | Default | Purpose |
|---|---|---|
ZSHARE_URL |
http://localhost:8080 |
External main-site origin accessed by users and agents |
ZSHARE_CA_FILE |
System trust store | Trusted PEM CA certificate for CLI access over private HTTPS |
ZSHARE_CONTENT_URL |
Empty | Optional dedicated content origin; when empty, content is served under the main site's /raw prefix with a sandbox CSP |
ZSHARE_LISTEN |
127.0.0.1:8080 (image: 0.0.0.0:8080) |
Backend listen address and port |
ZSHARE_ALLOW_NON_LOOPBACK |
0 (image: 1) |
1 permits a non-loopback listener; 0 restricts it to loopback. Other values are rejected. |
ZSHARE_DATA_DIR |
./data (image: /data) |
Persistent data directory (exclusively writable by the service account) |
- Expiring shares (10 min / 1 hour / 1 day / 1 week / 30 days / 1 year / permanent) return
404across all views, downloads, content assets, and comment APIs once expired; expired data is automatically cleaned up on startup and every 5 minutes in the background. - No extra domain required by default: content is served through
/raw/<date>/<uuid>/...on the main site with asandbox allow-scriptsCSP (opaque origin, unable to call main-site APIs or read main-site pages). For stronger isolation, configureZSHARE_CONTENT_URLon a separate host. - NGINX reverse proxy reference (NGINX terminates TLS and handles
100 Continue, without forwardingCookieorExpect):
location / {
allow 10.0.0.0/8;
deny all;
client_max_body_size 128m;
client_body_timeout 30s;
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Cookie "";
proxy_set_header Expect "";
proxy_request_buffering off;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}POST /api/v1/shares (main site only). Include X-Zshare-Name, and optionally X-Zshare-Entry and X-Zshare-Expires-In (decimal seconds, 0–31536000; omitted or 0 means permanent). Send raw bytes directly in the request body without multipart encoding:
Content-Type |
Request Body |
|---|---|
application/octet-stream |
Single file; X-Zshare-Filename is required |
application/zip |
ZIP archive |
application/x-tar |
TAR archive (used by the CLI when uploading directories) |
application/gzip |
TAR.GZ archive |
Returns 201 with {"url":"…","entry_url":"…"} on success. In the browser, append ?view=source on the main site to view raw source, or ?download=1 to download the original file.
Base path: /api/v1/shares/<date>/<uuid>/<name>/comments (same-origin main site only; write requests must include Content-Type: application/json and X-Zshare-Client-Secret):
| Method & Path | Description |
|---|---|
GET .../comments?file=<rel>[&since=<seq>] |
Fetch file comments and latest seq; returns 204 if unchanged |
POST .../comments |
Create a comment thread (supports general, text highlight, and lines range anchors); returns 201 |
POST .../comments/<thread_id>/replies |
Reply to a comment thread; returns 201 |
PATCH .../comments/<thread_id> |
Mark as resolved or reopen ({"resolved": true|false}) |
DELETE .../comments/<thread_id>/<item_id> |
Delete a comment or thread authored by the caller (verified via X-Zshare-Client-Secret hash) |