mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-01 19:38:34 +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) StartImport() error { return nil }
|
||||||
|
|
||||||
func (b *DumpBackend) FinishImport() error {
|
func (b *DumpBackend) FinishImport(result *models.ImportResult) error {
|
||||||
if b.print {
|
if b.print {
|
||||||
out := new(strings.Builder)
|
out := new(strings.Builder)
|
||||||
_, err := io.Copy(out, b.buffer)
|
_, err := io.Copy(out, b.buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println(out.String())
|
|
||||||
|
if result != nil {
|
||||||
|
result.Log(models.Output, out.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the io writer if it is closable
|
// 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 {
|
for exportResult := range results {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
processor.ImportBackend().FinishImport()
|
processor.ImportBackend().FinishImport(&result)
|
||||||
out <- handleError(result, err, progress)
|
out <- handleError(result, err, progress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -116,14 +116,14 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
|
||||||
ctx, exportResult, result.Copy(), out, progress)
|
ctx, exportResult, result.Copy(), out, progress)
|
||||||
result.Update(&importResult)
|
result.Update(&importResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
processor.ImportBackend().FinishImport()
|
processor.ImportBackend().FinishImport(&result)
|
||||||
out <- handleError(result, err, progress)
|
out <- handleError(result, err, progress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
progress <- p.FromImportResult(result, false)
|
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)
|
out <- handleError(result, err, progress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ func (b *JSPFBackend) StartImport() error {
|
||||||
return b.readJSPF()
|
return b.readJSPF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *JSPFBackend) FinishImport() error {
|
func (b *JSPFBackend) FinishImport(result *models.ImportResult) error {
|
||||||
return b.writeJSPF()
|
return b.writeJSPF()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,10 @@ func (b *LastfmApiBackend) InitConfig(config *config.ServiceConfig) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *LastfmApiBackend) StartImport() error { return nil }
|
func (b *LastfmApiBackend) StartImport() error { return nil }
|
||||||
func (b *LastfmApiBackend) FinishImport() error { return nil }
|
func (b *LastfmApiBackend) FinishImport(result *models.ImportResult) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *LastfmApiBackend) OAuth2Strategy(redirectURL *url.URL) auth.OAuth2Strategy {
|
func (b *LastfmApiBackend) OAuth2Strategy(redirectURL *url.URL) auth.OAuth2Strategy {
|
||||||
return lastfmStrategy{
|
return lastfmStrategy{
|
||||||
|
|
|
@ -73,8 +73,10 @@ func (b *ListenBrainzApiBackend) InitConfig(config *config.ServiceConfig) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ListenBrainzApiBackend) StartImport() error { return nil }
|
func (b *ListenBrainzApiBackend) StartImport() error { return nil }
|
||||||
func (b *ListenBrainzApiBackend) FinishImport() 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) {
|
func (b *ListenBrainzApiBackend) ExportListens(ctx context.Context, oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
|
@ -61,8 +61,10 @@ func (b *MalojaApiBackend) InitConfig(config *config.ServiceConfig) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *MalojaApiBackend) StartImport() error { return nil }
|
func (b *MalojaApiBackend) StartImport() error { return nil }
|
||||||
func (b *MalojaApiBackend) FinishImport() 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) {
|
func (b *MalojaApiBackend) ExportListens(ctx context.Context, oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||||
page := 0
|
page := 0
|
||||||
|
|
|
@ -126,7 +126,7 @@ func (b *ScrobblerLogBackend) StartImport() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ScrobblerLogBackend) FinishImport() error {
|
func (b *ScrobblerLogBackend) FinishImport(result *models.ImportResult) error {
|
||||||
return b.file.Close()
|
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()
|
||||||
fmt.Println(i18n.Tr("Import log:"))
|
fmt.Println(i18n.Tr("Import log:"))
|
||||||
for _, entry := range result.ImportLog {
|
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
|
// The implementation can perform all steps here to finalize the
|
||||||
// export/import and free used resources.
|
// export/import and free used resources.
|
||||||
FinishImport() error
|
FinishImport(result *ImportResult) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must be implemented by services supporting the export of listens.
|
// Must be implemented by services supporting the export of listens.
|
||||||
|
|
|
@ -169,6 +169,7 @@ type LovesResult ExportResult[LovesList]
|
||||||
type LogEntryType string
|
type LogEntryType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Output LogEntryType = ""
|
||||||
Info LogEntryType = "Info"
|
Info LogEntryType = "Info"
|
||||||
Warning LogEntryType = "Warning"
|
Warning LogEntryType = "Warning"
|
||||||
Error LogEntryType = "Error"
|
Error LogEntryType = "Error"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue