|
1 | | -# thumbly |
2 | | -It's a HTTP server to generate thumbnails on demand. |
| 1 | +# Thumbly is a on-demand image server for generating thumbnail dynamically. |
| 2 | +- It dynamically generate thumbnail image on request. |
| 3 | +- Generated thumbnails are cached in disk. |
| 4 | +- It provide secret url that is automatically deleted after specific time. |
| 5 | +- It use Imagemagick for image processing |
3 | 6 |
|
4 | | -Thumbly is not Mably |
| 7 | + |
| 8 | +# Supported image format |
| 9 | +* JPG |
| 10 | +* GIF |
| 11 | +* PNG |
| 12 | +* WEBP |
| 13 | + |
| 14 | + |
| 15 | +# Dependency |
| 16 | +* Imagemagick |
| 17 | + * https://www.imagemagick.org |
| 18 | + * Thumbly use Imagemagick for image processing |
| 19 | + |
| 20 | + |
| 21 | +# Configuration |
| 22 | + |
| 23 | +## app_config.yml |
| 24 | +It's application configuration file. |
| 25 | +```yaml |
| 26 | +# Server port |
| 27 | +port: |
| 28 | + main_http: 57910 |
| 29 | + api_http: 57911 |
| 30 | + |
| 31 | +# Cache configuration |
| 32 | +cache: |
| 33 | + root_directory: ".cache" |
| 34 | + total_size_of_origin_images: "1G" |
| 35 | + total_size_of_thumbnail_images: "1G" |
| 36 | +``` |
| 37 | +
|
| 38 | +## channel_config.yml |
| 39 | +It's channel configuration file. |
| 40 | +```yaml |
| 41 | +# Example-1 |
| 42 | +thumbly_example1: |
| 43 | + browser_cache_expiration: "3600s" |
| 44 | + normal_url_enabled: true |
| 45 | + secret_url_enabled: true |
| 46 | + type: "http" |
| 47 | + base_url: "https://data.forsnap.com" |
| 48 | + |
| 49 | +# Example-2 |
| 50 | +thumbly_example2: |
| 51 | + browser_cache_expiration: "3600s" |
| 52 | + normal_url_enabled: true |
| 53 | + secret_url_enabled: false |
| 54 | + type: "http" |
| 55 | + base_url: "https://data.forsnap.com" |
| 56 | + |
| 57 | +# Example-3 |
| 58 | +thumbly_example3: |
| 59 | + browser_cache_expiration: "3600s" |
| 60 | + normal_url_enabled: false |
| 61 | + secret_url_enabled: true |
| 62 | + type: "aws_s3" |
| 63 | + access_key: "" |
| 64 | + secret_key: "" |
| 65 | + region: "" |
| 66 | + bucket: "" |
| 67 | +``` |
| 68 | +
|
| 69 | +## logback.xml |
| 70 | +It's Logback configuration file that is famous logging library. |
| 71 | +* You can send error log to Telegram. |
| 72 | + 1. Uncomment *Telegram* configuration. |
| 73 | + 2. Set value of `<botToken>` and `<chatId>`. |
| 74 | + ```xml |
| 75 | + <appender name="TELEGRAM" class="com.github.paolodenti.telegram.logback.TelegramAppender"> |
| 76 | + <botToken></botToken> |
| 77 | + <chatId></chatId> |
| 78 | + ... |
| 79 | + </appender> |
| 80 | + ``` |
| 81 | + 3. Insert `<appender-ref ref="TELEGRAM"/>` into `<root>` |
| 82 | + ```xml |
| 83 | + <root level="WARN"> |
| 84 | + <appender-ref ref="FILE"/> |
| 85 | + <appender-ref ref="TELEGRAM"/> |
| 86 | + </root> |
| 87 | + ``` |
| 88 | +* You can send error log to Slack. |
| 89 | + 1. Uncomment *Slack* configuration. |
| 90 | + 2. Set value of `<webhookUri>`. |
| 91 | + ```xml |
| 92 | + <appender name="SLACK_SYNC" class="com.github.maricn.logback.SlackAppender"> |
| 93 | + <webhookUri></webhookUri> |
| 94 | + ... |
| 95 | + </appender> |
| 96 | + ``` |
| 97 | + 3. Insert `<appender-ref ref="SLACK"/>` into `<root>` |
| 98 | + ```xml |
| 99 | + <root level="WARN"> |
| 100 | + <appender-ref ref="FILE"/> |
| 101 | + <appender-ref ref="SLACK"/> |
| 102 | + </root> |
| 103 | + ``` |
| 104 | +* You can reload configuration but need not to restart application. |
| 105 | + |
| 106 | + |
| 107 | +# Server |
| 108 | +Thumbly has two servers. |
| 109 | +One is a main server that generate thumbnail |
| 110 | +The other is a restful API server that provide application information and additional functions. |
| 111 | + |
| 112 | +## Main HTTP Server |
| 113 | +### Usage |
| 114 | +```html |
| 115 | +http://example.com:{port}/{command}/{channel}/{path} |
| 116 | +``` |
| 117 | +* port |
| 118 | + * Server port |
| 119 | + * It's *main_http* in app_config.yml. |
| 120 | +* command |
| 121 | + * Thumbnail command |
| 122 | + * Command syntax : type-size-format-quality |
| 123 | + * Example |
| 124 | + * thumb-200x0-webp-100 |
| 125 | + * resize-200x200-origin |
| 126 | + * origin |
| 127 | + * thumb-0x200 |
| 128 | + * resize-100x100-origin-50 |
| 129 | + * origin-origin-origin-50 |
| 130 | +* channel |
| 131 | + * Channel name |
| 132 | + * It's *channel* in channel_config.yml |
| 133 | +* path |
| 134 | + * Origin path |
| 135 | + |
| 136 | +### Example |
| 137 | +```html |
| 138 | +http://example.com:57910/thumb-200x0-webp/thumbly_exampl1/test.jpg |
| 139 | +``` |
| 140 | + |
| 141 | +## API HTTP Server |
| 142 | +### Usage |
| 143 | +```html |
| 144 | +http://example.com:{port}/{domain}/{method} |
| 145 | +``` |
| 146 | + |
| 147 | +### Example |
| 148 | +```html |
| 149 | +http://example.com:57911/app/status |
| 150 | +http://example.com:57911/app/hello |
| 151 | +http://example.com:57911/app/ping |
| 152 | +``` |
| 153 | + |
| 154 | +### API |
| 155 | +#### GET /cache/origin/{channel}/{path} |
| 156 | +* Get cached origin image information |
| 157 | +##### Response |
| 158 | +```json |
| 159 | +{ |
| 160 | + "data": { |
| 161 | + "responseHeaders": { |
| 162 | + "cacheControl": "public", |
| 163 | + "contentLength": "7189763", |
| 164 | + "contentType": "image/jpeg", |
| 165 | + "date": "Sun, 16 Sep 2018 13:58:52 GMT", |
| 166 | + "etag": "\"5a66f210-6db503\"", |
| 167 | + "expires": "Sun, 16 Sep 2018 14:03:52 GMT", |
| 168 | + "lastModified": "Tue, 23 Jan 2018 08:28:00 GMT" |
| 169 | + }, |
| 170 | + "fileSize": 7189763, |
| 171 | + "filePath": ".cache/origin/e146f95f6e015c9999fb2f4ec4a9f041.jpg", |
| 172 | + "lastAccessedTimeSeconds": 0, |
| 173 | + "expiredTimeSeconds": 1537106634, |
| 174 | + "url": "https://data.forsnap.com/product/ae/934/portfolio5a66f20fbe831.jpg" |
| 175 | + } |
| 176 | +} |
| 177 | +``` |
| 178 | + |
| 179 | +#### DELETE /cache/origin/{channel}/{path} |
| 180 | +* Delete cached origin image (Purge) |
| 181 | +##### Response |
| 182 | +```json |
| 183 | +{"data": true} |
| 184 | +``` |
| 185 | + |
| 186 | +#### GET /image/secret/{secretPath} |
| 187 | +* Get secret url information |
| 188 | +##### Response |
| 189 | +```json |
| 190 | +{ |
| 191 | + "data": { |
| 192 | + "expired": 87, |
| 193 | + "originPath": "thumb-270x0-webp/thumbly_example1/product/ae/934/portfolio5a66f20fbe831.jpg" |
| 194 | + } |
| 195 | +} |
| 196 | +``` |
| 197 | + |
| 198 | +#### POST /image/secret |
| 199 | +* Set secret url |
| 200 | +##### Request |
| 201 | +```json |
| 202 | +{ |
| 203 | + "data": [ |
| 204 | + { |
| 205 | + "secretPath":"test3", |
| 206 | + "originPath":"thumb-270x0-webp/thumbly_example1/product/ae/934/portfolio5a66f20fbe831.jpg", |
| 207 | + "expired":100, |
| 208 | + } |
| 209 | + ] |
| 210 | +} |
| 211 | +``` |
| 212 | +##### Response |
| 213 | +```json |
| 214 | +{ |
| 215 | + "data": [ |
| 216 | + { |
| 217 | + "result": true, |
| 218 | + "expired": 100, |
| 219 | + "originPath": "thumb-270x0-webp/thumbly_example1/product/ae/934/portfolio5a66f20fbe831.jpg", |
| 220 | + "secretPath": "test3" |
| 221 | + } |
| 222 | + ] |
| 223 | +} |
| 224 | +``` |
| 225 | + |
| 226 | + |
| 227 | +#### GET /app/status |
| 228 | +* Get application status and environment. |
| 229 | +##### Response |
| 230 | +```json |
| 231 | +{ |
| 232 | + "data":{ |
| 233 | + "applicationVersion":"0.1.0-alpha.3", |
| 234 | + "cpuUsage":2.56, |
| 235 | + "threadInfo":{...}, |
| 236 | + "vmMemoryFree":"190M", |
| 237 | + "javaVersion":"1.8.0_25", |
| 238 | + "vmMemoryMax":"3,641M", |
| 239 | + "currentDate":"2018-09-16T18:48:58.795+09:00", |
| 240 | + "threadCount":15, |
| 241 | + "startedDate":"2018-09-16T18:48:40.901+09:00", |
| 242 | + "javaVendor":"", |
| 243 | + "runningTimeHour":0, |
| 244 | + "osName":"Mac OS X", |
| 245 | + "cpuProcessorCount":4, |
| 246 | + "vmMemoryTotalFree":"3,585M", |
| 247 | + "hostname":"", |
| 248 | + "osVersion":"10.11.6", |
| 249 | + "jarFile":"code13k-thumbly-0.1.0-alpha.3.jar", |
| 250 | + "vmMemoryAllocated":"245M", |
| 251 | + } |
| 252 | +} |
| 253 | +``` |
| 254 | +#### GET /app/hello |
| 255 | +* Hello, World |
| 256 | +##### Response |
| 257 | +```json |
| 258 | +{"data":"world"} |
| 259 | +``` |
| 260 | + |
| 261 | +#### GET /app/ping |
| 262 | +* Ping-Pong |
| 263 | +##### Response |
| 264 | +```json |
| 265 | +{"data":"pong"} |
0 commit comments