fix: 首页推荐数据格式异常

This commit is contained in:
guozhigq
2024-07-23 23:25:06 +08:00
parent 38b6b6b4e0
commit bc36493e60
12 changed files with 45 additions and 459 deletions

View File

@ -215,9 +215,8 @@ class VideoContent extends StatelessWidget {
children: [ children: [
if (videoItem.goto == 'bangumi') if (videoItem.goto == 'bangumi')
_buildBadge(videoItem.bangumiBadge, 'line', 9), _buildBadge(videoItem.bangumiBadge, 'line', 9),
if (videoItem.rcmdReason?.content != null && if (videoItem.rcmdReason != null)
videoItem.rcmdReason.content != '') _buildBadge(videoItem.rcmdReason, 'color'),
_buildBadge(videoItem.rcmdReason.content, 'color'),
if (videoItem.goto == 'picture') _buildBadge('动态', 'line', 9), if (videoItem.goto == 'picture') _buildBadge('动态', 'line', 9),
if (videoItem.isFollowed == 1) _buildBadge('已关注', 'color'), if (videoItem.isFollowed == 1) _buildBadge('已关注', 'color'),
Expanded( Expanded(

View File

@ -70,47 +70,43 @@ class VideoHttp {
// 添加额外的loginState变量模拟未登录状态 // 添加额外的loginState变量模拟未登录状态
static Future rcmdVideoListApp( static Future rcmdVideoListApp(
{bool loginStatus = true, required int freshIdx}) async { {bool loginStatus = true, required int freshIdx}) async {
try { var res = await Request().get(
var res = await Request().get( Api.recommendListApp,
Api.recommendListApp, data: {
data: { 'idx': freshIdx,
'idx': freshIdx, 'flush': '5',
'flush': '5', 'column': '4',
'column': '4', 'device': 'pad',
'device': 'pad', 'device_type': 0,
'device_type': 0, 'device_name': 'vivo',
'device_name': 'vivo', 'pull': freshIdx == 0 ? 'true' : 'false',
'pull': freshIdx == 0 ? 'true' : 'false', 'appkey': Constants.appKey,
'appkey': Constants.appKey, 'access_key': loginStatus
'access_key': loginStatus ? (localCache
? (localCache.get(LocalCacheKey.accessKey, .get(LocalCacheKey.accessKey, defaultValue: {})['value'] ??
defaultValue: {})['value'] ?? '')
'') : ''
: '' },
}, );
); if (res.data['code'] == 0) {
if (res.data['code'] == 0) { List<RecVideoItemAppModel> list = [];
List<RecVideoItemAppModel> list = []; List<int> blackMidsList =
List<int> blackMidsList = setting.get(SettingBoxKey.blackMidsList, defaultValue: [-1]);
setting.get(SettingBoxKey.blackMidsList, defaultValue: [-1]); for (var i in res.data['data']['items']) {
for (var i in res.data['data']['items']) { // 屏蔽推广和拉黑用户
// 屏蔽推广和拉黑用户 if (i['card_goto'] != 'ad_av' &&
if (i['card_goto'] != 'ad_av' && (!enableRcmdDynamic ? i['card_goto'] != 'picture' : true) &&
(!enableRcmdDynamic ? i['card_goto'] != 'picture' : true) && (i['args'] != null &&
(i['args'] != null && !blackMidsList.contains(i['args']['up_mid']))) {
!blackMidsList.contains(i['args']['up_mid']))) { RecVideoItemAppModel videoItem = RecVideoItemAppModel.fromJson(i);
RecVideoItemAppModel videoItem = RecVideoItemAppModel.fromJson(i); if (!RecommendFilter.filter(videoItem)) {
if (!RecommendFilter.filter(videoItem)) { list.add(videoItem);
list.add(videoItem);
}
} }
} }
return {'status': true, 'data': list};
} else {
return {'status': false, 'data': [], 'msg': res.data['message']};
} }
} catch (err) { return {'status': true, 'data': list};
return {'status': false, 'data': [], 'msg': err.toString()}; } else {
return {'status': false, 'data': [], 'msg': res.data['message']};
} }
} }

View File

@ -34,7 +34,7 @@ class RecVideoItemAppModel {
String? title; String? title;
int? isFollowed; int? isFollowed;
RcmdOwner? owner; RcmdOwner? owner;
RcmdReason? rcmdReason; String? rcmdReason;
String? goto; String? goto;
int? param; int? param;
String? uri; String? uri;
@ -64,17 +64,11 @@ class RecVideoItemAppModel {
//duration = json['cover_right_text']; //duration = json['cover_right_text'];
title = json['title']; title = json['title'];
owner = RcmdOwner.fromJson(json); owner = RcmdOwner.fromJson(json);
rcmdReason = json['rcmd_reason_style'] != null rcmdReason = json['bottom_rcmd_reason'] ?? json['top_rcmd_reason'];
? RcmdReason.fromJson(json['rcmd_reason_style'])
: null;
// 由于app端api并不会直接返回与owner的关注状态 // 由于app端api并不会直接返回与owner的关注状态
// 所以借用推荐原因是否为“已关注”、“新关注”等判别关注状态从而与web端接口等效 // 所以借用推荐原因是否为“已关注”、“新关注”等判别关注状态从而与web端接口等效
RegExp regex = RegExp(r'已关注|新关注'); RegExp regex = RegExp(r'已关注|新关注');
isFollowed = rcmdReason != null && isFollowed = regex.hasMatch(rcmdReason ?? '') ? 1 : 0;
rcmdReason!.content != null &&
regex.hasMatch(rcmdReason!.content!)
? 1
: 0;
// 如果是就无需再显示推荐原因交由view统一处理即可 // 如果是就无需再显示推荐原因交由view统一处理即可
if (isFollowed == 1) { if (isFollowed == 1) {
rcmdReason = null; rcmdReason = null;

View File

@ -1,19 +1,12 @@
import 'package:hive/hive.dart';
part 'model_owner.g.dart';
@HiveType(typeId: 3)
class Owner { class Owner {
Owner({ Owner({
this.mid, this.mid,
this.name, this.name,
this.face, this.face,
}); });
@HiveField(0)
int? mid; int? mid;
@HiveField(1)
String? name; String? name;
@HiveField(2)
String? face; String? face;
Owner.fromJson(Map<String, dynamic> json) { Owner.fromJson(Map<String, dynamic> json) {

View File

@ -1,47 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'model_owner.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class OwnerAdapter extends TypeAdapter<Owner> {
@override
final int typeId = 3;
@override
Owner read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Owner(
mid: fields[0] as int?,
name: fields[1] as String?,
face: fields[2] as String?,
);
}
@override
void write(BinaryWriter writer, Owner obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.mid)
..writeByte(1)
..write(obj.name)
..writeByte(2)
..write(obj.face);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is OwnerAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@ -1,9 +1,5 @@
import './model_owner.dart'; import './model_owner.dart';
import 'package:hive/hive.dart';
part 'model_rec_video_item.g.dart';
@HiveType(typeId: 0)
class RecVideoItemModel { class RecVideoItemModel {
RecVideoItemModel({ RecVideoItemModel({
this.id, this.id,
@ -21,32 +17,19 @@ class RecVideoItemModel {
this.rcmdReason, this.rcmdReason,
}); });
@HiveField(0)
int? id = -1; int? id = -1;
@HiveField(1)
String? bvid = ''; String? bvid = '';
@HiveField(2)
int? cid = -1; int? cid = -1;
@HiveField(3)
String? goto = ''; String? goto = '';
@HiveField(4)
String? uri = ''; String? uri = '';
@HiveField(5)
String? pic = ''; String? pic = '';
@HiveField(6)
String? title = ''; String? title = '';
@HiveField(7)
int? duration = -1; int? duration = -1;
@HiveField(8)
int? pubdate = -1; int? pubdate = -1;
@HiveField(9)
Owner? owner; Owner? owner;
@HiveField(10)
Stat? stat; Stat? stat;
@HiveField(11)
int? isFollowed; int? isFollowed;
@HiveField(12) String? rcmdReason;
RcmdReason? rcmdReason;
RecVideoItemModel.fromJson(Map<String, dynamic> json) { RecVideoItemModel.fromJson(Map<String, dynamic> json) {
id = json["id"]; id = json["id"];
@ -61,26 +44,20 @@ class RecVideoItemModel {
owner = Owner.fromJson(json["owner"]); owner = Owner.fromJson(json["owner"]);
stat = Stat.fromJson(json["stat"]); stat = Stat.fromJson(json["stat"]);
isFollowed = json["is_followed"] ?? 0; isFollowed = json["is_followed"] ?? 0;
rcmdReason = json["rcmd_reason"] != null rcmdReason = json["rcmd_reason"]?['content'];
? RcmdReason.fromJson(json["rcmd_reason"])
: RcmdReason(content: '');
} }
} }
@HiveType(typeId: 1)
class Stat { class Stat {
Stat({ Stat({
this.view, this.view,
this.like, this.like,
this.danmu, this.danmu,
}); });
@HiveField(0)
int? view;
@HiveField(1)
int? like;
@HiveField(2)
int? danmu;
int? view;
int? like;
int? danmu;
Stat.fromJson(Map<String, dynamic> json) { Stat.fromJson(Map<String, dynamic> json) {
// 无需在model中转换以保留原始数据在view层处理即可 // 无需在model中转换以保留原始数据在view层处理即可
view = json["view"]; view = json["view"];
@ -88,20 +65,3 @@ class Stat {
danmu = json['danmaku']; danmu = json['danmaku'];
} }
} }
@HiveType(typeId: 2)
class RcmdReason {
RcmdReason({
this.reasonType,
this.content,
});
@HiveField(0)
int? reasonType;
@HiveField(1)
String? content = '';
RcmdReason.fromJson(Map<String, dynamic> json) {
reasonType = json["reason_type"];
content = json["content"] ?? '';
}
}

View File

@ -1,154 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'model_rec_video_item.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class RecVideoItemModelAdapter extends TypeAdapter<RecVideoItemModel> {
@override
final int typeId = 0;
@override
RecVideoItemModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return RecVideoItemModel(
id: fields[0] as int?,
bvid: fields[1] as String?,
cid: fields[2] as int?,
goto: fields[3] as String?,
uri: fields[4] as String?,
pic: fields[5] as String?,
title: fields[6] as String?,
duration: fields[7] as int?,
pubdate: fields[8] as int?,
owner: fields[9] as Owner?,
stat: fields[10] as Stat?,
isFollowed: fields[11] as int?,
rcmdReason: fields[12] as RcmdReason?,
);
}
@override
void write(BinaryWriter writer, RecVideoItemModel obj) {
writer
..writeByte(13)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.bvid)
..writeByte(2)
..write(obj.cid)
..writeByte(3)
..write(obj.goto)
..writeByte(4)
..write(obj.uri)
..writeByte(5)
..write(obj.pic)
..writeByte(6)
..write(obj.title)
..writeByte(7)
..write(obj.duration)
..writeByte(8)
..write(obj.pubdate)
..writeByte(9)
..write(obj.owner)
..writeByte(10)
..write(obj.stat)
..writeByte(11)
..write(obj.isFollowed)
..writeByte(12)
..write(obj.rcmdReason);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is RecVideoItemModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class StatAdapter extends TypeAdapter<Stat> {
@override
final int typeId = 1;
@override
Stat read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Stat(
view: fields[0] as int?,
like: fields[1] as int?,
danmu: fields[2] as int?,
);
}
@override
void write(BinaryWriter writer, Stat obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.view)
..writeByte(1)
..write(obj.like)
..writeByte(2)
..write(obj.danmu);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is StatAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class RcmdReasonAdapter extends TypeAdapter<RcmdReason> {
@override
final int typeId = 2;
@override
RcmdReason read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return RcmdReason(
reasonType: fields[0] as int?,
content: fields[1] as String?,
);
}
@override
void write(BinaryWriter writer, RcmdReason obj) {
writer
..writeByte(2)
..writeByte(0)
..write(obj.reasonType)
..writeByte(1)
..write(obj.content);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is RcmdReasonAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@ -1,14 +1,8 @@
import 'package:hive/hive.dart';
part 'hot.g.dart';
@HiveType(typeId: 6)
class HotSearchModel { class HotSearchModel {
HotSearchModel({ HotSearchModel({
this.list, this.list,
}); });
@HiveField(0)
List<HotSearchItem>? list; List<HotSearchItem>? list;
HotSearchModel.fromJson(Map<String, dynamic> json) { HotSearchModel.fromJson(Map<String, dynamic> json) {
@ -18,7 +12,6 @@ class HotSearchModel {
} }
} }
@HiveType(typeId: 7)
class HotSearchItem { class HotSearchItem {
HotSearchItem({ HotSearchItem({
this.keyword, this.keyword,
@ -27,14 +20,10 @@ class HotSearchItem {
this.icon, this.icon,
}); });
@HiveField(0)
String? keyword; String? keyword;
@HiveField(1)
String? showName; String? showName;
// 4/5热 11话题 8普通 7直播 // 4/5热 11话题 8普通 7直播
@HiveField(2)
int? wordType; int? wordType;
@HiveField(3)
String? icon; String? icon;
HotSearchItem.fromJson(Map<String, dynamic> json) { HotSearchItem.fromJson(Map<String, dynamic> json) {

View File

@ -1,84 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'hot.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class HotSearchModelAdapter extends TypeAdapter<HotSearchModel> {
@override
final int typeId = 6;
@override
HotSearchModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return HotSearchModel(
list: (fields[0] as List?)?.cast<HotSearchItem>(),
);
}
@override
void write(BinaryWriter writer, HotSearchModel obj) {
writer
..writeByte(1)
..writeByte(0)
..write(obj.list);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is HotSearchModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
class HotSearchItemAdapter extends TypeAdapter<HotSearchItem> {
@override
final int typeId = 7;
@override
HotSearchItem read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return HotSearchItem(
keyword: fields[0] as String?,
showName: fields[1] as String?,
wordType: fields[2] as int?,
icon: fields[3] as String?,
);
}
@override
void write(BinaryWriter writer, HotSearchItem obj) {
writer
..writeByte(4)
..writeByte(0)
..write(obj.keyword)
..writeByte(1)
..write(obj.showName)
..writeByte(2)
..write(obj.wordType)
..writeByte(3)
..write(obj.icon);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is HotSearchItemAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@ -1,8 +1,3 @@
import 'package:hive/hive.dart';
part 'stat.g.dart';
@HiveType(typeId: 1)
class UserStat { class UserStat {
UserStat({ UserStat({
this.following, this.following,
@ -10,11 +5,8 @@ class UserStat {
this.dynamicCount, this.dynamicCount,
}); });
@HiveField(0)
int? following; int? following;
@HiveField(1)
int? follower; int? follower;
@HiveField(2)
int? dynamicCount; int? dynamicCount;
UserStat.fromJson(Map<String, dynamic> json) { UserStat.fromJson(Map<String, dynamic> json) {

View File

@ -1,47 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'stat.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class UserStatAdapter extends TypeAdapter<UserStat> {
@override
final int typeId = 1;
@override
UserStat read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return UserStat(
following: fields[0] as int?,
follower: fields[1] as int?,
dynamicCount: fields[2] as int?,
);
}
@override
void write(BinaryWriter writer, UserStat obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.following)
..writeByte(1)
..write(obj.follower)
..writeByte(2)
..write(obj.dynamicCount);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is UserStatAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@ -1,8 +1,6 @@
import 'dart:io'; import 'dart:io';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:pilipala/models/model_owner.dart';
import 'package:pilipala/models/search/hot.dart';
import 'package:pilipala/models/user/info.dart'; import 'package:pilipala/models/user/info.dart';
import '../models/common/gesture_mode.dart'; import '../models/common/gesture_mode.dart';
import 'global_data.dart'; import 'global_data.dart';
@ -54,11 +52,8 @@ class GStrorage {
} }
static void regAdapter() { static void regAdapter() {
Hive.registerAdapter(OwnerAdapter());
Hive.registerAdapter(UserInfoDataAdapter()); Hive.registerAdapter(UserInfoDataAdapter());
Hive.registerAdapter(LevelInfoAdapter()); Hive.registerAdapter(LevelInfoAdapter());
Hive.registerAdapter(HotSearchModelAdapter());
Hive.registerAdapter(HotSearchItemAdapter());
} }
static Future<void> close() async { static Future<void> close() async {