From 628e9b7bc02885d55b0ccbd90b07af74d0e7a7f7 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Thu, 20 Jan 2022 19:00:51 +0100 Subject: [PATCH 1/4] Add readme --- README.md | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lithium.md | 16 ---- 2 files changed, 228 insertions(+), 16 deletions(-) create mode 100644 README.md delete mode 100644 lithium.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b8f125 --- /dev/null +++ b/README.md @@ -0,0 +1,228 @@ +# Lithium + +Micro-service for file storage and processing written in Go. + +## Features + +- Image processing pipelines for various transformations +- Web API for storing & retrieving files + +## Requirements + +- [Go 1.17+](https://go.dev/) +- [*Docker*](https://docs.docker.com/) (optional) + +## Setup + +#### 1. Clone repository + +```shell +git clone git@gogs.informatik.hs-fulda.de:FabianVowie/Lithium.git +``` + +#### 2. Pull dependencies + +```shell +go get +``` + +#### 3. Build & start application + +```shell +go run . +``` + +**Run using [Docker](https://docs.docker.com/) container** + +```shell +docker run --rm -p 8000:8000 -v "$PWD":/usr/src/lithium -w /usr/src/lithium golang:1.17 go run . +``` + +## Testing + +```shell +go test ./... +``` + +### Run tests in verbose logging mode + +```shell +go test ./... -v +``` + +### Run tests in [Docker](https://docs.docker.com/) container + +```shell +docker run --rm -v "$PWD":/usr/src/lithium -w /usr/src/lithium golang:1.17 go test ./... +``` + +## API + +### `GET` `/` + +Show application information. + +**Example response**: + +```json +{ + "Name": "Lithium", + "Version": "0.1.0" +} +``` + +### `GET` `/{pipeline}` + +Show pipeline information. + +**Example response**: + +```json +{ + "name": "example pipeline", + "slug": "example", + "type": 0, + "remove_metadata": false, + "steps": [ + { + "name": "resize image", + "type": 0, + "options": { + "width": 1280, + "height": 720, + "upscale": false + } + } + ], + "output": { + "format": 0, + "quality": 90 + } +} +``` + +## Configuration + +Config options can be adjusted via the [`settings.json`](settings.json) file in the root directory. + +```json +{ + "endpoint": "0.0.0.0:8000", + "token": "changeme", + "storage_provider": { + "type": 0, + "base_path": "assets" + } +} +``` + +## Pipelines + +The project uses a pipeline system defined by [JSON](https://en.wikipedia.org/wiki/JSON) files located in the [config](config) folder. +Take a look at the [example pipeline configuration file](config/example.json). + +Available pipeline `type`s: `0` (Image), `1` (Video) + +```json +{ + "name": "example pipeline", + "slug": "example", + "type": 0, + "removeMetadata": false, + "steps": [], + "output": {} +} +``` + +### Images pipeline + +The image pipeline offers the following additional output options. + +Available `format` types: `0` (jpeg) +The `quality` field can contain any integer between 1 and 100. + +```json +{ + "output": { + "format": 0, + "quality": 90 + } +} +``` + +### Available pipeline steps + +Each pipeline step consists of an optional `name`, a predefined `type` and configurable `options`. +See the available options below for more information. + +```json +{ + "name": "step name", + "type": 0, + "options": {} +} +``` + +#### Resizing images + +Resize an image by a given `width` and `height`. + +**Step definition**: + +```json +{ + "type": 0, + "options": { + "width": 1280, + "height": 720 + } +} +``` + +#### Rotating images + +Rotate an image with a given `angle` in degrees. + +**Step definition**: + +```json +{ + "type": 1, + "options": { + "angle": 90.0 + } +} +``` + +#### Flipping images + +Flip an image with a given direction. +Allowed values for the `direction` option are `"h"` (horizontal), `"v"` (vertical) + +**Step definition**: + +```json +{ + "type": 2, + "options": { + "direction": "h" + } +} +``` + +#### Grayscale + +Convert the colorspace of an image into grayscale. + +**Step definition**: + +```json +{ + "type": 3 +} +``` + +## Authors + +- [Fabian Vowie](https://gogs.informatik.hs-fulda.de/FabianVowie) +- [Roman Zipp](https://gogs.informatik.hs-fulda.de/roman.zipp) diff --git a/lithium.md b/lithium.md deleted file mode 100644 index 6d0ed5c..0000000 --- a/lithium.md +++ /dev/null @@ -1,16 +0,0 @@ -# Lithium - -Micro-service for file storage and processing. - -## Features - -- File storing with various providers - - S3 (or S3 compatible like MinIO) - - Locally (for development purposes) -- File processing "pipelines" for various formats - - Compression, Resizing for images - - Encoding for videos - - Remove metadata (e.g. EXIF) -- File-based configuration for pipelines - - JSON/YAML/TOML? -- Web api to store and retrieve files From 2c8e91d2de65318a0062da7acc5ec720cf51497f Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Thu, 20 Jan 2022 19:01:03 +0100 Subject: [PATCH 2/4] Add missing flip direction field in example pipeline config --- config/example.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/example.json b/config/example.json index eb65944..f2c773c 100644 --- a/config/example.json +++ b/config/example.json @@ -22,7 +22,10 @@ }, { "name": "flip image", - "type": 2 + "type": 2, + "options": { + "direction": "h" + } }, { "name": "grayscale", From d5751e5a92841ba70e7d39b9db8099f5d08a7961 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Thu, 20 Jan 2022 19:04:44 +0100 Subject: [PATCH 3/4] Add metadata struct lowercase json tags --- README.md | 4 ++-- main.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8b8f125..dafc29e 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,8 @@ Show application information. ```json { - "Name": "Lithium", - "Version": "0.1.0" + "name": "Lithium", + "version": "0.1.0" } ``` diff --git a/main.go b/main.go index e8733c1..bac331a 100644 --- a/main.go +++ b/main.go @@ -14,8 +14,8 @@ const Name string = "Lithium" const Version string = "0.1.0" type Metadata struct { - Name string - Version string + Name string `json:"name"` + Version string `json:"version"` } func PipelineHandler(pipeline pipelines.IPipeline, storageProvider storage.IStorageProvider, w http.ResponseWriter, r *http.Request) { From 90e933f87fcf0e9d0da7ed9353b5620fe4b68cf1 Mon Sep 17 00:00:00 2001 From: Fabian Vowie Date: Thu, 20 Jan 2022 21:55:53 +0100 Subject: [PATCH 4/4] Add required authorization header for endpoints to readme --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index dafc29e..55f22e1 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,11 @@ docker run --rm -v "$PWD":/usr/src/lithium -w /usr/src/lithium golang:1.17 go te Show application information. +**Required headers**: +```shell +Authorization: Bearer +``` + **Example response**: ```json @@ -75,6 +80,11 @@ Show application information. Show pipeline information. +**Required headers**: +```shell +Authorization: Bearer +``` + **Example response**: ```json