forked from SPlayer-Dev/SPlayer
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathandroidCache.ts
More file actions
59 lines (52 loc) · 2 KB
/
Copy pathandroidCache.ts
File metadata and controls
59 lines (52 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { registerPlugin } from "@capacitor/core";
/** 缓存类型与 Java 端 CacheStorage.TYPE_* 保持一致 */
export type AndroidCacheType = "lyrics" | "covers" | "list-covers" | "list-data" | "exo";
export interface AndroidCacheReadResult {
hit: boolean;
/** base64 编码的二进制数据;hit=false 时不存在 */
data?: string;
size?: number;
}
export interface AndroidCacheWriteResult {
success: boolean;
message?: string;
}
export interface AndroidCacheListEntry {
key: string;
size: number;
/** 毫秒时间戳 */
mtime: number;
}
export interface AndroidCacheStats {
totalBytes: number;
/** 设备剩余可用字节(StatFs.getAvailableBytes());-1 表示读取失败 */
deviceFreeBytes: number;
/** 用户设定的原始上限(不含设备容量自适应) */
maxBytes: number;
/**
* 运行期有效上限:设备空间不足时会自动降到 `deviceFreeBytes * 0.6`,<br>
* 高于用户设定时仍以用户设定为准。enforceLimit 走的就是此值。
*/
effectiveMaxBytes: number;
/** 各类型分项占用 */
perType: Record<AndroidCacheType, number>;
}
export interface AndroidCachePlugin {
read(options: { type: AndroidCacheType; key: string }): Promise<AndroidCacheReadResult>;
/** data 必须是 base64 编码的字符串 */
write(options: {
type: AndroidCacheType;
key: string;
data: string;
}): Promise<AndroidCacheWriteResult>;
remove(options: { type: AndroidCacheType; key: string }): Promise<{ success: boolean }>;
list(options: { type: AndroidCacheType }): Promise<{ entries: AndroidCacheListEntry[] }>;
clear(options: { type: AndroidCacheType }): Promise<{ success: boolean }>;
clearAll(): Promise<{ success: boolean }>;
getStats(): Promise<AndroidCacheStats>;
setMaxBytes(options: {
maxBytes: number;
}): Promise<{ success: boolean; appliedMaxBytes: number }>;
enforceLimit(): Promise<{ success: boolean; totalBytes: number }>;
}
export const AndroidCache = registerPlugin<AndroidCachePlugin>("AndroidCache");