Skip to content

Commit

Permalink
People: Improve logging, command help, and handling of broken files #22
Browse files Browse the repository at this point in the history
  • Loading branch information
lastzero committed Oct 5, 2021
1 parent 00ced81 commit f7153cd
Show file tree
Hide file tree
Showing 43 changed files with 870 additions and 719 deletions.
876 changes: 445 additions & 431 deletions frontend/package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions frontend/src/dialog/photo/files.vue
Expand Up @@ -41,13 +41,13 @@
@click.stop.prevent="downloadFile(file)">
<translate>Download</translate>
</v-btn>
<v-btn v-if="features.edit && file.Type === 'jpg' && !file.Primary" small depressed dark
<v-btn v-if="features.edit && file.Type === 'jpg' && file.Error === '' && !file.Primary" small depressed dark
color="primary-button"
class="ma-0 action-primary"
@click.stop.prevent="primaryFile(file)">
<translate>Primary</translate>
</v-btn>
<v-btn v-if="features.edit && !file.Sidecar && !file.Primary && file.Root === '/'" small
<v-btn v-if="features.edit && !file.Sidecar && file.Error === '' && !file.Primary && file.Root === '/'" small
depressed dark color="primary-button"
class="ma-0 action-unstack"
@click.stop.prevent="unstackFile(file)">
Expand All @@ -66,6 +66,12 @@
</td>
<td>{{ file.UID | uppercase }}</td>
</tr>
<tr v-if="file.Error">
<td>
<translate>Error</translate>
</td>
<td><span class="body-2">{{ file.Error | uppercase }}</span></td>
</tr>
<tr v-if="file.InstanceID" title="XMP">
<td>
<translate>Instance ID</translate>
Expand Down Expand Up @@ -162,12 +168,6 @@
</td>
<td>{{ file.Chroma }} / 100</td>
</tr>
<tr v-if="file.Error">
<td>
<translate>Error</translate>
</td>
<td>{{ file.Error }}</td>
</tr>
<tr v-if="file.Missing">
<td>
<translate>Missing</translate>
Expand Down
4 changes: 2 additions & 2 deletions internal/api/covers.go
Expand Up @@ -76,15 +76,15 @@ func AlbumCover(router *gin.RouterGroup) {
f, err := query.AlbumCoverByUID(uid)

if err != nil {
log.Debugf("%s: no photos yet, using generic image for %s", albumCover, uid)
log.Debugf("%s: %s contains no photos, using generic cover", albumCover, uid)
c.Data(http.StatusOK, "image/svg+xml", albumIconSvg)
return
}

fileName := photoprism.FileName(f.FileRoot, f.FileName)

if !fs.FileExists(fileName) {
log.Errorf("%s: could not find original for %s", albumCover, fileName)
log.Errorf("%s: found no original for %s", albumCover, fileName)
c.Data(http.StatusOK, "image/svg+xml", albumIconSvg)

// Set missing flag so that the file doesn't show up in search results anymore.
Expand Down
2 changes: 1 addition & 1 deletion internal/api/covers_test.go
Expand Up @@ -15,7 +15,7 @@ func TestAlbumCover(t *testing.T) {

assert.Equal(t, http.StatusOK, r.Code)
})
t.Run("album has no photo (because is not existing)", func(t *testing.T) {
t.Run("album contains no photos (because is not existing)", func(t *testing.T) {
app, router, conf := NewApiTest()
AlbumCover(router)
r := PerformRequest(app, "GET", "/api/v1/albums/987-986435/t/"+conf.PreviewToken()+"/tile_500")
Expand Down
2 changes: 1 addition & 1 deletion internal/api/folder_cover.go
Expand Up @@ -85,7 +85,7 @@ func FolderCover(router *gin.RouterGroup) {
f, err := query.FolderCoverByUID(uid)

if err != nil {
log.Debugf("%s: no photos yet, using generic image for %s", folderCover, uid)
log.Debugf("%s: %s contains no photos, using generic cover", folderCover, uid)
c.Data(http.StatusOK, "image/svg+xml", folderIconSvg)
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/api/import.go
Expand Up @@ -77,7 +77,7 @@ func StartImport(router *gin.RouterGroup) {
}

if len(f.Albums) > 0 {
log.Debugf("import: files will be added to album %s", strings.Join(f.Albums, " and "))
log.Debugf("import: adding files to album %s", strings.Join(f.Albums, " and "))
opt.Albums = f.Albums
}

Expand Down
4 changes: 2 additions & 2 deletions internal/api/photo_unstack.go
Expand Up @@ -81,11 +81,11 @@ func PhotoUnstack(router *gin.RouterGroup) {
AbortEntityNotFound(c)
return
} else if related.Len() == 0 {
log.Errorf("photo: no files found for %s (unstack)", txt.Quote(baseName))
log.Errorf("photo: found no files for %s (unstack)", txt.Quote(baseName))
AbortEntityNotFound(c)
return
} else if related.Main == nil {
log.Errorf("photo: no main file found for %s (unstack)", txt.Quote(baseName))
log.Errorf("photo: found no main file for %s (unstack)", txt.Quote(baseName))
AbortEntityNotFound(c)
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/config.go
Expand Up @@ -85,9 +85,9 @@ func configAction(ctx *cli.Context) error {
fmt.Printf("%-25s %s\n", "site-url", conf.SiteUrl())
fmt.Printf("%-25s %s\n", "site-preview", conf.SitePreview())
fmt.Printf("%-25s %s\n", "site-title", conf.SiteTitle())
fmt.Printf("%-25s %s\n", "site-author", conf.SiteAuthor())
fmt.Printf("%-25s %s\n", "site-caption", conf.SiteCaption())
fmt.Printf("%-25s %s\n", "site-description", conf.SiteDescription())
fmt.Printf("%-25s %s\n", "site-author", conf.SiteAuthor())
fmt.Printf("%-25s %s\n", "cdn-url", conf.CdnUrl("/"))
fmt.Printf("%-25s %s\n", "content-uri", conf.ContentUri())
fmt.Printf("%-25s %s\n", "static-uri", conf.StaticUri())
Expand Down
6 changes: 3 additions & 3 deletions internal/commands/faces.go
Expand Up @@ -35,7 +35,7 @@ var FacesCommand = cli.Command{
Flags: []cli.Flag{
cli.BoolFlag{
Name: "fix, f",
Usage: "issues will be fixed automatically",
Usage: "automatically fixes issues",
},
},
Action: facesAuditAction,
Expand All @@ -46,7 +46,7 @@ var FacesCommand = cli.Command{
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "remove all people and faces",
Usage: "removes all people and faces",
},
},
Action: facesResetAction,
Expand All @@ -63,7 +63,7 @@ var FacesCommand = cli.Command{
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "update all faces",
Usage: "updates all faces",
},
},
Action: facesUpdateAction,
Expand Down
4 changes: 1 addition & 3 deletions internal/commands/index_test.go
Expand Up @@ -48,9 +48,7 @@ func TestIndexCommand(t *testing.T) {
// Expected index command output.
assert.Contains(t, output, "indexing originals")
assert.Contains(t, output, "classify: loading labels")
assert.Contains(t, output, "index: no .ppignore file found")
assert.Contains(t, output, "index: updating primary files")
assert.Contains(t, output, "index: flagging hidden files")
assert.Contains(t, output, "index: found no .ppignore file")
} else {
t.Fatal("log output missing")
}
Expand Down
30 changes: 15 additions & 15 deletions internal/commands/reset.go
Expand Up @@ -63,7 +63,7 @@ func resetAction(ctx *cli.Context) error {
}

removeSidecarJsonPrompt := promptui.Prompt{
Label: "Permanently delete all *.json photo sidecar files?",
Label: "Permanently remove all JSON photo sidecar files?",
IsConfirm: true,
}

Expand All @@ -77,7 +77,7 @@ func resetAction(ctx *cli.Context) error {
}

if len(matches) > 0 {
log.Infof("%d json photo sidecar files will be removed", len(matches))
log.Infof("removing %d JSON photo sidecar files", len(matches))

for _, name := range matches {
if err := os.Remove(name); err != nil {
Expand All @@ -89,16 +89,16 @@ func resetAction(ctx *cli.Context) error {

fmt.Println("")

log.Infof("removed json files [%s]", time.Since(start))
log.Infof("removed JSON sidecar files [%s]", time.Since(start))
} else {
log.Infof("no json files found")
log.Infof("found no JSON sidecar files")
}
} else {
log.Infof("keeping json sidecar files")
log.Infof("keeping JSON sidecar files")
}

removeSidecarYamlPrompt := promptui.Prompt{
Label: "Permanently delete all *.yml photo metadata backups?",
Label: "Permanently remove all YAML photo metadata backup files?",
IsConfirm: true,
}

Expand All @@ -112,7 +112,7 @@ func resetAction(ctx *cli.Context) error {
}

if len(matches) > 0 {
log.Infof("%d photo metadata backups will be removed", len(matches))
log.Infof("%d YAML photo metadata backup files will be removed", len(matches))

for _, name := range matches {
if err := os.Remove(name); err != nil {
Expand All @@ -124,16 +124,16 @@ func resetAction(ctx *cli.Context) error {

fmt.Println("")

log.Infof("removed files [%s]", time.Since(start))
log.Infof("removed YAML photo metadata backup files [%s]", time.Since(start))
} else {
log.Infof("no metadata backups found for removal")
log.Infof("found no YAML photo metadata backup files")
}
} else {
log.Infof("keeping backup files")
log.Infof("keeping YAML photo metadata backup files")
}

removeAlbumYamlPrompt := promptui.Prompt{
Label: "Permanently delete all *.yml album backups?",
Label: "Permanently remove all YAML album backup files?",
IsConfirm: true,
}

Expand All @@ -147,7 +147,7 @@ func resetAction(ctx *cli.Context) error {
}

if len(matches) > 0 {
log.Infof("%d album backups will be removed", len(matches))
log.Infof("%d YAML album backups will be removed", len(matches))

for _, name := range matches {
if err := os.Remove(name); err != nil {
Expand All @@ -159,12 +159,12 @@ func resetAction(ctx *cli.Context) error {

fmt.Println("")

log.Infof("removed files [%s]", time.Since(start))
log.Infof("removed YAML album backup files [%s]", time.Since(start))
} else {
log.Infof("no album backups found for removal")
log.Infof("found no YAML album backup files")
}
} else {
log.Infof("keeping backup files")
log.Infof("keeping YAML album backup files")
}

conf.Shutdown()
Expand Down
23 changes: 13 additions & 10 deletions internal/config/config.go
Expand Up @@ -42,6 +42,9 @@ var TotalMem uint64

const ApiUri = "/api/v1"
const StaticUri = "/static"
const DefaultWakeupInterval = int(15 * 60)
const DefaultAutoIndexDelay = int(5 * 60)
const DefaultAutoImportDelay = int(3 * 60)

// Megabyte in bytes.
const Megabyte = 1000 * 1000
Expand Down Expand Up @@ -328,6 +331,11 @@ func (c *Config) SiteTitle() string {
return c.options.SiteTitle
}

// SiteAuthor returns the site author / copyright.
func (c *Config) SiteAuthor() string {
return c.options.SiteAuthor
}

// SiteCaption returns a short site caption.
func (c *Config) SiteCaption() string {
return c.options.SiteCaption
Expand All @@ -338,11 +346,6 @@ func (c *Config) SiteDescription() string {
return c.options.SiteDescription
}

// SiteAuthor returns the site author / copyright.
func (c *Config) SiteAuthor() string {
return c.options.SiteAuthor
}

// Debug tests if debug mode is enabled.
func (c *Config) Debug() bool {
return c.options.Debug
Expand Down Expand Up @@ -372,7 +375,7 @@ func (c *Config) Public() bool {
return c.options.Public
}

// Modify Public state while running. For testing purposes only.
// SetPublic changes authentication while instance is running, for testing purposes only.
func (c *Config) SetPublic(p bool) {
if c.Debug() {
c.options.Public = p
Expand Down Expand Up @@ -472,7 +475,7 @@ func (c *Config) Workers() int {
// WakeupInterval returns the background worker wakeup interval duration.
func (c *Config) WakeupInterval() time.Duration {
if c.options.WakeupInterval <= 0 || c.options.WakeupInterval > 86400 {
return 15 * time.Minute
return time.Duration(DefaultWakeupInterval) * time.Second
}

return time.Duration(c.options.WakeupInterval) * time.Second
Expand All @@ -483,7 +486,7 @@ func (c *Config) AutoIndex() time.Duration {
if c.options.AutoIndex < 0 {
return time.Duration(0)
} else if c.options.AutoIndex == 0 || c.options.AutoIndex > 86400 {
return 5 * time.Minute
return time.Duration(DefaultAutoIndexDelay) * time.Second
}

return time.Duration(c.options.AutoIndex) * time.Second
Expand All @@ -494,13 +497,13 @@ func (c *Config) AutoImport() time.Duration {
if c.options.AutoImport < 0 || c.ReadOnly() {
return time.Duration(0)
} else if c.options.AutoImport == 0 || c.options.AutoImport > 86400 {
return 3 * time.Minute
return time.Duration(DefaultAutoImportDelay) * time.Second
}

return time.Duration(c.options.AutoImport) * time.Second
}

// GeoApi returns the preferred geo coding api (none or places).
// GeoApi returns the preferred geocoding api (none or places).
func (c *Config) GeoApi() string {
if c.options.DisablePlaces {
return ""
Expand Down

0 comments on commit f7153cd

Please sign in to comment.