You've already forked img-proxy-url-generator
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
0ab36c5ea6
|
|||
|
4d2a7418cb
|
|||
|
1ad11d7e08
|
|||
|
1f1cd68192
|
|||
|
3f8408cfd8
|
|||
|
4803855e61
|
|||
|
|
96f8d521ee | ||
|
|
b2637fcddb |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
.DS_Store
|
||||||
.idea/
|
.idea/
|
||||||
main
|
main
|
||||||
imgproxy
|
imgproxy
|
||||||
|
|||||||
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
FROM siteworxpro/golang:1.23.3 AS build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ADD . .
|
||||||
|
|
||||||
|
ENV GOPRIVATE=git.s.int
|
||||||
|
ENV GOPROXY=direct
|
||||||
|
ENV CGO_ENABLED=0
|
||||||
|
|
||||||
|
RUN go mod tidy && go build -o imgproxy .
|
||||||
|
|
||||||
|
FROM alpine AS runtime
|
||||||
|
|
||||||
|
EXPOSE 9000
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY --from=build /app/imgproxy /app/imgproxy
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/imgproxy", "grpc"]
|
||||||
28
README.md
28
README.md
@@ -106,3 +106,31 @@ generate a url with a specified format
|
|||||||
|
|
||||||
https://i.fooo.com/UMkz4OUNw6P9ShLdewuvW3ValMgCt263vZzU5gN57WQ/h:200/sm:1/enc/ECYxMeVBTjRxB7F-jdQ7W_-Fnv4YbmSJIKie-Hdtxd9vsmEKjU1YuWVSzdN97Mod.bmp
|
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`
|
||||||
7
Taskfile.yaml
Normal file
7
Taskfile.yaml
Normal 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
|
||||||
2
build.sh
2
build.sh
@@ -8,7 +8,7 @@ do
|
|||||||
|
|
||||||
if [[ ${arrIN[0]} == 'linux' || ${arrIN[0]} == 'darwin' || ${arrIN[0]} == 'freebsd' || ${arrIN[0]} == 'windows' ]]; then
|
if [[ ${arrIN[0]} == 'linux' || ${arrIN[0]} == 'darwin' || ${arrIN[0]} == 'freebsd' || ${arrIN[0]} == 'windows' ]]; then
|
||||||
echo "Building $distro..."
|
echo "Building $distro..."
|
||||||
GOOS=${arrIN[0]} GOARCH=${arrIN[1]} go build --ldflags="-X 'main.Version=$(git describe --tags --abbrev=0)'" -o "dist/img-proxy-url-generator_${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]}"
|
gpg --detach-sign "dist/img-proxy-url-generator_${arrIN[0]}_${arrIN[1]}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"encoding/base64"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,6 +15,26 @@ func pkcs7pad(data []byte, blockSize int) []byte {
|
|||||||
return append(data, padding...)
|
return append(data, padding...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Generator) Decrypt(s string) (string, error) {
|
||||||
|
c, err := aes.NewCipher(g.config.encryptionKeyBin)
|
||||||
|
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)
|
||||||
|
|
||||||
|
return string(cryptText), err
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Generator) generateBaseAesEncUrl(file []byte) (string, error) {
|
func (g *Generator) generateBaseAesEncUrl(file []byte) (string, error) {
|
||||||
c, err := aes.NewCipher(g.config.encryptionKeyBin)
|
c, err := aes.NewCipher(g.config.encryptionKeyBin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (g *Generator) StringToFormat(string string) (Format, error) {
|
func (g *Generator) StringToFormat(string string) (Format, error) {
|
||||||
switch strings.ToLower(string) {
|
s := strings.ToLower(string)
|
||||||
|
switch s {
|
||||||
case "jpg":
|
case "jpg":
|
||||||
return JPG, nil
|
return JPG, nil
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
@@ -33,6 +34,8 @@ func (g *Generator) StringToFormat(string string) (Format, error) {
|
|||||||
return GIF, nil
|
return GIF, nil
|
||||||
case "ico":
|
case "ico":
|
||||||
return ICO, nil
|
return ICO, nil
|
||||||
|
case "def":
|
||||||
|
case "default":
|
||||||
case "":
|
case "":
|
||||||
return DEF, nil
|
return DEF, nil
|
||||||
}
|
}
|
||||||
|
|||||||
23
go.mod
23
go.mod
@@ -1,25 +1,30 @@
|
|||||||
module github.com/siteworxpro/img-proxy-url-generator
|
module github.com/siteworxpro/img-proxy-url-generator
|
||||||
|
|
||||||
go 1.22.5
|
go 1.23.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aws/aws-sdk-go v1.54.19
|
github.com/aws/aws-sdk-go v1.55.5
|
||||||
github.com/bigkevmcd/go-configparser v0.0.0-20240624060122-ccd05f93a9d2
|
github.com/bigkevmcd/go-configparser v0.0.0-20240808124832-fc81059ea0bd
|
||||||
github.com/charmbracelet/lipgloss v0.12.1
|
github.com/charmbracelet/lipgloss v1.0.0
|
||||||
github.com/urfave/cli/v2 v2.27.2
|
github.com/urfave/cli/v2 v2.27.5
|
||||||
|
google.golang.org/grpc v1.68.0
|
||||||
|
google.golang.org/protobuf v1.35.2
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/charmbracelet/x/ansi v0.1.4 // indirect
|
github.com/charmbracelet/x/ansi v0.4.5 // indirect
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
github.com/muesli/termenv v0.15.2 // indirect
|
github.com/muesli/termenv v0.15.2 // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||||
golang.org/x/sys v0.22.0 // indirect
|
golang.org/x/net v0.31.0 // indirect
|
||||||
|
golang.org/x/sys v0.27.0 // indirect
|
||||||
|
golang.org/x/text v0.20.0 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
60
go.sum
60
go.sum
@@ -1,23 +1,21 @@
|
|||||||
github.com/aws/aws-sdk-go v1.54.18 h1:t8DGtN8A2wEiazoJxeDbfPsbxCKtjoRLuO7jBSgJzo4=
|
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
|
||||||
github.com/aws/aws-sdk-go v1.54.18/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
|
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
|
||||||
github.com/aws/aws-sdk-go v1.54.19 h1:tyWV+07jagrNiCcGRzRhdtVjQs7Vy41NwsuOcl0IbVI=
|
|
||||||
github.com/aws/aws-sdk-go v1.54.19/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 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
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-20240808124832-fc81059ea0bd h1:MsTk4yo6KVYdulsDscuH4AwiZN1CyuCJAg59EWE7HPQ=
|
||||||
github.com/bigkevmcd/go-configparser v0.0.0-20230427073640-c6b631f70126/go.mod h1:zqqfbfnDeSdRs1WihmMjSbhb2Ptw8Jbus831xoqiIec=
|
github.com/bigkevmcd/go-configparser v0.0.0-20240808124832-fc81059ea0bd/go.mod h1:vzEQfW+A1T+AMJmTIX+SXNLNECHOM7GEinHhw0IjykI=
|
||||||
github.com/bigkevmcd/go-configparser v0.0.0-20240624060122-ccd05f93a9d2 h1:2qnRmzKO1fVs2UOqyt6tRMpVB8FrOnx8IG8C2lK0cjU=
|
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
|
||||||
github.com/bigkevmcd/go-configparser v0.0.0-20240624060122-ccd05f93a9d2/go.mod h1:vzEQfW+A1T+AMJmTIX+SXNLNECHOM7GEinHhw0IjykI=
|
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
|
||||||
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
|
github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM=
|
||||||
github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
|
github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
|
||||||
github.com/charmbracelet/lipgloss v0.12.1 h1:/gmzszl+pedQpjCOH+wFkZr/N90Snz40J/NR7A0zQcs=
|
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
|
||||||
github.com/charmbracelet/lipgloss v0.12.1/go.mod h1:V2CiwIuhx9S1S1ZlADfOj9HmxeMAORuz5izHb0zGbB8=
|
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/charmbracelet/x/ansi v0.1.4 h1:IEU3D6+dWwPSgZ6HBH+v6oUuZ/nVawMiWj5831KfiLM=
|
|
||||||
github.com/charmbracelet/x/ansi v0.1.4/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
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/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
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 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 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
|
||||||
@@ -30,33 +28,35 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69
|
|||||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
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-isatty v0.0.20/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.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
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 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
|
||||||
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
|
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
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/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/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
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 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
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 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
|
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
|
||||||
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
|
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
|
||||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
|
|
||||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
|
|
||||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
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=
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||||
|
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
|
||||||
|
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
|
||||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f h1:C1QccEa9kUwvMgEUORqQD9S17QesQijxjZ84sO82mfo=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
|
||||||
|
google.golang.org/grpc v1.68.0 h1:aHQeeJbo8zAkAa3pRzrVjZlbz6uSfeOXlJNQM0RAbz0=
|
||||||
|
google.golang.org/grpc v1.68.0/go.mod h1:fmSPC5AsjSBCK54MyHRx48kpOti1/jRfOlwEWywNjWA=
|
||||||
|
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
||||||
|
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
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 h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
|||||||
304
grpc/imgurl.pb.go
Normal file
304
grpc/imgurl.pb.go
Normal 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
29
grpc/imgurl.proto
Normal 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
121
grpc/imgurl_grpc.pb.go
Normal 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
0
grpc/php/src/.gitkeep
Normal file
43
grpc/server.go
Normal file
43
grpc/server.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/siteworxpro/img-proxy-url-generator/generator"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GeneratorService struct {
|
||||||
|
UnimplementedGeneratorServer
|
||||||
|
imgGenerator *generator.Generator
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewService(imgGenerator *generator.Generator) *GeneratorService {
|
||||||
|
return &GeneratorService{imgGenerator: imgGenerator}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
167
main.go
167
main.go
@@ -1,16 +1,21 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bigkevmcd/go-configparser"
|
"github.com/bigkevmcd/go-configparser"
|
||||||
"github.com/siteworxpro/img-proxy-url-generator/aws"
|
"github.com/siteworxpro/img-proxy-url-generator/aws"
|
||||||
"github.com/siteworxpro/img-proxy-url-generator/generator"
|
"github.com/siteworxpro/img-proxy-url-generator/generator"
|
||||||
|
proto "github.com/siteworxpro/img-proxy-url-generator/grpc"
|
||||||
"github.com/siteworxpro/img-proxy-url-generator/printer"
|
"github.com/siteworxpro/img-proxy-url-generator/printer"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"google.golang.org/grpc"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var keyBin, saltBin []byte
|
var keyBin, saltBin []byte
|
||||||
@@ -21,6 +26,12 @@ var Version = "v0.0.0"
|
|||||||
|
|
||||||
var awsConfig aws.Config
|
var awsConfig aws.Config
|
||||||
|
|
||||||
|
type jsonRequest struct {
|
||||||
|
Image string `json:"image"`
|
||||||
|
Params []string `json:"params"`
|
||||||
|
Format string `json:"format"`
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
pr := printer.NewPrinter()
|
pr := printer.NewPrinter()
|
||||||
@@ -52,16 +63,76 @@ func main() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err := os.Stat("./templates")
|
commands = append(commands, &cli.Command{
|
||||||
if !os.IsNotExist(err) {
|
Name: "server",
|
||||||
commands = append(commands, &cli.Command{
|
Usage: "Start a webserver for s3 file browsing and the web service",
|
||||||
Name: "server",
|
Action: func(c *cli.Context) error {
|
||||||
Usage: "Start a webserver for s3 file browsing",
|
return startServer(c, pr)
|
||||||
Action: func(c *cli.Context) error {
|
},
|
||||||
return startServer(c, pr)
|
})
|
||||||
|
|
||||||
|
commands = append(commands, &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 {
|
||||||
|
err := initGenerator(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)
|
||||||
|
}
|
||||||
|
proto.RegisterGeneratorServer(s, proto.NewService(imgGenerator))
|
||||||
|
err = s.Serve(lis)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to serve: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
commands = append(commands, &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 {
|
||||||
|
err := initGenerator(c.String("config"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
plain, err := imgGenerator.Decrypt(c.String("url"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pr.LogSuccess(plain)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "img-proxy-url-generator",
|
Name: "img-proxy-url-generator",
|
||||||
@@ -82,7 +153,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err = app.Run(os.Args)
|
err := app.Run(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pr.LogError(err.Error())
|
pr.LogError(err.Error())
|
||||||
|
|
||||||
@@ -96,41 +167,73 @@ func startServer(c *cli.Context, p *printer.Printer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
awsClient := aws.NewClient(&awsConfig)
|
_, err = os.Stat("./templates")
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
awsClient := aws.NewClient(&awsConfig)
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
contToken := r.URL.Query().Get("next")
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
var next *string
|
||||||
contToken := r.URL.Query().Get("next")
|
if contToken == "" {
|
||||||
|
next = nil
|
||||||
|
} else {
|
||||||
|
next = &contToken
|
||||||
|
}
|
||||||
|
|
||||||
var next *string
|
contents, err := awsClient.ListBucketContents(next)
|
||||||
if contToken == "" {
|
if err != nil {
|
||||||
next = nil
|
return
|
||||||
} else {
|
}
|
||||||
next = &contToken
|
|
||||||
}
|
for i, content := range contents.Images {
|
||||||
|
contents.Images[i].Url, _ = signURL("s3://"+awsConfig.Bucket+"/"+content.Name, []string{"pr:sq"}, "")
|
||||||
|
contents.Images[i].Download, _ = signURL("s3://"+awsConfig.Bucket+"/"+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)
|
||||||
|
|
||||||
contents, err := awsClient.ListBucketContents(next)
|
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, content := range contents.Images {
|
bodyContents := make([]byte, r.ContentLength)
|
||||||
contents.Images[i].Url, _ = signURL("s3://"+awsConfig.Bucket+"/"+content.Name, []string{"pr:sq"}, "")
|
_, _ = r.Body.Read(bodyContents)
|
||||||
contents.Images[i].Download, _ = signURL("s3://"+awsConfig.Bucket+"/"+content.Name, []string{""}, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
file, _ := os.ReadFile("./templates/index.gohtml")
|
|
||||||
|
|
||||||
tmpl := template.Must(template.New("index").Parse(string(file)))
|
|
||||||
|
|
||||||
err = tmpl.Execute(w, contents)
|
|
||||||
|
|
||||||
|
jr := jsonRequest{}
|
||||||
|
err = json.Unmarshal(bodyContents, &jr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println(err.Error())
|
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")
|
p.LogSuccess("Starting http server on port 8080. http://localhost:8080")
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe("0.0.0.0:8080", nil))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user