mod: 本地缓存字段修改、登录状态

This commit is contained in:
guozhigq
2023-08-20 14:28:50 +08:00
parent 8627869309
commit 83341cd62b
29 changed files with 217 additions and 167 deletions

View File

@ -10,8 +10,8 @@ class Data {
static Future historyStatus() async {
Box localCache = GStrorage.localCache;
Box user = GStrorage.user;
if (user.get(UserBoxKey.userMid) == null) {
Box userInfoCache = GStrorage.userInfo;
if (userInfoCache.get('userInfoCache') == null) {
return;
}
var res = await UserHttp.historyStatus();

View File

@ -7,7 +7,6 @@ import 'package:pilipala/models/search/hot.dart';
import 'package:pilipala/models/user/info.dart';
class GStrorage {
static late final Box user;
static late final Box recVideo;
static late final Box userInfo;
static late final Box hotKeyword;
@ -21,13 +20,6 @@ class GStrorage {
final path = dir.path;
await Hive.initFlutter('$path/hive');
regAdapter();
// 用户信息
user = await Hive.openBox(
'user',
compactionStrategy: (entries, deletedEntries) {
return deletedEntries > 10;
},
);
// 首页推荐视频
recVideo = await Hive.openBox(
'recVideo',
@ -36,7 +28,12 @@ class GStrorage {
},
);
// 登录用户信息
userInfo = await Hive.openBox('userInfo');
userInfo = await Hive.openBox(
'userInfo',
compactionStrategy: (entries, deletedEntries) {
return deletedEntries > 2;
},
);
// 本地缓存
localCache = await Hive.openBox('localCache');
// 设置
@ -75,8 +72,8 @@ class GStrorage {
}
static Future<void> close() async {
user.compact();
user.close();
// user.compact();
// user.close();
recVideo.compact();
recVideo.close();
userInfo.compact();
@ -94,19 +91,6 @@ class GStrorage {
}
}
// 约定 key
class UserBoxKey {
static const String userName = 'userName';
// 头像
static const String userFace = 'userFace';
// mid
static const String userMid = 'userMid';
// 登录状态
static const String userLogin = 'userLogin';
// 凭证
static const String accessKey = 'accessKey';
}
class SettingBoxKey {
static const String themeMode = 'themeMode';
static const String feedBackEnable = 'feedBackEnable';
@ -130,6 +114,12 @@ class SettingBoxKey {
class LocalCacheKey {
// 历史记录暂停状态 默认false 记录
static const String historyPause = 'historyPause';
// access_key
static const String accessKey = 'accessKey';
//
static const String wbiKeys = 'wbiKeys';
static const String timeStamp = 'timeStamp';
}
class VideoBoxKey {

View File

@ -109,8 +109,10 @@ class WbiSign {
// 获取最新的 img_key 和 sub_key 可以从缓存中获取
static Future<Map<String, dynamic>> getWbiKeys() async {
DateTime nowDate = DateTime.now();
if (localCache.get('wbiKeys') != null &&
DateTime.fromMillisecondsSinceEpoch(localCache.get('timeStamp')).day ==
if (localCache.get(LocalCacheKey.wbiKeys) != null &&
DateTime.fromMillisecondsSinceEpoch(
localCache.get(LocalCacheKey.timeStamp))
.day ==
nowDate.day) {
Map cacheWbiKeys = localCache.get('wbiKeys');
return Map<String, dynamic>.from(cacheWbiKeys);
@ -129,8 +131,8 @@ class WbiSign {
.substring(subUrl.lastIndexOf('/') + 1, subUrl.length)
.split('.')[0]
};
localCache.put('wbiKeys', wbiKeys);
localCache.put('timeStamp', nowDate.millisecondsSinceEpoch);
localCache.put(LocalCacheKey.wbiKeys, wbiKeys);
localCache.put(LocalCacheKey.timeStamp, nowDate.millisecondsSinceEpoch);
return wbiKeys;
}