Skip to content

Commit

Permalink
Improve UX and title generation from file names
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
  • Loading branch information
lastzero committed Jun 29, 2020
1 parent cf773b5 commit bfd7393
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 73 deletions.
32 changes: 16 additions & 16 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-istanbul": "^6.0.0",
"browserslist": "^4.12.1",
"browserslist": "^4.12.2",
"chai": "^4.2.0",
"chalk": "^4.1.0",
"chart.js": "^2.9.3",
Expand All @@ -54,7 +54,7 @@
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^3.0.4",
"eslint-plugin-html": "^6.0.2",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/component/p-navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</v-list-tile-content>
</v-list-tile>

<v-list-tile to="/review" @click="" v-if="$config.feature('review') && config.count.review > 0"
<v-list-tile to="/review" @click="" v-if="$config.feature('review')"
class="p-navigation-review">
<v-list-tile-content>
<v-list-tile-title>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/pages/album/photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@
if (this.results.length > 1) {
this.$notify.info(this.$gettext('All ') + this.results.length + this.$gettext(' entries loaded'));
}
} else if (this.results.length >= Photo.limit()) {
this.offset = offset;
this.scrollDisabled = true;
this.$notify.warn(this.$gettext("Can't load more, limit reached"));
} else {
this.offset = offset + count;
this.page++;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/library/files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
dirty: false,
results: [],
loading: true,
filesLimit: 500,
filesLimit: 1111,
filesOffset: 0,
page: 0,
selection: [],
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/pages/photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@
if (this.results.length > 1) {
this.$notify.info(this.$gettext('All ') + this.results.length + this.$gettext(' photos loaded'));
}
} else if (this.results.length >= Photo.limit()) {
this.offset = offset;
this.scrollDisabled = true;
this.$notify.warn(this.$gettext("Can't load more, limit reached"));
} else {
this.offset = offset + count;
this.page++;
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/share/photos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
if (this.results.length > 1) {
this.$notify.info(this.$gettext('All ') + this.results.length + this.$gettext(' entries loaded'));
}
} else if (this.results.length >= Photo.limit()) {
this.offset = offset;
this.scrollDisabled = true;
this.$notify.warn(this.$gettext("Can't load more, limit reached"));
} else {
this.offset = offset + count;
this.page++;
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/image v0.0.0-20200618115811-c13761719519 // indirect
golang.org/x/net v0.0.0-20200625001655-4c5254603344
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/ugjka/go-tz.v2 v2.0.9
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4 h1:5/PjkGUjvEU5Gl6BxmvKRPpqo2uNMv4rcHBMwzk/st8=
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down
49 changes: 26 additions & 23 deletions internal/api/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,31 @@ func wsReader(ws *websocket.Conn, writeMutex *sync.Mutex, connId string, conf *c
break
}

log.Debugf("websocket: received %d bytes", len(m))

var info clientInfo

if err := json.Unmarshal(m, &info); err != nil {
log.Error(err)
// Do nothing.
} else {
if sess := Session(info.SessionToken); sess.Valid() {
log.Debug("websocket: authenticated")

wsAuth.mutex.Lock()
wsAuth.user[connId] = sess.User
wsAuth.mutex.Unlock()

writeMutex.Lock()
ws.SetWriteDeadline(time.Now().Add(30 * time.Second))
var clientConfig config.ClientConfig

if sess.User.Guest() {
if err := ws.WriteJSON(gin.H{"event": "config.updated", "data": event.Data{"config": conf.GuestConfig()}}); err != nil {
log.Error(err)
}
clientConfig = conf.GuestConfig()
} else if sess.User.Registered() {
if err := ws.WriteJSON(gin.H{"event": "config.updated", "data": event.Data{"config": conf.UserConfig()}}); err != nil {
log.Error(err)
}
clientConfig = conf.UserConfig()
} else {
if err := ws.WriteJSON(gin.H{"event": "config.updated", "data": event.Data{"config": conf.PublicConfig()}}); err != nil {
log.Error(err)
}
clientConfig = conf.PublicConfig()
}

writeMutex.Lock()
ws.SetWriteDeadline(time.Now().Add(30 * time.Second))

if err := ws.WriteJSON(gin.H{"event": "config.updated", "data": event.Data{"config": clientConfig}}); err != nil {
// Do nothing.
}

writeMutex.Unlock()
Expand Down Expand Up @@ -117,13 +113,24 @@ func wsWriter(ws *websocket.Conn, writeMutex *sync.Mutex, connId string) {
for {
select {
case <-pingTicker.C:
writeMutex.Lock()
ws.SetWriteDeadline(time.Now().Add(30 * time.Second))

if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
writeMutex.Unlock()
return
}

writeMutex.Unlock()
case msg := <-s.Receiver:
wsAuth.mutex.RLock()
user := wsAuth.user[connId]

user := entity.UnknownPerson

if hit, ok := wsAuth.user[connId]; ok {
user = hit
}

wsAuth.mutex.RUnlock()

if user.Registered() {
Expand All @@ -132,9 +139,9 @@ func wsWriter(ws *websocket.Conn, writeMutex *sync.Mutex, connId string) {

if err := ws.WriteJSON(gin.H{"event": msg.Name, "data": msg.Fields}); err != nil {
writeMutex.Unlock()
log.Debug(err)
return
}

writeMutex.Unlock()
}
}
Expand All @@ -144,14 +151,12 @@ func wsWriter(ws *websocket.Conn, writeMutex *sync.Mutex, connId string) {
// GET /api/v1/ws
func Websocket(router *gin.RouterGroup) {
if router == nil {
log.Error("websocket: router is nil")
return
}

conf := service.Config()

if conf == nil {
log.Error("websocket: conf is nil")
return
}

Expand All @@ -160,8 +165,8 @@ func Websocket(router *gin.RouterGroup) {
r := c.Request

ws, err := wsConnection.Upgrade(w, r, nil)

if err != nil {
log.Error(err)
return
}

Expand All @@ -180,8 +185,6 @@ func Websocket(router *gin.RouterGroup) {
}
wsAuth.mutex.Unlock()

log.Debug("websocket: connected")

go wsWriter(ws, &writeMutex, connId)

wsReader(ws, &writeMutex, connId, conf)
Expand Down
6 changes: 3 additions & 3 deletions internal/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *Config) PublicConfig() ClientConfig {
return c.UserConfig()
}

defer log.Debug(capture.Time(time.Now(), "config: public config created"))
defer log.Debug(capture.Time(time.Now(), "client config created (public)"))

settings := c.Settings()

Expand Down Expand Up @@ -155,7 +155,7 @@ func (c *Config) PublicConfig() ClientConfig {

// GuestConfig returns client config values for the sharing with guests.
func (c *Config) GuestConfig() ClientConfig {
defer log.Debug(capture.Time(time.Now(), "config: guest config created"))
defer log.Debug(capture.Time(time.Now(), "client config created (guest)"))

settings := c.Settings()

Expand Down Expand Up @@ -196,7 +196,7 @@ func (c *Config) GuestConfig() ClientConfig {

// UserConfig returns client configuration values for registered users.
func (c *Config) UserConfig() ClientConfig {
defer log.Debug(capture.Time(time.Now(), "config: user config created"))
defer log.Debug(capture.Time(time.Now(), "client config created (user)"))

result := ClientConfig{
Settings: *c.Settings(),
Expand Down
4 changes: 2 additions & 2 deletions internal/entity/photo.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,13 @@ func (m *Photo) DetailsLoaded() bool {

// TitleFromFileName returns a photo title based on the file name and/or path.
func (m *Photo) TitleFromFileName() string {
if fs.NonCanonical(m.PhotoName) {
if !fs.IsID(m.PhotoName) {
if title := txt.TitleFromFileName(m.PhotoName); title != "" {
return title
}
}

if m.OriginalName != "" && fs.NonCanonical(m.OriginalName) {
if m.OriginalName != "" && !fs.IsID(m.OriginalName) {
if title := txt.TitleFromFileName(m.OriginalName); title != "" {
return title
} else if title := txt.TitleFromFileName(path.Dir(m.OriginalName)); title != "" {
Expand Down
4 changes: 2 additions & 2 deletions internal/entity/photo_maintain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func (m *Photo) EstimateCountry() {
countryCode = code
}

if countryCode == unknown && fs.NonCanonical(m.PhotoName) {
if countryCode == unknown && !fs.IsID(m.PhotoName) {
if code := txt.CountryCode(m.PhotoName); code != unknown {
countryCode = code
} else if code := txt.CountryCode(m.PhotoPath); code != unknown {
countryCode = code
}
}

if countryCode == unknown && m.OriginalName != "" && fs.NonCanonical(m.OriginalName) {
if countryCode == unknown && m.OriginalName != "" && !fs.IsID(m.OriginalName) {
if code := txt.CountryCode(m.OriginalName); code != UnknownCountry.ID {
countryCode = code
}
Expand Down
7 changes: 3 additions & 4 deletions internal/meta/sanitize.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package meta

import (
"regexp"
"strings"
)

var DscTitleRegexp = regexp.MustCompile("\\D{3}[\\d_]\\d{4}(.JPG)?")
"github.com/photoprism/photoprism/pkg/fs"
)

var UnwantedDescriptions = map[string]bool{
"OLYMPUS DIGITAL CAMERA": true,
Expand Down Expand Up @@ -37,7 +36,7 @@ func SanitizeUID(value string) string {
func SanitizeTitle(value string) string {
value = SanitizeString(value)

if dsc := DscTitleRegexp.FindString(value); dsc == value {
if fs.IsID(value) {
value = ""
}

Expand Down
7 changes: 4 additions & 3 deletions internal/photoprism/index_mediafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
fileChanged := true
fileExists := false
photoExists := false
stripSequence := Config().Settings().Index.Group

event.Publish("index.indexing", event.Data{
"fileHash": fileHash,
Expand Down Expand Up @@ -138,7 +139,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
} else {
photo.PhotoQuality = -1

if yamlName := fs.TypeYaml.FindFirst(m.FileName(), []string{Config().SidecarPath(), fs.HiddenPath}, Config().OriginalsPath(), Config().Settings().Index.Group); yamlName != "" {
if yamlName := fs.TypeYaml.FindFirst(m.FileName(), []string{Config().SidecarPath(), fs.HiddenPath}, Config().OriginalsPath(), stripSequence); yamlName != "" {
if err := photo.LoadFromYaml(yamlName); err != nil {
log.Errorf("index: %s (restore from yaml) for %s", err.Error(), quotedName)
} else {
Expand Down Expand Up @@ -168,7 +169,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
file.OriginalName = originalName

if file.FilePrimary && photo.OriginalName == "" {
photo.OriginalName = originalName
photo.OriginalName = fs.Base(originalName, stripSequence)
}
}

Expand Down Expand Up @@ -530,7 +531,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (

w := txt.Keywords(photo.Details.Keywords)

if fs.NonCanonical(fileBase) {
if !fs.IsID(fileBase) {
w = append(w, txt.FilenameKeywords(filePath)...)
w = append(w, txt.FilenameKeywords(fileBase)...)
}
Expand Down
Loading

0 comments on commit bfd7393

Please sign in to comment.