Introduce a --language flag on the /requestbook command and a DefaultLanguage plugin setting so releases can be filtered by language. The post message is now rendered after fetching releases, allowing the localized title from the provider metadata to be used in the announcement post. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
68 lines
2.3 KiB
Go
68 lines
2.3 KiB
Go
package shelfmark
|
|
|
|
// Book represents a book from a Shelfmark metadata search result.
|
|
type Book struct {
|
|
Provider string `json:"provider"`
|
|
ProviderID string `json:"provider_id"`
|
|
ProviderDisplayName string `json:"provider_display_name"`
|
|
Title string `json:"title"`
|
|
SearchTitle string `json:"search_title"`
|
|
SearchAuthor string `json:"search_author"`
|
|
Authors []string `json:"authors"`
|
|
CoverURL string `json:"cover_url"`
|
|
TitlesByLanguage map[string]string `json:"titles_by_language"`
|
|
}
|
|
|
|
// LocalizedTitle returns the title for the given language code, falling back
|
|
// to the default Title if no localized version is available.
|
|
func (b *Book) LocalizedTitle(language string) string {
|
|
if language != "" && b.TitlesByLanguage != nil {
|
|
if t, ok := b.TitlesByLanguage[language]; ok && t != "" {
|
|
return t
|
|
}
|
|
}
|
|
return b.Title
|
|
}
|
|
|
|
// Release represents a downloadable release from Shelfmark.
|
|
type Release struct {
|
|
Source string `json:"source"`
|
|
SourceID string `json:"source_id"`
|
|
Title string `json:"title"`
|
|
Format string `json:"format"`
|
|
Size string `json:"size"`
|
|
Extra map[string]any `json:"extra"`
|
|
}
|
|
|
|
// SearchResponse is the response from GET /api/metadata/search.
|
|
type SearchResponse struct {
|
|
Books []Book `json:"books"`
|
|
Provider string `json:"provider"`
|
|
Query string `json:"query"`
|
|
Page int `json:"page"`
|
|
TotalFound int `json:"total_found"`
|
|
HasMore bool `json:"has_more"`
|
|
}
|
|
|
|
// ReleasesResponse is the response from GET /api/releases.
|
|
type ReleasesResponse struct {
|
|
Releases []Release `json:"releases"`
|
|
Book Book `json:"book"`
|
|
SourcesSearched []string `json:"sources_searched"`
|
|
Errors []string `json:"errors"`
|
|
}
|
|
|
|
// QueueResponse is the response from POST /api/releases/download.
|
|
type QueueResponse struct {
|
|
Status string `json:"status"`
|
|
Priority int `json:"priority"`
|
|
Error string `json:"error"`
|
|
}
|
|
|
|
// AuthCheckResponse is the response from GET /api/auth/check.
|
|
type AuthCheckResponse struct {
|
|
Authenticated bool `json:"authenticated"`
|
|
AuthRequired bool `json:"auth_required"`
|
|
AuthMode string `json:"auth_mode"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
}
|