Use cache module
This commit is contained in:
parent
17128a889b
commit
334c9f852a
|
@ -8,7 +8,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Settings } from 'modules';
|
||||
import { Settings, Cache } from 'modules';
|
||||
import BuiltinModule from './BuiltinModule';
|
||||
import { WebpackModules, ReactComponents, MonkeyPatch, Patcher, DiscordApi, Security } from 'modules';
|
||||
import { VueInjector, Reflection } from 'ui';
|
||||
|
@ -20,7 +20,6 @@ import E2EEMessageButton from './E2EEMessageButton.vue';
|
|||
import aes256 from 'aes256';
|
||||
|
||||
let seed = Math.random().toString(36).replace(/[^a-z]+/g, '');
|
||||
const imageCache = [];
|
||||
|
||||
export default new class E2EE extends BuiltinModule {
|
||||
|
||||
|
@ -128,7 +127,7 @@ export default new class E2EE extends BuiltinModule {
|
|||
const haveKey = this.getKey(DiscordApi.currentChannel.id);
|
||||
if (!haveKey) return;
|
||||
|
||||
const cached = imageCache.find(item => item.src === src);
|
||||
const cached = Cache.find('e2ee:images', item => item.src === src);
|
||||
if (cached) {
|
||||
Logger.info('E2EE', 'Returning encrypted image from cache');
|
||||
try {
|
||||
|
@ -149,7 +148,7 @@ export default new class E2EE extends BuiltinModule {
|
|||
const sliced = arr.slice(aobindex);
|
||||
const image = new TextDecoder().decode(sliced);
|
||||
|
||||
imageCache.push({ src, image });
|
||||
Cache.push('e2ee:images', { src, image });
|
||||
|
||||
if (!component || !component.props) {
|
||||
Logger.warn('E2EE', 'Component seems to be gone');
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
import { DOM, BdUI, BdMenu, Modals, Reflection, Toasts } from 'ui';
|
||||
import BdCss from './styles/index.scss';
|
||||
import { Events, CssEditor, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, WebpackModules, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi, BdWebApi, Connectivity } from 'modules';
|
||||
import { Events, CssEditor, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, WebpackModules, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi, BdWebApi, Connectivity, Cache } from 'modules';
|
||||
import { ClientLogger as Logger, ClientIPC, Utils } from 'common';
|
||||
import { BuiltinManager, EmoteModule, ReactDevtoolsModule, VueDevtoolsModule, TrackingProtection } from 'builtin';
|
||||
import electron from 'electron';
|
||||
|
@ -37,6 +37,7 @@ class BetterDiscord {
|
|||
EmoteModule,
|
||||
BdWebApi,
|
||||
Connectivity,
|
||||
Cache,
|
||||
Logger, ClientIPC, Utils,
|
||||
|
||||
plugins: PluginManager.localContent,
|
||||
|
|
|
@ -8,17 +8,28 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
const CACHE = [];
|
||||
|
||||
export default class Cache {
|
||||
|
||||
static get cache() {
|
||||
return CACHE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get something from cache
|
||||
* @param {String} where Cache identifier
|
||||
* @param {any} data Data to push
|
||||
*/
|
||||
static push(where, data) {
|
||||
if (!this.cache[where]) this.cache[where] = [];
|
||||
this.cache[where].push(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find something in cache
|
||||
* @param {String} where Cache identifier
|
||||
* @param {Function} what Find callback
|
||||
*/
|
||||
static find(where, what) {
|
||||
if (!this.cache[where]) this.cache[where] = [];
|
||||
return this.cache[where].find(what);
|
||||
|
|
|
@ -25,3 +25,4 @@ export { default as DiscordApi, Modules as DiscordApiModules } from './discordap
|
|||
export { default as BdWebApi } from './bdwebapi';
|
||||
export { default as Connectivity } from './connectivity';
|
||||
export { default as Security } from './security';
|
||||
export { default as Cache } from './cache';
|
||||
|
|
Loading…
Reference in New Issue