47 Commits

Author SHA1 Message Date
d94c9bf4e6 novalagung is going to love this.
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 3m13s
2025-05-22 20:28:01 -04:00
f00f9b0946 forgot a contact page woops haha
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 5m7s
2025-05-22 20:18:20 -04:00
b0d4f3f890 Updated
Some checks failed
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Has been cancelled
2025-05-22 20:15:01 -04:00
e9e0d30c7a [FIX] asdf
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 1m44s
2025-05-22 18:46:03 -04:00
0c458dd965 you do wanna make me cry and i wanna say goodbye
Some checks failed
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Has been cancelled
2025-05-22 18:38:25 -04:00
2b865568c0 That last commit was cringe
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 8m33s
2025-05-20 16:55:07 -04:00
05fc22e966 Plloi rebase plx?
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 5m18s
2025-05-20 16:37:16 -04:00
6159a1509d I'm sorry.
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 2m10s
2025-05-20 16:33:43 -04:00
e86c892b8f Fixing JC6's bug.
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 11m23s
2025-05-20 15:11:49 -04:00
61f42c5297 Nitpicking about alphabetizing methods, minor OCD thing
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 2m9s
2025-05-20 14:41:20 -04:00
17971f34c1 Programming the flux capacitor
Some checks failed
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Has been cancelled
2025-05-20 14:31:53 -04:00
d66dbe89cb happy monday _ bleh _
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 5m26s
2025-05-20 11:18:41 -04:00
9af291f4d2 copy and paste is not a design pattern
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 3m37s
2025-05-13 22:02:03 -04:00
3a61962c04 I expected something different.
Some checks failed
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Failing after 3m7s
2025-05-13 21:55:09 -04:00
7a8d0714f5 bara bra grejjor
Some checks failed
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Has been cancelled
2025-05-13 21:54:32 -04:00
bcd287b3b3 asdfasdfasdfasdfasdfasdfadsf
Some checks failed
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Failing after 2m24s
2025-05-13 21:47:47 -04:00
2b1e5561a0 They came from... Behind 2025-05-13 21:44:19 -04:00
6804c31a33 Is there an achievement for this? 2025-05-13 10:04:59 -04:00
d890bcbd2e It's time to go home 2025-05-13 10:04:17 -04:00
Ron Rise
dda3961e0e Merge pull request #20 from siteworxpro/interactive
Some checks failed
Go Tests / build (1.22.x) (push) Failing after 4m35s
Interactive
2025-05-13 09:51:46 -04:00
f6bc6231e5 lets drink beer 2025-05-13 09:50:04 -04:00
23629a40a8 Batman! (this commit has no parents) 2025-05-13 09:49:02 -04:00
9dbd7ecab8 We should get someone from Purdue to do this. They are the boilerplaters. 2025-05-12 22:58:55 -04:00
48d7730a5c derp, helper method rename 2025-05-12 21:58:17 -04:00
0aa8065640 Fixed some shit 2025-05-12 20:24:55 -04:00
e3271ea47a Updated go version 1.24.0 2025-02-25 09:13:08 -05:00
85938a2def Code re-organization
Some checks failed
Go Tests / build (1.22.x) (push) Failing after 1m27s
2025-01-26 18:20:45 -05:00
b93d1c29b8 Updates 2024-12-26 11:38:31 -05:00
0ab36c5ea6 grpc
Some checks failed
Go Tests / build (1.22.x) (push) Failing after 1m43s
2024-11-17 12:32:29 -05:00
4d2a7418cb Added grpc web service 2024-11-17 11:22:49 -05:00
1ad11d7e08 Added grpc web service 2024-11-17 11:07:26 -05:00
1f1cd68192 merged master
Some checks failed
Go Tests / build (1.22.x) (push) Failing after 5m6s
2024-11-17 09:20:38 -05:00
3f8408cfd8 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	go.sum
2024-11-17 09:19:49 -05:00
4803855e61 Added web service 2024-11-17 09:19:31 -05:00
Ron Rise
96f8d521ee Merge pull request #10 from siteworxpro/dependabot/go_modules/github.com/charmbracelet/lipgloss-0.13.0
Bump github.com/charmbracelet/lipgloss from 0.12.1 to 0.13.0
2024-09-15 09:28:55 -04:00
dependabot[bot]
b2637fcddb Bump github.com/charmbracelet/lipgloss from 0.12.1 to 0.13.0
Bumps [github.com/charmbracelet/lipgloss](https://github.com/charmbracelet/lipgloss) from 0.12.1 to 0.13.0.
- [Release notes](https://github.com/charmbracelet/lipgloss/releases)
- [Changelog](https://github.com/charmbracelet/lipgloss/blob/master/.goreleaser.yml)
- [Commits](https://github.com/charmbracelet/lipgloss/compare/v0.12.1...v0.13.0)

---
updated-dependencies:
- dependency-name: github.com/charmbracelet/lipgloss
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-21 10:11:25 +00:00
a773b38794 Merge branch 'master' of github.com:siteworxpro/img-proxy-url-generator
Some checks failed
Go Tests / build (1.22.x) (push) Failing after 1m53s
2024-07-12 21:01:55 -04:00
287d80ce86 Add browser 2024-07-12 20:59:54 -04:00
Ron Rise
398ec7af81 Update README.md
Signed-off-by: Ron Rise <29732851+ronrise@users.noreply.github.com>
2024-07-09 10:20:06 -04:00
d0e55c9a6b Signing builds 2024-05-17 09:00:34 -04:00
0271d575ab added dependabot
Some checks failed
Go Tests / build (1.22.x) (push) Failing after 5m25s
2024-05-07 14:20:54 -04:00
a834bc6384 added tests
updated go version and packages
2024-05-07 14:14:28 -04:00
Ron Rise
889ba3cb48 Update issue templates 2024-04-23 16:30:05 -04:00
Ron Rise
1e75f7823b Create LICENSE
Signed-off-by: Ron Rise <29732851+ronrise@users.noreply.github.com>
2024-04-23 16:29:15 -04:00
e8eff432fc code cleanup 2024-04-23 10:27:07 -04:00
984909a648 readme updated 2024-04-23 09:03:06 -04:00
0d4a7fdb94 build script 2024-04-23 08:59:55 -04:00
53 changed files with 2826 additions and 254 deletions

View File

@@ -0,0 +1,46 @@
on:
create:
tags:
- 'v*'
name: 🏗️✨ Build Workflow
jobs:
Build:
name: 🖥️ 🔨 Build
runs-on: ubuntu-latest
steps:
- name: 🛡️ 🔒 Add Siteworx CA Certificates
run: |
curl -Ls https://siteworxpro.com/hosted/Siteworx+Root+CA.pem -o /usr/local/share/ca-certificates/sw.crt
update-ca-certificates
- name: 📖 🔍 Checkout Repository Code
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: 🔑 🔐 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: 🏗️ 🔧 Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Replace entrypoint
run: |
sed -i 's/server/grpc/g' Dockerfile
sed -i 's/8080/9000/g' Dockerfile
- name: 🐳 🔨 Build Grpc Container
uses: docker/build-push-action@v6
with:
sbom: true
provenance: true
platforms: linux/arm64,linux/amd64
context: .
dockerfile: Dockerfile
push: true
tags: siteworxpro/img-proxy-url-generator:${{ gitea.ref_name }}-grpc

View File

@@ -0,0 +1,41 @@
on:
create:
tags:
- 'v*'
name: 🏗️✨ Build Workflow
jobs:
Build:
name: 🖥️ 🔨 Build
runs-on: ubuntu-latest
steps:
- name: 🛡️ 🔒 Add Siteworx CA Certificates
run: |
curl -Ls https://siteworxpro.com/hosted/Siteworx+Root+CA.pem -o /usr/local/share/ca-certificates/sw.crt
update-ca-certificates
- name: 📖 🔍 Checkout Repository Code
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: 🔑 🔐 Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: 🏗️ 🔧 Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 🐳 🔨 Build Server Container
uses: docker/build-push-action@v6
with:
sbom: true
provenance: true
platforms: linux/arm64,linux/amd64
context: .
dockerfile: Dockerfile
push: true
tags: siteworxpro/img-proxy-url-generator:${{ gitea.ref_name }}

View File

@@ -0,0 +1,38 @@
on:
push:
branches:
- "*"
name: 🧪 ✨ Unit Tests Workflow
jobs:
test-go:
env:
GO_VERSION: '1.24.3'
name: 🔍 🐹 Go Tests
runs-on: ubuntu-latest
steps:
- name: 🛡️ 🔒 Add Siteworx CA Certificates
run: |
curl -Ls https://siteworxpro.com/hosted/Siteworx+Root+CA.pem -o /usr/local/share/ca-certificates/sw.crt
update-ca-certificates
- name: ⚙️ 🐹 Set up Go Environment
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: 📖 🔍 Checkout Repository Code
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: 📦 📥 Install Dependencies
run: |
go mod download
- name: ✅ 🔍 Run Go Tests
run: |
go test -v ./... -coverprofile=coverage.out

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.DS_Store
.idea/
main
imgproxy

26
Dockerfile Normal file
View File

@@ -0,0 +1,26 @@
FROM siteworxpro/golang:1.24.3 AS build
WORKDIR /app
ADD . .
ENV GOPRIVATE=git.siteworxpro.com
ENV GOPROXY=direct
ENV CGO_ENABLED=0
RUN go mod tidy && go build -o imgproxy .
FROM alpine:latest AS runtime
EXPOSE 8080
WORKDIR /app
COPY --from=build /app/imgproxy /app/imgproxy
RUN adduser -u 1001 -g appuser appuser -D && \
chown -R appuser:appuser /app
USER 1001
ENTRYPOINT ["/app/imgproxy", "server"]

201
LICENSE Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1,25 +1,29 @@
# img-proxy url generator
[host](https://docs.imgproxy.net/installation) an instance of img-proxy
img proxy [docs](https://docs.imgproxy.net/usage/processing)
## build
you can optionally hard code a path prefix on build
you can optionally hard code a path prefix when building
```shell
go build --ldflags="-X 'github.com/siteworxpro/img-proxy-url-generator/generator.PathPrefix=s3://mybucket'"
```
## config file
###### params
### params
[img-proxy]
- `key` sha256 hmac key
- `salt` sha256 hmac salt
- `host` img-proxy server hostname
- `encryption-key` aes encryption key
- `plain-url` send plain filename. bypasses all encoding
- `plain-url` bypasses all encoding and uses plain filename
example config file
```ini
[img-proxy]
key=2c...47
@@ -29,7 +33,18 @@ encryption-key=1c...0b
plain-url=1
```
## usage
## usage examples
### interactive
```shell
./imgproxy interactive
```
![img](./assets/interactive.gif)
### command line
generate a plain url with an insecure signature
```ini
@@ -73,7 +88,7 @@ salt=3f...4a
https://i.fooo.com/NIColt6GBjtbquJXAtEMMsptARPw0CdeduEcu-S9Voc/raw:1/bG9jYWw6Ly9teS1zdXBlci1pbWFnZS5wbmc
```
generate an encrypted url
generate an encrypted url with a signature
```ini
[img-proxy]
host=https://i.fooo.com
@@ -88,7 +103,7 @@ encryption-key=1c...0b
https://i.fooo.com/m3YtaMSgL86qCnfKCnS2i9_vLRmJSogdBx1o86cWbuc/raw:1/enc/F6FAWktv2SAFe5UQwMme0pB6JwKQJVtTI_6Xx-PUfKANdQk0pD1I13NPnv0CvkFT
```
generate a url with params
generate with params
```bash
./imgproxy --image "local:///my-super-image.png" -p h:200 -p rot:90
@@ -96,9 +111,48 @@ https://i.fooo.com/q-CfgLiuHTXDiZg7vBsUbZB3nkhzfsPgNrK0x20b878/h:200/rot:90/sm:1
```
generate a url a format
generate a url with a specified format
```bash
./imgproxy --image "local:///my-super-image.png" --format bmp -p h:200
https://i.fooo.com/UMkz4OUNw6P9ShLdewuvW3ValMgCt263vZzU5gN57WQ/h:200/sm:1/enc/ECYxMeVBTjRxB7F-jdQ7W_-Fnv4YbmSJIKie-Hdtxd9vsmEKjU1YuWVSzdN97Mod.bmp
```
## decryption
if you need to decrypt a url you have already created just copy the encrypted portion of the url
```shell
./imgproxy decrypt -u ECYxMeVBTjRxB7F-jdQ7W_-Fnv4YbmSJIKie-Hdtxd9vsmEKjU1YuWVSzdN97Mod
```
## web service
you can also serve request via a web request
```shell
./imgproxy server
```
```shell
curl --location 'http://localhost:8080/generate' \
--header 'Content-Type: application/json' \
--data '{
"image": "s3://my.image.bucket/C81A0923.jpg",
"params": [
"q:40",
"w:400"
],
"format": "bmp"
}'
```
`https://i.fooo.com/UMkz4OUNw6P9ShLdewuvW3ValMgCt263vZzU5gN57WQ/h:200/sm:1/enc/ECYxMeVBTjRxB7F-jdQ7W_-Fnv4YbmSJIKie-Hdtxd9vsmEKjU1YuWVSzdN97Mod.bmp`
## gRPC server
you can also serve request via a gRPC request
```shell
./imgproxy grpc
```
```
listening on :9000
```

7
Taskfile.yaml Normal file
View File

@@ -0,0 +1,7 @@
version: '3'
tasks:
proto-build:
cmds:
- protoc --go_out=grpc --proto_path=grpc --go_opt=paths=source_relative --php_out=grpc/php/src --go-grpc_out=grpc --go-grpc_opt=paths=source_relative $(find grpc -iname "*.proto")
silent: true

BIN
assets/interactive.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 686 KiB

38
aws/client.go Normal file
View File

@@ -0,0 +1,38 @@
package aws
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/siteworxpro/img-proxy-url-generator/config"
)
type Service struct {
s3 *s3.S3
bucket string
}
func NewClient(config *config.Config) *Service {
var accessCredentials *credentials.Credentials
staticCredentials := credentials.NewStaticCredentials(config.Aws.AwsKey, config.Aws.AwsSecret, config.Aws.AwsToken)
awsSession := session.Must(session.NewSession(&aws.Config{
Credentials: staticCredentials,
Region: aws.String("us-east-1"),
}))
if config.Aws.AwsRole != "" {
assumeRoleCredentials := stscreds.NewCredentials(awsSession, config.Aws.AwsRole)
accessCredentials = assumeRoleCredentials
} else {
accessCredentials = staticCredentials
}
return &Service{
s3: s3.New(awsSession, &aws.Config{Credentials: accessCredentials}),
bucket: config.Aws.AwsBucket,
}
}

52
aws/s3.go Normal file
View File

@@ -0,0 +1,52 @@
package aws
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
)
type Image struct {
Url string
Download string
Name string
S3Path string
}
type BucketList struct {
Images []Image
StartAfter string
}
func (s *Service) ListBucketContents(continuationToken *string) (*BucketList, error) {
v2, err := s.s3.ListObjectsV2(&s3.ListObjectsV2Input{
Bucket: aws.String(s.bucket),
MaxKeys: aws.Int64(20),
ContinuationToken: continuationToken,
})
if err != nil {
return nil, err
}
bucketList := BucketList{
Images: make([]Image, 0),
}
if v2.NextContinuationToken != nil {
bucketList.StartAfter = *v2.NextContinuationToken
}
for _, item := range v2.Contents {
if *item.Size == 0 {
continue
}
image := Image{
Name: *item.Key,
S3Path: "s3://" + s.bucket + "/" + *item.Key,
}
bucketList.Images = append(bucketList.Images, image)
}
return &bucketList, nil
}

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
go install
go mod tidy
for distro in $(go tool dist list)
do
@@ -8,6 +8,7 @@ do
if [[ ${arrIN[0]} == 'linux' || ${arrIN[0]} == 'darwin' || ${arrIN[0]} == 'freebsd' || ${arrIN[0]} == 'windows' ]]; then
echo "Building $distro..."
GOOS=${arrIN[0]} GOARCH=${arrIN[1]} go build --ldflags="-X 'main.Version=$(git describe --tags --abbrev=0)'" -o dist/img_proxy_${arrIN[0]}_${arrIN[1]}
GOOS=${arrIN[0]} GOARCH=${arrIN[1]} GO111MODULE=on CGO_ENABLED=0 go build --ldflags="-X 'main.Version=$(git describe --tags --abbrev=0)'" -o "dist/img-proxy-url-generator_${arrIN[0]}_${arrIN[1]}"
gpg --detach-sign "dist/img-proxy-url-generator_${arrIN[0]}_${arrIN[1]}"
fi
done

43
commands/decrypt.go Normal file
View File

@@ -0,0 +1,43 @@
package commands
import (
"github.com/siteworxpro/img-proxy-url-generator/config"
"github.com/siteworxpro/img-proxy-url-generator/generator"
"github.com/siteworxpro/img-proxy-url-generator/printer"
"github.com/urfave/cli/v2"
)
func DecryptCommand() *cli.Command {
return &cli.Command{
Name: "decrypt",
Usage: "decrypt an image url contents",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "url",
Aliases: []string{"u"},
Required: true,
},
},
Action: func(c *cli.Context) error {
pr := printer.NewPrinter()
cfg, err := config.NewConfig(c.String("config"))
if err != nil {
return err
}
ig, err := generator.NewGenerator(cfg)
if err != nil {
return err
}
plain, err := ig.Decrypt(c.String("url"))
if err != nil {
return err
}
pr.LogSuccess(plain)
return nil
},
}
}

79
commands/generate.go Normal file
View File

@@ -0,0 +1,79 @@
package commands
import (
"fmt"
"github.com/siteworxpro/img-proxy-url-generator/config"
"github.com/siteworxpro/img-proxy-url-generator/generator"
"github.com/siteworxpro/img-proxy-url-generator/printer"
"github.com/urfave/cli/v2"
)
func GenerateCommand() *cli.Command {
return &cli.Command{
Name: "generate",
Usage: "Generate an image from a URL",
Action: runGenerate,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "image",
Aliases: []string{"i"},
Required: true,
},
&cli.StringFlag{
Name: "format",
Aliases: []string{"f"},
Usage: "Convert the image to the specified format",
},
&cli.StringSliceFlag{
Name: "params",
Aliases: []string{"p"},
Usage: "Processing options to be passed to the generator ref: https://docs.imgproxy.net/usage/processing",
},
},
}
}
func runGenerate(c *cli.Context) error {
p := printer.NewPrinter()
_, err := config.NewConfig(c.String("config"))
if err != nil {
return err
}
url, err := signURL(c.String("image"), c.StringSlice("params"), c.String("format"))
if err != nil {
return err
}
p.LogInfo("Url Generated...")
println(url)
return nil
}
func signURL(file string, params []string, formatS string) (string, error) {
cfg := config.GetConfig()
if cfg == nil {
return "", fmt.Errorf("config not loaded")
}
ig, err := generator.NewGenerator(cfg)
if err != nil {
return "", err
}
format, err := ig.StringToFormat(formatS)
if err != nil {
return "", err
}
url, err := ig.GenerateUrl(file, params, format)
if err != nil {
return "", err
}
return url, nil
}

53
commands/grpc.go Normal file
View File

@@ -0,0 +1,53 @@
package commands
import (
"fmt"
"github.com/siteworxpro/img-proxy-url-generator/config"
proto "github.com/siteworxpro/img-proxy-url-generator/grpc"
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
"log"
"net"
)
func GrpcCommand() *cli.Command {
return &cli.Command{
Name: "grpc",
Usage: "Start a grpc service",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "port",
Aliases: []string{"p"},
Usage: "Port to listen on",
Required: false,
Value: 9000,
},
},
Action: func(c *cli.Context) error {
cfg, err := config.NewConfig(c.String("config"))
if err != nil {
return err
}
s := grpc.NewServer()
addr := fmt.Sprintf(":%d", c.Int("port"))
println("listening on", addr)
lis, err := net.Listen("tcp", addr)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
svc, err := proto.NewService(cfg)
if err != nil {
log.Fatalf("failed to serve: %v", err)
}
proto.RegisterGeneratorServer(s, svc)
err = s.Serve(lis)
if err != nil {
log.Fatalf("failed to serve: %v", err)
}
return nil
},
}
}

24
commands/interactive.go Normal file
View File

@@ -0,0 +1,24 @@
package commands
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/siteworxpro/img-proxy-url-generator/interactive"
"github.com/urfave/cli/v2"
)
func Interactive() *cli.Command {
return &cli.Command{
Name: "interactive",
Usage: "Start an interactive session",
Action: func(c *cli.Context) error {
p := tea.NewProgram(interactive.InitialModel(c), tea.WithAltScreen())
if _, err := p.Run(); err != nil {
return fmt.Errorf("error running interactive session: %w", err)
}
return nil
},
}
}

22
commands/report.go Normal file
View File

@@ -0,0 +1,22 @@
package commands
import (
"github.com/siteworxpro/img-proxy-url-generator/config"
"github.com/siteworxpro/img-proxy-url-generator/report"
"github.com/urfave/cli/v2"
)
func ReportCommand() *cli.Command {
return &cli.Command{
Name: "report",
Usage: "Generate usage report",
Action: func(c *cli.Context) error {
cf, err := config.NewConfig(c.String("config"))
if err != nil {
return err
}
return report.Handle(cf)
},
}
}

124
commands/server.go Normal file
View File

@@ -0,0 +1,124 @@
package commands
import (
"encoding/json"
"fmt"
"github.com/siteworxpro/img-proxy-url-generator/aws"
"github.com/siteworxpro/img-proxy-url-generator/config"
"github.com/siteworxpro/img-proxy-url-generator/generator"
"github.com/siteworxpro/img-proxy-url-generator/printer"
"github.com/urfave/cli/v2"
"html/template"
"log"
"net/http"
"os"
"strings"
)
type jsonRequest struct {
Image string `json:"image"`
Params []string `json:"params"`
Format string `json:"format"`
}
func ServerCommand() *cli.Command {
return &cli.Command{
Name: "server",
Usage: "Start a webserver for s3 file browsing and the web service",
Action: func(c *cli.Context) error {
p := printer.NewPrinter()
return startServer(c, p)
},
}
}
func startServer(c *cli.Context, p *printer.Printer) error {
cfg, err := config.NewConfig(c.String("config"))
if err != nil {
return err
}
ig, err := generator.NewGenerator(cfg)
if err != nil {
return err
}
_, err = os.Stat("./templates")
if !os.IsNotExist(err) {
awsClient := aws.NewClient(cfg)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
return
}
contToken := r.URL.Query().Get("next")
var next *string
if contToken == "" {
next = nil
} else {
next = &contToken
}
contents, err := awsClient.ListBucketContents(next)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = w.Write([]byte(err.Error()))
return
}
for i, content := range contents.Images {
contents.Images[i].Url, _ = ig.GenerateUrl("s3://"+cfg.Aws.AwsBucket+"/"+content.Name, []string{"pr:sq"}, "")
contents.Images[i].Download, _ = ig.GenerateUrl("s3://"+cfg.Aws.AwsBucket+"/"+content.Name, []string{""}, "")
}
file, _ := os.ReadFile("./templates/index.gohtml")
tmpl := template.Must(template.New("index").Parse(string(file)))
err = tmpl.Execute(w, contents)
if err != nil {
println(err.Error())
}
})
}
http.HandleFunc("/generate", func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.WriteHeader(404)
return
}
bodyContents := make([]byte, r.ContentLength)
_, _ = r.Body.Read(bodyContents)
jr := jsonRequest{}
err = json.Unmarshal(bodyContents, &jr)
if err != nil {
println(err.Error())
w.WriteHeader(500)
return
}
url, err := signURL(jr.Image, jr.Params, jr.Format)
if err != nil {
println(err.Error())
w.WriteHeader(500)
return
}
log.Println(fmt.Sprintf("%s - [%s] - (%s)", jr.Image, strings.Join(jr.Params, ","), url))
_, _ = w.Write([]byte(url))
})
p.LogSuccess("Starting http server on port 8080. http://localhost:8080")
log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil))
return nil
}

24
config/aws.go Normal file
View File

@@ -0,0 +1,24 @@
package config
import "github.com/bigkevmcd/go-configparser"
type awsConfig struct {
AwsKey string
AwsSecret string
AwsToken string
AwsRegion string
AwsBucket string
AwsRole string
}
func getAwsConfig(p *configparser.ConfigParser) *awsConfig {
ac := &awsConfig{}
ac.AwsKey, _ = p.Get("aws", "key")
ac.AwsSecret, _ = p.Get("aws", "secret")
ac.AwsToken, _ = p.Get("aws", "token")
ac.AwsRegion, _ = p.Get("aws", "region")
ac.AwsBucket, _ = p.Get("aws", "bucket")
ac.AwsRole, _ = p.Get("aws", "role")
return ac
}

54
config/config.go Normal file
View File

@@ -0,0 +1,54 @@
package config
import (
"github.com/bigkevmcd/go-configparser"
"sync"
)
type Config struct {
initializeOnce sync.Once
Generator *GeneratorConfig
Aws *awsConfig
Redis *redisConfig
}
var c *Config
func GetConfig() *Config {
if c == nil {
return nil
}
return c
}
// NewConfig returns a new Config struct
func NewConfig(path string) (*Config, error) {
if path == "" {
path = "imgproxy.cfg"
}
p, err := configparser.NewConfigParserFromFile(path)
if err != nil {
return nil, err
}
c = &Config{}
gc, err := getGeneratorConfig(p)
if err != nil {
return nil, err
}
c.Generator = gc
if p.HasSection("aws") {
c.Aws = getAwsConfig(p)
}
if p.HasSection("redis") {
c.Redis = getRedisConfig(p)
}
return c, nil
}

43
config/generator.go Normal file
View File

@@ -0,0 +1,43 @@
package config
import (
"fmt"
"github.com/bigkevmcd/go-configparser"
)
type GeneratorConfig struct {
Salt []byte
Key []byte
Host string
EncryptionKey string
PlainUrl bool
}
func getGeneratorConfig(p *configparser.ConfigParser) (*GeneratorConfig, error) {
var config string
var err error
gc := &GeneratorConfig{}
if !p.HasSection("img-proxy") {
return nil, fmt.Errorf("config error - [img-proxy] config required")
}
config, _ = p.Get("img-proxy", "key")
gc.Key = []byte(config)
config, _ = p.Get("img-proxy", "salt")
gc.Salt = []byte(config)
if config, err = p.Get("img-proxy", "host"); err != nil {
return nil, err
}
gc.Host = config
config, _ = p.Get("img-proxy", "plain-url")
gc.PlainUrl = config == "true" || config == "1"
config, _ = p.Get("img-proxy", "encryption-key")
gc.EncryptionKey = config
return gc, nil
}

19
config/redis.go Normal file
View File

@@ -0,0 +1,19 @@
package config
import "github.com/bigkevmcd/go-configparser"
type redisConfig struct {
Host string
Port string
Password string
DB string
}
func getRedisConfig(p *configparser.ConfigParser) *redisConfig {
rc := &redisConfig{}
rc.Host, _ = p.Get("redis", "host")
rc.Port, _ = p.Get("redis", "port")
rc.Password, _ = p.Get("redis", "password")
rc.DB, _ = p.Get("redis", "db")
return rc
}

7
generator/base64.go Normal file
View File

@@ -0,0 +1,7 @@
package generator
import "encoding/base64"
func (g *Generator) generateBase64Url(file []byte) (string, error) {
return base64.RawURLEncoding.EncodeToString(file), nil
}

27
generator/base64_test.go Normal file
View File

@@ -0,0 +1,27 @@
package generator
import (
"github.com/siteworxpro/img-proxy-url-generator/config"
"testing"
)
func TestGenerator_GenerateBase64(t *testing.T) {
g, err := NewGenerator(&config.Config{
Generator: &config.GeneratorConfig{
Key: []byte("f2d1f37016b7d12ab27b25377f39fd84e2d3368472ff096261ce7ac3e8490af429d43803836ad6a42a3bd9fb859a38137173619cb00bcb6fe3870e3feab2b764"),
Salt: []byte("919ed8813f76abfd42968b10e05258db"),
},
})
if err != nil {
t.Fatal(err)
}
url, err := g.generateBase64Url([]byte("test://file"))
if err != nil {
return
}
if url != "dGVzdDovL2ZpbGU" {
t.Errorf("url is wrong: %s", url)
}
}

85
generator/crypt.go Normal file
View File

@@ -0,0 +1,85 @@
package generator
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"errors"
"io"
)
func pkcs7pad(data []byte, blockSize int) []byte {
padLen := blockSize - len(data)%blockSize
padding := bytes.Repeat([]byte{byte(padLen)}, padLen)
return append(data, padding...)
}
func pkcs7unpad(data []byte) ([]byte, error) {
length := len(data)
if length == 0 {
return nil, errors.New("invalid padding size")
}
padLen := int(data[length-1])
if padLen > length || padLen == 0 {
return nil, errors.New("invalid padding")
}
for _, v := range data[length-padLen:] {
if int(v) != padLen {
return nil, errors.New("invalid padding")
}
}
return data[:length-padLen], nil
}
func (g *Generator) Decrypt(s string) (string, error) {
c, err := aes.NewCipher(g.encryptionKey)
if err != nil {
return "", err
}
decoded, err := base64.RawURLEncoding.DecodeString(s)
if err != nil {
return "", err
}
iv := decoded[:aes.BlockSize]
cryptText := decoded[aes.BlockSize:]
cbc := cipher.NewCBCDecrypter(c, iv)
cbc.CryptBlocks(cryptText, cryptText)
decrypted, err := pkcs7unpad(cryptText)
if err != nil {
return "", err
}
return string(decrypted), err
}
func (g *Generator) generateBaseAesEncUrl(file []byte) (string, error) {
c, err := aes.NewCipher(g.encryptionKey)
if err != nil {
return "", err
}
data := pkcs7pad(file, aes.BlockSize)
ciphertext := make([]byte, aes.BlockSize+len(data))
iv := ciphertext[:aes.BlockSize]
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
return "", err
}
mode := cipher.NewCBCEncrypter(c, iv)
mode.CryptBlocks(ciphertext[aes.BlockSize:], data)
encryptedURL, err := g.generateBase64Url(ciphertext)
if err != nil {
return "", err
}
return "enc/" + encryptedURL, nil
}

View File

@@ -17,8 +17,13 @@ const (
DEF Format = "default"
)
func ToPtr(format Format) *Format {
return &format
}
func (g *Generator) StringToFormat(string string) (Format, error) {
switch strings.ToLower(string) {
s := strings.ToLower(string)
switch s {
case "jpg":
return JPG, nil
case "jpeg":
@@ -33,6 +38,8 @@ func (g *Generator) StringToFormat(string string) (Format, error) {
return GIF, nil
case "ico":
return ICO, nil
case "def":
case "default":
case "":
return DEF, nil
}

60
generator/format_test.go Normal file
View File

@@ -0,0 +1,60 @@
package generator
import (
"github.com/siteworxpro/img-proxy-url-generator/config"
"testing"
)
func TestGenerator_StringToFormat(t *testing.T) {
g, err := NewGenerator(&config.Config{
Generator: &config.GeneratorConfig{
Key: []byte("2c90317177aa7a3c44fa6804bf9bf466930f36ac9262bfdae972e836a9f83d239fd6bcee0c91a29ada58cc7329c787f35d2309f0984f2fd315e2c27bac8ac247"),
Salt: []byte("2777def3372a385f4aa7e62b2b431927"),
},
})
if err != nil {
t.Fatal(err)
}
formats := []string{"jpg", "jpeg", "png", "gif", "bmp", "webp", "ico", ""}
for _, format := range formats {
format, err := g.StringToFormat(format)
if err != nil {
t.Error(err)
}
if !isFormat(format) {
t.Error("format not match")
}
}
}
func TestGenerator_StringToFormatError(t *testing.T) {
g, err := NewGenerator(&config.Config{
Generator: &config.GeneratorConfig{
Key: []byte("f2d1f37016b7d12ab27b25377f39fd84e2d3368472ff096261ce7ac3e8490af429d43803836ad6a42a3bd9fb859a38137173619cb00bcb6fe3870e3feab2b764"),
Salt: []byte("919ed8813f76abfd42968b10e05258db"),
},
})
if err != nil {
t.Fatal(err)
}
_, err = g.StringToFormat("notaformat")
if err == nil {
t.Error("format did not return error")
}
}
func isFormat(t interface{}) bool {
switch t.(type) {
case Format:
return true
default:
return false
}
}

5
generator/plain.go Normal file
View File

@@ -0,0 +1,5 @@
package generator
func (g *Generator) generatePlainUrl(file string) (string, error) {
return "plain/" + file, nil
}

26
generator/plain_test.go Normal file
View File

@@ -0,0 +1,26 @@
package generator
import (
"github.com/siteworxpro/img-proxy-url-generator/config"
"testing"
)
func TestGenerator_GenerateUrl(t *testing.T) {
g, err := NewGenerator(&config.Config{
Generator: &config.GeneratorConfig{
Key: []byte("f2d1f37016b7d12ab27b25377f39fd84e2d3368472ff096261ce7ac3e8490af429d43803836ad6a42a3bd9fb859a38137173619cb00bcb6fe3870e3feab2b764"),
Salt: []byte("919ed8813f76abfd42968b10e05258db"),
PlainUrl: true,
},
})
if err != nil {
t.Fatal(err)
}
url, _ := g.generatePlainUrl("local:///test.png")
if url != "plain/local:///test.png" {
t.Errorf("url is %s", url)
}
}

24
generator/signature.go Normal file
View File

@@ -0,0 +1,24 @@
package generator
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"github.com/siteworxpro/img-proxy-url-generator/printer"
)
func (g *Generator) generateSignature(path string) string {
var signature string
if len(g.keyBin) == 0 || len(g.salt) == 0 {
signature = "insecure"
printer.NewPrinter().LogWarning("Insecure url generated. Provide salt and key to sign and secure url.")
} else {
mac := hmac.New(sha256.New, g.keyBin)
mac.Write(g.salt)
mac.Write([]byte(path))
signature = base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
}
return signature
}

View File

@@ -1,103 +1,48 @@
package generator
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"github.com/siteworxpro/img-proxy-url-generator/printer"
"io"
"github.com/siteworxpro/img-proxy-url-generator/config"
"strings"
)
type Generator struct {
config Config
}
type Config struct {
Salt []byte
saltBin []byte
Key []byte
keyBin []byte
Host string
EncryptionKey *string
encryptionKeyBin []byte
PlainUrl bool
salt []byte
encryptionKey []byte
}
var PathPrefix string
func NewGenerator(config Config) (*Generator, error) {
func NewGenerator(config *config.Config) (*Generator, error) {
var err error
gen := new(Generator)
gen.config = config
if gen.config.keyBin, err = hex.DecodeString(string(gen.config.Key)); err != nil {
if gen.keyBin, err = hex.DecodeString(string(config.Generator.Key)); err != nil {
return nil, err
}
if gen.config.saltBin, err = hex.DecodeString(string(gen.config.Salt)); err != nil {
if gen.salt, err = hex.DecodeString(string(config.Generator.Salt)); err != nil {
return nil, err
}
if gen.config.EncryptionKey != nil && *gen.config.EncryptionKey != "" {
if gen.config.encryptionKeyBin, err = hex.DecodeString(*gen.config.EncryptionKey); err != nil {
return nil, fmt.Errorf("Key expected to be hex-encoded string")
if config.Generator.EncryptionKey != "" {
if gen.encryptionKey, err = hex.DecodeString(config.Generator.EncryptionKey); err != nil {
return nil, fmt.Errorf("key expected to be hex-encoded string")
}
}
return gen, nil
}
func (g *Generator) generatePlainUrl(file []byte) {
}
func (g *Generator) generateBase64Url(file []byte) string {
return base64.RawURLEncoding.EncodeToString(file)
}
func pkcs7pad(data []byte, blockSize int) []byte {
padLen := blockSize - len(data)%blockSize
padding := bytes.Repeat([]byte{byte(padLen)}, padLen)
return append(data, padding...)
}
func (g *Generator) generateBaseAesEncUrl(file []byte) (string, error) {
c, err := aes.NewCipher(g.config.encryptionKeyBin)
if err != nil {
return "", err
}
data := pkcs7pad(file, aes.BlockSize)
ciphertext := make([]byte, aes.BlockSize+len(data))
iv := ciphertext[:aes.BlockSize]
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
return "", err
}
mode := cipher.NewCBCEncrypter(c, iv)
mode.CryptBlocks(ciphertext[aes.BlockSize:], data)
encryptedURL := g.generateBase64Url(ciphertext)
return "enc/" + encryptedURL, nil
}
func (g *Generator) GenerateUrl(file string, params []string, format Format) (string, error) {
if params == nil || len(params) == 0 || params[0] == "" {
params = []string{"raw:1"}
} else {
params = append(params, "sm:1")
}
params = append(params, "sm:1")
if PathPrefix != "" {
file = PathPrefix + file
@@ -107,17 +52,17 @@ func (g *Generator) GenerateUrl(file string, params []string, format Format) (st
var url string
var err error
if g.config.PlainUrl {
url = "plain/" + file
} else if g.config.encryptionKeyBin != nil {
if config.GetConfig().Generator.PlainUrl {
url, err = g.generatePlainUrl(file)
} else if g.encryptionKey != nil {
url, err = g.generateBaseAesEncUrl([]byte(file))
} else {
url, err = g.generateBase64Url([]byte(file))
}
if err != nil {
return "", err
}
} else {
url = g.generateBase64Url([]byte(file))
}
path := fmt.Sprintf("%s%s", paramString, url)
@@ -125,18 +70,7 @@ func (g *Generator) GenerateUrl(file string, params []string, format Format) (st
path = path + "." + string(format)
}
var signature string
if len(g.config.keyBin) == 0 || len(g.config.saltBin) == 0 {
signature = "insecure"
signature := g.generateSignature(path)
printer.NewPrinter().LogWarning("Insecure url generated. Provide salt and key to sign and secure url.")
} else {
mac := hmac.New(sha256.New, g.config.keyBin)
mac.Write(g.config.saltBin)
mac.Write([]byte(path))
signature = base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
}
return fmt.Sprintf("%s/%s%s", g.config.Host, signature, path), nil
return fmt.Sprintf("%s/%s%s", config.GetConfig().Generator.Host, signature, path), nil
}

53
go.mod
View File

@@ -1,23 +1,50 @@
module github.com/siteworxpro/img-proxy-url-generator
go 1.21.1
require github.com/bigkevmcd/go-configparser v0.0.0-20230427073640-c6b631f70126
go 1.24.0
require (
github.com/aws/aws-sdk-go v1.49.16 // indirect
github.com/aws/aws-sdk-go v1.55.7
github.com/bigkevmcd/go-configparser v0.0.0-20250311182818-a679eef33309
github.com/charmbracelet/bubbles v0.21.0
github.com/charmbracelet/bubbletea v1.3.5
github.com/charmbracelet/huh v0.7.0
github.com/charmbracelet/lipgloss v1.1.0
github.com/redis/go-redis/v9 v9.8.0
github.com/urfave/cli/v2 v2.27.6
google.golang.org/grpc v1.72.0
google.golang.org/protobuf v1.36.6
)
require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/lipgloss v0.10.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/catppuccin/go v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/colorprofile v0.3.1 // indirect
github.com/charmbracelet/x/ansi v0.9.2 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/urfave/cli/v2 v2.27.1 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sys v0.12.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250512202823-5a2f75b736a9 // indirect
)

145
go.sum
View File

@@ -1,16 +1,76 @@
github.com/aws/aws-sdk-go v1.49.16 h1:KAQwhLg296hfffRdh+itA9p7Nx/3cXS/qOa3uF9ssig=
github.com/aws/aws-sdk-go v1.49.16/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aws/aws-sdk-go v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE=
github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/bigkevmcd/go-configparser v0.0.0-20230427073640-c6b631f70126 h1:uru++pUKoS/yYU3Ohq9VItZdK/cT7FFJH/UUjOlxc+s=
github.com/bigkevmcd/go-configparser v0.0.0-20230427073640-c6b631f70126/go.mod h1:zqqfbfnDeSdRs1WihmMjSbhb2Ptw8Jbus831xoqiIec=
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
github.com/bigkevmcd/go-configparser v0.0.0-20250311182818-a679eef33309 h1:h2H7P1M0rXm8LTJMhZWr3SAleTmR6vg+7PM1BkTumaw=
github.com/bigkevmcd/go-configparser v0.0.0-20250311182818-a679eef33309/go.mod h1:vzEQfW+A1T+AMJmTIX+SXNLNECHOM7GEinHhw0IjykI=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/catppuccin/go v0.3.0 h1:d+0/YicIq+hSTo5oPuRi5kOpqkVA5tAsU6dNhvRu+aY=
github.com/catppuccin/go v0.3.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs=
github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg=
github.com/charmbracelet/bubbletea v1.3.5 h1:JAMNLTbqMOhSwoELIr0qyP4VidFq72/6E9j7HHmRKQc=
github.com/charmbracelet/bubbletea v1.3.5/go.mod h1:TkCnmH+aBd4LrXhXcqrKiYwRs7qyQx5rBgH5fVY3v54=
github.com/charmbracelet/colorprofile v0.3.1 h1:k8dTHMd7fgw4bnFd7jXTLZrSU/CQrKnL3m+AxCzDz40=
github.com/charmbracelet/colorprofile v0.3.1/go.mod h1:/GkGusxNs8VB/RSOh3fu0TJmQ4ICMMPApIIVn0KszZ0=
github.com/charmbracelet/huh v0.7.0 h1:W8S1uyGETgj9Tuda3/JdVkc3x7DBLZYPZc4c+/rnRdc=
github.com/charmbracelet/huh v0.7.0/go.mod h1:UGC3DZHlgOKHvHC07a5vHag41zzhpPFj34U92sOmyuk=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.9.2 h1:92AGsQmNTRMzuzHEYfCdjQeUzTrgE1vfO5/7fEVoXdY=
github.com/charmbracelet/x/ansi v0.9.2/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k=
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/conpty v0.1.0 h1:4zc8KaIcbiL4mghEON8D72agYtSeIgq8FSThSPQIb+U=
github.com/charmbracelet/x/conpty v0.1.0/go.mod h1:rMFsDJoDwVmiYM10aD4bH2XiRgwI7NYJtQgl5yskjEQ=
github.com/charmbracelet/x/errors v0.0.0-20240508181413-e8d8b6e2de86 h1:JSt3B+U9iqk37QUU2Rvb6DSBYRLtWqFqfxf8l5hOZUA=
github.com/charmbracelet/x/errors v0.0.0-20240508181413-e8d8b6e2de86/go.mod h1:2P0UgXMEa6TsToMSuFqKFQR+fZTO9CNGUNokkPatT/0=
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ=
github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4=
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY=
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
github.com/charmbracelet/x/xpty v0.1.2 h1:Pqmu4TEJ8KeA9uSkISKMU3f+C1F6OGBn8ABuGlqCbtI=
github.com/charmbracelet/x/xpty v0.1.2/go.mod h1:XK2Z0id5rtLWcpeNiMYBccNNBrP2IJnzHI0Lq13Xzq4=
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -18,31 +78,68 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/redis/go-redis/v9 v9.8.0 h1:q3nRvjrlge/6UD7eTu/DSg2uYiU2mCL0G/uzBWqhicI=
github.com/redis/go-redis/v9 v9.8.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/urfave/cli/v2 v2.27.6 h1:VdRdS98FNhKZ8/Az8B7MTyGQmpIr36O1EHybx/LaZ4g=
github.com/urfave/cli/v2 v2.27.6/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=
go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=
go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=
go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250512202823-5a2f75b736a9 h1:IkAfh6J/yllPtpYFU0zZN1hUPYdT0ogkBT/9hMxHjvg=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250512202823-5a2f75b736a9/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM=
google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

304
grpc/imgurl.pb.go Normal file
View File

@@ -0,0 +1,304 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.34.1
// protoc v5.28.3
// source: imgurl.proto
package grpc
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Format int32
const (
Format_JPG Format = 0
Format_PNG Format = 1
Format_BMP Format = 2
Format_WEBP Format = 3
Format_GIF Format = 4
Format_ICO Format = 5
)
// Enum value maps for Format.
var (
Format_name = map[int32]string{
0: "JPG",
1: "PNG",
2: "BMP",
3: "WEBP",
4: "GIF",
5: "ICO",
}
Format_value = map[string]int32{
"JPG": 0,
"PNG": 1,
"BMP": 2,
"WEBP": 3,
"GIF": 4,
"ICO": 5,
}
)
func (x Format) Enum() *Format {
p := new(Format)
*p = x
return p
}
func (x Format) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (Format) Descriptor() protoreflect.EnumDescriptor {
return file_imgurl_proto_enumTypes[0].Descriptor()
}
func (Format) Type() protoreflect.EnumType {
return &file_imgurl_proto_enumTypes[0]
}
func (x Format) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use Format.Descriptor instead.
func (Format) EnumDescriptor() ([]byte, []int) {
return file_imgurl_proto_rawDescGZIP(), []int{0}
}
type UrlRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Image string `protobuf:"bytes,1,opt,name=image,proto3" json:"image,omitempty"`
Params []string `protobuf:"bytes,2,rep,name=params,proto3" json:"params,omitempty"`
Format *Format `protobuf:"varint,3,opt,name=format,proto3,enum=Format,oneof" json:"format,omitempty"`
}
func (x *UrlRequest) Reset() {
*x = UrlRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_imgurl_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UrlRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UrlRequest) ProtoMessage() {}
func (x *UrlRequest) ProtoReflect() protoreflect.Message {
mi := &file_imgurl_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UrlRequest.ProtoReflect.Descriptor instead.
func (*UrlRequest) Descriptor() ([]byte, []int) {
return file_imgurl_proto_rawDescGZIP(), []int{0}
}
func (x *UrlRequest) GetImage() string {
if x != nil {
return x.Image
}
return ""
}
func (x *UrlRequest) GetParams() []string {
if x != nil {
return x.Params
}
return nil
}
func (x *UrlRequest) GetFormat() Format {
if x != nil && x.Format != nil {
return *x.Format
}
return Format_JPG
}
type UrlResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"`
}
func (x *UrlResponse) Reset() {
*x = UrlResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_imgurl_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UrlResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UrlResponse) ProtoMessage() {}
func (x *UrlResponse) ProtoReflect() protoreflect.Message {
mi := &file_imgurl_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UrlResponse.ProtoReflect.Descriptor instead.
func (*UrlResponse) Descriptor() ([]byte, []int) {
return file_imgurl_proto_rawDescGZIP(), []int{1}
}
func (x *UrlResponse) GetUrl() string {
if x != nil {
return x.Url
}
return ""
}
var File_imgurl_proto protoreflect.FileDescriptor
var file_imgurl_proto_rawDesc = []byte{
0x0a, 0x0c, 0x69, 0x6d, 0x67, 0x75, 0x72, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x6b,
0x0a, 0x0a, 0x55, 0x72, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05,
0x69, 0x6d, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x6d, 0x61,
0x67, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03,
0x28, 0x09, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x24, 0x0a, 0x06, 0x66, 0x6f,
0x72, 0x6d, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x07, 0x2e, 0x46, 0x6f, 0x72,
0x6d, 0x61, 0x74, 0x48, 0x00, 0x52, 0x06, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x88, 0x01, 0x01,
0x42, 0x09, 0x0a, 0x07, 0x5f, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x22, 0x1f, 0x0a, 0x0b, 0x55,
0x72, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72,
0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x2a, 0x3f, 0x0a, 0x06,
0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x12, 0x07, 0x0a, 0x03, 0x4a, 0x50, 0x47, 0x10, 0x00, 0x12,
0x07, 0x0a, 0x03, 0x50, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x42, 0x4d, 0x50, 0x10,
0x02, 0x12, 0x08, 0x0a, 0x04, 0x57, 0x45, 0x42, 0x50, 0x10, 0x03, 0x12, 0x07, 0x0a, 0x03, 0x47,
0x49, 0x46, 0x10, 0x04, 0x12, 0x07, 0x0a, 0x03, 0x49, 0x43, 0x4f, 0x10, 0x05, 0x32, 0x34, 0x0a,
0x09, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x27, 0x0a, 0x08, 0x47, 0x65,
0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x0b, 0x2e, 0x55, 0x72, 0x6c, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x0c, 0x2e, 0x55, 0x72, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x00, 0x42, 0x90, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63,
0x6f, 0x6d, 0x2f, 0x73, 0x69, 0x74, 0x65, 0x77, 0x6f, 0x72, 0x78, 0x70, 0x72, 0x6f, 0x2f, 0x69,
0x6d, 0x67, 0x2d, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2d, 0x75, 0x72, 0x6c, 0x2d, 0x67, 0x65, 0x6e,
0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x67, 0x72, 0x70, 0x63, 0xca, 0x02, 0x26, 0x53, 0x69,
0x74, 0x65, 0x77, 0x6f, 0x72, 0x78, 0x5c, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x5c, 0x49,
0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5c, 0x49, 0x6d, 0x67, 0x50,
0x72, 0x6f, 0x78, 0x79, 0xe2, 0x02, 0x2f, 0x53, 0x69, 0x74, 0x65, 0x77, 0x6f, 0x72, 0x78, 0x5c,
0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x5c, 0x49, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x73, 0x5c, 0x49, 0x6d, 0x67, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x5c, 0x4d, 0x65,
0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_imgurl_proto_rawDescOnce sync.Once
file_imgurl_proto_rawDescData = file_imgurl_proto_rawDesc
)
func file_imgurl_proto_rawDescGZIP() []byte {
file_imgurl_proto_rawDescOnce.Do(func() {
file_imgurl_proto_rawDescData = protoimpl.X.CompressGZIP(file_imgurl_proto_rawDescData)
})
return file_imgurl_proto_rawDescData
}
var file_imgurl_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_imgurl_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_imgurl_proto_goTypes = []interface{}{
(Format)(0), // 0: Format
(*UrlRequest)(nil), // 1: UrlRequest
(*UrlResponse)(nil), // 2: UrlResponse
}
var file_imgurl_proto_depIdxs = []int32{
0, // 0: UrlRequest.format:type_name -> Format
1, // 1: Generator.Generate:input_type -> UrlRequest
2, // 2: Generator.Generate:output_type -> UrlResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_imgurl_proto_init() }
func file_imgurl_proto_init() {
if File_imgurl_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_imgurl_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UrlRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_imgurl_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UrlResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
file_imgurl_proto_msgTypes[0].OneofWrappers = []interface{}{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imgurl_proto_rawDesc,
NumEnums: 1,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_imgurl_proto_goTypes,
DependencyIndexes: file_imgurl_proto_depIdxs,
EnumInfos: file_imgurl_proto_enumTypes,
MessageInfos: file_imgurl_proto_msgTypes,
}.Build()
File_imgurl_proto = out.File
file_imgurl_proto_rawDesc = nil
file_imgurl_proto_goTypes = nil
file_imgurl_proto_depIdxs = nil
}

29
grpc/imgurl.proto Normal file
View File

@@ -0,0 +1,29 @@
syntax = "proto3";
option go_package = "github.com/siteworxpro/img-proxy-url-generator/grpc";
option php_namespace = "SomeNamespace\\ImgProxy";
option php_metadata_namespace = "SomeNamespace\\ImgProxy\\Metadata";
message UrlRequest {
string image = 1;
repeated string params = 2;
optional Format format = 3;
}
enum Format {
JPG = 0;
PNG = 1;
BMP = 2;
WEBP = 3;
GIF = 4;
ICO = 5;
}
message UrlResponse {
string url = 1;
}
service Generator {
rpc Generate (UrlRequest) returns (UrlResponse) {}
}

121
grpc/imgurl_grpc.pb.go Normal file
View File

@@ -0,0 +1,121 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v5.28.3
// source: imgurl.proto
package grpc
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Generator_Generate_FullMethodName = "/Generator/Generate"
)
// GeneratorClient is the client API for Generator service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type GeneratorClient interface {
Generate(ctx context.Context, in *UrlRequest, opts ...grpc.CallOption) (*UrlResponse, error)
}
type generatorClient struct {
cc grpc.ClientConnInterface
}
func NewGeneratorClient(cc grpc.ClientConnInterface) GeneratorClient {
return &generatorClient{cc}
}
func (c *generatorClient) Generate(ctx context.Context, in *UrlRequest, opts ...grpc.CallOption) (*UrlResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UrlResponse)
err := c.cc.Invoke(ctx, Generator_Generate_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// GeneratorServer is the server API for Generator service.
// All implementations must embed UnimplementedGeneratorServer
// for forward compatibility.
type GeneratorServer interface {
Generate(context.Context, *UrlRequest) (*UrlResponse, error)
mustEmbedUnimplementedGeneratorServer()
}
// UnimplementedGeneratorServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedGeneratorServer struct{}
func (UnimplementedGeneratorServer) Generate(context.Context, *UrlRequest) (*UrlResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Generate not implemented")
}
func (UnimplementedGeneratorServer) mustEmbedUnimplementedGeneratorServer() {}
func (UnimplementedGeneratorServer) testEmbeddedByValue() {}
// UnsafeGeneratorServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to GeneratorServer will
// result in compilation errors.
type UnsafeGeneratorServer interface {
mustEmbedUnimplementedGeneratorServer()
}
func RegisterGeneratorServer(s grpc.ServiceRegistrar, srv GeneratorServer) {
// If the following call pancis, it indicates UnimplementedGeneratorServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Generator_ServiceDesc, srv)
}
func _Generator_Generate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UrlRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(GeneratorServer).Generate(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Generator_Generate_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GeneratorServer).Generate(ctx, req.(*UrlRequest))
}
return interceptor(ctx, in, info, handler)
}
// Generator_ServiceDesc is the grpc.ServiceDesc for Generator service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Generator_ServiceDesc = grpc.ServiceDesc{
ServiceName: "Generator",
HandlerType: (*GeneratorServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Generate",
Handler: _Generator_Generate_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "imgurl.proto",
}

0
grpc/php/src/.gitkeep Normal file
View File

49
grpc/server.go Normal file
View File

@@ -0,0 +1,49 @@
package grpc
import (
"context"
"fmt"
"github.com/siteworxpro/img-proxy-url-generator/config"
"github.com/siteworxpro/img-proxy-url-generator/generator"
"log"
"strings"
)
type GeneratorService struct {
UnimplementedGeneratorServer
imgGenerator *generator.Generator
}
func NewService(config *config.Config) (*GeneratorService, error) {
g, err := generator.NewGenerator(config)
if err != nil {
return nil, err
}
return &GeneratorService{imgGenerator: g}, nil
}
func (s *GeneratorService) Generate(c context.Context, r *UrlRequest) (*UrlResponse, error) {
defer c.Done()
var err error
format := generator.DEF
if r.Format != nil {
format, err = s.imgGenerator.StringToFormat(r.Format.String())
if err != nil {
println(err.Error())
return nil, err
}
}
url, err := s.imgGenerator.GenerateUrl(r.Image, r.Params, format)
if err != nil {
println(err.Error())
return nil, err
}
log.Println(fmt.Sprintf("%s - [%s] - (%s)", r.Image, strings.Join(r.Params, ","), url))
return &UrlResponse{Url: url}, nil
}

140
interactive/model.go Normal file
View File

@@ -0,0 +1,140 @@
package interactive
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
cbhelp "github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
"github.com/siteworxpro/img-proxy-url-generator/config"
"github.com/siteworxpro/img-proxy-url-generator/generator"
"github.com/siteworxpro/img-proxy-url-generator/interactive/params"
"github.com/urfave/cli/v2"
)
type Model struct {
Fields []huh.Field
generator *generator.Generator
url *string
format *generator.Format
selectedParams *[]UrlParam
err error
focusField huh.Field
inParamsFields bool
help cbhelp.Model
}
type UrlParam interface {
Value() string
Display() string
Key() string
Input() []huh.Field
}
func InitialModel(c *cli.Context) Model {
m := Model{
url: aws.String(""),
selectedParams: &[]UrlParam{},
format: generator.ToPtr(generator.DEF),
}
fields := make([]huh.Field, 0)
fields = append(fields, m.initialFields()...)
m.Fields = fields
cfg, _ := config.NewConfig(c.String("config"))
if cfg == nil {
err := fmt.Errorf("config not loaded")
m.err = err
return m
}
g, err := generator.NewGenerator(cfg)
if err != nil {
m.err = err
return m
}
m.generator = g
m.help = cbhelp.New()
return m
}
func (m Model) initialFields() []huh.Field {
fields := make([]huh.Field, 0)
options := []UrlParam{
params.NewHeight(),
params.NewWidth(),
params.NewResize(),
params.NewMinWidth(),
params.NewMinHeight(),
params.NewQuality(),
params.NewZoom(),
params.NewEnlarge(),
}
var huhOptions []huh.Option[UrlParam]
for _, option := range options {
huhOptions = append(huhOptions, huh.NewOption[UrlParam](option.Display(), option))
}
fields = append(fields,
huh.NewInput().
Key("imgUrl").
Description("The URL of the image to generate a proxy for.").
Title("Image URL").
Value(m.url).
Prompt("Enter the image URL:"),
)
fields = append(fields,
huh.NewMultiSelect[UrlParam]().
Description("Params to add to the URL.").
Options(huhOptions...).
Value(m.selectedParams).
WithKeyMap(&huh.KeyMap{
MultiSelect: huh.MultiSelectKeyMap{
Up: key.NewBinding(key.WithKeys("up"), key.WithHelp("up", "up")),
Down: key.NewBinding(key.WithKeys("down"), key.WithHelp("down", "down")),
Toggle: key.NewBinding(key.WithKeys(" "), key.WithHelp(" ", "toggle")),
},
}),
)
fields = append(fields, huh.NewSelect[generator.Format]().
Description("Convert the image format.").
Options(
huh.NewOption[generator.Format]("JPEG", generator.JPG),
huh.NewOption[generator.Format]("PNG", generator.PNG),
huh.NewOption[generator.Format]("BMP", generator.BMP),
huh.NewOption[generator.Format]("WEBP", generator.WEBP),
huh.NewOption[generator.Format]("GIF", generator.GIF),
huh.NewOption[generator.Format]("ICO", generator.ICO),
huh.NewOption[generator.Format]("Default", generator.DEF),
).
Key("format").
Title("Format").
Value(m.format).
WithKeyMap(&huh.KeyMap{
Select: huh.SelectKeyMap{
Up: key.NewBinding(key.WithKeys("up"), key.WithHelp("up", "up")),
Down: key.NewBinding(key.WithKeys("down"), key.WithHelp("down", "down")),
},
}),
)
return fields
}
func (m Model) Init() tea.Cmd {
return nil
}

View File

@@ -0,0 +1,51 @@
package params
import (
"github.com/charmbracelet/huh"
)
type Enlarge struct {
enlarge *[]string
field huh.Field
}
func NewEnlarge() *Enlarge {
e := &Enlarge{
enlarge: &[]string{},
field: huh.NewMultiSelect[string]().
Options(
huh.NewOption("true", "true"),
).
Description("Whether to enlarge the image.").
WithKeyMap(
huh.NewDefaultKeyMap(),
),
}
e.enlarge = &[]string{}
e.field.(*huh.MultiSelect[string]).Value(e.enlarge)
return e
}
func (e Enlarge) Display() string {
return "enlarge"
}
func (e Enlarge) Value() string {
value := "0"
if len(*e.enlarge) > 0 {
value = "1"
}
return value
}
func (e Enlarge) Key() string {
return "el"
}
func (e Enlarge) Input() []huh.Field {
return []huh.Field{e.field}
}

View File

@@ -0,0 +1,41 @@
package params
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/charmbracelet/huh"
)
type Height struct {
paramValue *string
field *huh.Input
}
func NewHeight() *Height {
h := &Height{
paramValue: aws.String(""),
field: huh.NewInput().
Key("h").
Description("The height of the image.").
Title("Height"),
}
h.field.Value(h.paramValue)
return h
}
func (h Height) Display() string {
return "height"
}
func (h Height) Value() string {
return *h.paramValue
}
func (h Height) Key() string {
return "h"
}
func (h Height) Input() []huh.Field {
return []huh.Field{h.field}
}

View File

@@ -0,0 +1,42 @@
package params
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/charmbracelet/huh"
)
type MinHeight struct {
paramValue *string
field *huh.Input
}
func NewMinHeight() *MinHeight {
mh := &MinHeight{
paramValue: nil,
field: huh.NewInput().
Key("min-height").
Description("The minimum height of the image.").
Title("Min Height"),
}
mh.paramValue = aws.String("")
mh.field.Value(mh.paramValue)
return mh
}
func (mh MinHeight) Display() string {
return "min-height"
}
func (mh MinHeight) Value() string {
return *mh.paramValue
}
func (mh MinHeight) Key() string {
return "mh"
}
func (mh MinHeight) Input() []huh.Field {
return []huh.Field{mh.field}
}

View File

@@ -0,0 +1,42 @@
package params
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/charmbracelet/huh"
)
type MinWidth struct {
paramValue *string
field *huh.Input
}
func NewMinWidth() *MinWidth {
mw := &MinWidth{
paramValue: nil,
field: huh.NewInput().
Key("min-width").
Description("The minimum width of the image.").
Title("Min Width"),
}
mw.paramValue = aws.String("")
mw.field.Value(mw.paramValue)
return mw
}
func (mw MinWidth) Display() string {
return "min-width"
}
func (mw MinWidth) Value() string {
return *mw.paramValue
}
func (mw MinWidth) Key() string {
return "mw"
}
func (mw MinWidth) Input() []huh.Field {
return []huh.Field{mw.field}
}

View File

@@ -0,0 +1,41 @@
package params
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/charmbracelet/huh"
)
type Quality struct {
value *string
field *huh.Input
}
func NewQuality() *Quality {
z := &Quality{
value: aws.String(""),
field: huh.NewInput().
Key("q").
Description("Quality of the image 0-100").
Title("Quality"),
}
z.field.Value(z.value)
return z
}
func (z *Quality) Value() string {
return *z.value
}
func (z *Quality) Display() string {
return "quality"
}
func (z *Quality) Key() string {
return "q"
}
func (z *Quality) Input() []huh.Field {
return []huh.Field{z.field}
}

View File

@@ -0,0 +1,99 @@
package params
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/charmbracelet/huh"
)
type Resize struct {
fields []huh.Field
height *string
width *string
resizeType *string
enlarge *[]string
extent *[]string
}
func NewResize() *Resize {
rs := &Resize{
fields: []huh.Field{
huh.NewInput().
Key("resize.height").
Description("The height of the image.").
Title("Height"),
huh.NewInput().
Key("resize.width").
Description("The width of the image.").
Title("Width"),
huh.NewSelect[string]().
Title("Resize Type").
Options(
huh.NewOption("fit", "fit"),
huh.NewOption("fill", "fill"),
huh.NewOption("fill-down", "fill-down"),
huh.NewOption("force", "force"),
huh.NewOption("auto", "auto"),
).WithKeyMap(huh.NewDefaultKeyMap()),
huh.NewMultiSelect[string]().
Options(
huh.NewOption("true", "true"),
).
Description("Whether to enlarge the image.").
WithKeyMap(
huh.NewDefaultKeyMap(),
),
huh.NewMultiSelect[string]().
Options(
huh.NewOption("true", "true"),
).
Description("Whether to extend the image.").
WithKeyMap(
huh.NewDefaultKeyMap(),
),
},
}
rs.height = aws.String("")
rs.width = aws.String("")
rs.enlarge = &[]string{}
rs.extent = &[]string{}
rs.resizeType = aws.String("auto")
rs.fields[0].(*huh.Input).Value(rs.height)
rs.fields[1].(*huh.Input).Value(rs.width)
rs.fields[2].(*huh.Select[string]).Value(rs.resizeType)
rs.fields[3].(*huh.MultiSelect[string]).Value(rs.enlarge)
rs.fields[4].(*huh.MultiSelect[string]).Value(rs.extent)
return rs
}
func (r Resize) Display() string {
return "resize"
}
func (r Resize) Value() string {
if *r.height == "" || *r.width == "" {
return ""
}
resize := "0"
if *r.enlarge != nil && len(*r.enlarge) > 0 {
resize = "1"
}
extent := "0"
if *r.extent != nil && len(*r.extent) > 0 {
extent = "1"
}
return *r.resizeType + ":" + *r.height + ":" + *r.width + ":" + resize + ":" + extent
}
func (r Resize) Key() string {
return "rs"
}
func (r Resize) Input() []huh.Field {
return r.fields
}

View File

@@ -0,0 +1,41 @@
package params
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/charmbracelet/huh"
)
type Width struct {
paramValue *string
field *huh.Input
}
func NewWidth() *Width {
w := &Width{
paramValue: aws.String(""),
field: huh.NewInput().
Key("h").
Description("The width of the image.").
Title("Width"),
}
w.field.Value(w.paramValue)
return w
}
func (h Width) Display() string {
return "width"
}
func (h Width) Value() string {
return *h.paramValue
}
func (h Width) Key() string {
return "h"
}
func (h Width) Input() []huh.Field {
return []huh.Field{h.field}
}

View File

@@ -0,0 +1,41 @@
package params
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/charmbracelet/huh"
)
type Zoom struct {
zoom *string
field huh.Field
}
func NewZoom() *Zoom {
z := &Zoom{
zoom: aws.String(""),
field: huh.NewInput().
Key("z").
Description("Percentage to zoom the image (1.4 == 140%) .").
Title("Zoom"),
}
z.field.(*huh.Input).Value(z.zoom)
return z
}
func (z *Zoom) Value() string {
return *z.zoom
}
func (z *Zoom) Display() string {
return "zoom"
}
func (z *Zoom) Key() string {
return "z"
}
func (z *Zoom) Input() []huh.Field {
return []huh.Field{z.field}
}

108
interactive/update.go Normal file
View File

@@ -0,0 +1,108 @@
package interactive
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
)
// Helper: find index of current focusField in a given field slice.
//
//goland:noinspection GoMixedReceiverTypes
func (m *Model) findCurrentFieldIndex(fields []huh.Field) int {
for i, field := range fields {
if field == m.focusField {
return i
}
}
return -1
}
// Helper: blur current, focus next (wraps to 0)
//
//goland:noinspection GoMixedReceiverTypes
func (m *Model) focusNextField(fields []huh.Field) {
index := m.findCurrentFieldIndex(fields)
next := (index + 1) % len(fields)
m.focusField.Blur()
m.focusField = fields[next]
m.focusField.Focus()
}
// Helper: focus a specific field by index
//
//goland:noinspection GoMixedReceiverTypes
func (m *Model) focusFieldByIndex(fields []huh.Field, index int) {
if index >= 0 && index < len(fields) {
m.focusField.Blur()
m.focusField = fields[index]
m.focusField.Focus()
}
}
// Helper: get all selected param fields as a flat slice
//
//goland:noinspection GoMixedReceiverTypes
func (m *Model) selectedParamFields() []huh.Field {
var fields []huh.Field
for _, param := range *m.selectedParams {
fields = append(fields, param.Input()...)
}
return fields
}
//goland:noinspection GoMixedReceiverTypes
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
model := m // copy, since Bubble Tea prefers value receivers, but we'll operate on &model internally
if model.focusField == nil && len(model.Fields) > 0 {
model.Fields[0].Focus()
model.focusField = model.Fields[0]
}
if keyMsg, ok := msg.(tea.KeyMsg); ok {
switch keyMsg.String() {
case "tab":
mainFields := model.Fields
paramFields := model.selectedParamFields()
if model.inParamsFields && len(paramFields) > 0 {
index := model.findCurrentFieldIndex(paramFields)
if index == -1 {
break
}
if index == len(paramFields)-1 {
// Last param field: cycle to main fields
model.inParamsFields = false
model.focusFieldByIndex(mainFields, 0)
} else {
model.focusNextField(paramFields)
}
} else {
index := model.findCurrentFieldIndex(mainFields)
if index == -1 {
break
}
if index == len(mainFields)-1 && len(paramFields) > 0 {
// Last main field & params exist: go to params
model.inParamsFields = true
model.focusFieldByIndex(paramFields, 0)
} else {
model.focusNextField(mainFields)
}
}
case "ctrl+c", "esc":
return model, tea.Quit
case "enter":
return model, nil
default:
if model.focusField != nil {
md, cmd := model.focusField.(huh.Field).Update(msg)
if md != nil {
model.focusField = md.(huh.Field)
}
return model, cmd
}
}
}
return model, nil
}

71
interactive/view.go Normal file
View File

@@ -0,0 +1,71 @@
package interactive
import (
"fmt"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/lipgloss"
)
func (m Model) View() string {
fieldStyle := lipgloss.NewStyle().PaddingBottom(1)
if m.err != nil {
return lipgloss.
NewStyle().
Bold(true).
Foreground(lipgloss.Color("red")).
Background(lipgloss.Color("black")).
Render("Error: " + m.err.Error() + "\n" + "Press Ctrl+C to exit.")
}
output := lipgloss.NewStyle().
Foreground(lipgloss.Color("5")).
PaddingBottom(1).
Bold(true).
Underline(true).
Render("Welcome to the img-proxy URL Generator!") + "\n"
for _, field := range m.Fields {
output += fieldStyle.Render("\n" + field.View())
}
for _, field := range *m.selectedParams {
for _, f := range field.Input() {
output += fieldStyle.Render("\n" + f.View())
}
}
if *m.url == "" {
return output + "\n" + m.renderHelp()
}
// Generate the URL
params := make([]string, 0)
for _, field := range *m.selectedParams {
if field.Value() != "" {
params = append(params, field.Key()+":"+field.Value())
}
}
url, _ := m.generator.GenerateUrl(*m.url, params, *m.format)
output += fmt.Sprintf("\nGenerated URL: %s\n\n", lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#0000ff")).
Render(url))
output += m.renderHelp()
return output
}
func (m Model) renderHelp() string {
return m.help.ShortHelpView([]key.Binding{
key.NewBinding(key.WithKeys("ctrl+c", "esc"), key.WithHelp("esc", "quit")),
key.NewBinding(key.WithKeys("up"), key.WithHelp("↑", "cursor up")),
key.NewBinding(key.WithKeys("down"), key.WithHelp("↓", "cursor down")),
key.NewBinding(key.WithKeys(" "), key.WithHelp("space", "select")),
key.NewBinding(key.WithKeys("tab"), key.WithHelp("tab", "next field")),
})
}

130
main.go
View File

@@ -1,63 +1,39 @@
package main
import (
"fmt"
"github.com/bigkevmcd/go-configparser"
"github.com/siteworxpro/img-proxy-url-generator/generator"
cliCommands "github.com/siteworxpro/img-proxy-url-generator/commands"
"github.com/siteworxpro/img-proxy-url-generator/printer"
"github.com/urfave/cli/v2"
"os"
)
var keyBin, saltBin []byte
var imgGenerator *generator.Generator
var Version = "v0.0.0"
func main() {
pr := printer.NewPrinter()
var commands []*cli.Command
commands = append(commands, cliCommands.GenerateCommand())
commands = append(commands, cliCommands.ServerCommand())
commands = append(commands, cliCommands.ReportCommand())
commands = append(commands, cliCommands.GrpcCommand())
commands = append(commands, cliCommands.DecryptCommand())
commands = append(commands, cliCommands.Interactive())
app := &cli.App{
Name: "img-proxy-url-generator",
Usage: "URL Generator for the img proxy service",
DefaultCommand: "generate",
DefaultCommand: "interactive",
Version: Version,
Commands: []*cli.Command{
{
Name: "generate",
Usage: "Generate an image from a URL",
Action: func(c *cli.Context) error {
return run(c, pr)
},
},
},
Commands: commands,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "image",
Aliases: []string{"i"},
Required: true,
},
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Config file to load from",
DefaultText: "imgproxy.cfg",
},
&cli.StringFlag{
Name: "format",
Aliases: []string{"f"},
Usage: "Convert the image to the specified format",
},
&cli.StringSliceFlag{
Name: "params",
Aliases: []string{"p"},
Usage: "Processing options to be passed to the generator ref: https://docs.imgproxy.net/usage/processing",
},
},
Action: func(c *cli.Context) error {
return run(c, pr)
},
}
@@ -68,87 +44,3 @@ func main() {
os.Exit(1)
}
}
func run(c *cli.Context, p *printer.Printer) error {
err := initGenerator(c.String("config"))
if err != nil {
return err
}
url, err := signURL(c.String("image"), c.StringSlice("params"), c.String("format"))
if err != nil {
return err
}
p.LogInfo("Url Generated...")
println(url)
return nil
}
func initGenerator(config string) error {
var err error
if config == "" {
config = "imgproxy.cfg"
}
p, err := configparser.NewConfigParserFromFile(config)
if err != nil {
return err
}
if !p.HasSection("img-proxy") {
return fmt.Errorf("config error - [img-proxy] config required")
}
config, err = p.Get("img-proxy", "key")
if config != "" {
keyBin = []byte(config)
}
config, err = p.Get("img-proxy", "salt")
saltBin = []byte(config)
hostConf, err := p.Get("img-proxy", "host")
if err != nil {
return err
}
plainConfig, err := p.Get("img-proxy", "plain-url")
encKey, err := p.Get("img-proxy", "encryption-key")
generatorConfig := generator.Config{
Salt: saltBin,
Key: keyBin,
Host: hostConf,
EncryptionKey: &encKey,
PlainUrl: plainConfig != "",
}
imgGenerator, err = generator.NewGenerator(generatorConfig)
if err != nil {
return err
}
return nil
}
func signURL(file string, params []string, formatS string) (string, error) {
format, err := imgGenerator.StringToFormat(formatS)
if err != nil {
return "", err
}
url, err := imgGenerator.GenerateUrl(file, params, format)
if err != nil {
return "", err
}
return url, nil
}

65
redis/client.go Normal file
View File

@@ -0,0 +1,65 @@
package redis
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
"github.com/siteworxpro/img-proxy-url-generator/config"
"strconv"
)
type Redis struct {
initialized redisStatus
client *redis.Client
}
type redisStatus uint8
const (
redisStatusUninitialized redisStatus = iota
redisStatusInitialized
)
var singleton *Redis
func New(config *config.Config) (*Redis, error) {
if singleton != nil && singleton.initialized == redisStatusUninitialized {
return singleton, nil
}
db, err := strconv.ParseInt(config.Redis.DB, 10, 64)
if err != nil {
db = 0
}
port := config.Redis.Port
if port == "" {
port = "6379"
}
rdb := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", config.Redis.Host, port),
DB: int(db),
Password: config.Redis.Password,
})
_, err = rdb.Ping(context.Background()).Result()
if err != nil {
return nil, fmt.Errorf("failed to connect to redis: %w", err)
}
singleton = &Redis{
initialized: redisStatusInitialized,
client: rdb,
}
return singleton, nil
}
func (r *Redis) GetClient() *redis.Client {
return r.client
}
func (r *Redis) Close() error {
return r.client.Close()
}

75
report/command.go Normal file
View File

@@ -0,0 +1,75 @@
package report
import (
"context"
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/siteworxpro/img-proxy-url-generator/aws"
"github.com/siteworxpro/img-proxy-url-generator/config"
"github.com/siteworxpro/img-proxy-url-generator/generator"
"github.com/siteworxpro/img-proxy-url-generator/redis"
"sort"
"strconv"
"time"
)
const lastAccessKey = "imgproxy:%s:last_access"
const requestsKey = "imgproxy:%s:requests"
var rowStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFFFF"))
var headerStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFFFF")).Bold(true)
func Handle(config *config.Config) error {
a := aws.NewClient(config)
r, err := redis.New(config)
ig, err := generator.NewGenerator(config)
if err != nil {
return err
}
var continuationToken *string
list, err := a.ListBucketContents(continuationToken)
if err != nil {
return err
}
var rows [][]string
for list.StartAfter != "" {
for _, image := range list.Images {
dlUrl, err := ig.GenerateUrl(image.S3Path, []string{}, generator.DEF)
if err != nil {
return err
}
lastAccessedS, err := r.GetClient().Get(context.Background(), fmt.Sprintf(lastAccessKey, image.S3Path)).Result()
lastAccessedI, _ := strconv.ParseInt(lastAccessedS, 10, 64)
lastAccessed := time.Unix(lastAccessedI, 0)
requestsCount, err := r.GetClient().Get(context.Background(), fmt.Sprintf(requestsKey, image.S3Path)).Result()
rows = append(rows, []string{image.S3Path, requestsCount, lastAccessed.Format(time.DateTime), dlUrl})
}
continuationToken = &list.StartAfter
list, err = a.ListBucketContents(continuationToken)
}
// sort by last accessed
sort.Slice(rows, func(i, j int) bool {
return rows[i][2] > rows[j][2]
})
t := table.New().StyleFunc(func(row int, col int) lipgloss.Style {
switch {
case row == 0:
return headerStyle
default:
return rowStyle
}
}).
Headers("Image", "Times Accessed", "Last Accessed", "URL").
Rows(rows...)
fmt.Println(t)
return nil
}

31
templates/index.gohtml Normal file
View File

@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
a {
text-decoration: none;
}
</style>
</head>
<body>
<div class="flex flex-row flex-wrap justify-around text-center">
{{ range .Images }}
<div style="border: 1px solid #222222;" class="w-1/5 p-5 m-5 flex flex-wrap justify-center">
<div>
<a href="{{ .Download }}" target="_blank">
<img style="background-color: #222222" src="{{ .Url }}" alt="{{ .Name }}"/>
</a>
</div>
<div class="w-full">
{{ .S3Path }}
</div>
</div>
{{ end }}
</div>
<div class="p-10 text-right">
<a href="/?next={{ .StartAfter }}">Next</a>
</div>
</body>
</html>