mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-05 19:23:07 +02:00
Add option for reading images from local filesystem
This commit is contained in:
@@ -144,6 +144,7 @@ $ xxd -g 2 -l 64 -p /dev/random | tr -d '\n'
|
|||||||
* `IMGPROXY_CONCURRENCY` — the maximum number of image requests to be processed simultaneously. Default: double number of CPU cores;
|
* `IMGPROXY_CONCURRENCY` — the maximum number of image requests to be processed simultaneously. Default: double number of CPU cores;
|
||||||
* `IMGPROXY_MAX_CLIENTS` — the maximum number of simultaneous active connections. Default: `IMGPROXY_CONCURRENCY * 5`;
|
* `IMGPROXY_MAX_CLIENTS` — the maximum number of simultaneous active connections. Default: `IMGPROXY_CONCURRENCY * 5`;
|
||||||
* `IMGPROXY_TTL` — duration in seconds sent in `Expires` and `Cache-Control: max-age` headers. Default: `3600` (1 hour);
|
* `IMGPROXY_TTL` — duration in seconds sent in `Expires` and `Cache-Control: max-age` headers. Default: `3600` (1 hour);
|
||||||
|
* `IMGPROXY_LOCAL_FILESYSTEM_ROOT` — root directory path for serving images from local filesystem via `local:///image.ext`. Default: disabled
|
||||||
|
|
||||||
#### Security
|
#### Security
|
||||||
|
|
||||||
|
19
config.go
19
config.go
@@ -85,6 +85,8 @@ type config struct {
|
|||||||
Salt []byte
|
Salt []byte
|
||||||
|
|
||||||
Secret string
|
Secret string
|
||||||
|
|
||||||
|
LocalFileSystemRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
var conf = config{
|
var conf = config{
|
||||||
@@ -98,6 +100,7 @@ var conf = config{
|
|||||||
MaxSrcResolution: 16800000,
|
MaxSrcResolution: 16800000,
|
||||||
Quality: 80,
|
Quality: 80,
|
||||||
GZipCompression: 5,
|
GZipCompression: 5,
|
||||||
|
LocalFileSystemRoot: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -132,6 +135,8 @@ func init() {
|
|||||||
|
|
||||||
strEnvConfig(&conf.Secret, "IMGPROXY_SECRET")
|
strEnvConfig(&conf.Secret, "IMGPROXY_SECRET")
|
||||||
|
|
||||||
|
strEnvConfig(&conf.LocalFileSystemRoot, "IMGPROXY_LOCAL_FILESYSTEM_ROOT")
|
||||||
|
|
||||||
if len(conf.Key) == 0 {
|
if len(conf.Key) == 0 {
|
||||||
log.Fatalln("Key is not defined")
|
log.Fatalln("Key is not defined")
|
||||||
}
|
}
|
||||||
@@ -187,6 +192,20 @@ func init() {
|
|||||||
log.Fatalf("GZip compression can't be greater than 9, now - %d\n", conf.GZipCompression)
|
log.Fatalf("GZip compression can't be greater than 9, now - %d\n", conf.GZipCompression)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.LocalFileSystemRoot != "" {
|
||||||
|
stat, err := os.Stat(conf.LocalFileSystemRoot)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Cannot use local directory: %s", err)
|
||||||
|
} else {
|
||||||
|
if !stat.IsDir() {
|
||||||
|
log.Fatalf("Cannot use local directory: not a directory")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if conf.LocalFileSystemRoot == "/" {
|
||||||
|
log.Print("Exposing root via IMGPROXY_LOCAL_FILESYSTEM_ROOT is unsafe")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initVips()
|
initVips()
|
||||||
initDownloading()
|
initDownloading()
|
||||||
}
|
}
|
||||||
|
@@ -56,8 +56,13 @@ func (r *netReader) GrowBuf(s int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initDownloading() {
|
func initDownloading() {
|
||||||
|
transport := &http.Transport{}
|
||||||
|
if conf.LocalFileSystemRoot != "" {
|
||||||
|
transport.RegisterProtocol("local", http.NewFileTransport(http.Dir(conf.LocalFileSystemRoot)))
|
||||||
|
}
|
||||||
downloadClient = &http.Client{
|
downloadClient = &http.Client{
|
||||||
Timeout: time.Duration(conf.DownloadTimeout) * time.Second,
|
Timeout: time.Duration(conf.DownloadTimeout) * time.Second,
|
||||||
|
Transport: transport,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user