feat(client): 对接详情/播放/进度续看/收藏(K1 看剧闭环)+ 三态 UI
后端接口从 6 个扩到 13 个,全部走真数据:
- 新增 api:playback_api(/app/episodes/{id}/play)、watch_api(/app/watch/*)、
library_api(/app/favorites*);票据从 CatalogApi 搬到 PlaybackApi
- 新增 repository:PlaybackRepository(含票据 TTL 缓存,默认 10 分钟,时钟可注入)、
FavoriteRepository、WatchHistoryRepository 换成服务端模型(每剧一条续看记录,删掉 demoProfileId)
- PlayerLogic:起播前取票(拿不到给三态 UI,失败可重试);accessType 驱动锁定文案,
不在前端猜;签名地址原样交给播放器(只补 host,不动 path/query);
进度上报节流 5s → 10s,切集/退出/切后台各补一次,播完带 finished
- 续看定位:服务端记录里的那一集才 seek(其它集从头播),续看位置进详情/播放页时读一次
- FavoriteController:收藏以服务端为准,乐观更新 + 失败回滚;退出登录清空
- UI 三态:详情页(加载/失败可重试/空剧集 + 续看进度条 + 收藏按钮)、
播放页(票据加载中/失败可重试/后端判定不可播)、我的页(续看失败可重试、收藏三态、最近观看)
- l10n 新增 8 个键(en/zh/id 三份):网络/进度/收藏失败、锁定提示、续看文案等
测试:flutter test 188 全过(存量 27 个测试文件未跑红);新增票据过期重取、进度节流、
续看定位、收藏回滚、签名 query 原样保留、真实后端端到端联调(live_watch_flow)
This commit is contained in:
1 parent
94ff9f1177
commit
d7eff4ca59
48 files changed
+2411
-377
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/home_feed.dart';
|
||||
import 'package:fruitshorts/core/data/models/play_ticket.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/catalog_repository.dart';
|
||||
|
||||
/// 测试用目录数据:三部分区里的短剧,标题与后端演示数据保持一致。
|
||||
@@ -20,16 +19,6 @@ class FakeCatalogRepository implements CatalogRepository {
|
||||
return dramas.firstWhere((drama) => drama.id == dramaId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PlayTicket> resolvePlay(String episodeId) async {
|
||||
return PlayTicket(
|
||||
episodeId: episodeId,
|
||||
accessible: true,
|
||||
accessType: PlayTicket.free,
|
||||
playUrl: 'https://example.test/$episodeId.mp4',
|
||||
);
|
||||
}
|
||||
|
||||
HomeFeed _feed() => HomeFeed(
|
||||
sections: [FeedSection(code: 'hot', title: '热门推荐', dramas: dramas)],
|
||||
);
|
||||
|
||||
@@ -1,44 +1,67 @@
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
import 'package:fruitshorts/core/data/models/watch_progress.dart';
|
||||
|
||||
/// Records every history interaction so tests can assert on the key it used.
|
||||
/// 记录每次进度读取/上报,方便断言"读了哪部剧、上报了哪一集"。
|
||||
///
|
||||
/// 服务端模型:每部剧一条续看记录(不再是 profile+剧+集),所以 `reads` 里是 dramaId。
|
||||
class FakeWatchHistory implements WatchHistoryRepository {
|
||||
final List<String> reads = [];
|
||||
final List<String> writes = [];
|
||||
|
||||
/// Position returned by [positionFor] when [failReads] is false.
|
||||
/// 便捷写法:只关心"有续看位置"时直接给这个值(默认落在第 1 集)。
|
||||
Duration? saved;
|
||||
|
||||
/// Last episode returned by [lastEpisodeId].
|
||||
/// 便捷写法:续看记录落在哪一集(配合 [saved] 使用)。
|
||||
String? lastEpisode;
|
||||
|
||||
/// 精确控制:按剧返回不同记录。
|
||||
final Map<String, WatchProgress> records = {};
|
||||
|
||||
/// [recent] 的返回值。
|
||||
List<WatchProgress> recentRecords = const [];
|
||||
|
||||
bool failReads = false;
|
||||
bool failWrites = false;
|
||||
|
||||
@override
|
||||
Future<Duration?> positionFor(
|
||||
String profileId,
|
||||
String dramaId,
|
||||
String episodeId,
|
||||
) async {
|
||||
reads.add('$profileId|$dramaId|$episodeId');
|
||||
Future<WatchProgress?> progressFor(String dramaId) async {
|
||||
reads.add(dramaId);
|
||||
if (failReads) throw StateError('history unavailable');
|
||||
return saved;
|
||||
final record = records[dramaId];
|
||||
if (record != null) return record;
|
||||
if (saved == null) return null;
|
||||
return WatchProgress(
|
||||
dramaId: dramaId,
|
||||
episodeId: lastEpisode ?? '$dramaId-1',
|
||||
position: saved!,
|
||||
duration: const Duration(minutes: 5),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String?> lastEpisodeId(String profileId, String dramaId) async {
|
||||
if (failReads) throw StateError('history unavailable');
|
||||
return lastEpisode;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> save(
|
||||
String profileId,
|
||||
String dramaId,
|
||||
String episodeId,
|
||||
Duration position,
|
||||
) async {
|
||||
Future<WatchProgress?> save({
|
||||
required String episodeId,
|
||||
required Duration position,
|
||||
Duration? duration,
|
||||
bool finished = false,
|
||||
}) async {
|
||||
if (failWrites) throw StateError('history unavailable');
|
||||
writes.add('$profileId|$dramaId|$episodeId|${position.inMilliseconds}');
|
||||
writes.add('$episodeId|${position.inMilliseconds}|$finished');
|
||||
return WatchProgress(
|
||||
dramaId: '',
|
||||
episodeId: episodeId,
|
||||
position: position,
|
||||
duration: duration ?? Duration.zero,
|
||||
finished: finished,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<WatchProgress>> recent({int limit = 20}) async {
|
||||
if (failReads) throw StateError('history unavailable');
|
||||
return recentRecords.take(limit).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> remove(String dramaId) async => records.remove(dramaId);
|
||||
}
|
||||
Reference in new issue
Block a user