scotty/internal/backends/export.go
Philipp Wolfer b8e6ccffdb
Initial implementation of unified export/import progress
Both export and import progress get updated over a unified channel.
Most importantly this allows updating the import total from latest
export results.
2025-05-05 11:38:29 +02:00

53 lines
1.7 KiB
Go

/*
Copyright © 2023-2025 Philipp Wolfer <phw@uploadedlobster.com>
Scotty is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later version.
Scotty is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
Scotty. If not, see <https://www.gnu.org/licenses/>.
*/
package backends
import (
"time"
"go.uploadedlobster.com/scotty/internal/models"
)
type ExportProcessor[T models.ListensResult | models.LovesResult] interface {
ExportBackend() models.Backend
Process(oldestTimestamp time.Time, results chan T, progress chan models.TransferProgress)
}
type ListensExportProcessor struct {
Backend models.ListensExport
}
func (p ListensExportProcessor) ExportBackend() models.Backend {
return p.Backend
}
func (p ListensExportProcessor) Process(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
defer close(results)
p.Backend.ExportListens(oldestTimestamp, results, progress)
}
type LovesExportProcessor struct {
Backend models.LovesExport
}
func (p LovesExportProcessor) ExportBackend() models.Backend {
return p.Backend
}
func (p LovesExportProcessor) Process(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.TransferProgress) {
defer close(results)
p.Backend.ExportLoves(oldestTimestamp, results, progress)
}