From 9e3ec5de55522c2cd91add24985bc8b8ec80ac16 Mon Sep 17 00:00:00 2001 From: Lumither Tao Date: Fri, 31 May 2024 15:32:05 +0800 Subject: [PATCH] release(V20240531) --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.sh | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e69de29..1f77754 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,65 @@ +# `s3medul`: S3 Media Uploader + +`s3medul` is a shell script designed for bloggers that use s3 compatible storage to serve their image/media. + +It will automatically compress and upload images to the s3 storage, and print the remote address of its different +versions. + +## Requirements + +- `ffmpeg`: Convert any format of media to png for compatibility +- `cwebp`: Convert png image to webp format +- [`pngquant`](https://github.com/kornelski/pngquant): Compress png media +- `openssl`: Authentication +- `curl`: HTTP client + +## Usage + +```bash +main.sh +``` + +For example: + +```bash +main.sh ./test.jpg ./test.png ./test/* +``` + +## Configuration + +in the `.env` in the dir: + +```dotenv +S3KEY=xxx # S3 Access Key +S3SECRET=xxxxx # S3 Sccret Key +S3BUCKET=xxxxxx # S3 Bucket Name +S3ENDPOINT=xxxxx # S3 Server Address +``` + +Here is an example (non-working): + +```dotenv +S3KEY=AKIAIOSFODNN7EXAMPLE +S3SECRET=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY +S3BUCKET=blog +S3ENDPOINT=oss.example.com +``` + +## Example + +```bash +~/Pictures/Hongkai 3rd > tree +. +└── Elysia&Eden.jpg + +1 directory, 1 file +~/Pictures/Hongkai 3rd > ~/dev/s3medul/main.sh ./* +/tmp/s3medul/1717140478071754403/orig/1717140478080742716_Elysia&Eden.jpg - 3.7M + -> https://oss.example.com/blog/pictures/orig/1717140478080742716_Elysia&Eden.jpg + +/tmp/s3medul/1717140478071754403/compr/1717140478080742716_Elysia&Eden.png - 2.5M + -> https://oss.example.com/blog/pictures/compr/1717140478080742716_Elysia&Eden.png + +/tmp/s3medul/1717140478071754403/compr/1717140478080742716_Elysia&Eden.webp - 308K + -> https://oss.example.com/blog/pictures/compr/1717140478080742716_Elysia&Eden.webp +``` diff --git a/main.sh b/main.sh index d7fdf70..cb0600b 100755 --- a/main.sh +++ b/main.sh @@ -67,7 +67,7 @@ function s3upload() { -H "Content-Type: ${content_type}" \ -H "Authorization: AWS ${S3KEY}:${signature}" \ "https://${S3ENDPOINT}${resource}" - printf "${file}\n\t-> https://${S3ENDPOINT}${resource}\n\n" + printf "%s - %s\n\t-> https://%s%s\n\n" "${file}" "$(du -sh "$file" | sed 's/\s.*//')" "${S3ENDPOINT}" "${resource}" } # push orig img