-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathcache.web.js
More file actions
83 lines (69 loc) · 2.21 KB
/
Copy pathcache.web.js
File metadata and controls
83 lines (69 loc) · 2.21 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { urlStream } from '~/utils/url'
export const getCache = async (cacheName, key) => {
const caches = await window.caches.open(cacheName)
if (!caches) return null
return await caches.match(key)
}
export const clearCache = async () => {
const keys = [
'api',
'coverArt',
'images',
'lyrics',
'apiLongResponse',
]
keys.forEach(async (key) => {
await window.caches.delete(key)
})
}
export const clearSongCache = async () => {
await window.caches.delete('song')
}
export const getStatCache = async () => {
const caches = await window.caches.keys()
const stats = []
for (const name of caches) {
const cache = await window.caches.open(name)
const keys = await cache.keys()
stats.push({ name, count: keys.length })
}
return stats.sort((a, b) => a.name.localeCompare(b.name))
}
export const getJsonCache = async (cacheName, url) => {
const cache = await getCache(cacheName, url)
if (!cache) return null
const json = await cache.json()
if (!json) return null
return json['subsonic-response']
}
export const setJsonCache = async (_cacheName, _key, _json) => {
// Service worker already do this
}
export const isSongCached = async (config, songId, streamFormat, maxBitrate) => {
return getCache('song', urlStream(config, songId, streamFormat, maxBitrate))
}
export const getSongCachedInfo = async (config, songId, streamFormat, maxBitrate) => {
const cache = await getCache('song', urlStream(config, songId, streamFormat, maxBitrate))
if (!cache) return null
return [
{ title: 'Is cached', value: 'Yes' },
{ title: 'Size', value: `${(cache.headers.get('content-length') / (1024 * 1024)).toFixed(2)} MB` },
]
}
export const deleteSongCache = async (config, songId, streamFormat, maxBitrate) => {
const url = urlStream(config, songId, streamFormat, maxBitrate)
await window.caches.open('song')
.then(cache => cache.delete(url))
}
export const getListCacheSong = async () => {
return []
}
export const getPathSong = (_songId, _streamFormat) => {
return null
}
export const getSongsCacheSize = async (_songIds, _streamFormat) => {
return 0
}
export const initCacheSong = async () => {
if (global) global.listCacheSong = []
}