mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-27 22:47:57 +02:00
Restructured code, moved all modules into internal
For now all modules are considered internal. This might change later
This commit is contained in:
parent
f94e0f1e85
commit
857661ebf9
76 changed files with 121 additions and 68 deletions
95
internal/models/interfaces.go
Normal file
95
internal/models/interfaces.go
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
||||
|
||||
This file is part of Scotty.
|
||||
|
||||
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 models
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"go.uploadedlobster.com/scotty/internal/auth"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
// A listen service backend.
|
||||
// All listen services must implement this interface.
|
||||
type Backend interface {
|
||||
// Return the name of the interface
|
||||
Name() string
|
||||
|
||||
// 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 {
|
||||
Backend
|
||||
|
||||
// Returns OAuth2 config suitable for this backend
|
||||
OAuth2Strategy(redirectUrl *url.URL) auth.OAuth2Strategy
|
||||
|
||||
// Setup the OAuth2 client
|
||||
OAuth2Setup(token oauth2.TokenSource) error
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue