diff --git a/Makefile b/Makefile
index c1deac1178f2c824ff5d1418b7de10e010e1eb86..743c0fd2e391830b12b52616a9acd68b37ef9aa3 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,19 @@ GO_TEST=go test -v -timeout 100ms -shuffle on -parallel `nproc`
GO_BUILD=go build -v -ldflags '-w -s'
GO_RUN=go run -v
+# Development setup
+DB_TYPE?=sqlite
+DB_CON?=main.db
+LOG_LEVEL?=error
+SCHEDULER_COUNT?=`nproc`
+CACHE_PATH?=$(HOME)/cache
+AES_KEY?=`openssl rand -rand /dev/urandom 32 | base64`
+
+ifneq (,$(wildcard ./.env))
+ include .env
+ export
+endif
+
all: build
build: sass tmpl
@@ -19,9 +32,12 @@ upx --best --ultra-brute $(OUT)
run: sass
$(GO_RUN) $(SERVER) \
- --log-level error \
- --aes-key=6368616e676520746869732070617373 \
- --cache-path=${HOME}/.thumb
+ --db-type=$(DB_TYPE) \
+ --db-con="$(DB_CON)" \
+ --log-level=$(LOG_LEVEL) \
+ --scheduler-count=$(SCHEDULER_COUNT) \
+ --cache-path="$(CACHE_PATH)" \
+ --aes-key="$(AES_KEY)"
sass:
@mkdir -p static
@@ -75,3 +91,7 @@ -exec gci write -s standard -s default -s "prefix(git.sr.ht/~gabrielgio/img)" {} +
alignment:
betteralign -apply ./...
+
+watch:
+ find . \( ! -name "*.qtpl.go" -a \( -name "*.go" -o -name "*.qtpl" -o -name "main.scss" \) \) | \
+ entr -sr 'make run'
diff --git a/README.md b/README.md
index a008d7f85f3780fae96c8df6ca4dfc0a0e314da7..256cfb303cbc74475e5647634cc9aa0693f2cc18 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,59 @@
# Lens
A read only file explorer with media capabilities.
-
-# Dev requirements
+
+# Dev
+
+To run the project you simply need to run:
+
+```bash
+make run
+```
+
+It should run using sqlite with a randon AES key. But if you don't set a
+`AES_KEY` a new one will generated every time the project is realead and you
+will be logged out.
+
+You can also create a `.env` file which will be read by make to populate the
+environment variables, e.g.:
+
+```ini
+# .env
+DB_TYPE=psql
+DB_CON=host=localhost user=admin password=admin dbname=lens port=5432
+LOG_LEVEL=error
+SCHEDULER_COUNT=10
+CACHE_PATH=/home/myhome/.thumb
+AES_KEY=X4Eu3OT/WqUtUJhGLUtQ4xRahwhWYaSs+k2a03Kz1A8=
+```
+
+Obs.: don't quote the value, that will be done automatically.
+
+Throughout the development you can also run `make watch` for a hot reload
+experience. It will feedback loop a bit faster.
+
+## Build and install
+
+To build you simply run:
+```
+make
+```
+
+And a `./bin/lens` will be created.
+
+To install run:
+
+```
+make install
+```
+
+Or you can pass a custom target folder.
+
+```
+PREFIX=~/.local/ make install
+```
+
+# Requirements
## qtc
diff --git a/cmd/server/main.go b/cmd/server/main.go
index a3d5124e758937ca88d4b1cc89160e87f191bb39..035d00aba84f2c6f54ce952f28c9b28b6b719e9e 100644
--- a/cmd/server/main.go
+++ b/cmd/server/main.go
@@ -2,7 +2,7 @@ package main
import (
"context"
- "encoding/hex"
+ "encoding/base64"
"errors"
"net/http"
"os"
@@ -66,7 +66,7 @@ if *dbType == "sqlite" {
*schedulerCount = 1
}
- hexKey, err := hex.DecodeString(*key)
+ baseKey, err := base64.StdEncoding.DecodeString(*key)
if err != nil {
panic("failed to decode key database: " + err.Error())
}
@@ -84,7 +84,7 @@ )
// middleware
var (
- authMiddleware = ext.NewAuthMiddleware(hexKey, logger.WithField("context", "auth"))
+ authMiddleware = ext.NewAuthMiddleware(baseKey, logger.WithField("context", "auth"))
logMiddleware = ext.NewLogMiddleare(logger.WithField("context", "http"))
initialMiddleware = ext.NewInitialSetupMiddleware(userRepository)
)
@@ -99,7 +99,7 @@ scheduler := worker.NewScheduler(*schedulerCount)
// controller
var (
- userController = service.NewAuthController(userRepository, userRepository, hexKey)
+ userController = service.NewAuthController(userRepository, userRepository, baseKey)
fileSystemController = service.NewFileSystemController(fileSystemRepository, userRepository)
)