I got bored during 4th of July weekend, so a mini weekend hackathon to put something together.
In short:
- file hosting, and
- link shortening, and
- pastebin
Project is inspired by https://github.com/raftario/filite. Actually, index.html
is adopted from filite
, because I'm too lazy to write a frontend.
If you want to exchange some files (say 50MB of photos from last week's trip) with a friend, one of you can use TryCloudflare, then run b
with baseURL set to your tunnel, so the other person can quickly upload/download file.
If you want pastebin, bit.ly, and Firefox Send (roughly) all in the same spot, then b
is perfect for you. You can even setup access control so POST
requests can only come from your VPN, or requiring a password, so you can leave b
running openly on the internet.
Sometimes you just want to show off the shortest domain you own and let everyone knows 😂.
Please see config.yaml
for reference.
./bin/b.exe -config config.yaml
The default config.yaml
should be sufficient for most use cases. Visit http://127.0.0.1:3000
to use the web interface.
Uploading a file:
# Specifying an expiration time is in TODO.
curl -X PUT -F file=@Alaska.jpg https://example.com:3000/f-alaskan
{"result":"https://example.com:3000/f-alaskan","error":null,"messages":[]}
Pasting some text:
# Optionally, you can specify when the paste expires in seconds: https://example.com:3000/t-footxt/60
cat foo.txt | curl -X PUT --data-binary @- https://example.com:3000/t-footxt
{"result":"https://example.com:3000/t-footxt","error":null,"messages":[]}
Shortening a link:
# Optionally, you can specify when the link expires in seconds: https://example.com:3000/l-longurl/60
curl -H "Content-Type: application/json" \
-X PUT \
--data '{"url": "https://llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch.co.uk/"}' \
https://example.com:3000/l-longurl
{"result":"https://example.com:3000/l-longurl","error":null,"messages":[]}
In a future version it is planned to add:
S3/S3-compatible storage to back file hosting(done!)*SQL and its garden varieties for link/text/file metadata(added SQLite forapp.Backend
, notapp.FastBackend
though)Environmental variables based configurations(done viaconfig.yaml
)- Access control
- TTL for file service
- Anything you feel like you want to add. The interface exists in
app/backend.go
Requirements:
- Golang 1.16.5
- Docker & Docker-Compose
- Your favorite IDE
- First, run
docker-compose up -d
- Then, ensure that the tests pass with
go test -v -race ./...
Disclaimer: I mainly test on Windows, and Github Actions test on ubuntu. macOS is currently untested.
go build -tags sqlite_omit_load_extension,osusergo,netgo -ldflags="-s -w -linkmode external -extldflags -static" -o bin/b.exe ./cmd/b/
This will build b
in bin/b.exe
with stripped debug info, and statically without dynamically linked libs.
For building on macOS host (amd64/arm64), remove -extldflags -static
.