Rename ThumbToken to PreviewToken

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-05-27 19:56:56 +02:00
parent 6f6e3799dc
commit 94846c2337
21 changed files with 41 additions and 41 deletions

View file

@ -152,8 +152,8 @@ class Config {
return this.values["downloadToken"]; return this.values["downloadToken"];
} }
thumbToken() { previewToken() {
return this.values["thumbToken"]; return this.values["previewToken"];
} }
} }

View file

@ -45,7 +45,7 @@ export class Album extends RestModel {
} }
thumbnailUrl(type) { thumbnailUrl(type) {
return `/api/v1/albums/${this.getId()}/t/${config.thumbToken()}/${type}`; return `/api/v1/albums/${this.getId()}/t/${config.previewToken()}/${type}`;
} }
thumbnailSrcset() { thumbnailSrcset() {

View file

@ -80,7 +80,7 @@ export class File extends RestModel {
return "/api/v1/svg/raw"; return "/api/v1/svg/raw";
} }
return `/api/v1/t/${this.Hash}/t/${config.thumbToken()}/${type}`; return `/api/v1/t/${this.Hash}/t/${config.previewToken()}/${type}`;
} }
getDownloadUrl() { getDownloadUrl() {

View file

@ -36,7 +36,7 @@ export class Label extends RestModel {
} }
thumbnailUrl(type) { thumbnailUrl(type) {
return `/api/v1/labels/${this.getId()}/t/${config.thumbToken()}/${type}`; return `/api/v1/labels/${this.getId()}/t/${config.previewToken()}/${type}`;
} }
thumbnailSrcset() { thumbnailSrcset() {

View file

@ -167,7 +167,7 @@ export class Photo extends RestModel {
return ""; return "";
} }
return `/api/v1/videos/${file.Hash}/${config.thumbToken()}/${TypeMP4}`; return `/api/v1/videos/${file.Hash}/${config.previewToken()}/${TypeMP4}`;
} }
mainFile() { mainFile() {
@ -205,13 +205,13 @@ export class Photo extends RestModel {
let video = this.videoFile(); let video = this.videoFile();
if (video && video.Hash) { if (video && video.Hash) {
return `/api/v1/t/${video.Hash}/${config.thumbToken()}/${type}`; return `/api/v1/t/${video.Hash}/${config.previewToken()}/${type}`;
} }
return "/api/v1/svg/photo"; return "/api/v1/svg/photo";
} }
return `/api/v1/t/${hash}/${config.thumbToken()}/${type}`; return `/api/v1/t/${hash}/${config.previewToken()}/${type}`;
} }
getDownloadUrl() { getDownloadUrl() {

View file

@ -177,7 +177,7 @@ export class Thumb extends Model {
} }
return `/api/v1/t/${file.Hash}/${config.thumbToken()}/${type}`; return `/api/v1/t/${file.Hash}/${config.previewToken()}/${type}`;
} }
static downloadUrl(file) { static downloadUrl(file) {

View file

@ -166,7 +166,7 @@
let id = features[i].id; let id = features[i].id;
let marker = this.markers[id]; let marker = this.markers[id];
let token = this.$config.thumbToken(); let token = this.$config.previewToken();
if (!marker) { if (!marker) {
let el = document.createElement('div'); let el = document.createElement('div');
el.className = 'marker'; el.className = 'marker';

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -270,20 +270,20 @@ func TestAlbumThumbnail(t *testing.T) {
t.Run("invalid type", func(t *testing.T) { t.Run("invalid type", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
AlbumThumbnail(router, conf) AlbumThumbnail(router, conf)
r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba7/t/"+conf.ThumbToken()+"/xxx") r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba7/t/"+conf.PreviewToken()+"/xxx")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
t.Run("album has no photo (because is not existing)", func(t *testing.T) { t.Run("album has no photo (because is not existing)", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
AlbumThumbnail(router, conf) AlbumThumbnail(router, conf)
r := PerformRequest(app, "GET", "/api/v1/albums/987-986435/t/"+conf.ThumbToken()+"/tile_500") r := PerformRequest(app, "GET", "/api/v1/albums/987-986435/t/"+conf.PreviewToken()+"/tile_500")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
t.Run("album: could not find original", func(t *testing.T) { t.Run("album: could not find original", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
AlbumThumbnail(router, conf) AlbumThumbnail(router, conf)
r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba8/t/"+conf.ThumbToken()+"/tile_500") r := PerformRequest(app, "GET", "/api/v1/albums/at9lxuqxpogaaba8/t/"+conf.PreviewToken()+"/tile_500")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
} }

View file

@ -112,20 +112,20 @@ func TestLabelThumbnail(t *testing.T) {
t.Run("invalid type", func(t *testing.T) { t.Run("invalid type", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
LabelThumbnail(router, conf) LabelThumbnail(router, conf)
r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c2/t/"+conf.ThumbToken()+"/xxx") r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c2/t/"+conf.PreviewToken()+"/xxx")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
t.Run("invalid label", func(t *testing.T) { t.Run("invalid label", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
LabelThumbnail(router, conf) LabelThumbnail(router, conf)
r := PerformRequest(app, "GET", "/api/v1/labels/xxx/t/"+conf.ThumbToken()+"/tile_500") r := PerformRequest(app, "GET", "/api/v1/labels/xxx/t/"+conf.PreviewToken()+"/tile_500")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
t.Run("could not find original", func(t *testing.T) { t.Run("could not find original", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
LabelThumbnail(router, conf) LabelThumbnail(router, conf)
r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c3/t/"+conf.ThumbToken()+"/tile_500") r := PerformRequest(app, "GET", "/api/v1/labels/lt9k3pw1wowuy3c3/t/"+conf.PreviewToken()+"/tile_500")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
} }

View file

@ -11,21 +11,21 @@ func TestGetThumbnail(t *testing.T) {
t.Run("invalid type", func(t *testing.T) { t.Run("invalid type", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
GetThumbnail(router, conf) GetThumbnail(router, conf)
r := PerformRequest(app, "GET", "/api/v1/t/1/"+conf.ThumbToken()+"/xxx") r := PerformRequest(app, "GET", "/api/v1/t/1/"+conf.PreviewToken()+"/xxx")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
t.Run("invalid hash", func(t *testing.T) { t.Run("invalid hash", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
GetThumbnail(router, conf) GetThumbnail(router, conf)
r := PerformRequest(app, "GET", "/api/v1/t/1/"+conf.ThumbToken()+"/tile_500") r := PerformRequest(app, "GET", "/api/v1/t/1/"+conf.PreviewToken()+"/tile_500")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
t.Run("could not find original", func(t *testing.T) { t.Run("could not find original", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
GetThumbnail(router, conf) GetThumbnail(router, conf)
r := PerformRequest(app, "GET", "/api/v1/t/2cad9168fa6acc5c5c2965ddf6ec465ca42fd818/"+conf.ThumbToken()+"/tile_500") r := PerformRequest(app, "GET", "/api/v1/t/2cad9168fa6acc5c5c2965ddf6ec465ca42fd818/"+conf.PreviewToken()+"/tile_500")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
} }

View file

@ -10,25 +10,25 @@ func TestGetVideo(t *testing.T) {
t.Run("invalid hash", func(t *testing.T) { t.Run("invalid hash", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
GetVideo(router, conf) GetVideo(router, conf)
r := PerformRequest(app, "GET", "/api/v1/videos/xxx/"+conf.ThumbToken()+"/mp4") r := PerformRequest(app, "GET", "/api/v1/videos/xxx/"+conf.PreviewToken()+"/mp4")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
t.Run("invalid type", func(t *testing.T) { t.Run("invalid type", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
GetVideo(router, conf) GetVideo(router, conf)
r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd831/"+conf.ThumbToken()+"/xxx") r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd831/"+conf.PreviewToken()+"/xxx")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
t.Run("file for video not found", func(t *testing.T) { t.Run("file for video not found", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
GetVideo(router, conf) GetVideo(router, conf)
r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd831/"+conf.ThumbToken()+"/mp4") r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd831/"+conf.PreviewToken()+"/mp4")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
t.Run("file with error", func(t *testing.T) { t.Run("file with error", func(t *testing.T) {
app, router, conf := NewApiTest() app, router, conf := NewApiTest()
GetVideo(router, conf) GetVideo(router, conf)
r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd832/"+conf.ThumbToken()+"/mp4") r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd832/"+conf.PreviewToken()+"/mp4")
assert.Equal(t, http.StatusOK, r.Code) assert.Equal(t, http.StatusOK, r.Code)
}) })
} }

View file

@ -102,7 +102,7 @@ func configAction(ctx *cli.Context) error {
// Thumbnails // Thumbnails
fmt.Printf("%-25s %s\n", "download-token", conf.DownloadToken()) fmt.Printf("%-25s %s\n", "download-token", conf.DownloadToken())
fmt.Printf("%-25s %s\n", "thumb-token", conf.ThumbToken()) fmt.Printf("%-25s %s\n", "thumb-token", conf.PreviewToken())
fmt.Printf("%-25s %s\n", "thumb-filter", conf.ThumbFilter()) fmt.Printf("%-25s %s\n", "thumb-filter", conf.ThumbFilter())
fmt.Printf("%-25s %t\n", "thumb-uncached", conf.ThumbUncached()) fmt.Printf("%-25s %t\n", "thumb-uncached", conf.ThumbUncached())
fmt.Printf("%-25s %d\n", "thumb-size", conf.ThumbSize()) fmt.Printf("%-25s %d\n", "thumb-size", conf.ThumbSize())

View file

@ -43,14 +43,14 @@ func (c *Config) DownloadToken() string {
// InvalidToken returns true if the token is invalid. // InvalidToken returns true if the token is invalid.
func (c *Config) InvalidToken(t string) bool { func (c *Config) InvalidToken(t string) bool {
return c.ThumbToken() != t && c.DownloadToken() != t return c.PreviewToken() != t && c.DownloadToken() != t
} }
// ThumbToken returns the THUMBNAILS api token (you can optionally use a static value for permanent caching). // PreviewToken returns the THUMBNAILS api token (you can optionally use a static value for permanent caching).
func (c *Config) ThumbToken() string { func (c *Config) PreviewToken() string {
if c.params.ThumbToken == "" { if c.params.PreviewToken == "" {
c.params.ThumbToken = rnd.Token(8) c.params.PreviewToken = rnd.Token(8)
} }
return c.params.ThumbToken return c.params.PreviewToken
} }

View file

@ -35,7 +35,7 @@ type ClientConfig struct {
Countries []entity.Country `json:"countries"` Countries []entity.Country `json:"countries"`
Thumbnails []Thumbnail `json:"thumbnails"` Thumbnails []Thumbnail `json:"thumbnails"`
DownloadToken string `json:"downloadToken"` DownloadToken string `json:"downloadToken"`
ThumbToken string `json:"thumbToken"` PreviewToken string `json:"previewToken"`
JSHash string `json:"jsHash"` JSHash string `json:"jsHash"`
CSSHash string `json:"cssHash"` CSSHash string `json:"cssHash"`
Settings Settings `json:"settings"` Settings Settings `json:"settings"`
@ -133,7 +133,7 @@ func (c *Config) PublicClientConfig() ClientConfig {
JSHash: fs.Checksum(c.HttpStaticBuildPath() + "/app.js"), JSHash: fs.Checksum(c.HttpStaticBuildPath() + "/app.js"),
CSSHash: fs.Checksum(c.HttpStaticBuildPath() + "/app.css"), CSSHash: fs.Checksum(c.HttpStaticBuildPath() + "/app.css"),
Clip: txt.ClipDefault, Clip: txt.ClipDefault,
ThumbToken: "public", PreviewToken: "public",
DownloadToken: "public", DownloadToken: "public",
} }
@ -164,7 +164,7 @@ func (c *Config) ClientConfig() ClientConfig {
Colors: colors.All.List(), Colors: colors.All.List(),
Thumbnails: Thumbnails, Thumbnails: Thumbnails,
DownloadToken: c.DownloadToken(), DownloadToken: c.DownloadToken(),
ThumbToken: c.ThumbToken(), PreviewToken: c.PreviewToken(),
JSHash: fs.Checksum(c.HttpStaticBuildPath() + "/app.js"), JSHash: fs.Checksum(c.HttpStaticBuildPath() + "/app.js"),
CSSHash: fs.Checksum(c.HttpStaticBuildPath() + "/app.css"), CSSHash: fs.Checksum(c.HttpStaticBuildPath() + "/app.css"),
Clip: txt.ClipDefault, Clip: txt.ClipDefault,

View file

@ -266,10 +266,10 @@ var GlobalFlags = []cli.Flag{
EnvVar: "PHOTOPRISM_DOWNLOAD_TOKEN", EnvVar: "PHOTOPRISM_DOWNLOAD_TOKEN",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "thumb-token", Name: "preview-token",
Usage: "url `TOKEN` for thumbnails and video streaming", Usage: "url `TOKEN` for thumbnails and video streaming",
Value: "static", Value: "static",
EnvVar: "PHOTOPRISM_THUMB_TOKEN", EnvVar: "PHOTOPRISM_PREVIEW_TOKEN",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "thumb-filter, f", Name: "thumb-filter, f",

View file

@ -79,7 +79,7 @@ type Params struct {
UploadNSFW bool `yaml:"upload-nsfw" flag:"upload-nsfw"` UploadNSFW bool `yaml:"upload-nsfw" flag:"upload-nsfw"`
GeoCodingApi string `yaml:"geocoding-api" flag:"geocoding-api"` GeoCodingApi string `yaml:"geocoding-api" flag:"geocoding-api"`
DownloadToken string `yaml:"download-token" flag:"download-token"` DownloadToken string `yaml:"download-token" flag:"download-token"`
ThumbToken string `yaml:"thumb-token" flag:"thumb-token"` PreviewToken string `yaml:"preview-token" flag:"preview-token"`
ThumbFilter string `yaml:"thumb-filter" flag:"thumb-filter"` ThumbFilter string `yaml:"thumb-filter" flag:"thumb-filter"`
ThumbUncached bool `yaml:"thumb-uncached" flag:"thumb-uncached"` ThumbUncached bool `yaml:"thumb-uncached" flag:"thumb-uncached"`
ThumbSize int `yaml:"thumb-size" flag:"thumb-size"` ThumbSize int `yaml:"thumb-size" flag:"thumb-size"`