Simple file sharing server utilizing nginx X-Accel file serving.
Go to file
x3 d3c07e1dc1
Use content type from request only if not empty
2024-02-28 14:30:14 +01:00
auth First!! 2024-02-25 17:25:07 +01:00
config Make template directory configurable from config.json 2024-02-25 19:03:35 +01:00
controller Use content type from request only if not empty 2024-02-28 14:30:14 +01:00
db Graceful shutdown on CTRL-C 2024-02-28 11:48:10 +01:00
id First!! 2024-02-25 17:25:07 +01:00
model First!! 2024-02-25 17:25:07 +01:00
net Graceful shutdown on CTRL-C 2024-02-28 11:48:10 +01:00
templates First!! 2024-02-25 17:25:07 +01:00
view Make template directory configurable from config.json 2024-02-25 19:03:35 +01:00
README.md ID Cache location fix pt3 2024-02-28 13:47:37 +01:00
go.mod First!! 2024-02-25 17:25:07 +01:00
go.sum First!! 2024-02-25 17:25:07 +01:00
main.go Graceful shutdown on CTRL-C 2024-02-28 11:48:10 +01:00

README.md

ngfshare

Simple file sharing server utilizing nginx X-Accel file serving.

Setup

Example config.json

{
    "Port": 8987,
    "Address": "127.0.0.1",
    "DBpath": "/var/lib/ngfshare/database.db",
    "StoreDir": "/var/lib/ngfshare/store",
    "HTMLTemplateDir": "/var/lib/ngfshare/templates",
    "UrlPrefix": "https://share.yourdomain.xyz",
    "IdLen": 5,
    "AuthKeyLen": 30
}

Example nginx server configuration

server {
    listen 443 ssl;
    server_name share.yourdomain.xyz;
    root /nonexistent;

    location / {
        proxy_set_header Host $host; # Not actually required
        proxy_pass http://127.0.0.1:8987;
    }
    location /store/ {
        internal;
        alias /var/lib/ngfshare/store/;
    }
}

(Optional) Caching based only on file id can be enabled with this example configuration

# Will match '/-{id}' '/-{id}/' '/-{id}/name' but not '/-{id}/name/' or '/-{id}/name/other'
location ~ ^/-([a-zA-Z0-9]+)(?:/?$|/[^/]+$)
    # Other caching options are omitted here...
    proxy_cache_revalidate on;
    proxy_cache_key "$host$1";
    # Other options omitted...
}

Then run with ./ngfshare -config /path/to/config.json. To generate an auth key, run ./ngfshare -config /path/to/config.json -genauth.

Api

Upload

Files can be uploaded by making a POST request to /api/upload with the Authorization header set to the auth key generated above.

Example

curl 'https://share.yourdomain.xyz/api/upload' -H 'Authorization: authkey' -F 'file=@img.png'

This returns a json dict

{
  "id": "A5HjC",
  "filename": "img.png",
  "url": "https://share.yourdomain.xyz/-A5HjC/img.png",
  "url_short": "https://share.yourdomain.xyz/-A5HjC",
  "delete_url": "https://share.yourdomain.xyz/api/delete/A5HjC"
}

Delete

Make a POST request to /api/delete/{id} with the Authorization header set.

Example

curl -X POST 'https://share.yourdomain.xyz/api/delete/A5HjC' -H 'Authorization: authkey'

Returns

{
  "status": "OK"
}

Web

There is a web interface for it as well. Login with the auth key. Once logged in, a list of files are shown. New files can be uploaded, and deleted from the web interface. You can also probably tell I'm not a web designer.

Inspiration

Inspired by https://github.com/mtlynch/picoshare. This saves the files into the sqlite3 database. I didn't like that, so thats why I made this.