youtube handling + special site handling framework
This commit is contained in:
parent
6a88d9d0f4
commit
17d4d46d09
4 changed files with 97 additions and 8 deletions
43
loader.go
Normal file
43
loader.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue