The code for my Rust-powered file server at https://files.axolotlmaid.com - customizable and open for anyone to use.
- Show contents / previews of files uploaded
- Highlighted code in preview with highlight.js
- Image viewer with zooming and panning
- Uploading, deleting, renaming, directory of uploads with optional authorization
- Ability to manage and upload files from the directory of uploads
- View information of a specific file and see uploads in JSON form
- Generate password with specified length on start up for more security
- Option to generate filenames and its length
- Metrics for Prometheus and Grafana
See it in usage at these links:
You can also view the gallery by going here.
To upload a file or multiple files, make a POST request to the /api/upload
route with the file(s) attached with the header Authorization
with its value set to the password. The server will write the file using its original filename as sent in the request, not the field name.
Example response:
{
"files": [
{
"name": "file_name",
"url": "file_url"
},
{
"name": "file_name",
"url": "file_url"
}
],
"success": true
}
To delete a file, make a DELETE request to /api/delete
with the Authorization
header and set the body to the JSON example below:
{
"name": "file_name_here"
}
To rename a file, do the same request as deleting but instead to the route /api/rename
with the method PUT and set the body to the JSON example below:
{
"name": "file_name_here",
"new_name": "new_file_name_here"
}
To view all the uploads (also known as the directory), go to /
and enter the optional password. You can also delete and rename files and also upload on this page.
There is also an option to do this in JSON form, to do this, create a GET request to /api/uploads
which will return every file uploaded in a JSON string array. The Authorization
header may be required if PROTECT_DIRECTORY
is enabled in .env.
There is two ways to view a specific file - you can either go to the URL with all the fancy styling which is /file_name_here
or go to the same URL but with /raw
and only the file itself at the end like /file_name_here/raw
To view information of a file (name, size, modified time, url), create a GET request to /file_name_here/info
like you would do above but with /info
as the suffix. This does not require authorization.
You can either build the image manually or pull it from ghcr.io.
$ git clone https://github.com/trafficlunar/files
$ cd files
# (optional) change favicon.ico to whatever you want
$ docker build -t files .
$ docker pull ghcr.io/trafficlunar/files:latest
Note
Read .env.example for more information on these variables.
docker run -d \
--restart=always \
-e BASE_URL="http://localhost:3000" \
-e PAGE_TITLE="files" \
-e PASSWORD="" \
-e PROTECT_DIRECTORY=true \
-e ENABLE_FILE_ACTIONS_DIRECTORY=true \
-e GENERATE_PASSWORD=true \
-e GENERATE_PASSWORD_LENGTH=16 \
-e GENERATE_FILENAME=false \
-e GENERATE_FILENAME_LENGTH=8 \
-e METRICS_ENABLED=true \
-p 3000:3000 \
-p 3001:3001 \
-v /path/to/uploads/:/app/uploads/ \
--name files \
ghcr.io/trafficlunar/files:latest # or files:latest
- Clone the repository
git clone https://github.com/trafficlunar/files
cd files
- Rename
.env.preview
to.env
and edit to your liking - (optional) Change the
favicon.ico
to whatever you want - Build and run the server
cargo build --release
./target/release/files