Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ENV CURIER_PORT="39800"
ENV CURIER_STORAGE_PATH="/uploads/"

COPY --from=builder /app/curier /curier
COPY --from=builder /tmp /tmp

EXPOSE 39800

Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ A small Go server for sharing files across the internet.

## How to setup

### Docker environment
### Docker

You can download the Dockerfile and build the image yourself, or simply pull it from the repo:
```bash
docker pull ghcr.io/adipeterca/curier:latest
docker run -p 39800:39800 ghcr.io/adipeterca/curier:latest
```

### Linux environment

**I strongly recommend using Docker, as it simplifies the configuration a lot**.
### Linux

If you want to use a precompiled binary, please refer to the [Release](https://github.com/adipeterca/curier/releases) section.

### Windows environment
### Windows

Because not many servers run Windows, the support I can provide for this platform is limited.
You can download a precompiled binary from the [Release](https://github.com/adipeterca/curier/releases) section or use a Docker container.
Expand All @@ -35,8 +33,16 @@ For default values, check [config.go](https://github.com/adipeterca/curier/blob/
| Variable name | Description |
|--|--|
|`CURIER_STORAGE_PATH`|Absolute path where the file uploads will be stored on disk|
|`CURIER_BASE_URL`|Default prefix for the `/download/{id}` URL|
|`CURIER_HOST`|Network address to bind to|
|`CURIER_PORT`|Port to use (also affects the port used inside the container)|
|`CURIER_FILE_RETENTION_TIME`|How many hours (minimum 1) to keep the files on disk|
|`CURIER_MAX_FILE_SIZE`|Maximum allowed size for each file upload|
|`CURIER_ALLOWED_FILE_EXTENSIONS`|A `;` separated list of file extensions, lowercase only (the last entry needs to have a `;` too)|
|`CURIER_ALLOWED_FILE_EXTENSIONS`|A `;` separated list of file extensions, lowercase only (the last entry needs to have a `;` too)|

## Technical details

In no particular order:
- the application uses cryptographically secure IDs (128-bit randomness) to reference uploaded files
- files expire and get deleted automatically
- it comes as a single binary, with no external dependencies
- the frontend has some UX elements that prevent a user from uploading an invalid / unaccepted file (however, **THIS IS DONE PURELY AS A UX FEATURE, NOT A SECURITY FEATURE**)
67 changes: 67 additions & 0 deletions cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"log"
"os"
"path/filepath"
"time"
)

func startCleanup() {
ticker := time.NewTicker(1 * time.Hour)
go func() {
for range ticker.C {
cleanup()
}
}()
}

// Will it even panic? If so, it will crash the whole app - need to keep an eye on this
func cleanup() {

log.Printf("INFO: Started a routine cleanup for expired files at %s\n", time.Now())
entries, err := os.ReadDir(storagePath)
if err != nil {
log.Printf("ERROR: could not read storage directory: %s\n", err)
return
}

for _, entry := range entries {
if entry.IsDir() {
continue
}
if filepath.Ext(entry.Name()) == ".meta" {
continue
}

id := entry.Name()
filePath := filepath.Join(storagePath, id)

if isExpired(id) {
err = os.Remove(filePath)
if err != nil {
log.Printf("ERROR: could not remove %s, reason: %s\n", filePath, err)
}

err = os.Remove(filePath + ".meta")
if err != nil {
log.Printf("ERROR: could not remove %s, reason: %s\n", filePath+".meta", err)
}
}
}

log.Printf("INFO: Finished a routine cleanup at %s\n", time.Now())
}

func isExpired(id string) bool {

metaFile, err := readMeta(id)
if err != nil {
log.Printf("ERROR: could not delete meta file for %s during cleanup, reason: %s\n", id, err)
// Return 'false' as a "skip this file"
return false
}

retention := time.Duration(fileRetentionTime) * time.Hour
return time.Since(metaFile.UploadedAt) > retention
}
13 changes: 9 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package main

import "embed"
import (
"embed"
"html/template"
)

//go:embed static
var staticFiles embed.FS

//go:embed templates
var templateFiles embed.FS

var shareTemplate *template.Template

// All variables can be overwritten by using environment variables.
// All env vars need to start with `CURIER_` followed by the variable name in uppercase, each word separated with an underscore.
//
Expand All @@ -19,15 +24,15 @@ var templateFiles embed.FS
// Where to save the uploaded files
var storagePath = "uploads/"

// URL base path that will prefix all download links
var urlBasePath = "http://localhost"

// Network address to bind to - default 0.0.0.0
var host = "0.0.0.0"

// Port to listen on - default 39800
var port = "39800"

// How many hours (minimum 1) to hold the files on disk - default 12 hours
var fileRetentionTime int64 = 12

// --- Public variables ---
//
// This information can be queried by a GET request to the `/config/` endpoint.
Expand Down
Loading
Loading