Files
stpweb/backend/graph/spotify.resolvers.go
T
adamfandClaude Opus 5.5 aa4c3b1a67
Test and deploy / test (push) Successful in 58s
Test and deploy / deploy (push) Successful in 3m4s
Finish the Renovate batch: go.sum, gqlgen regen, lockfile, katex hold
The Renovate branches changed go.mod and package.json without go.sum or
package-lock.json, so this tidies the module graph, regenerates the gqlgen
code for v0.17.98 and refreshes the lockfile.

katex stays on 0.16: @mdit/plugin-katex renders with its own katex ^0.16
and Markdown.vue loads only the stylesheet from the top-level package, so
0.19's CSS would no longer match the rendered HTML. renovate.json5 now caps
it below 0.17 so the bump is not proposed again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 15:14:21 +00:00

73 lines
2.2 KiB
Go

package graph
// This file will be automatically regenerated based on the schema, any resolver
// implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.98
import (
"context"
"adam-french.co.uk/backend/graph/model"
)
// SpotifyListening is the resolver for the spotifyListening field.
func (r *queryResolver) SpotifyListening(ctx context.Context) (*model.SpotifyPlaying, error) {
// A nil client means the OAuth flow has never been completed. Report that
// as null rather than an error so the home page renders without it.
if r.Store.SpotifyClient == nil {
r.Store.LogSpotifyUnauthenticated("spotifyListening")
return nil, nil
}
playing, err := r.Store.SpotifyClient.PlayerCurrentlyPlaying(ctx)
if err != nil {
return nil, err
}
result := &model.SpotifyPlaying{Playing: playing.Playing}
if playing.Item != nil {
result.Track = mapSpotifyTrack(playing.Item)
}
return result, nil
}
// SpotifyRecent is the resolver for the spotifyRecent field.
func (r *queryResolver) SpotifyRecent(ctx context.Context) ([]*model.SpotifyRecentItem, error) {
if r.Store.SpotifyClient == nil {
r.Store.LogSpotifyUnauthenticated("spotifyRecent")
return []*model.SpotifyRecentItem{}, nil
}
// Shared one-minute cache, filled by whichever of this resolver and the
// REST /spotify/recent endpoint misses it first.
played, err := r.Store.RecentlyPlayedTracks(ctx)
if err != nil {
return nil, err
}
return mapRecentItems(played), nil
}
// SpotifyNeedsReauth is the resolver for the spotifyNeedsReauth field.
//
// Admin-gated: false for everyone else, so this query leaks nothing. Admin is
// read from the access-token claims the AuthContextMiddleware resolved, not
// the database — the same trade-off AdminMiddleware makes (revocation waits
// for token expiry).
func (r *queryResolver) SpotifyNeedsReauth(ctx context.Context) (bool, error) {
if r.Store.SpotifyClient != nil {
return false, nil
}
// A soft check, deliberately not @admin: the directive would turn this
// into an error on the public home page query.
if !IsAdminFromCtx(ctx) {
return false, nil
}
r.Store.LogSpotifyUnauthenticated("spotifyNeedsReauth")
return true, nil
}