feat: save progress to continue_watching_entry only
Replace SaveWatchProgress (UPDATE watch_list_entry) with UpsertContinueWatchingEntry so progress persists for any anime without creating watchlist entries.
This commit is contained in:
@@ -19,6 +19,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type playbackService struct {
|
type playbackService struct {
|
||||||
@@ -197,6 +199,17 @@ func (s *playbackService) BuildWatchData(ctx context.Context, animeID int, title
|
|||||||
startTime = entry.CurrentTimeSeconds
|
startTime = entry.CurrentTimeSeconds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fall back to continue_watching_entry for progress if not in watchlist
|
||||||
|
if startTime == 0 {
|
||||||
|
cwEntry, err := s.repo.GetContinueWatchingEntry(ctx, db.GetContinueWatchingEntryParams{
|
||||||
|
UserID: userID,
|
||||||
|
AnimeID: int64(animeID),
|
||||||
|
})
|
||||||
|
if err == nil && cwEntry.CurrentEpisode.Valid && strconv.FormatInt(cwEntry.CurrentEpisode.Int64, 10) == episode {
|
||||||
|
startTime = cwEntry.CurrentTimeSeconds
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Get Episodes list
|
// 4. Get Episodes list
|
||||||
@@ -286,8 +299,8 @@ func (s *playbackService) BuildWatchData(ctx context.Context, animeID int, title
|
|||||||
"Providers": []domain.ProviderData{
|
"Providers": []domain.ProviderData{
|
||||||
{Streams: streams},
|
{Streams: streams},
|
||||||
},
|
},
|
||||||
"ModeSources": modeSources,
|
"ModeSources": modeSources,
|
||||||
"InitialMode": mode,
|
"InitialMode": mode,
|
||||||
"AvailableModes": func() []string {
|
"AvailableModes": func() []string {
|
||||||
var modes []string
|
var modes []string
|
||||||
for m := range modeSources {
|
for m := range modeSources {
|
||||||
@@ -296,7 +309,7 @@ func (s *playbackService) BuildWatchData(ctx context.Context, animeID int, title
|
|||||||
sort.Strings(modes)
|
sort.Strings(modes)
|
||||||
return modes
|
return modes
|
||||||
}(),
|
}(),
|
||||||
"Segments": segments,
|
"Segments": segments,
|
||||||
}
|
}
|
||||||
|
|
||||||
return map[string]any{
|
return map[string]any{
|
||||||
@@ -310,13 +323,15 @@ func (s *playbackService) BuildWatchData(ctx context.Context, animeID int, title
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *playbackService) SaveProgress(ctx context.Context, userID string, animeID int64, episode int, timeSeconds float64) error {
|
func (s *playbackService) SaveProgress(ctx context.Context, userID string, animeID int64, episode int, timeSeconds float64) error {
|
||||||
params := db.SaveWatchProgressParams{
|
_, err := s.repo.UpsertContinueWatchingEntry(ctx, db.UpsertContinueWatchingEntryParams{
|
||||||
|
ID: uuid.New().String(),
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
AnimeID: animeID,
|
AnimeID: animeID,
|
||||||
CurrentEpisode: sql.NullInt64{Int64: int64(episode), Valid: true},
|
CurrentEpisode: sql.NullInt64{Int64: int64(episode), Valid: true},
|
||||||
CurrentTimeSeconds: timeSeconds,
|
CurrentTimeSeconds: timeSeconds,
|
||||||
}
|
DurationSeconds: sql.NullFloat64{Valid: false},
|
||||||
return s.repo.SaveWatchProgress(ctx, params)
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *playbackService) fetchSkipSegments(ctx context.Context, malID int, episode string) []SkipSegment {
|
func (s *playbackService) fetchSkipSegments(ctx context.Context, malID int, episode string) []SkipSegment {
|
||||||
|
|||||||
Reference in New Issue
Block a user