diff options
Diffstat (limited to 'src/api/server/LocalApi.js')
-rw-r--r-- | src/api/server/LocalApi.js | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js index eba236f16..e95d750ac 100644 --- a/src/api/server/LocalApi.js +++ b/src/api/server/LocalApi.js | |||
@@ -1,4 +1,9 @@ | |||
1 | import SettingsModel from '../../models/Settings'; | 1 | import { remote } from 'electron'; |
2 | import du from 'du'; | ||
3 | |||
4 | import { getServicePartitionsDirectory } from '../../helpers/service-helpers.js'; | ||
5 | |||
6 | const { session } = remote; | ||
2 | 7 | ||
3 | export default class LocalApi { | 8 | export default class LocalApi { |
4 | // App | 9 | // App |
@@ -15,7 +20,7 @@ export default class LocalApi { | |||
15 | async getAppSettings() { | 20 | async getAppSettings() { |
16 | const settingsString = localStorage.getItem('app'); | 21 | const settingsString = localStorage.getItem('app'); |
17 | try { | 22 | try { |
18 | const settings = new SettingsModel(JSON.parse(settingsString) || {}); | 23 | const settings = JSON.parse(settingsString) || {}; |
19 | console.debug('LocalApi::getAppSettings resolves', settings); | 24 | console.debug('LocalApi::getAppSettings resolves', settings); |
20 | 25 | ||
21 | return settings; | 26 | return settings; |
@@ -32,4 +37,31 @@ export default class LocalApi { | |||
32 | localStorage.setItem('app', JSON.stringify(settings)); | 37 | localStorage.setItem('app', JSON.stringify(settings)); |
33 | } | 38 | } |
34 | } | 39 | } |
40 | |||
41 | // Services | ||
42 | async getAppCacheSize() { | ||
43 | const partitionsDir = getServicePartitionsDirectory(); | ||
44 | return new Promise((resolve, reject) => { | ||
45 | du(partitionsDir, (err, size) => { | ||
46 | if (err) reject(err); | ||
47 | |||
48 | console.debug('LocalApi::getAppCacheSize resolves', size); | ||
49 | resolve(size); | ||
50 | }); | ||
51 | }); | ||
52 | } | ||
53 | |||
54 | async clearCache(serviceId) { | ||
55 | const s = session.fromPartition(`persist:service-${serviceId}`); | ||
56 | |||
57 | console.debug('LocalApi::clearCache resolves', serviceId); | ||
58 | return new Promise(resolve => s.clearCache(resolve)); | ||
59 | } | ||
60 | |||
61 | async clearAppCache() { | ||
62 | const s = session.defaultSession; | ||
63 | |||
64 | console.debug('LocalApi::clearCache clearAppCache'); | ||
65 | return new Promise(resolve => s.clearCache(resolve)); | ||
66 | } | ||
35 | } | 67 | } |