If dump does no write to file, output the result as log

This commit is contained in:
Philipp Wolfer 2025-05-24 20:54:20 +02:00
parent 312d9860cf
commit 4da5697435
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
10 changed files with 29 additions and 15 deletions

View file

@ -73,14 +73,17 @@ func (b *DumpBackend) InitConfig(config *config.ServiceConfig) error {
func (b *DumpBackend) StartImport() error { return nil }
func (b *DumpBackend) FinishImport() error {
func (b *DumpBackend) FinishImport(result *models.ImportResult) error {
if b.print {
out := new(strings.Builder)
_, err := io.Copy(out, b.buffer)
if err != nil {
return err
}
fmt.Println(out.String())
if result != nil {
result.Log(models.Output, out.String())
}
}
// Close the io writer if it is closable

View file

@ -107,7 +107,7 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
for exportResult := range results {
if err := ctx.Err(); err != nil {
processor.ImportBackend().FinishImport()
processor.ImportBackend().FinishImport(&result)
out <- handleError(result, err, progress)
return
}
@ -116,14 +116,14 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
ctx, exportResult, result.Copy(), out, progress)
result.Update(&importResult)
if err != nil {
processor.ImportBackend().FinishImport()
processor.ImportBackend().FinishImport(&result)
out <- handleError(result, err, progress)
return
}
progress <- p.FromImportResult(result, false)
}
if err := processor.ImportBackend().FinishImport(); err != nil {
if err := processor.ImportBackend().FinishImport(&result); err != nil {
out <- handleError(result, err, progress)
return
}

View file

@ -90,7 +90,7 @@ func (b *JSPFBackend) StartImport() error {
return b.readJSPF()
}
func (b *JSPFBackend) FinishImport() error {
func (b *JSPFBackend) FinishImport(result *models.ImportResult) error {
return b.writeJSPF()
}

View file

@ -70,8 +70,10 @@ func (b *LastfmApiBackend) InitConfig(config *config.ServiceConfig) error {
return nil
}
func (b *LastfmApiBackend) StartImport() error { return nil }
func (b *LastfmApiBackend) FinishImport() error { return nil }
func (b *LastfmApiBackend) StartImport() error { return nil }
func (b *LastfmApiBackend) FinishImport(result *models.ImportResult) error {
return nil
}
func (b *LastfmApiBackend) OAuth2Strategy(redirectURL *url.URL) auth.OAuth2Strategy {
return lastfmStrategy{

View file

@ -73,8 +73,10 @@ func (b *ListenBrainzApiBackend) InitConfig(config *config.ServiceConfig) error
return nil
}
func (b *ListenBrainzApiBackend) StartImport() error { return nil }
func (b *ListenBrainzApiBackend) FinishImport() error { return nil }
func (b *ListenBrainzApiBackend) StartImport() error { return nil }
func (b *ListenBrainzApiBackend) FinishImport(result *models.ImportResult) error {
return nil
}
func (b *ListenBrainzApiBackend) ExportListens(ctx context.Context, oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
startTime := time.Now()

View file

@ -61,8 +61,10 @@ func (b *MalojaApiBackend) InitConfig(config *config.ServiceConfig) error {
return nil
}
func (b *MalojaApiBackend) StartImport() error { return nil }
func (b *MalojaApiBackend) FinishImport() error { return nil }
func (b *MalojaApiBackend) StartImport() error { return nil }
func (b *MalojaApiBackend) FinishImport(result *models.ImportResult) error {
return nil
}
func (b *MalojaApiBackend) ExportListens(ctx context.Context, oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
page := 0

View file

@ -126,7 +126,7 @@ func (b *ScrobblerLogBackend) StartImport() error {
return nil
}
func (b *ScrobblerLogBackend) FinishImport() error {
func (b *ScrobblerLogBackend) FinishImport(result *models.ImportResult) error {
return b.file.Close()
}

View file

@ -157,7 +157,11 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
fmt.Println()
fmt.Println(i18n.Tr("Import log:"))
for _, entry := range result.ImportLog {
fmt.Println(i18n.Tr("%v: %v", entry.Type, entry.Message))
if entry.Type != models.Output {
fmt.Println(i18n.Tr("%v: %v", entry.Type, entry.Message))
} else {
fmt.Println(entry.Message)
}
}
}

View file

@ -46,7 +46,7 @@ type ImportBackend interface {
// The implementation can perform all steps here to finalize the
// export/import and free used resources.
FinishImport() error
FinishImport(result *ImportResult) error
}
// Must be implemented by services supporting the export of listens.

View file

@ -169,6 +169,7 @@ type LovesResult ExportResult[LovesList]
type LogEntryType string
const (
Output LogEntryType = ""
Info LogEntryType = "Info"
Warning LogEntryType = "Warning"
Error LogEntryType = "Error"