diff --git a/lib/http/dynamics.dart b/lib/http/dynamics.dart index 5226cb296..95b08d0fc 100644 --- a/lib/http/dynamics.dart +++ b/lib/http/dynamics.dart @@ -23,6 +23,7 @@ import 'package:PiliPlus/utils/accounts.dart'; import 'package:PiliPlus/utils/utils.dart'; import 'package:PiliPlus/utils/wbi_sign.dart'; import 'package:dio/dio.dart'; +import 'package:flutter/foundation.dart' show kDebugMode; class DynamicsHttp { static Future> followDynamic({ @@ -59,8 +60,11 @@ class DynamicsHttp { ); } return Success(data); - } catch (err) { - return Error(err.toString()); + } catch (e, s) { + if (kDebugMode) { + rethrow; + } + return Error('$e\n\n$s'); } } else { return Error(code == 4101132 ? '没有数据' : res.data['message']); @@ -267,8 +271,11 @@ class DynamicsHttp { if (res.data['code'] == 0) { try { return Success(DynamicItemModel.fromJson(res.data['data']['item'])); - } catch (err) { - return Error(err.toString()); + } catch (e, s) { + if (kDebugMode) { + rethrow; + } + return Error('$e\n\n$s'); } } else { return Error(res.data['message']); diff --git a/lib/http/live.dart b/lib/http/live.dart index bceca1459..442a585cf 100644 --- a/lib/http/live.dart +++ b/lib/http/live.dart @@ -25,6 +25,7 @@ import 'package:PiliPlus/utils/accounts/account.dart'; import 'package:PiliPlus/utils/app_sign.dart'; import 'package:PiliPlus/utils/wbi_sign.dart'; import 'package:dio/dio.dart'; +import 'package:flutter/foundation.dart' show kDebugMode; abstract final class LiveHttp { static Account get recommend => Accounts.get(AccountType.recommend); @@ -659,8 +660,11 @@ abstract final class LiveHttp { if (res.data['code'] == 0) { try { return Success(SuperChatData.fromJson(res.data['data'])); - } catch (e) { - return Error(e.toString()); + } catch (e, s) { + if (kDebugMode) { + rethrow; + } + return Error('$e\n\n$s'); } } else { return Error(res.data['message']); diff --git a/lib/http/login.dart b/lib/http/login.dart index 742753db4..a897628dc 100644 --- a/lib/http/login.dart +++ b/lib/http/login.dart @@ -14,6 +14,7 @@ import 'package:PiliPlus/utils/utils.dart'; import 'package:crypto/crypto.dart'; import 'package:dio/dio.dart'; import 'package:encrypt/encrypt.dart'; +import 'package:flutter/foundation.dart' show kDebugMode; class LoginHttp { static final String deviceId = LoginUtils.genDeviceId(); @@ -46,8 +47,11 @@ class LoginHttp { try { final Map data = res.data['data']; return Success((authCode: data['auth_code'], url: data['url'])); - } catch (e) { - return Error(e.toString()); + } catch (e, s) { + if (kDebugMode) { + rethrow; + } + return Error('$e\n\n$s'); } } else { return Error(res.data['message']); diff --git a/lib/http/member.dart b/lib/http/member.dart index 3cc8fbf0f..885508a87 100644 --- a/lib/http/member.dart +++ b/lib/http/member.dart @@ -29,6 +29,7 @@ import 'package:PiliPlus/utils/app_sign.dart'; import 'package:PiliPlus/utils/utils.dart'; import 'package:PiliPlus/utils/wbi_sign.dart'; import 'package:dio/dio.dart'; +import 'package:flutter/foundation.dart' show kDebugMode; class MemberHttp { static Future reportMember( @@ -430,8 +431,11 @@ class MemberHttp { return memberDynamic(offset: data.offset, mid: mid); } return Success(data); - } catch (err) { - return Error(err.toString()); + } catch (e, s) { + if (kDebugMode) { + rethrow; + } + return Error('$e\n\n$s'); } } else { Map errMap = const { diff --git a/lib/http/search.dart b/lib/http/search.dart index ebb095317..31e1cb0e8 100644 --- a/lib/http/search.dart +++ b/lib/http/search.dart @@ -14,6 +14,7 @@ import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/request_utils.dart'; import 'package:PiliPlus/utils/wbi_sign.dart'; import 'package:dio/dio.dart'; +import 'package:flutter/foundation.dart' show kDebugMode; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; @@ -118,9 +119,11 @@ class SearchHttp { // break; } return Success(data); - } catch (err) { - debugPrint(err.toString()); - return Error(err.toString()); + } catch (e, s) { + if (kDebugMode) { + rethrow; + } + return Error('$e\n\n$s'); } } else { return Error(resData['message'], code: resData['code']); @@ -164,9 +167,11 @@ class SearchHttp { if (res.data['code'] == 0) { try { return Success(SearchAllData.fromJson(res.data['data'])); - } catch (err) { - debugPrint(err.toString()); - return Error(err.toString()); + } catch (e, s) { + if (kDebugMode) { + rethrow; + } + return Error('$e\n\n$s'); } } else { return Error(res.data['message'] ?? '没有相关数据'); diff --git a/lib/http/video.dart b/lib/http/video.dart index 745548a1c..a34a35875 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -33,7 +33,7 @@ import 'package:PiliPlus/utils/recommend_filter.dart'; import 'package:PiliPlus/utils/storage_pref.dart'; import 'package:PiliPlus/utils/wbi_sign.dart'; import 'package:dio/dio.dart'; -import 'package:flutter/foundation.dart'; +import 'package:flutter/foundation.dart' show kDebugMode, compute; /// view层根据 status 判断渲染逻辑 class VideoHttp { @@ -256,8 +256,11 @@ class VideoHttp { ); } return Error(_parseVideoErr(res.data['code'], res.data['message'])); - } catch (err) { - return Error(err.toString()); + } catch (e, s) { + if (kDebugMode) { + rethrow; + } + return Error('$e\n\n$s'); } } diff --git a/lib/models/dynamics/result.dart b/lib/models/dynamics/result.dart index 12d81d15b..5e87fb65b 100644 --- a/lib/models/dynamics/result.dart +++ b/lib/models/dynamics/result.dart @@ -7,6 +7,7 @@ import 'package:PiliPlus/models/model_avatar.dart'; import 'package:PiliPlus/models_new/live/live_feed_index/watched_show.dart'; import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/storage_pref.dart'; +import 'package:PiliPlus/utils/utils.dart'; class DynamicsDataModel { bool? hasMore; @@ -87,7 +88,7 @@ class DynamicsDataModel { } offset = json['offset']; - total = json['total']; + total = Utils.safeToInt(json['total']); } } @@ -122,7 +123,6 @@ class DynamicItemModel { basic = Basic.fromJson(json['item']['basic']); } idStr = json['item']?['id_str']; - // type = json['type']; // int if (json['item']?['modules'] case List list) { modules = ItemModulesModel.fromOpusJson(list); } else { @@ -137,16 +137,13 @@ class DynamicItemModel { class Fallback { String? id; - int? type; Fallback({ this.id, - this.type, }); factory Fallback.fromJson(Map json) => Fallback( id: json['id'], - type: json['type'], ); } @@ -170,8 +167,6 @@ class ItemModulesModel { ModuleBlocked? moduleBlocked; ModuleFold? moduleFold; - // moduleBottom - ItemModulesModel.fromJson(Map json) { moduleAuthor = json['module_author'] != null ? ModuleAuthorModel.fromJson(json['module_author']) @@ -179,7 +174,6 @@ class ItemModulesModel { moduleDynamic = json['module_dynamic'] != null ? ModuleDynamicModel.fromJson(json['module_dynamic']) : null; - // moduleInter = ModuleInterModel.fromJson(json['module_interaction']); moduleStat = json['module_stat'] != null ? ModuleStatModel.fromJson(json['module_stat']) : null; @@ -234,10 +228,6 @@ class ItemModulesModel { ? null : ModuleStatModel.fromJson(i['module_stat']); break; - // case 'MODULE_TYPE_BOTTOM': - // break; - // default: - // if (kDebugMode) debugPrint('unknown type: ${i}'); } } } @@ -246,12 +236,10 @@ class ItemModulesModel { class ModuleFold { List? ids; String? statement; - int? type; ModuleFold.fromJson(Map json) { ids = (json['ids'] as List?)?.fromCast(); statement = json['statement']; - type = json['type']; } } @@ -263,7 +251,7 @@ class ModuleCollection { ModuleCollection.fromJson(Map json) { count = json['count']; - id = json['id']; + id = Utils.safeToInt(json['id']); name = json['name']; title = json['title']; } @@ -281,23 +269,19 @@ class ModuleTop { class ModuleTopDisplay { ModuleTopAlbum? album; - int? type; ModuleTopDisplay.fromJson(Map json) { album = json['album'] == null ? null : ModuleTopAlbum.fromJson(json['album']); - type = json['type']; } } class ModuleTopAlbum { List? pics; - int? type; ModuleTopAlbum.fromJson(Map json) { pics = (json['pics'] as List?)?.map((e) => Pic.fromJson(e)).toList(); - type = json['type']; } } @@ -311,7 +295,7 @@ class ModuleBlocked { ModuleBlocked.fromJson(Map json) { bgImg = json['bg_img'] == null ? null : BgImg.fromJson(json['bg_img']); - blockedType = json['blocked_type']; + blockedType = Utils.safeToInt(json['blocked_type']); button = json['button'] == null ? null : Button.fromJson(json['button']); title = json['title']; hintMessage = json['hint_message']; @@ -320,35 +304,27 @@ class ModuleBlocked { } class Button { - int? handleType; String? icon; String? jumpUrl; String? text; JumpStyle? jumpStyle; - int? status; - int? type; Check? check; Button.fromJson(Map json) { - handleType = json['handle_type']; icon = json['icon']; jumpUrl = json['jump_url']; text = json['text']; jumpStyle = json['jump_style'] == null ? null : JumpStyle.fromJson(json['jump_style']); - status = json['status']; - type = json['type']; check = json['check'] == null ? null : Check.fromJson(json['check']); } } class Check { - int? disable; String? text; Check.fromJson(Map json) { - disable = json['disable']; text = json['text']; } } @@ -366,22 +342,17 @@ class BgImg { class Basic { String? commentIdStr; int? commentType; - Map? likeIcon; String? ridStr; Basic.fromJson(Map json) { commentIdStr = json['comment_id_str']; - commentType = json['comment_type']; - likeIcon = json['like_icon']; + commentType = Utils.safeToInt(json['comment_type']); ridStr = json['rid_str']; } } // 单个动态详情 - 作者信息 class ModuleAuthorModel extends Avatar { - bool? following; - String? jumpUrl; - String? label; String? pubAction; String? pubTime; int? pubTs; @@ -392,12 +363,9 @@ class ModuleAuthorModel extends Avatar { if (json['official'] != null) { officialVerify ??= BaseOfficialVerify.fromJson(json['official']); // opus } - following = json['following']; - jumpUrl = json['jump_url']; - label = json['label']; pubAction = json['pub_action']; pubTime = json['pub_time']; - pubTs = json['pub_ts'] == 0 ? null : json['pub_ts']; + pubTs = json['pub_ts'] == 0 ? null : Utils.safeToInt(json['pub_ts']); type = json['type']; if (PendantAvatar.showDynDecorate) { decorate = json['decorate'] == null @@ -412,51 +380,30 @@ class ModuleAuthorModel extends Avatar { class Decorate { String? cardUrl; Fan? fan; - int? id; - String? jumpUrl; - String? name; - int? type; Decorate({ this.cardUrl, this.fan, - this.id, - this.jumpUrl, - this.name, - this.type, }); factory Decorate.fromJson(Map json) => Decorate( cardUrl: json["card_url"], fan: json["fan"] == null ? null : Fan.fromJson(json["fan"]), - id: json["id"], - jumpUrl: json["jump_url"], - name: json["name"], - type: json["type"], ); } class Fan { String? color; - bool? isFan; - String? numPrefix; String? numStr; - int? number; Fan({ this.color, - this.isFan, - this.numPrefix, this.numStr, - this.number, }); factory Fan.fromJson(Map json) => Fan( color: json["color"], - isFan: json["is_fan"], - numPrefix: json["num_prefix"], numStr: json["num_str"], - number: json["number"], ); } @@ -490,16 +437,6 @@ class ModuleDynamicModel { } } -// 单个动态详情 - 评论?信息 -// class ModuleInterModel { -// ModuleInterModel({ - -// }); - -// ModuleInterModel.fromJson(Map json) { - -// } -// } class DynamicAddModel { DynamicAddModel({ this.type, @@ -536,23 +473,17 @@ class DynamicAddModel { class AddMatch { Button? button; - String? headText; - String? idStr; String? jumpUrl; MatchInfo? matchInfo; AddMatch({ this.button, - this.headText, - this.idStr, this.jumpUrl, this.matchInfo, }); factory AddMatch.fromJson(Map json) => AddMatch( button: json["button"] == null ? null : Button.fromJson(json["button"]), - headText: json["head_text"], - idStr: json["id_str"], jumpUrl: json["jump_url"], matchInfo: json["match_info"] == null ? null @@ -565,7 +496,6 @@ class MatchInfo { List? centerTop; TTeam? leftTeam; TTeam? rightTeam; - int? status; dynamic subTitle; String? title; @@ -574,7 +504,6 @@ class MatchInfo { this.centerTop, this.leftTeam, this.rightTeam, - this.status, this.subTitle, this.title, }); @@ -588,25 +517,21 @@ class MatchInfo { rightTeam: json["right_team"] == null ? null : TTeam.fromJson(json["right_team"]), - status: json["status"], subTitle: json["sub_title"], title: json["title"], ); } class TTeam { - int? id; String? name; String? pic; TTeam({ - this.id, this.name, this.pic, }); factory TTeam.fromJson(Map json) => TTeam( - id: json["id"], name: json["name"], pic: json["pic"], ); @@ -617,11 +542,7 @@ class AddCommon { String? cover; String? desc1; String? desc2; - String? headText; - String? idStr; String? jumpUrl; - int? style; - String? subType; String? title; AddCommon({ @@ -629,11 +550,7 @@ class AddCommon { this.cover, this.desc1, this.desc2, - this.headText, - this.idStr, this.jumpUrl, - this.style, - this.subType, this.title, }); @@ -642,11 +559,7 @@ class AddCommon { cover: json["cover"], desc1: json["desc1"], desc2: json["desc2"], - headText: json["head_text"], - idStr: json["id_str"], jumpUrl: json["jump_url"], - style: json["style"], - subType: json["sub_type"], title: json["title"], ); } @@ -656,24 +569,14 @@ class UpowerLottery { Desc? desc; Hint? hint; String? jumpUrl; - int? rid; - int? state; String? title; - int? upMid; - int? upowerActionState; - int? upowerLevel; UpowerLottery({ this.button, this.desc, this.hint, this.jumpUrl, - this.rid, - this.state, this.title, - this.upMid, - this.upowerActionState, - this.upowerLevel, }); factory UpowerLottery.fromJson(Map json) => UpowerLottery( @@ -681,82 +584,49 @@ class UpowerLottery { desc: json["desc"] == null ? null : Desc.fromJson(json["desc"]), hint: json["hint"] == null ? null : Hint.fromJson(json["hint"]), jumpUrl: json["jump_url"], - rid: json["rid"], - state: json["state"], title: json["title"], - upMid: json["up_mid"], - upowerActionState: json["upower_action_state"], - upowerLevel: json["upower_level"], ); } class Hint { - int? style; String? text; Hint({ - this.style, this.text, }); factory Hint.fromJson(Map json) => Hint( - style: json["style"], text: json["text"], ); } class JumpStyle { - String? iconUrl; String? text; JumpStyle({ - this.iconUrl, this.text, }); factory JumpStyle.fromJson(Map json) => JumpStyle( - iconUrl: json["icon_url"], text: json["text"], ); } class Vote { Vote({ - this.choiceCnt, - this.defaultShare, - this.share, - this.endTime, this.joinNum, - this.status, - this.type, - this.uid, this.voteId, + this.desc, }); - int? choiceCnt; - String? share; - int? defaultShare; - int? endTime; int? joinNum; - int? status; - int? type; - int? uid; int? voteId; String? desc; Vote.fromJson(Map json) { + joinNum = Utils.safeToInt(json['join_num']); + voteId = Utils.safeToInt(json['vote_id']); desc = json['desc']; - choiceCnt = json['choice_cnt']; - share = json['share']; - defaultShare = json['default_share']; - endTime = json['end_time'] is int - ? json['end_time'] - : int.parse(json['end_time']); - joinNum = json['join_num']; - status = json['status']; - type = json['type']; - uid = json['uid']; - voteId = json['vote_id']; } } @@ -764,31 +634,19 @@ class Ugc { Ugc({ this.cover, this.descSecond, - this.duration, - this.headText, - this.idStr, this.jumpUrl, - this.multiLine, this.title, }); String? cover; String? descSecond; - String? duration; - String? headText; - String? idStr; String? jumpUrl; - bool? multiLine; String? title; Ugc.fromJson(Map json) { cover = json['cover']; descSecond = json['desc_second']; - duration = json['duration']; - headText = json['head_text']; - idStr = json['id_str']; jumpUrl = json['jump_url']; - multiLine = json['multi_line']; title = json['title']; } } @@ -799,26 +657,20 @@ class Reserve { this.desc1, this.desc2, this.desc3, - this.jumpUrl, this.reserveTotal, this.rid, this.state, - this.stype, this.title, - this.upMid, }); ReserveBtn? button; Desc? desc1; Desc? desc2; Desc? desc3; - String? jumpUrl; int? reserveTotal; int? rid; int? state; - int? stype; String? title; - int? upMid; Reserve.fromJson(Map json) { button = json['button'] == null @@ -827,14 +679,11 @@ class Reserve { desc1 = json['desc1'] == null ? null : Desc.fromJson(json['desc1']); desc2 = json['desc2'] == null ? null : Desc.fromJson(json['desc2']); desc3 = json['desc3'] == null ? null : Desc.fromJson(json['desc3']); - jumpUrl = json['jump_url']; - reserveTotal = json['reserve_total']; - rid = json['rid']; - state = json['state']; - state = json['state']; - stype = json['stype']; + reserveTotal = Utils.safeToInt(json['reserve_total']); + rid = Utils.safeToInt(json['rid']); + state = Utils.safeToInt(json['state']); + state = Utils.safeToInt(json['state']); title = json['title']; - upMid = json['up_mid']; } } @@ -855,11 +704,11 @@ class ReserveBtn { String? jumpUrl; ReserveBtn.fromJson(Map json) { - status = json['status']; - type = json['type']; + status = Utils.safeToInt(json['status']); + type = Utils.safeToInt(json['type']); checkText = json['check']?['text'] ?? '已预约'; uncheckText = json['uncheck']?['text'] ?? '预约'; - disable = json['uncheck']?['disable']; + disable = Utils.safeToInt(json['uncheck']?['disable']); jumpText = json['jump_style']?['text']; jumpUrl = json['jump_url']; } @@ -867,71 +716,50 @@ class ReserveBtn { class Desc { Desc({ - this.style, this.text, - this.visible, this.jumpUrl, }); - int? style; String? text; - bool? visible; String? jumpUrl; Desc.fromJson(Map json) { - style = json['style']; text = json['text']; - visible = json['visible']; jumpUrl = json["jump_url"]; } } class Good { Good({ - this.headIcon, - this.headText, this.items, - this.jumpUrl, }); - String? headIcon; - String? headText; List? items; - String? jumpUrl; Good.fromJson(Map json) { - headIcon = json['head_icon']; - headText = json['head_text']; items = (json['items'] as List?) ?.map((e) => GoodItem.fromJson(e)) .toList(); - jumpUrl = json['jump_url']; } } class GoodItem { GoodItem({ - this.brief, this.cover, - this.id, this.jumpDesc, this.jumpUrl, this.name, this.price, }); - String? brief; String? cover; - dynamic id; String? jumpDesc; String? jumpUrl; String? name; String? price; GoodItem.fromJson(Map json) { - brief = json['brief']; cover = json['cover']; - id = json['id']; jumpDesc = json['jump_desc']; jumpUrl = json['jump_url']; name = json['name']; @@ -956,11 +784,9 @@ class DynamicDescModel { } } -// class DynamicMajorModel { DynamicMajorModel({ this.archive, - this.draw, this.ugcSeason, this.opus, this.pgc, @@ -976,16 +802,12 @@ class DynamicMajorModel { }); DynamicArchiveModel? archive; - DynamicDrawModel? draw; DynamicArchiveModel? ugcSeason; DynamicOpusModel? opus; DynamicArchiveModel? pgc; DynamicLiveModel? liveRcmd; DynamicLive2Model? live; DynamicNoneModel? none; - // MAJOR_TYPE_DRAW 图片 - // MAJOR_TYPE_ARCHIVE 视频 - // MAJOR_TYPE_OPUS 图文/文章 String? type; DynamicArchiveModel? courses; Common? common; @@ -999,9 +821,6 @@ class DynamicMajorModel { archive = json['archive'] != null ? DynamicArchiveModel.fromJson(json['archive']) : null; - draw = json['draw'] != null - ? DynamicDrawModel.fromJson(json['draw']) - : null; ugcSeason = json['ugc_season'] != null ? DynamicArchiveModel.fromJson(json['ugc_season']) : null; @@ -1042,15 +861,13 @@ class Music { int? id; String? cover; String? title; - String? jumpUrl; String? label; Music.fromJson(Map json) { - id = json['id']; + id = Utils.safeToInt(json['id']); cover = json['cover']; title = json['title']; label = json['label']; - jumpUrl = json['jump_url']; } } @@ -1074,11 +891,9 @@ class Medialist { class SubscriptionNew { LiveRcmd? liveRcmd; - String? style; SubscriptionNew({ this.liveRcmd, - this.style, }); factory SubscriptionNew.fromJson(Map json) => @@ -1086,39 +901,32 @@ class SubscriptionNew { liveRcmd: json["live_rcmd"] == null ? null : LiveRcmd.fromJson(json["live_rcmd"]), - style: json["style"], ); } class LiveRcmd { LiveRcmdContent? content; - int? reserveType; LiveRcmd({ this.content, - this.reserveType, }); factory LiveRcmd.fromJson(Map json) => LiveRcmd( content: json["content"] == null ? null : LiveRcmdContent.fromJson(jsonDecode(json["content"])), - reserveType: json["reserve_type"], ); } class LiveRcmdContent { - int? type; LivePlayInfo? livePlayInfo; LiveRcmdContent({ - this.type, this.livePlayInfo, }); factory LiveRcmdContent.fromJson(Map json) => LiveRcmdContent( - type: json["type"], livePlayInfo: json["live_play_info"] == null ? null : LivePlayInfo.fromJson(json["live_play_info"]), @@ -1127,80 +935,44 @@ class LiveRcmdContent { class LivePlayInfo { int? roomId; - int? uid; int? liveStatus; - int? roomType; - int? playType; String? title; String? cover; - int? online; - int? areaId; String? areaName; - int? parentAreaId; - String? parentAreaName; - int? liveScreenType; - int? liveStartTime; - String? link; WatchedShow? watchedShow; - int? roomPaidType; LivePlayInfo({ this.roomId, - this.uid, this.liveStatus, - this.roomType, - this.playType, this.title, this.cover, - this.online, - this.areaId, this.areaName, - this.parentAreaId, - this.parentAreaName, - this.liveScreenType, - this.liveStartTime, - this.link, this.watchedShow, - this.roomPaidType, }); factory LivePlayInfo.fromJson(Map json) => LivePlayInfo( - roomId: json["room_id"], - uid: json["uid"], - liveStatus: json["live_status"], - roomType: json["room_type"], - playType: json["play_type"], + roomId: Utils.safeToInt(json["room_id"]), + liveStatus: Utils.safeToInt(json["live_status"]), title: json["title"], cover: json["cover"], - online: json["online"], - areaId: json["area_id"], areaName: json["area_name"], - parentAreaId: json["parent_area_id"], - parentAreaName: json["parent_area_name"], - liveScreenType: json["live_screen_type"], - liveStartTime: json["live_start_time"], - link: json["link"], watchedShow: json["watched_show"] == null ? null : WatchedShow.fromJson(json["watched_show"]), - roomPaidType: json["room_paid_type"], ); } class DynamicTopicModel { DynamicTopicModel({ this.id, - this.jumpUrl, this.name, }); int? id; - String? jumpUrl; String? name; DynamicTopicModel.fromJson(Map json) { - id = json['id']; - jumpUrl = json['jump_url']; + id = Utils.safeToInt(json['id']); name = json['name']; } } @@ -1212,8 +984,6 @@ class DynamicArchiveModel { this.badge, this.bvid, this.cover, - this.desc, - this.disablePreview, this.durationText, this.jumpUrl, this.stat, @@ -1228,8 +998,6 @@ class DynamicArchiveModel { Badge? badge; String? bvid; String? cover; - String? desc; - int? disablePreview; String? durationText; String? jumpUrl; Stat? stat; @@ -1239,19 +1007,18 @@ class DynamicArchiveModel { int? seasonId; DynamicArchiveModel.fromJson(Map json) { - id = json['id']; - aid = json['aid'] is String ? int.parse(json['aid']) : json['aid']; + id = Utils.safeToInt(json['id']); + aid = Utils.safeToInt(json['aid']); badge = json['badge'] == null ? null : Badge.fromJson(json['badge']); bvid = json['bvid'] ?? json['epid'].toString() ?? ' '; cover = json['cover']; - disablePreview = json['disable_preview']; durationText = json['duration_text']; jumpUrl = json['jump_url']; stat = json['stat'] != null ? Stat.fromJson(json['stat']) : null; title = json['title']; - type = json['type']; - epid = json['epid']; - seasonId = json['season_id']; + type = Utils.safeToInt(json['type']); + epid = Utils.safeToInt(json['epid']); + seasonId = Utils.safeToInt(json['season_id']); } } @@ -1267,37 +1034,18 @@ class Badge { } } -class DynamicDrawModel { - DynamicDrawModel({ - this.id, - this.items, - }); - - int? id; - List? items; - - DynamicDrawModel.fromJson(Map json) { - id = json['id']; - items = (json['items'] as List?) - ?.map((e) => DynamicDrawItemModel.fromJson(e)) - .toList(); - } -} - class DynamicOpusModel { DynamicOpusModel({ - this.jumpUrl, this.pics, this.summary, this.title, }); - String? jumpUrl; List? pics; SummaryModel? summary; String? title; + DynamicOpusModel.fromJson(Map json) { - jumpUrl = json['jump_url']; pics = (json['pics'] as List?) ?.map((e) => OpusPicModel.fromJson(e)) .toList(); @@ -1333,6 +1081,7 @@ class RichTextNodeItem { this.type, this.rid, }); + Emoji? emoji; String? origText; String? text; @@ -1356,22 +1105,12 @@ class RichTextNodeItem { } class Emoji { - // String? iconUrl; - // String? webpUrl; - // String? gifUrl; String? url; late num size; - String? text; - num? type; Emoji.fromJson(Map json) { - // iconUrl = json['icon_url']; - // webpUrl = json['webp_url']; - // gifUrl = json['gif_url']; url = json['webp_url'] ?? json['gif_url'] ?? json['icon_url']; size = json['size'] ?? 1; - text = json['text']; - type = json['type']; } } @@ -1379,7 +1118,9 @@ class DynamicNoneModel { DynamicNoneModel({ this.tips, }); + String? tips; + DynamicNoneModel.fromJson(Map json) { tips = json['tips']; } @@ -1400,73 +1141,32 @@ class OpusPicModel { String? liveUrl; OpusPicModel.fromJson(Map json) { - width = json['width']; - height = json['height']; + width = Utils.safeToInt(json['width']); + height = Utils.safeToInt(json['height']); src = json['src']; url = json['url']; liveUrl = json['live_url']; } } -class DynamicDrawItemModel { - DynamicDrawItemModel({ - this.height, - this.size, - this.src, - this.tags, - this.width, - }); - int? height; - int? size; - String? src; - List? tags; - int? width; - DynamicDrawItemModel.fromJson(Map json) { - height = json['height']; - size = json['size'].toInt(); - src = json['src']; - tags = json['tags']; - width = json['width']; - } -} - class DynamicLiveModel { - DynamicLiveModel({ - this.content, - }); - - String? content; - int? type; - Map? livePlayInfo; - int? uid; - String? parentAreaName; int? roomId; - String? liveId; int? liveStatus; String? cover; - int? online; String? areaName; String? title; - int? liveStartTime; WatchedShow? watchedShow; DynamicLiveModel.fromJson(Map json) { - content = json['content']; if (json['content'] != null) { Map data = jsonDecode(json['content']); - - type = data['type']; Map livePlayInfo = data['live_play_info']; - uid = livePlayInfo['uid']; - parentAreaName = livePlayInfo['parent_area_name']; - roomId = livePlayInfo['room_id']; - liveId = livePlayInfo['live_id']; - liveStatus = livePlayInfo['live_status']; + + roomId = Utils.safeToInt(livePlayInfo['room_id']); + liveStatus = Utils.safeToInt(livePlayInfo['live_status']); cover = livePlayInfo['cover']; - online = livePlayInfo['online']; areaName = livePlayInfo['area_name']; title = livePlayInfo['title']; - liveStartTime = livePlayInfo['live_start_time']; watchedShow = livePlayInfo['watched_show'] == null ? null : WatchedShow.fromJson(livePlayInfo['watched_show']); @@ -1479,33 +1179,24 @@ class DynamicLive2Model { this.badge, this.cover, this.descFirst, - this.descSecond, this.id, - this.jumpUrl, this.liveState, - this.reserveType, this.title, }); Badge? badge; String? cover; String? descFirst; - String? descSecond; int? id; - String? jumpUrl; int? liveState; - int? reserveType; String? title; DynamicLive2Model.fromJson(Map json) { badge = json['badge'] == null ? null : Badge.fromJson(json['badge']); cover = json['cover']; descFirst = json['desc_first']; - descSecond = json['desc_second']; - id = json['id']; - jumpUrl = json['jump_url']; - liveState = json['live_state']; - reserveType = json['reserve_type']; + id = Utils.safeToInt(json['id']); + liveState = Utils.safeToInt(json['live_state']); title = json['title']; } } @@ -1535,7 +1226,6 @@ class ModuleStatModel { DynamicStat? forward; DynamicStat? like; DynamicStat? favorite; - // DynamicStat? coin; ModuleStatModel.fromJson(Map json) { comment = json['comment'] == null @@ -1555,26 +1245,16 @@ class ModuleStatModel { class DynamicStat { DynamicStat({ this.count, - this.forbidden, this.status, }); int? count; - bool? forbidden; bool? status; DynamicStat.fromJson(Map json) { - count = json['count'] == 0 ? null : _parseInt(json['count']); - forbidden = json['forbidden']; + count = json['count'] == 0 ? null : Utils.safeToInt(json['count']); status = json['status']; } - - static int? _parseInt(dynamic x) => switch (x) { - int() => x, - String() => int.tryParse(x), - double() => x.toInt(), - _ => null, - }; } class Stat { diff --git a/lib/models/model_owner.dart b/lib/models/model_owner.dart index bd54b2117..add6e448b 100644 --- a/lib/models/model_owner.dart +++ b/lib/models/model_owner.dart @@ -1,4 +1,5 @@ import 'package:PiliPlus/models/model_video.dart'; +import 'package:PiliPlus/utils/utils.dart'; import 'package:hive/hive.dart'; part 'model_owner.g.dart'; @@ -20,7 +21,7 @@ class Owner implements BaseOwner { String? face; Owner.fromJson(Map json) { - mid = json["mid"]; + mid = Utils.safeToInt(json["mid"]); name = json["name"]; face = json['face']; } diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index c1894c327..42dfa3e37 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -25,6 +25,13 @@ abstract class Utils { static final bool isDesktop = Platform.isWindows || Platform.isMacOS || Platform.isLinux; + static int? safeToInt(dynamic value) => switch (value) { + int e => e, + String e => int.tryParse(e), + num e => e.toInt(), + _ => null, + }; + static Future get isWiFi async { try { return Utils.isMobile &&