mirror of
https://git.sr.ht/~phw/scotty
synced 2025-05-31 10:58:35 +02:00
If dump does no write to file, output the result as log
This commit is contained in:
parent
312d9860cf
commit
4da5697435
10 changed files with 29 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -169,6 +169,7 @@ type LovesResult ExportResult[LovesList]
|
|||
type LogEntryType string
|
||||
|
||||
const (
|
||||
Output LogEntryType = ""
|
||||
Info LogEntryType = "Info"
|
||||
Warning LogEntryType = "Warning"
|
||||
Error LogEntryType = "Error"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue