auto-sign thumbnails
This commit is contained in:
parent
f348bb92e3
commit
6a88d9d0f4
3 changed files with 16 additions and 179 deletions
17
processor.go
17
processor.go
|
|
@ -2,12 +2,14 @@ package imagorvideoextended
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"github.com/antchfx/htmlquery"
|
||||
"github.com/cshum/imagor"
|
||||
"github.com/cshum/imagor/imagorpath"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"go.uber.org/zap"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -39,6 +41,18 @@ func (p *Processor) Shutdown(_ context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func subThumbnail(url string) string {
|
||||
key := os.Getenv("IMAGOR_SECRET")
|
||||
params := imagorpath.Params{
|
||||
Image: url,
|
||||
FitIn: true,
|
||||
Width: 400,
|
||||
Height: 400,
|
||||
}
|
||||
path := imagorpath.Generate(params, imagorpath.NewHMACSigner(sha256.New, 0, key))
|
||||
return path
|
||||
}
|
||||
|
||||
// Process implements imagor.Processor interface
|
||||
func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorpath.Params, load imagor.LoadFunc) (out *imagor.Blob, err error) {
|
||||
defer func() {
|
||||
|
|
@ -57,6 +71,7 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
|
|||
}
|
||||
}
|
||||
}()
|
||||
|
||||
var mime = mimetype.Detect(in.Sniff())
|
||||
|
||||
if typ := mime.String(); !strings.HasPrefix(typ, "text/html") {
|
||||
|
|
@ -103,7 +118,7 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
|
|||
case "og:image":
|
||||
fallthrough
|
||||
case "twitter:image:src":
|
||||
meta.Image = val
|
||||
meta.Image = subThumbnail(val)
|
||||
break
|
||||
|
||||
case "og:title":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue