Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added database for plugins #822

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added icons/coverNotAvailable.webp
Binary file not shown.
Binary file added icons/multisrc/hotnovelpub/eznovels/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/multisrc/hotnovelpub/hotnovelpub/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/multisrc/hotnovelpub/icons/eznovels.png
Binary file not shown.
Binary file removed icons/multisrc/hotnovelpub/icons/hotnovelpub.png
Binary file not shown.
Binary file removed icons/multisrc/hotnovelpub/icons/lanovels.png
Binary file not shown.
Binary file removed icons/multisrc/hotnovelpub/icons/lightnoveldaily.png
Binary file not shown.
Binary file removed icons/multisrc/hotnovelpub/icons/thnovels.png
Binary file not shown.
Binary file added icons/multisrc/hotnovelpub/lanovels/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/multisrc/hotnovelpub/thnovels/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/multisrc/ifreedom/bookhamster/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/multisrc/ifreedom/icons/bookhamster.png
Binary file not shown.
Binary file removed icons/multisrc/ifreedom/icons/ifreedom.png
Binary file not shown.
Binary file added icons/multisrc/ifreedom/ifreedom/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/multisrc/lightnovelwp/allnovelread.png
Binary file not shown.
Binary file added icons/multisrc/lightnovelwp/allnovelread/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/multisrc/lightnovelwp/bacalightnovel.png
Binary file not shown.
Binary file added icons/multisrc/lightnovelwp/bacalightnovel/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/multisrc/lightnovelwp/centralnovel.png
Binary file not shown.
Binary file added icons/multisrc/lightnovelwp/centralnovel/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/multisrc/lightnovelwp/daotranslate.png
Binary file not shown.
Binary file added icons/multisrc/lightnovelwp/daotranslate/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/multisrc/lightnovelwp/genesistls.png
Binary file not shown.
Binary file added icons/multisrc/lightnovelwp/genesistls/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/multisrc/lightnovelwp/knoxt.png
Binary file not shown.
Binary file added icons/multisrc/lightnovelwp/knoxt/icon.png
Binary file removed icons/multisrc/lightnovelwp/kolnovel.png
Diff not rendered.
Binary file added icons/multisrc/lightnovelwp/kolnovel/icon.png
Binary file removed icons/multisrc/lightnovelwp/lightnovelbrasil.png
Diff not rendered.
Binary file removed icons/multisrc/lightnovelwp/lightnovelfr.png
Diff not rendered.
Binary file added icons/multisrc/lightnovelwp/lightnovelfr/icon.png
Binary file removed icons/multisrc/lightnovelwp/noblemtl.png
Diff not rendered.
Binary file added icons/multisrc/lightnovelwp/noblemtl/icon.png
Binary file removed icons/multisrc/lightnovelwp/novelsknight.png
Diff not rendered.
Binary file added icons/multisrc/lightnovelwp/novelsknight/icon.png
Binary file removed icons/multisrc/lightnovelwp/novelsparadise.png
Diff not rendered.
Binary file removed icons/multisrc/lightnovelwp/noveltr.png
Diff not rendered.
Binary file added icons/multisrc/lightnovelwp/noveltr/icon.png
Binary file removed icons/multisrc/lightnovelwp/pandamtl.png
Diff not rendered.
Binary file added icons/multisrc/lightnovelwp/pandamtl/icon.png
Binary file removed icons/multisrc/lightnovelwp/systemtranslation.png
Diff not rendered.
Binary file removed icons/multisrc/lightnovelwp/universalnovel.png
Diff not rendered.
Binary file removed icons/multisrc/lightnovelwp/whitemoonlightnovels.png
Diff not rendered.
Binary file removed icons/multisrc/madara/1stkissnovel.png
Diff not rendered.
Binary file added icons/multisrc/madara/1stkissnovel/icon.png
Binary file removed icons/multisrc/madara/armtl.png
Diff not rendered.
Binary file removed icons/multisrc/madara/arnovel.png
Diff not rendered.
Binary file added icons/multisrc/madara/arnovel/icon.png
Binary file removed icons/multisrc/madara/asuralightnovel.png
Diff not rendered.
Binary file added icons/multisrc/madara/asuralightnovel/icon.png
Binary file removed icons/multisrc/madara/boxnovel.png
Diff not rendered.
Binary file added icons/multisrc/madara/boxnovel/icon.png
Binary file removed icons/multisrc/madara/clicknovel.png
Diff not rendered.
Binary file removed icons/multisrc/madara/cratenovel.png
Diff not rendered.
Binary file removed icons/multisrc/madara/e-novel.png
Diff not rendered.
Binary file added icons/multisrc/madara/e-novel/icon.png
Binary file removed icons/multisrc/madara/fanstranslations.png
Diff not rendered.
Binary file added icons/multisrc/madara/fanstranslations/icon.png
Binary file removed icons/multisrc/madara/foxaholic.png
Diff not rendered.
Binary file added icons/multisrc/madara/foxaholic/icon.png
Binary file removed icons/multisrc/madara/hizomanga.png
Diff not rendered.
Binary file added icons/multisrc/madara/hizomanga/icon.png
Binary file removed icons/multisrc/madara/kiniga.png
Diff not rendered.
Binary file added icons/multisrc/madara/kiniga/icon.png
Binary file removed icons/multisrc/madara/latestnovel.png
Diff not rendered.
Binary file removed icons/multisrc/madara/lnheaven.png
Diff not rendered.
Binary file added icons/multisrc/madara/lnheaven/icon.png
Binary file removed icons/multisrc/madara/meionovel.png
Diff not rendered.
Binary file added icons/multisrc/madara/meionovel/icon.png
Binary file removed icons/multisrc/madara/morenovel.png
Diff not rendered.
Binary file added icons/multisrc/madara/morenovel/icon.png
Binary file removed icons/multisrc/madara/mostnovel.png
Diff not rendered.
Binary file added icons/multisrc/madara/mostnovel/icon.png
Binary file removed icons/multisrc/madara/mtlnovel.club.png
Diff not rendered.
Binary file added icons/multisrc/madara/mtlnovel.club/icon.png
Binary file removed icons/multisrc/madara/mysticalmerries.png
Diff not rendered.
Binary file added icons/multisrc/madara/mysticalmerries/icon.png
Binary file removed icons/multisrc/madara/neosekaitls.png
Diff not rendered.
Binary file added icons/multisrc/madara/neosekaitls/icon.png
Binary file removed icons/multisrc/madara/nitromanga.png
Diff not rendered.
Binary file added icons/multisrc/madara/nitromanga/icon.png
Binary file removed icons/multisrc/madara/nocturnetls.png
Diff not rendered.
Binary file added icons/multisrc/madara/nocturnetls/icon.png
Binary file removed icons/multisrc/madara/noobchantranslation.png
Diff not rendered.
Binary file removed icons/multisrc/madara/novel-lucky.png
Diff not rendered.
Binary file added icons/multisrc/madara/novel-lucky/icon.png
Binary file removed icons/multisrc/madara/novel4up.png
Diff not rendered.
Binary file added icons/multisrc/madara/novel4up/icon.png
Binary file removed icons/multisrc/madara/novelmultiverse.png
Diff not rendered.
Binary file added icons/multisrc/madara/novelmultiverse/icon.png
Binary file removed icons/multisrc/madara/novelr18.png
Diff not rendered.
Binary file added icons/multisrc/madara/novelr18/icon.png
Binary file removed icons/multisrc/madara/novelstic.png
Diff not rendered.
Binary file added icons/multisrc/madara/novelstic/icon.png
Binary file removed icons/multisrc/madara/noveltl.png
Diff not rendered.
Binary file added icons/multisrc/madara/noveltl/icon.png
Binary file removed icons/multisrc/madara/onlymtl.png
Diff not rendered.
Binary file added icons/multisrc/madara/onlymtl/icon.png
Binary file removed icons/multisrc/madara/panchotranslations.png
Diff not rendered.
Binary file added icons/multisrc/madara/panchotranslations/icon.png
Binary file removed icons/multisrc/madara/readwebnovels.png
Diff not rendered.
Binary file added icons/multisrc/madara/readwebnovels/icon.png
Binary file removed icons/multisrc/madara/riwyat.png
Diff not rendered.
Binary file added icons/multisrc/madara/riwyat/icon.png
Binary file removed icons/multisrc/madara/salmonlatte.png
Diff not rendered.
Binary file added icons/multisrc/madara/salmonlatte/icon.png
Binary file removed icons/multisrc/madara/sleepttls.png
Diff not rendered.
Binary file added icons/multisrc/madara/sleepttls/icon.png
Binary file removed icons/multisrc/madara/sonicmtl.png
Diff not rendered.
Binary file added icons/multisrc/madara/sonicmtl/icon.png
Binary file removed icons/multisrc/madara/sugarbabies.png
Diff not rendered.
Binary file removed icons/multisrc/madara/sweetescapetl.png
Diff not rendered.
Binary file added icons/multisrc/madara/sweetescapetl/icon.png
Binary file removed icons/multisrc/madara/teamxnovel.png
Diff not rendered.
Binary file removed icons/multisrc/madara/wbnovel.png
Diff not rendered.
Binary file added icons/multisrc/madara/wbnovel/icon.png
Binary file removed icons/multisrc/madara/webnoveloku.png
Diff not rendered.
Binary file added icons/multisrc/madara/webnoveloku/icon.png
Binary file removed icons/multisrc/madara/webnovelover.png
Diff not rendered.
Binary file added icons/multisrc/madara/webnovelover/icon.png
Binary file removed icons/multisrc/madara/wuxiaworld.site.png
Diff not rendered.
Binary file added icons/multisrc/madara/wuxiaworld.site/icon.png
Binary file removed icons/multisrc/madara/zetrotl.png
Diff not rendered.
Binary file added icons/multisrc/madara/zetrotl/icon.png
Binary file removed icons/multisrc/madara/zinnovel.png
Diff not rendered.
Binary file added icons/multisrc/madara/zinnovel/icon.png
Binary file modified icons/multisrc/readnovelfull/readnovelfull.png
Binary file added icons/multisrc/readwn/fannovel/icon.png
Binary file removed icons/multisrc/readwn/icons/fannovel.png
Diff not rendered.
Binary file removed icons/multisrc/readwn/icons/ltnovel.png
Diff not rendered.
Binary file removed icons/multisrc/readwn/icons/wuxiacity.png
Diff not rendered.
Binary file removed icons/multisrc/readwn/icons/wuxiamtl.png
Diff not rendered.
Binary file removed icons/multisrc/readwn/icons/wuxiap.png
Diff not rendered.
Binary file added icons/multisrc/readwn/ltnovel/icon.png
Binary file added icons/multisrc/readwn/wuxiacity/icon.png
Binary file added icons/multisrc/readwn/wuxiamtl/icon.png
Binary file added icons/multisrc/readwn/wuxiap/icon.png
Binary file added icons/multisrc/rulate/erolate/icon.png
Binary file removed icons/multisrc/rulate/icons/erolate.png
Diff not rendered.
Binary file removed icons/multisrc/rulate/icons/rulate.png
Diff not rendered.
Binary file added icons/multisrc/rulate/rulate/icon.png
Binary file removed icons/multisrc/wpmangastream/icons/kol-novel.png
Diff not rendered.
Diff not rendered.
Binary file removed icons/multisrc/wpmangastream/icons/lightnovelfr.png
Diff not rendered.
Binary file removed icons/multisrc/wpmangastream/icons/lshnovel.png
Diff not rendered.
Binary file modified icons/src/cn/69shu/icon.png
Binary file modified icons/src/cn/69xinshu/icon.png
Binary file modified icons/src/cn/linovelib/icon.png
Binary file removed icons/src/coverNotAvailable.jpg
Diff not rendered.
Binary file modified icons/src/en/allnovelfull/icon.png
Binary file removed icons/src/en/comrademao/icon.png
Diff not rendered.
Binary file modified icons/src/en/divinedaolibrary/icon.png
Binary file added icons/src/en/earlynovel/icon.png
Binary file modified icons/src/en/faqwikius/icon.png
Binary file removed icons/src/en/freenovelupdates/icon.png
Diff not rendered.
Binary file modified icons/src/en/freewebnovel/icon.png
Binary file modified icons/src/en/lightnovelpub/icon.png
Binary file modified icons/src/en/lightnovelworld/icon.png
Binary file modified icons/src/en/lnmtl/icon.png
Binary file modified icons/src/en/mtlnovel/icon.png
Binary file modified icons/src/en/mtlreader/icon.png
Binary file modified icons/src/en/novelbin/icon.png
Binary file modified icons/src/en/novelbuddy/icon.png
Binary file removed icons/src/en/novelforest/icon.png
Diff not rendered.
Binary file modified icons/src/en/novelfull/icon.png
Binary file modified icons/src/en/novelupdates/icon.png
Binary file modified icons/src/en/pawread/icon.png
Binary file modified icons/src/en/ranobes/icon.png
Binary file modified icons/src/en/readlitenovel/icon.png
Binary file modified icons/src/en/royalroad/icon.png
Binary file modified icons/src/en/scribblehub/icon.png
Binary file modified icons/src/en/storyseedling/icon.png
Binary file removed icons/src/en/wordpress/icon.png
Diff not rendered.
Binary file modified icons/src/en/wtrlab/icon.png
Binary file modified icons/src/en/wuxiaworld/icon.png
Binary file removed icons/src/es/hasutl/icon.png
Diff not rendered.
Binary file removed icons/src/es/novelasligera/icon.png
Diff not rendered.
Binary file removed icons/src/es/skynovels/icon.png
Diff not rendered.
Binary file modified icons/src/es/tunovelaligera/icon.png
Binary file removed icons/src/es/yuukitls/icon.png
Diff not rendered.
Binary file modified icons/src/fr/chireads/icon.png
Binary file modified icons/src/fr/noveldeglace/icon.png
Binary file modified icons/src/id/indowebnovel/icon.png
Binary file modified icons/src/id/novelringan/icon.png
Binary file modified icons/src/id/sakuranovel/icon.png
Binary file modified icons/src/jp/syosetu/icon.png
Binary file removed icons/src/jp/syosetu/not_found.png
Diff not rendered.
Binary file removed icons/src/kr/agitoon/agit.png
Diff not rendered.
Binary file added icons/src/kr/agitoon/icon.png
Binary file modified icons/src/ru/authortoday/icon.png
Binary file modified icons/src/ru/bookriver/icon.png
Binary file modified icons/src/ru/ficbook/icon.png
Binary file modified icons/src/ru/freedlit/icon.png
Binary file modified icons/src/ru/jaomix/icon.png
Binary file modified icons/src/ru/neobook/icon.png
Binary file modified icons/src/ru/novelovh/icon.png
Binary file modified icons/src/ru/noveltl/icon.png
Binary file modified icons/src/ru/ranobehub/icon.png
Binary file modified icons/src/ru/ranobelib/icon.png
Binary file modified icons/src/ru/ranoberf/icon.png
Binary file modified icons/src/ru/zelluloza/icon.png
Binary file removed icons/src/tr/epiknovel/icon.png
Diff not rendered.
Binary file modified icons/src/uk/smakolykytl/icon.png
Binary file modified icons/src/vi/hakolightnovel/icon.png
Binary file modified icons/src/vi/lightnovelvn/icon.png
Binary file modified icons/src/vi/nettruyen/icon.png
Binary file modified icons/src/vi/truyenchu/icon.png
Binary file modified icons/src/vi/truyenconect/icon.png
Binary file modified icons/src/vi/truyenfull/icon.png
2 changes: 1 addition & 1 deletion libs/defaultCover.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const defaultCover =
'https://github.com/LNReader/lnreader-plugins/blob/main/icons/src/coverNotAvailable.jpg?raw=true';
'https://github.com/LNReader/lnreader-plugins/blob/master/icons/coverNotAvailable.webp?raw=true';
134 changes: 134 additions & 0 deletions libs/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import fs from 'fs';
import path from 'path';

/**
* Represents a storage system with methods for setting, getting, and deleting key-value pairs.
*/
class Storage {
private db: Record<
string,
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 the storage.
*
* @param pluginID - The ID of the plugin.
* @param key - The key to set.
* @param value - The value to set.
* @param expires - Optional. The expiration date for the key-value pair.
*/
set(
pluginID: string,
key: string,
value: any,
expires?: Date | number,
): void {
if (!this.db[pluginID]) this.db[pluginID] = {};
this.db[pluginID][key] = {
created: new Date(),
value,
expires: expires instanceof Date ? expires.getTime() : expires,
};
}

/**
* Gets the value associated with a key from the storage.
*
* @param pluginID - The ID of the plugin.
* @param key - The key to retrieve.
* @param raw - Optional. If true, returns the raw storage item object.
* @returns The value associated with the key or undefined if not found or expired.
*/
get(pluginID: string, key: string, raw?: boolean): any {
const item = this.db[pluginID]?.[key];
if (item?.expires && Date.now() > item.expires) {
this.delete(pluginID, key);
return undefined;
}
return raw ? item : item?.value;
}

/**
* Gets all keys associated with a plugin from the storage.
*
* @param pluginID - The ID of the plugin.
* @returns An array of keys associated with the plugin.
*/
getAllKeys(pluginID: string): string[] {
return Object.keys(this.db[pluginID] || {});
}

/**
* Deletes a key from the storage.
*
* @param pluginID - The ID of the plugin.
* @param key - The key to delete.
*/
delete(pluginID: string, key: string): void {
delete this.db[pluginID]?.[key];
}

/**
* Clears all keys associated with a plugin from the storage.
*
* @param pluginID - The ID of the plugin.
*/
clearAll(pluginID: string): void {
delete this.db[pluginID];
}
}

// 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]: string | undefined;
}

/**
* Represents a simplified version of the browser's localStorage.
*/
class LocalStorage {
db: Record<string, StorageObject>;

/**
* Initializes a new instance of the LocalStorage class.
*/
constructor() {
this.db = {};
}

/**
* Gets the storage object associated with a plugin ID.
*
* @param pluginID - The ID of the plugin.
* @returns The storage object associated with the plugin ID.
*/
get(pluginID: string): StorageObject | undefined {
return this.db[pluginID] || {};
}
}

// Export singleton instances of LocalStorage and sessionStorage
export const localStorage = new LocalStorage();
export const sessionStorage = new LocalStorage();
Loading
Loading