mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37:05 +02:00
refactor: generic common cmd processing
This commit is contained in:
parent
a87686af57
commit
7c85ba05ab
5 changed files with 182 additions and 149 deletions
51
internal/backends/export.go
Normal file
51
internal/backends/export.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Copyright © 2023 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.Progress)
|
||||
}
|
||||
|
||||
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.Progress) {
|
||||
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.Progress) {
|
||||
p.Backend.ExportLoves(oldestTimestamp, results, progress)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue