mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-25 06:18:42 -05:00
* feature(thumbnails): add the ability to define custom image processors * fix(ci): add exported member comment * docs(thumbnails): mention processors in readme * fix: codacy and code review feedback * fix: thumbnail readme markdown Co-authored-by: Martin <github@diemattels.at> --------- Co-authored-by: Martin <github@diemattels.at>
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package storage
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// NewInMemoryStorage creates a new InMemory instance.
|
|
func NewInMemoryStorage() InMemory {
|
|
return InMemory{
|
|
store: make(map[string][]byte),
|
|
}
|
|
}
|
|
|
|
// InMemory represents an in memory storage for thumbnails
|
|
// Can be used during development
|
|
type InMemory struct {
|
|
store map[string][]byte
|
|
}
|
|
|
|
func (s InMemory) Stat(key string) bool {
|
|
_, exists := s.store[key]
|
|
return exists
|
|
}
|
|
|
|
// Get loads the thumbnail from memory.
|
|
func (s InMemory) Get(key string) ([]byte, error) {
|
|
return s.store[key], nil
|
|
}
|
|
|
|
// Set stores the thumbnail in memory.
|
|
func (s InMemory) Put(key string, thumbnail []byte) error {
|
|
s.store[key] = thumbnail
|
|
return nil
|
|
}
|
|
|
|
// BuildKey generates a unique key to store and retrieve the thumbnail.
|
|
func (s InMemory) BuildKey(r Request) string {
|
|
parts := []string{
|
|
r.Checksum,
|
|
r.Resolution.String(),
|
|
}
|
|
|
|
if r.Characteristic != "" {
|
|
parts = append(parts, r.Characteristic)
|
|
}
|
|
|
|
parts = append(parts, strings.Join(r.Types, ","))
|
|
|
|
return strings.Join(parts, "+")
|
|
}
|