mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Download: Add Disabled, Originals, MediaRaw & MediaSidecar Flags #2234
Extends DownloadSettings with 4 additional options: - Name: File name pattern for downloaded files (existed) - Disabled: Disables downloads - Originals: Only download files stored in "originals" folder - MediaRaw: Include RAW image files - MediaSidecar: Include metadata sidecar files (JSON, XMP, YAML)
This commit is contained in:
62
internal/config/config_auth.go
Normal file
62
internal/config/config_auth.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/rnd"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func isBcrypt(s string) bool {
|
||||
b, err := regexp.MatchString(`^\$2[ayb]\$.{56}$`, s)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// CheckPassword compares given password p with the admin password
|
||||
func (c *Config) CheckPassword(p string) bool {
|
||||
ap := c.AdminPassword()
|
||||
|
||||
if isBcrypt(ap) {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(ap), []byte(p))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
return ap == p
|
||||
}
|
||||
|
||||
// InvalidDownloadToken checks if the token is invalid.
|
||||
func (c *Config) InvalidDownloadToken(t string) bool {
|
||||
return c.DownloadToken() != t
|
||||
}
|
||||
|
||||
// DownloadToken returns the DOWNLOAD api token (you can optionally use a static value for permanent caching).
|
||||
func (c *Config) DownloadToken() string {
|
||||
if c.options.DownloadToken == "" {
|
||||
c.options.DownloadToken = rnd.GenerateToken(8)
|
||||
}
|
||||
|
||||
return c.options.DownloadToken
|
||||
}
|
||||
|
||||
// InvalidPreviewToken checks if the preview token is invalid.
|
||||
func (c *Config) InvalidPreviewToken(t string) bool {
|
||||
return c.PreviewToken() != t && c.DownloadToken() != t
|
||||
}
|
||||
|
||||
// PreviewToken returns the preview image api token (based on the unique storage serial by default).
|
||||
func (c *Config) PreviewToken() string {
|
||||
if c.options.PreviewToken == "" {
|
||||
if c.Public() {
|
||||
c.options.PreviewToken = "public"
|
||||
} else if c.Serial() == "" {
|
||||
return "********"
|
||||
} else {
|
||||
c.options.PreviewToken = c.SerialChecksum()
|
||||
}
|
||||
}
|
||||
|
||||
return c.options.PreviewToken
|
||||
}
|
||||
Reference in New Issue
Block a user