imagorvideoextended/loader.go
Failure 17d4d46d09
Some checks failed
docker / Docker (push) Has been cancelled
test / Test (push) Has been cancelled
youtube handling + special site handling framework
2024-08-06 08:50:35 -07:00

43 lines
1 KiB
Go

package imagorvideoextended
import (
"github.com/cshum/imagor"
"net/http"
"net/url"
"strings"
)
/*
This was started to handle YouTube, however it turns out they leak just enough info to be useful in the processing
phase. This can still be used for sites that have more info in the URL than the connection, though.
Currently unloaded to eke out some more perf
*/
type LoaderOption func(h *SpecialLoader)
// SpecialLoader HTTP Loader implements imagor.Loader interface
type SpecialLoader struct {
}
func NewSpecialLoader(options ...LoaderOption) *SpecialLoader {
loader := &SpecialLoader{}
for _, option := range options {
option(loader)
}
return loader
}
func (loader *SpecialLoader) Get(_ *http.Request, key string) (*imagor.Blob, error) {
components, err := url.Parse(key)
if err != nil {
return nil, imagor.ErrInvalid
}
hostname := components.Hostname()
if trimmed, ok := strings.CutPrefix(hostname, "www."); ok {
hostname = trimmed
}
switch components.Hostname() {
default:
return nil, imagor.ErrInvalid
}
}