https://github.com/rogusdev/onetime-downloader
Generate onetime download links for files stored in cloud storage
https://github.com/rogusdev/onetime-downloader
Last synced: 10 months ago
JSON representation
Generate onetime download links for files stored in cloud storage
- Host: GitHub
- URL: https://github.com/rogusdev/onetime-downloader
- Owner: rogusdev
- License: mit
- Created: 2020-07-13T14:38:23.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2020-10-01T04:37:04.000Z (over 5 years ago)
- Last Synced: 2025-02-15T07:36:27.463Z (about 1 year ago)
- Language: Rust
- Size: 98.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# onetime-downloader
Generate onetime download links for files stored in some kind of (cloud based?) storage
## TODO:
- [x] 2 api keys in header for curl: 1) add and list available files 2) create and list download links
- [x] get endpoint returns json list of available files in storage
- [x] post endpoint to add available file to storage
- [x] post endpoint to create/store + return custom (random) url to download one of those files with tracking of use
- [x] get endpoint to download file using custom url
- [x] updated downloaded_at and prevent future downloads when downloading file
- [x] get endpoint returns json list of available links for a given filename
- [x] separate out modules into files and maybe folders (storage providers)
- [ ] unit tests for ^
- [x] dockerfile to run ^
- [x] download header specifies filename!
- [x] `expires_at` with default from env and optional override per link -- maybe default (for link) per file too?
- [x] read filename from file, override with provided filename only if present
- [x] update file if a new version is uploaded
- [x] delete files + links
- [ ] zero copy in links/files from input? (&str not String)
- [ ] JSON error responses when things go wrong
- [ ] use `e.into()` for converting errors into `MyError`
- [ ] react UI to manage list of files + links, etc
- [ ] google sso to login for managing list -- remove api keys?...
- [ ] audit trail of what actions taken by which users in ui
- [ ] setup 3 subdomains: 1 for downloads, 1 for ui, 1 for api
- [ ] rate limiting by IP that increases as more limits get triggered
- [x] support storage provider: dynamodb
- [x] support storage provider: postgres
- [ ] support storage provider: redis
- [ ] support storage provider: mongo
- [ ] support other storage providers, plugin style: s3, gcs, azure blob, mysql, rds, aurora
- [ ] google sso browser login to view list in UI
- [ ] button to generate link for file in UI
- [ ] support other SSO auth providers, plugin style
## Setup
Docker:
```
docker network create www
docker rm -f onetime-downloader
docker build -t onetime-downloader .
docker run --env-file .env -e PG_HOST=postgres-www -p 8080:8080 --network=www --name onetime-downloader onetime-downloader
docker run -d --restart=always --env-file .env -e PG_HOST=postgres-www -e FILE_MAX_LEN=4000000 --network=www -l 'caddy'='downloads.chrisrogus.com' -l 'caddy.reverse_proxy'='$CONTAINER_IP:8080' --name onetime-downloader onetime-downloader
docker exec -it onetime-downloader bash
```
## Initialize
### Postgres
```
--DROP SCHEMA IF EXISTS onetime CASCADE;
CREATE SCHEMA IF NOT EXISTS onetime;
CREATE TABLE IF NOT EXISTS onetime.files (
filename TEXT NOT NULL PRIMARY KEY,
contents BYTEA NOT NULL,
created_at BIGINT NOT NULL,
updated_at BIGINT NOT NULL
);
CREATE TABLE IF NOT EXISTS onetime.links (
token TEXT NOT NULL PRIMARY KEY,
filename TEXT NOT NULL,
note TEXT NULL,
created_at BIGINT NOT NULL,
expires_at BIGINT NOT NULL,
downloaded_at BIGINT,
ip_address TEXT
);
```
docker:
```
docker rm -f postgres-www
docker run -d --restart=always -p 5432:5432 --network=www -v $PWD/postgres-data:/var/lib/postgresql --name postgres-www -e POSTGRES_PASSWORD=badpassword postgres:12.4-alpine
docker run -it --rm --network www postgres:12.4-alpine psql -h postgres-www -U postgres
psql -h localhost -p 5432 -U postgres -d postgres
\d onetime.*
```
### Dynamodb
```
aws dynamodb delete-table \
--profile rogusdev-chris \
--table-name Onetime.Links
aws dynamodb create-table \
--profile rogusdev-chris \
--table-name Onetime.Files \
--attribute-definitions \
AttributeName=Filename,AttributeType=S \
--key-schema \
AttributeName=Filename,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
# AttributeName=Contents,AttributeType=B \
# AttributeName=CreatedAt,AttributeType=N \
# AttributeName=UpdatedAt,AttributeType=N \
aws dynamodb create-table \
--profile rogusdev-chris \
--table-name Onetime.Links \
--attribute-definitions \
AttributeName=Token,AttributeType=S \
--key-schema \
AttributeName=Token,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
# AttributeName=Filename,AttributeType=S \
# AttributeName=CreatedAt,AttributeType=N \
# AttributeName=DownloadedAt,AttributeType=N \
# AttributeName=Ip,AttributeType=N \
```