mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-16 01:59:29 +02:00
93 lines
3.2 KiB
Go
93 lines
3.2 KiB
Go
/*
|
|
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
*/
|
|
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/spf13/viper"
|
|
"golang.org/x/oauth2"
|
|
)
|
|
|
|
// A listen service backend.
|
|
// All listen services must implement this interface.
|
|
type Backend interface {
|
|
// Initialize the backend from a config.
|
|
FromConfig(config *viper.Viper) Backend
|
|
}
|
|
|
|
type ImportBackend interface {
|
|
Backend
|
|
|
|
// If the backend needs to setup resources before starting to import,
|
|
// this can be done here.
|
|
StartImport() error
|
|
|
|
// The implementation can perform all steps here to finalize the
|
|
// export/import and free used resources.
|
|
FinishImport() error
|
|
}
|
|
|
|
// Must be implemented by services supporting the export of listens.
|
|
type ListensExport interface {
|
|
Backend
|
|
|
|
// Returns a list of all listens newer then oldestTimestamp.
|
|
// The returned list of listens is supposed to be ordered by the
|
|
// Listen.ListenedAt timestamp, with the oldest entry first.
|
|
ExportListens(oldestTimestamp time.Time, results chan ListensResult, progress chan Progress)
|
|
}
|
|
|
|
// Must be implemented by services supporting the import of listens.
|
|
type ListensImport interface {
|
|
ImportBackend
|
|
|
|
// Imports the given list of listens.
|
|
ImportListens(export ListensResult, importResult ImportResult, progress chan Progress) (ImportResult, error)
|
|
}
|
|
|
|
// Must be implemented by services supporting the export of loves.
|
|
type LovesExport interface {
|
|
Backend
|
|
|
|
// Returns a list of all loves newer then oldestTimestamp.
|
|
// The returned list of listens is supposed to be ordered by the
|
|
// Love.Created timestamp, with the oldest entry first.
|
|
ExportLoves(oldestTimestamp time.Time, results chan LovesResult, progress chan Progress)
|
|
}
|
|
|
|
// Must be implemented by services supporting the import of loves.
|
|
type LovesImport interface {
|
|
ImportBackend
|
|
|
|
// Imports the given list of loves.
|
|
ImportLoves(export LovesResult, importResult ImportResult, progress chan Progress) (ImportResult, error)
|
|
}
|
|
|
|
// Must be implemented by backends requiring OAuth2 authentication
|
|
type OAuth2Authenticator interface {
|
|
// Returns OAuth2 config suitable for this backend
|
|
OAuth2Config(redirectUrl string) oauth2.Config
|
|
|
|
// Setup the OAuth2 client
|
|
OAuth2Setup(redirectUrl string, token *oauth2.Token) error
|
|
}
|