Micro-service for file storage and processing written in Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
4.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. # Lithium
  2. Micro-service for file storage and processing written in Go.
  3. ## Features
  4. - Image processing pipelines for various transformations
  5. - Web API for storing & retrieving files
  6. ## Requirements
  7. - [Go 1.17+](https://go.dev/)
  8. - [_Docker_](https://docs.docker.com/) (optional)
  9. ## Setup
  10. #### 1. Clone repository
  11. ```shell
  12. git clone git@gogs.informatik.hs-fulda.de:FabianVowie/Lithium.git
  13. ```
  14. #### 2. Pull dependencies
  15. ```shell
  16. go get
  17. ```
  18. #### 3. Build & start application
  19. ```shell
  20. go run .
  21. ```
  22. **Run using [Docker](https://docs.docker.com/) container**
  23. ```shell
  24. docker run --rm -p 8000:8000 -v "$PWD":/usr/src/lithium -w /usr/src/lithium golang:1.17 go run .
  25. ```
  26. ## Testing
  27. ```shell
  28. go test ./...
  29. ```
  30. ### Run tests in verbose logging mode
  31. ```shell
  32. go test ./... -v
  33. ```
  34. ### Run tests in [Docker](https://docs.docker.com/) container
  35. ```shell
  36. docker run --rm -v "$PWD":/usr/src/lithium -w /usr/src/lithium golang:1.17 go test ./...
  37. ```
  38. ## Configuration
  39. Config options can be adjusted via the [`settings.json`](settings.json) file in the root directory.
  40. ```json
  41. {
  42. "endpoint": "0.0.0.0:8000",
  43. "token": "changeme",
  44. "rate_limiter": {
  45. "requests_per_minute": 20,
  46. "allowed_burst": 5
  47. },
  48. "storage_provider": {
  49. "type": 0,
  50. "base_path": "assets"
  51. }
  52. }
  53. ```
  54. ## Rate Limiting
  55. By default, the rate limiting takes place on a per-route basis. When the limit for a specific route is hit, the response will return a status code `429: Too Many Requests`.
  56. | Headers | Explanation |
  57. | --------------------- | -------------------------------- |
  58. | X-Ratelimit-Limit | Allowed requests per minute |
  59. | X-Ratelimit-Remaining | Remaining requests |
  60. | X-Ratelimit-Reset | Seconds until requests replenish |
  61. ## API
  62. ### `GET` `/`
  63. Show application information.
  64. **Required headers**:
  65. ```shell
  66. Authorization: Bearer <Token>
  67. ```
  68. **Example response**:
  69. ```json
  70. {
  71. "name": "Lithium",
  72. "version": "0.1.0"
  73. }
  74. ```
  75. ### `GET` `/pipelines/{pipeline}`
  76. Show pipeline information.
  77. **Required headers**:
  78. ```shell
  79. Authorization: Bearer <Token>
  80. ```
  81. **Example response**:
  82. ```json
  83. {
  84. "name": "example pipeline",
  85. "slug": "example",
  86. "type": 0,
  87. "remove_metadata": false,
  88. "steps": [
  89. {
  90. "name": "resize image",
  91. "type": 0,
  92. "options": {
  93. "width": 1280,
  94. "height": 720,
  95. "upscale": false
  96. }
  97. }
  98. ],
  99. "output": {
  100. "format": "jpg",
  101. "quality": 90
  102. }
  103. }
  104. ```
  105. ## Pipelines
  106. The project uses a pipeline system defined by [JSON](https://en.wikipedia.org/wiki/JSON) files located in the [config](config) folder.
  107. Take a look at the [example pipeline configuration file](config/example.json).
  108. Available pipeline `type`s: `0` (Image), `1` (Video)
  109. ```json
  110. {
  111. "name": "example pipeline",
  112. "slug": "example",
  113. "type": 0,
  114. "removeMetadata": false,
  115. "steps": [],
  116. "output": {}
  117. }
  118. ```
  119. ### Images pipeline
  120. The image pipeline offers the following additional output options.
  121. Available `format` types: `jpg` (or `jpeg`), `png`, `gif`, `tif` (or `tiff`) and `bmp`
  122. The `quality` field can contain any integer between 1 and 100.
  123. ```json
  124. {
  125. "output": {
  126. "format": "jpg",
  127. "quality": 90
  128. }
  129. }
  130. ```
  131. ### Available pipeline steps
  132. Each pipeline step consists of an optional `name`, a predefined `type` and configurable `options`.
  133. See the available options below for more information.
  134. ```json
  135. {
  136. "name": "step name",
  137. "type": 0,
  138. "options": {}
  139. }
  140. ```
  141. #### Resizing images
  142. Resize an image by a given `width` and `height`.
  143. **Step definition**:
  144. ```json
  145. {
  146. "type": 0,
  147. "options": {
  148. "width": 1280,
  149. "height": 720
  150. }
  151. }
  152. ```
  153. #### Rotating images
  154. Rotate an image with a given `angle` in degrees.
  155. **Step definition**:
  156. ```json
  157. {
  158. "type": 1,
  159. "options": {
  160. "angle": 90.0
  161. }
  162. }
  163. ```
  164. #### Flipping images
  165. Flip an image with a given direction.
  166. Allowed values for the `direction` option are `"h"` (horizontal), `"v"` (vertical)
  167. **Step definition**:
  168. ```json
  169. {
  170. "type": 2,
  171. "options": {
  172. "direction": "h"
  173. }
  174. }
  175. ```
  176. #### Grayscale
  177. Convert the colorspace of an image into grayscale.
  178. **Step definition**:
  179. ```json
  180. {
  181. "type": 3
  182. }
  183. ```
  184. #### Fit
  185. Scales down the image to fit the specified maximum width and height.
  186. **Step definition**:
  187. ```json
  188. {
  189. "type": 4,
  190. "options": {
  191. "height": 300,
  192. "width": 200
  193. }
  194. }
  195. ```
  196. #### Invert
  197. Invert image colors.
  198. **Step definition**:
  199. ```json
  200. {
  201. "type": 5
  202. }
  203. ```
  204. #### Blur
  205. Blur image using Gaussian functions.
  206. **Step definition**:
  207. ```json
  208. {
  209. "type": 6,
  210. "options": {
  211. "sigma": 50.0
  212. }
  213. }
  214. ```
  215. ## Authors
  216. - [Fabian Vowie](https://gogs.informatik.hs-fulda.de/FabianVowie)
  217. - [Roman Zipp](https://gogs.informatik.hs-fulda.de/roman.zipp)