-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): improve image proxy usage
- use main downloader cache - use image proxy for thumbhash
- Loading branch information
Showing
14 changed files
with
156 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,14 @@ | ||
package service | ||
|
||
import ( | ||
"crypto/hmac" | ||
"crypto/sha256" | ||
"encoding/base64" | ||
|
||
"github.com/ncarlier/readflow/internal/model" | ||
imageproxy "github.com/ncarlier/readflow/pkg/image-proxy" | ||
) | ||
|
||
// encode image URL to Image Proxy path | ||
func encodeImageProxyPath(url, size string) string { | ||
return "/resize:fit:" + size + "/" + base64.StdEncoding.EncodeToString([]byte(url)) | ||
} | ||
|
||
// GetArticleThumbnail return article thumbnail URL | ||
func (reg *Registry) GetArticleThumbnailHash(article *model.Article, size string) string { | ||
if article.Image == nil || *article.Image == "" { | ||
return "" | ||
// GetArticleThumbnailHashSet return article thumbnail hash set | ||
func (reg *Registry) GetArticleThumbnailHashSet(article *model.Article) *[]imageproxy.ImageProxyHashSet { | ||
if reg.imageProxy.URL() == "" || article.Image == nil || *article.Image == "" { | ||
return nil | ||
} | ||
path := encodeImageProxyPath(*article.Image, size) | ||
|
||
mac := hmac.New(sha256.New, reg.conf.Hash.SecretKey.Value) | ||
mac.Write(reg.conf.Hash.SecretSalt.Value) | ||
mac.Write([]byte(path)) | ||
return base64.RawURLEncoding.EncodeToString(mac.Sum(nil)) | ||
return reg.imageProxy.GetHashSet(*article.Image) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.