Fix gallery export panic (#4311)

* Load URLs when exporting galleries
* Remove err.Error()
* Log gallery DisplayName rather than PrimaryChecksum
This commit is contained in:
DingDongSoLong4
2023-11-27 01:43:34 +02:00
committed by GitHub
parent a8140c11ec
commit 0e7c58a5a6
2 changed files with 82 additions and 79 deletions

View File

@@ -52,7 +52,7 @@ type ImportObjectsInput struct {
func CreateImportTask(a models.HashAlgorithm, input ImportObjectsInput) (*ImportTask, error) {
baseDir, err := instance.Paths.Generated.TempDir("import")
if err != nil {
logger.Errorf("error creating temporary directory for import: %s", err.Error())
logger.Errorf("error creating temporary directory for import: %v", err)
return nil, err
}
@@ -93,12 +93,12 @@ func (t *ImportTask) Start(ctx context.Context) {
defer func() {
err := fsutil.RemoveDir(t.BaseDir)
if err != nil {
logger.Errorf("error removing directory %s: %s", t.BaseDir, err.Error())
logger.Errorf("error removing directory %s: %v", t.BaseDir, err)
}
}()
if err := t.unzipFile(); err != nil {
logger.Errorf("error unzipping provided file for import: %s", err.Error())
logger.Errorf("error unzipping provided file for import: %v", err)
return
}
}
@@ -119,7 +119,7 @@ func (t *ImportTask) Start(ctx context.Context) {
err := t.resetter.Reset()
if err != nil {
logger.Errorf("Error resetting database: %s", err.Error())
logger.Errorf("Error resetting database: %v", err)
return
}
}
@@ -139,7 +139,7 @@ func (t *ImportTask) unzipFile() error {
defer func() {
err := os.Remove(t.TmpZip)
if err != nil {
logger.Errorf("error removing temporary zip file %s: %s", t.TmpZip, err.Error())
logger.Errorf("error removing temporary zip file %s: %v", t.TmpZip, err)
}
}()
@@ -207,7 +207,7 @@ func (t *ImportTask) ImportPerformers(ctx context.Context) {
index := i + 1
performerJSON, err := jsonschema.LoadPerformerFile(filepath.Join(path, fi.Name()))
if err != nil {
logger.Errorf("[performers] failed to read json: %s", err.Error())
logger.Errorf("[performers] failed to read json: %v", err)
continue
}
@@ -222,7 +222,7 @@ func (t *ImportTask) ImportPerformers(ctx context.Context) {
return performImport(ctx, importer, t.DuplicateBehaviour)
}); err != nil {
logger.Errorf("[performers] <%s> import failed: %s", fi.Name(), err.Error())
logger.Errorf("[performers] <%s> import failed: %v", fi.Name(), err)
}
}
@@ -250,7 +250,7 @@ func (t *ImportTask) ImportStudios(ctx context.Context) {
index := i + 1
studioJSON, err := jsonschema.LoadStudioFile(filepath.Join(path, fi.Name()))
if err != nil {
logger.Errorf("[studios] failed to read json: %s", err.Error())
logger.Errorf("[studios] failed to read json: %v", err)
continue
}
@@ -267,7 +267,7 @@ func (t *ImportTask) ImportStudios(ctx context.Context) {
continue
}
logger.Errorf("[studios] <%s> failed to create: %s", fi.Name(), err.Error())
logger.Errorf("[studios] <%s> failed to create: %v", fi.Name(), err)
continue
}
}
@@ -281,7 +281,7 @@ func (t *ImportTask) ImportStudios(ctx context.Context) {
if err := r.WithTxn(ctx, func(ctx context.Context) error {
return t.importStudio(ctx, orphanStudioJSON, nil)
}); err != nil {
logger.Errorf("[studios] <%s> failed to create: %s", orphanStudioJSON.Name, err.Error())
logger.Errorf("[studios] <%s> failed to create: %v", orphanStudioJSON.Name, err)
continue
}
}
@@ -312,7 +312,7 @@ func (t *ImportTask) importStudio(ctx context.Context, studioJSON *jsonschema.St
for _, childStudioJSON := range s {
// map is nil since we're not checking parent studios at this point
if err := t.importStudio(ctx, childStudioJSON, nil); err != nil {
return fmt.Errorf("failed to create child studio <%s>: %s", childStudioJSON.Name, err.Error())
return fmt.Errorf("failed to create child studio <%s>: %v", childStudioJSON.Name, err)
}
}
@@ -341,7 +341,7 @@ func (t *ImportTask) ImportMovies(ctx context.Context) {
index := i + 1
movieJSON, err := jsonschema.LoadMovieFile(filepath.Join(path, fi.Name()))
if err != nil {
logger.Errorf("[movies] failed to read json: %s", err.Error())
logger.Errorf("[movies] failed to read json: %v", err)
continue
}
@@ -357,7 +357,7 @@ func (t *ImportTask) ImportMovies(ctx context.Context) {
return performImport(ctx, movieImporter, t.DuplicateBehaviour)
}); err != nil {
logger.Errorf("[movies] <%s> import failed: %s", fi.Name(), err.Error())
logger.Errorf("[movies] <%s> import failed: %v", fi.Name(), err)
continue
}
}
@@ -386,7 +386,7 @@ func (t *ImportTask) ImportFiles(ctx context.Context) {
index := i + 1
fileJSON, err := jsonschema.LoadFileFile(filepath.Join(path, fi.Name()))
if err != nil {
logger.Errorf("[files] failed to read json: %s", err.Error())
logger.Errorf("[files] failed to read json: %v", err)
continue
}
@@ -403,7 +403,7 @@ func (t *ImportTask) ImportFiles(ctx context.Context) {
continue
}
logger.Errorf("[files] <%s> failed to create: %s", fi.Name(), err.Error())
logger.Errorf("[files] <%s> failed to create: %v", fi.Name(), err)
continue
}
}
@@ -417,7 +417,7 @@ func (t *ImportTask) ImportFiles(ctx context.Context) {
if err := r.WithTxn(ctx, func(ctx context.Context) error {
return t.importFile(ctx, orphanFileJSON, nil)
}); err != nil {
logger.Errorf("[files] <%s> failed to create: %s", orphanFileJSON.DirEntry().Path, err.Error())
logger.Errorf("[files] <%s> failed to create: %v", orphanFileJSON.DirEntry().Path, err)
continue
}
}
@@ -446,7 +446,7 @@ func (t *ImportTask) importFile(ctx context.Context, fileJSON jsonschema.DirEntr
for _, childFileJSON := range s {
// map is nil since we're not checking parent studios at this point
if err := t.importFile(ctx, childFileJSON, nil); err != nil {
return fmt.Errorf("failed to create child file <%s>: %s", childFileJSON.DirEntry().Path, err.Error())
return fmt.Errorf("failed to create child file <%s>: %v", childFileJSON.DirEntry().Path, err)
}
}
@@ -475,7 +475,7 @@ func (t *ImportTask) ImportGalleries(ctx context.Context) {
index := i + 1
galleryJSON, err := jsonschema.LoadGalleryFile(filepath.Join(path, fi.Name()))
if err != nil {
logger.Errorf("[galleries] failed to read json: %s", err.Error())
logger.Errorf("[galleries] failed to read json: %v", err)
continue
}
@@ -513,7 +513,7 @@ func (t *ImportTask) ImportGalleries(ctx context.Context) {
return nil
}); err != nil {
logger.Errorf("[galleries] <%s> import failed to commit: %s", fi.Name(), err.Error())
logger.Errorf("[galleries] <%s> import failed to commit: %v", fi.Name(), err)
continue
}
}
@@ -541,7 +541,7 @@ func (t *ImportTask) ImportTags(ctx context.Context) {
index := i + 1
tagJSON, err := jsonschema.LoadTagFile(filepath.Join(path, fi.Name()))
if err != nil {
logger.Errorf("[tags] failed to read json: %s", err.Error())
logger.Errorf("[tags] failed to read json: %v", err)
continue
}
@@ -556,7 +556,7 @@ func (t *ImportTask) ImportTags(ctx context.Context) {
continue
}
logger.Errorf("[tags] <%s> failed to import: %s", fi.Name(), err.Error())
logger.Errorf("[tags] <%s> failed to import: %v", fi.Name(), err)
continue
}
}
@@ -566,7 +566,7 @@ func (t *ImportTask) ImportTags(ctx context.Context) {
if err := r.WithTxn(ctx, func(ctx context.Context) error {
return t.importTag(ctx, orphanTagJSON, nil, true)
}); err != nil {
logger.Errorf("[tags] <%s> failed to create: %s", orphanTagJSON.Name, err.Error())
logger.Errorf("[tags] <%s> failed to create: %v", orphanTagJSON.Name, err)
continue
}
}
@@ -599,7 +599,7 @@ func (t *ImportTask) importTag(ctx context.Context, tagJSON *jsonschema.Tag, pen
continue
}
return fmt.Errorf("failed to create child tag <%s>: %s", childTagJSON.Name, err.Error())
return fmt.Errorf("failed to create child tag <%s>: %v", childTagJSON.Name, err)
}
}
@@ -630,7 +630,7 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
sceneJSON, err := jsonschema.LoadSceneFile(filepath.Join(path, fi.Name()))
if err != nil {
logger.Infof("[scenes] <%s> json parse failure: %s", fi.Name(), err.Error())
logger.Infof("[scenes] <%s> json parse failure: %v", fi.Name(), err)
continue
}
@@ -671,7 +671,7 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
return nil
}); err != nil {
logger.Errorf("[scenes] <%s> import failed: %s", fi.Name(), err.Error())
logger.Errorf("[scenes] <%s> import failed: %v", fi.Name(), err)
}
}
@@ -700,7 +700,7 @@ func (t *ImportTask) ImportImages(ctx context.Context) {
imageJSON, err := jsonschema.LoadImageFile(filepath.Join(path, fi.Name()))
if err != nil {
logger.Infof("[images] <%s> json parse failure: %s", fi.Name(), err.Error())
logger.Infof("[images] <%s> json parse failure: %v", fi.Name(), err)
continue
}
@@ -720,7 +720,7 @@ func (t *ImportTask) ImportImages(ctx context.Context) {
return performImport(ctx, imageImporter, t.DuplicateBehaviour)
}); err != nil {
logger.Errorf("[images] <%s> import failed: %s", fi.Name(), err.Error())
logger.Errorf("[images] <%s> import failed: %v", fi.Name(), err)
}
}