Feat: Vite + React (#991)

* remove test_web

* integrate reactjs-vite

* update lint-staged

* simple cors proxy server which handles cookies and redirections

* overrider global fetch with proxy call

* simple examples for set cookies and fetch request

* app bar

* add redux

* loadPlugins.
error: cant load urlencode module

* add ts-node for transforming

* plugin search & select

* plugin slice

* accordion components

* path item & popular novel

* optional for filters

* search novel

* parse novel

* parseChapter

* update cookies

* default filters

* fix: import path

* bundler module resolution

* new json_plugins

* fix: generate multisrc (missing filters)

* fix: host scripts

* fix: plugin code path

* remove typechecking action
This commit is contained in:
nyagami
2024-06-16 18:13:41 +07:00
committed by GitHub
parent a4cb781f32
commit d36e8ec85f
333 changed files with 5857 additions and 28579 deletions
+108
View File
@@ -0,0 +1,108 @@
import fs from 'fs';
import path from 'path';
class Storage {
private db: Record<string, { created: Date; value: any; expires?: number }>;
/**
* Initializes a new instance of the Storage class.
*/
constructor() {
this.db = {};
}
/**
* Sets a key-value pair in storage.
*
* @param {string} key - The key to set.
* @param {any} value - The value to set.
* @param {Date | number} [expires] - Optional expiry date or time in milliseconds.
*/
set(key: string, value: any, expires?: Date | number): void {
this.db[key] = {
created: new Date(),
value,
expires: expires instanceof Date ? expires.getTime() : expires,
};
}
/**
* Retrieves the value for a given key from storage.
*
* @param {string} key - The key to retrieve the value for.
* @param {boolean} [raw] - Optional flag to return the raw stored item.
* @returns {any} The stored value or undefined if key is not found.
*/
get(key: string, raw?: boolean): any {
const item = this.db[key];
if (item?.expires && Date.now() > item.expires) {
this.delete(key);
return undefined;
}
return raw ? item : item?.value;
}
/**
* Retrieves all keys set by the `set` method.
*
* @returns {string[]} An array of keys.
*/
getAllKeys(): string[] {
return Object.keys(this.db);
}
/**
* Deletes a key from the storage.
*
* @param pluginID - The ID of the plugin.
* @param key - The key to delete.
*/
delete(key: string): void {
delete this.db[key];
}
/**
* Clears all stored items from storage.
*/
clearAll(pluginID: string): void {
this.db = {};
}
}
// Export a singleton instance of the Storage class
export const storage = new Storage();
/*
These parameters cannot be implemented in `test-web`.
They are generated in the browser when js-scripts are executed
Read more
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
*/
/**
* Represents the structure of a storage object with string keys and values.
*/
interface StorageObject {
[key: string]: any;
}
/**
* Represents a simplified version of the browser's localStorage.
*/
class LocalStorage {
private db: StorageObject;
constructor() {
this.db = {};
}
get(): StorageObject | undefined {
return this.db;
}
}
// Export singleton instances of LocalStorage and sessionStorage
export const localStorage = new LocalStorage();
export const sessionStorage = new LocalStorage();