added service file, removed unnecessary default values, new omitdomain feature, improved readme

This commit is contained in:
vysion 2021-01-20 00:43:19 -08:00
parent bc365b0526
commit baad27a4a4
5 changed files with 43 additions and 17 deletions

View File

@ -6,7 +6,7 @@
A file host server with server security in mind. Intended for private use.
### Features
## Features
- Excellent compatibility with image capture suites like ShareX/MagicCap/etc.
- Limit requests to a certain amount for an interval that you can choose
@ -19,23 +19,39 @@ A file host server with server security in mind. Intended for private use.
- Sanitize files to prevent against phishing attacks
- Public/private mode (private by default)
### How to setup
## Setup
Make sure you have a Google Cloud Storage service account's JSON key and a Redis instance set up somewhere.
- Put the GCS JSON key in `conf/` as `key.json`.
- Put your config in `conf/` as `config.yml` using `conf/example.yml` as a reference.
- Optionally, you can replace `favicon.ico` with your own icon! (It must have the same name)
- If you're using this with ShareX, check `example/example.sxcu` for a template sxcu file.
- If you're using this with ShareX, check `example/tytanium.sxcu` for a template sxcu file.
### Run with Docker
Now you can choose to either run Tytanium with Docker or as a service on your system.
- Choose Docker if **you already have docker setup on your server**.
- Choose systemd if **you want to run it without any virtualization or don't want to install Docker**.
### Option 1: Run with Docker
- Ensure first that you have Docker installed on your system.
- Build the image with `docker build -t tytanium .`
- Make sure to bind the port you choose (default is `3030`) to other ports on your system. Here's an example of how you would run it, after building the image.
`docker container run -d -p 127.0.0.1:3030:3030 tytanium`
### Run with systemd/service file/etc.
### Option 2: Run as a systemd service
Just build and run the executable.
- Download the binary to the same directory where `conf/` is located.
- Mark it as executable with `chmod 0744 <binary file>`.
- Copy `example/tytanium.service` to `/lib/systemd/system`.
- Edit the WorkingDirectory and ExecFile to match the locations of the binary file.
- Run `systemctl daemon-reload`.
At this point, you can run the program using `systemctl start tytanium`. You can check on its status by running `systemctl status tytanium`.
If anything goes wrong, you can check `journalctl -u tytanium` and find out what happened.
### How to Upload
Create a POST request to `/upload` with a file in the field "file". You can also set `omitdomain` to 1 if you don't want the host's original domain appended before the file name in the response. E.g: `a.png` instead of `https://a.com/a.png`

12
example/tytanium.service Normal file
View File

@ -0,0 +1,12 @@
[Unit]
Description=Tytanium File Host
[Service]
Type=simple
Restart=always
RestartSec=5s
ExecStart=
WorkingDirectory=
[Install]
WantedBy=multi-user.target

10
main.go
View File

@ -12,7 +12,7 @@ import (
)
const (
Version = "1.13.0"
Version = "1.13.1"
GCSKeyLoc = "./conf/key.json"
)
@ -37,15 +37,7 @@ func main() {
viper.SetDefault("server.maxconnsperip", 16)
viper.SetDefault("security.maxsizebytes", 52428800)
viper.SetDefault("security.publicmode", false)
// Make 20 requests globally per minute. Overrides all path-specific rate limits.
viper.SetDefault("security.ratelimit.global", 20)
// Upload 10 times per minute.
viper.SetDefault("security.ratelimit.upload", 10)
viper.SetDefault("security.ratelimit.resetafter", 60000)
// Download 50 MB per 5 minutes.
viper.SetDefault("security.bandwidthlimit.download", 52428800)
// Upload 250 MB per 5 minutes.
viper.SetDefault("security.bandwidthlimit.upload", 262144000)
viper.SetDefault("security.bandwidthlimit.resetafter", 60000*5)
err := viper.Unmarshal(&configuration)
if err != nil {

View File

@ -91,6 +91,12 @@ func (b *BaseHandler) ServeUpload(ctx *fasthttp.RequestCtx) {
return
}
u := fmt.Sprintf("%s/%s", net.GetRoot(ctx), fileName)
var u string
if mp.Value["omitdomain"] != nil && len(mp.Value["omitdomain"]) > 0 && mp.Value["omitdomain"][0] == "1" {
u = fileName
} else {
u = fmt.Sprintf("%s/%s", net.GetRoot(ctx), fileName)
}
SendTextResponse(ctx, u, fasthttp.StatusOK)
}