Compare commits
4 Commits
1ebac7ee15
...
2cf475931c
| Author | SHA1 | Date | |
|---|---|---|---|
| 2cf475931c | |||
| 41dddef354 | |||
| d54b0bcdef | |||
| c7ed97a452 |
229
desktop/loading.html
Normal file
229
desktop/loading.html
Normal file
@@ -0,0 +1,229 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Waifuboard</title>
|
||||
<style>
|
||||
:root {
|
||||
--color-bg: #09090b;
|
||||
--color-primary: #8b5cf6;
|
||||
--color-text: #ffffff;
|
||||
--color-text-dim: #a1a1aa;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: linear-gradient(135deg, #18181b 0%, var(--color-bg) 100%);
|
||||
color: var(--color-text);
|
||||
font-family: 'Inter', system-ui, -apple-system, sans-serif;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 400px;
|
||||
height: 300px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border-radius: 16px;
|
||||
-webkit-app-region: drag;
|
||||
}
|
||||
|
||||
body::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 0 0 1px rgba(255,255,255,0.05),
|
||||
0 20px 40px rgba(0,0,0,0.6);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
img {
|
||||
-webkit-user-drag: none;
|
||||
user-drag: none;
|
||||
}
|
||||
|
||||
.bg-particle {
|
||||
position: absolute;
|
||||
background: var(--color-primary);
|
||||
border-radius: 50%;
|
||||
opacity: 0;
|
||||
animation: particleFloat 8s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.bg-particle:nth-child(1) {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
top: 20%;
|
||||
left: 10%;
|
||||
animation-delay: 0s;
|
||||
}
|
||||
|
||||
.bg-particle:nth-child(2) {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
top: 60%;
|
||||
left: 80%;
|
||||
animation-delay: 2s;
|
||||
}
|
||||
|
||||
.bg-particle:nth-child(3) {
|
||||
width: 3px;
|
||||
height: 3px;
|
||||
top: 40%;
|
||||
left: 20%;
|
||||
animation-delay: 4s;
|
||||
}
|
||||
|
||||
.bg-particle:nth-child(4) {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
top: 70%;
|
||||
left: 70%;
|
||||
animation-delay: 1s;
|
||||
}
|
||||
|
||||
.splash-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 28px;
|
||||
width: 100%;
|
||||
animation: fadeIn 0.5s ease-out;
|
||||
}
|
||||
|
||||
.brand-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.brand-container.horizontal {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 14px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.brand-icon {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
object-fit: contain;
|
||||
animation: iconPulse 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.brand-name {
|
||||
font-size: 25px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.02em;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
color: #ffffff;
|
||||
line-height: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.spinner-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border: 5px solid rgba(139, 92, 246, 0.2);
|
||||
border-top: 5px solid var(--color-primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
font-size: 12px;
|
||||
color: #a1a1aa;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.1em;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes iconPulse {
|
||||
0%, 100% {
|
||||
transform: scale(1);
|
||||
filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.4));
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.05);
|
||||
filter: drop-shadow(0 0 16px rgba(139, 92, 246, 0.6));
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes particleFloat {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(0) scale(0);
|
||||
}
|
||||
25% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.6;
|
||||
transform: translateY(-100px) scale(1);
|
||||
}
|
||||
75% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
100% {
|
||||
opacity: 0;
|
||||
transform: translateY(-200px) scale(0);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="bg-particle"></div>
|
||||
<div class="bg-particle"></div>
|
||||
<div class="bg-particle"></div>
|
||||
<div class="bg-particle"></div>
|
||||
|
||||
<div class="splash-container">
|
||||
<div class="brand-container horizontal">
|
||||
<img src="public/assets/waifuboards.ico" alt="Waifuboard Logo" class="brand-icon">
|
||||
<h1 class="brand-name">Waifuboard</h1>
|
||||
</div>
|
||||
|
||||
<div class="spinner-wrapper">
|
||||
<div class="spinner"></div>
|
||||
<span class="loading-text">Loading</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,6 +3,9 @@ const { fork } = require('child_process');
|
||||
const path = require('path');
|
||||
const log = require('electron-log');
|
||||
|
||||
const sessionId = new Date().toISOString().replace(/[:.]/g, '-');
|
||||
log.transports.file.resolvePath = () => path.join(app.getPath('userData'), 'logs', `${sessionId}.log`);
|
||||
|
||||
log.transports.file.level = 'info';
|
||||
log.format = '[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}] {text}';
|
||||
|
||||
@@ -61,6 +64,23 @@ function startBackend() {
|
||||
});
|
||||
}
|
||||
|
||||
let splash;
|
||||
|
||||
function createSplash() {
|
||||
splash = new BrowserWindow({
|
||||
width: 400,
|
||||
height: 300,
|
||||
frame: false,
|
||||
transparent: false,
|
||||
alwaysOnTop: true,
|
||||
resizable: false,
|
||||
hasShadow: false,
|
||||
backgroundColor: '#00000000'
|
||||
});
|
||||
|
||||
splash.loadFile('loading.html');
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
win = new BrowserWindow({
|
||||
width: 1200,
|
||||
@@ -75,6 +95,7 @@ function createWindow() {
|
||||
});
|
||||
|
||||
win.setMenu(null);
|
||||
win.maximize();
|
||||
|
||||
win.loadURL('http://localhost:54322');
|
||||
|
||||
@@ -98,15 +119,17 @@ process.on('uncaughtException', (err) => {
|
||||
});
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
log.info('--- Application Started ---');
|
||||
console.log("Logs location:", log.transports.file.getFile().path);
|
||||
startBackend();
|
||||
await waitForServer(54322);
|
||||
createWindow();
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||
});
|
||||
createSplash();
|
||||
try {
|
||||
await waitForServer(54322);
|
||||
createWindow();
|
||||
splash.close();
|
||||
} catch (e) {
|
||||
splash.close();
|
||||
log.error(e);
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
|
||||
144
desktop/package-lock.json
generated
144
desktop/package-lock.json
generated
@@ -10,7 +10,7 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@fastify/static": "^8.3.0",
|
||||
"@ryuziii/discord-rpc": "^1.0.1-rc.1",
|
||||
"@xhayper/discord-rpc": "^1.3.0",
|
||||
"bcryptjs": "^3.0.3",
|
||||
"bindings": "^1.5.0",
|
||||
"cheerio": "^1.1.2",
|
||||
@@ -98,6 +98,65 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@discordjs/collection": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-2.1.1.tgz",
|
||||
"integrity": "sha512-LiSusze9Tc7qF03sLCujF5iZp7K+vRNEDBZ86FT9aQAv3vxMLihUvKvpsCWiQ2DJq1tVckopKm1rxomgNUc9hg==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/discordjs/discord.js?sponsor"
|
||||
}
|
||||
},
|
||||
"node_modules/@discordjs/rest": {
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-2.6.0.tgz",
|
||||
"integrity": "sha512-RDYrhmpB7mTvmCKcpj+pc5k7POKszS4E2O9TYc+U+Y4iaCP+r910QdO43qmpOja8LRr1RJ0b3U+CqVsnPqzf4w==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@discordjs/collection": "^2.1.1",
|
||||
"@discordjs/util": "^1.1.1",
|
||||
"@sapphire/async-queue": "^1.5.3",
|
||||
"@sapphire/snowflake": "^3.5.3",
|
||||
"@vladfrangu/async_event_emitter": "^2.4.6",
|
||||
"discord-api-types": "^0.38.16",
|
||||
"magic-bytes.js": "^1.10.0",
|
||||
"tslib": "^2.6.3",
|
||||
"undici": "6.21.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/discordjs/discord.js?sponsor"
|
||||
}
|
||||
},
|
||||
"node_modules/@discordjs/rest/node_modules/undici": {
|
||||
"version": "6.21.3",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.21.3.tgz",
|
||||
"integrity": "sha512-gBLkYIlEnSp8pFbT64yFgGE6UIB9tAkhukC23PmMDCe5Nd+cRqKxSjw5y54MK2AZMgZfJWMaNE4nYUHgi1XEOw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18.17"
|
||||
}
|
||||
},
|
||||
"node_modules/@discordjs/util": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/util/-/util-1.2.0.tgz",
|
||||
"integrity": "sha512-3LKP7F2+atl9vJFhaBjn4nOaSWahZ/yWjOvA4e5pnXkt2qyXRCHLxoBQy81GFtLGCq7K9lPm9R517M1U+/90Qg==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"discord-api-types": "^0.38.33"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/discordjs/discord.js?sponsor"
|
||||
}
|
||||
},
|
||||
"node_modules/@electron/asar": {
|
||||
"version": "3.2.18",
|
||||
"resolved": "https://registry.npmjs.org/@electron/asar/-/asar-3.2.18.tgz",
|
||||
@@ -1364,14 +1423,24 @@
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/@ryuziii/discord-rpc": {
|
||||
"version": "1.0.1-rc.1",
|
||||
"resolved": "https://registry.npmjs.org/@ryuziii/discord-rpc/-/discord-rpc-1.0.1-rc.1.tgz",
|
||||
"integrity": "sha512-q9YgU8Rj9To1LWzo4u8cXOHUorEkB5KZ5cdW80KoYtAUx+nQy7wYCEFiNh8kcmqFqQ8m3Fsx1IXx3UpVymkaSw==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@types/ws": "^8.18.1",
|
||||
"ws": "^8.18.3"
|
||||
"node_modules/@sapphire/async-queue": {
|
||||
"version": "1.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.5.tgz",
|
||||
"integrity": "sha512-cvGzxbba6sav2zZkH8GPf2oGk9yYoD5qrNWdu9fRehifgnFZJMV+nuy2nON2roRO4yQQ+v7MK/Pktl/HgfsUXg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=v14.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@sapphire/snowflake": {
|
||||
"version": "3.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.5.5.tgz",
|
||||
"integrity": "sha512-xzvBr1Q1c4lCe7i6sRnrofxeO1QTP/LKQ6A6qy0iB4x5yfiSfARMEQEghojzTNALDTcv8En04qYNIco9/K9eZQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=v14.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@sindresorhus/is": {
|
||||
@@ -1520,6 +1589,7 @@
|
||||
"version": "24.10.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz",
|
||||
"integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~7.16.0"
|
||||
@@ -1555,15 +1625,6 @@
|
||||
"license": "MIT",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/@types/ws": {
|
||||
"version": "8.18.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
|
||||
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/yauzl": {
|
||||
"version": "2.10.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz",
|
||||
@@ -1575,6 +1636,31 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@vladfrangu/async_event_emitter": {
|
||||
"version": "2.4.7",
|
||||
"resolved": "https://registry.npmjs.org/@vladfrangu/async_event_emitter/-/async_event_emitter-2.4.7.tgz",
|
||||
"integrity": "sha512-Xfe6rpCTxSxfbswi/W/Pz7zp1WWSNn4A0eW4mLkQUewCrXXtMj31lCg+iQyTkh/CkusZSq9eDflu7tjEDXUY6g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=v14.0.0",
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@xhayper/discord-rpc": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@xhayper/discord-rpc/-/discord-rpc-1.3.0.tgz",
|
||||
"integrity": "sha512-0NmUTiODl7u3UEjmO6y0Syp3dmgVLAt2EHrH4QKTQcXRwtF8Wl7Eipdn/GSSZ8HkDwxQFvcDGJMxT9VWB0pH8g==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@discordjs/rest": "^2.5.1",
|
||||
"@vladfrangu/async_event_emitter": "^2.4.6",
|
||||
"discord-api-types": "^0.38.16",
|
||||
"ws": "^8.18.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.20.7"
|
||||
}
|
||||
},
|
||||
"node_modules/@xmldom/xmldom": {
|
||||
"version": "0.8.11",
|
||||
"resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.11.tgz",
|
||||
@@ -3051,6 +3137,15 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/discord-api-types": {
|
||||
"version": "0.38.37",
|
||||
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.38.37.tgz",
|
||||
"integrity": "sha512-Cv47jzY1jkGkh5sv0bfHYqGgKOWO1peOrGMkDFM4UmaGMOTgOW8QSexhvixa9sVOiz8MnVOBryWYyw/CEVhj7w==",
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"scripts/actions/documentation"
|
||||
]
|
||||
},
|
||||
"node_modules/dmg-builder": {
|
||||
"version": "26.0.12",
|
||||
"resolved": "https://registry.npmjs.org/dmg-builder/-/dmg-builder-26.0.12.tgz",
|
||||
@@ -4983,6 +5078,12 @@
|
||||
"node": "20 || >=22"
|
||||
}
|
||||
},
|
||||
"node_modules/magic-bytes.js": {
|
||||
"version": "1.12.1",
|
||||
"resolved": "https://registry.npmjs.org/magic-bytes.js/-/magic-bytes.js-1.12.1.tgz",
|
||||
"integrity": "sha512-ThQLOhN86ZkJ7qemtVRGYM+gRgR8GEXNli9H/PMvpnZsE44Xfh3wx9kGJaldg314v85m+bFW6WBMaVHJc/c3zA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/make-error": {
|
||||
"version": "1.3.6",
|
||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||
@@ -7444,6 +7545,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.8.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
||||
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
|
||||
"license": "0BSD"
|
||||
},
|
||||
"node_modules/tunnel-agent": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
|
||||
@@ -7497,6 +7604,7 @@
|
||||
"version": "7.16.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
||||
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/unique-filename": {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"type": "commonjs",
|
||||
"dependencies": {
|
||||
"@fastify/static": "^8.3.0",
|
||||
"@ryuziii/discord-rpc": "^1.0.1-rc.1",
|
||||
"@xhayper/discord-rpc": "^1.3.0",
|
||||
"bcryptjs": "^3.0.3",
|
||||
"bindings": "^1.5.0",
|
||||
"cheerio": "^1.1.2",
|
||||
|
||||
@@ -87,15 +87,16 @@ export async function getChapters(req: any, reply: FastifyReply) {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const source = req.query.source || 'anilist';
|
||||
const provider = req.query.provider;
|
||||
|
||||
const isExternal = source !== 'anilist';
|
||||
return await booksService.getChaptersForBook(id, isExternal);
|
||||
} catch {
|
||||
return await booksService.getChaptersForBook(id, isExternal, provider);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return { chapters: [] };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function getChapterContent(req: any, reply: FastifyReply) {
|
||||
try {
|
||||
const { bookId, chapter, provider } = req.params;
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
// @ts-ignore
|
||||
import { DiscordRPCClient } from "@ryuziii/discord-rpc";
|
||||
import { Client } from "@xhayper/discord-rpc";
|
||||
|
||||
let rpcClient: DiscordRPCClient | null = null;
|
||||
let rpcClient: Client | null = null;
|
||||
let reconnectTimer: NodeJS.Timeout | null = null;
|
||||
let connected: boolean = false;
|
||||
let connected = false;
|
||||
|
||||
type RPCMode = "watching" | "reading" | string;
|
||||
|
||||
interface RPCData {
|
||||
details?: string;
|
||||
state?: string;
|
||||
mode?: RPCMode;
|
||||
mode?: string;
|
||||
startTimestamp?: number;
|
||||
endTimestamp?: number;
|
||||
paused?: boolean;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
@@ -30,91 +32,68 @@ function attemptReconnect(clientId: string) {
|
||||
}
|
||||
|
||||
export function initRPC(clientId: string) {
|
||||
|
||||
if (rpcClient) {
|
||||
try { rpcClient.destroy(); } catch (e) {}
|
||||
try { rpcClient.destroy(); } catch {}
|
||||
rpcClient = null;
|
||||
}
|
||||
|
||||
if (reconnectTimer) {
|
||||
clearTimeout(reconnectTimer);
|
||||
reconnectTimer = null;
|
||||
}
|
||||
|
||||
console.log(`Discord RPC: Starting with id ...${clientId.slice(-4)}`);
|
||||
|
||||
try {
|
||||
|
||||
rpcClient = new DiscordRPCClient({
|
||||
clientId: clientId,
|
||||
transport: 'ipc'
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Discord RPC:', err);
|
||||
return;
|
||||
}
|
||||
rpcClient = new Client({ clientId });
|
||||
|
||||
rpcClient.on("ready", () => {
|
||||
connected = true;
|
||||
const user = rpcClient?.user ? rpcClient.user.username : 'User';
|
||||
console.log(`Discord RPC: Authenticated for: ${user}`);
|
||||
console.log("Discord RPC conectado");
|
||||
|
||||
setTimeout(() => {
|
||||
setActivity({ details: "Browsing", state: "In App", mode: "idle" });
|
||||
setActivity({ details: "Browsing", state: "In App" });
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
rpcClient.on('disconnected', () => {
|
||||
console.log('Discord RPC: Desconexión detectada.');
|
||||
rpcClient.on("disconnected", () => {
|
||||
connected = false;
|
||||
attemptReconnect(clientId);
|
||||
});
|
||||
|
||||
rpcClient.on('error', (err: { message: any; }) => {
|
||||
console.error('[Discord RPC] Error:', err.message);
|
||||
|
||||
if (connected) {
|
||||
attemptReconnect(clientId);
|
||||
}
|
||||
rpcClient.on("error", () => {
|
||||
if (connected) attemptReconnect(clientId);
|
||||
});
|
||||
|
||||
try {
|
||||
rpcClient.connect().catch((err: { message: any; }) => {
|
||||
console.error('Discord RPC: Error al conectar', err.message);
|
||||
|
||||
attemptReconnect(clientId);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Discord RPC: Error al iniciar la conexión', err);
|
||||
rpcClient.login().catch(() => {
|
||||
attemptReconnect(clientId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function setActivity(data: RPCData = {}) {
|
||||
if (!rpcClient || !connected) return;
|
||||
|
||||
let type;
|
||||
let state = data.state;
|
||||
let details = data.details;
|
||||
let type = 0;
|
||||
if (data.mode === "watching") type = 3;
|
||||
if (data.mode === "reading") type = 0;
|
||||
|
||||
if (data.mode === "watching") {
|
||||
type = 3
|
||||
} else if (data.mode === "reading") {
|
||||
type = 0
|
||||
const activity: any = {
|
||||
details: data.details,
|
||||
state: data.state,
|
||||
type,
|
||||
instance: false
|
||||
};
|
||||
|
||||
if (data.paused) {
|
||||
activity.largeImageText = "⏸ ";
|
||||
delete activity.startTimestamp;
|
||||
delete activity.endTimestamp;
|
||||
} else {
|
||||
type = 0
|
||||
activity.largeImageKey = "bigpicture";
|
||||
activity.largeImageText = data.version ?? "v2.0.0";
|
||||
|
||||
if (data.startTimestamp && data.endTimestamp) {
|
||||
activity.startTimestamp = data.startTimestamp;
|
||||
activity.endTimestamp = data.endTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
rpcClient.setActivity({
|
||||
details: details,
|
||||
state: state,
|
||||
type: type,
|
||||
startTimestamp: new Date(),
|
||||
largeImageKey: "bigpicture",
|
||||
largeImageText: "v2.0.0",
|
||||
instance: false
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Discord RPC: Failed to set activity", error);
|
||||
}
|
||||
rpcClient.user?.setActivity(activity);
|
||||
}
|
||||
@@ -11,16 +11,29 @@ export function init() {
|
||||
}
|
||||
|
||||
export async function setRPC(request: FastifyRequest, reply: FastifyReply) {
|
||||
const { details, state, mode } = request.body as {
|
||||
const {
|
||||
details,
|
||||
state,
|
||||
mode,
|
||||
startTimestamp,
|
||||
endTimestamp,
|
||||
paused
|
||||
} = request.body as {
|
||||
details?: string;
|
||||
state?: string;
|
||||
mode?: "watching" | "reading" | string;
|
||||
startTimestamp?: number;
|
||||
endTimestamp?: number;
|
||||
paused?: boolean;
|
||||
};
|
||||
|
||||
setActivity({
|
||||
details,
|
||||
state,
|
||||
mode
|
||||
mode,
|
||||
startTimestamp,
|
||||
endTimestamp,
|
||||
paused
|
||||
});
|
||||
|
||||
return reply.send({ ok: true });
|
||||
|
||||
@@ -168,20 +168,39 @@ export async function deleteUser(req: FastifyRequest, reply: FastifyReply) {
|
||||
const { id } = req.params as { id: string };
|
||||
const userId = parseInt(id, 10);
|
||||
|
||||
const body = (req.body ?? {}) as { password?: string };
|
||||
const password = body.password;
|
||||
|
||||
if (!userId || isNaN(userId)) {
|
||||
return reply.code(400).send({ error: "Invalid user id" });
|
||||
}
|
||||
|
||||
const result = await userService.deleteUser(userId);
|
||||
|
||||
if (result && result.changes > 0) {
|
||||
return { success: true, message: "User deleted successfully" };
|
||||
} else {
|
||||
const user = await userService.getUserById(userId);
|
||||
if (!user) {
|
||||
return reply.code(404).send({ error: "User not found" });
|
||||
}
|
||||
|
||||
if (user.has_password) {
|
||||
if (!password) {
|
||||
return reply.code(401).send({ error: "Password required" });
|
||||
}
|
||||
|
||||
const isValid = await userService.verifyPassword(userId, password);
|
||||
if (!isValid) {
|
||||
return reply.code(401).send({ error: "Incorrect password" });
|
||||
}
|
||||
}
|
||||
|
||||
const result = await userService.deleteUser(userId);
|
||||
|
||||
if (result.changes > 0) {
|
||||
return reply.send({ success: true });
|
||||
}
|
||||
|
||||
return reply.code(500).send({ error: "Failed to delete user" });
|
||||
|
||||
} catch (err) {
|
||||
console.error("Delete User Error:", (err as Error).message);
|
||||
console.error("Delete User Error:", err);
|
||||
return reply.code(500).send({ error: "Failed to delete user" });
|
||||
}
|
||||
}
|
||||
@@ -246,16 +265,17 @@ export async function changePassword(req: FastifyRequest, reply: FastifyReply) {
|
||||
return reply.code(404).send({ error: "User not found" });
|
||||
}
|
||||
|
||||
// Si el usuario tiene contraseña actual, debe proporcionar la contraseña actual
|
||||
if (user.has_password && currentPassword) {
|
||||
const isValid = await userService.verifyPassword(userId, currentPassword);
|
||||
if (user.has_password) {
|
||||
if (!currentPassword) {
|
||||
return reply.code(401).send({ error: "Current password required" });
|
||||
}
|
||||
|
||||
const isValid = await userService.verifyPassword(userId, currentPassword);
|
||||
if (!isValid) {
|
||||
return reply.code(401).send({ error: "Current password is incorrect" });
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar la contraseña (null para eliminarla, string para establecerla)
|
||||
await userService.updateUser(userId, { password: newPassword });
|
||||
|
||||
return reply.send({
|
||||
|
||||
@@ -7,6 +7,8 @@ let currentExtension = '';
|
||||
let plyrInstance;
|
||||
let hlsInstance;
|
||||
let totalEpisodes = 0;
|
||||
let animeTitle = "";
|
||||
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const firstKey = params.keys().next().value;
|
||||
@@ -40,11 +42,8 @@ async function loadMetadata() {
|
||||
let format = '';
|
||||
let seasonYear = '';
|
||||
let season = '';
|
||||
let episodesCount = 0;
|
||||
let characters = [];
|
||||
|
||||
if (isAnilistFormat) {
|
||||
|
||||
title = data.title.romaji || data.title.english || data.title.native || 'Anime Title';
|
||||
description = data.description || 'No description available.';
|
||||
coverImage = data.coverImage?.large || data.coverImage?.medium || '';
|
||||
@@ -64,18 +63,9 @@ async function loadMetadata() {
|
||||
|
||||
document.getElementById('anime-title-details').innerText = title;
|
||||
document.getElementById('anime-title-details2').innerText = title;
|
||||
animeTitle = title;
|
||||
document.title = `Watching ${title} - Ep ${currentEpisode}`;
|
||||
|
||||
fetch("/api/rpc", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({
|
||||
details: title,
|
||||
state: `Episode ${currentEpisode}`,
|
||||
mode: "watching"
|
||||
})
|
||||
});
|
||||
|
||||
const tempDiv = document.createElement('div');
|
||||
tempDiv.innerHTML = description;
|
||||
document.getElementById('detail-description').innerText = tempDiv.textContent || tempDiv.innerText || 'No description available.';
|
||||
@@ -350,21 +340,63 @@ function playVideo(url, subtitles = []) {
|
||||
settings: ['captions', 'quality', 'speed']
|
||||
});
|
||||
|
||||
let alreadyTriggered = false;
|
||||
let rpcActive = false;
|
||||
let lastSeek = 0;
|
||||
|
||||
video.addEventListener('timeupdate', () => {
|
||||
video.addEventListener("play", () => {
|
||||
if (!video.duration) return;
|
||||
|
||||
const percent = (video.currentTime / video.duration) * 100;
|
||||
const elapsed = Math.floor(video.currentTime);
|
||||
const start = Math.floor(Date.now() / 1000) - elapsed;
|
||||
const end = start + Math.floor(video.duration);
|
||||
|
||||
if (percent >= 80 && !alreadyTriggered) {
|
||||
alreadyTriggered = true;
|
||||
sendProgress();
|
||||
}
|
||||
sendRPC({
|
||||
startTimestamp: start,
|
||||
endTimestamp: end
|
||||
});
|
||||
|
||||
rpcActive = true;
|
||||
});
|
||||
|
||||
video.addEventListener("pause", () => {
|
||||
if (!rpcActive) return;
|
||||
|
||||
video.play().catch(() => console.log("Autoplay blocked"));
|
||||
sendRPC({
|
||||
paused: true
|
||||
});
|
||||
});
|
||||
|
||||
video.addEventListener("seeking", () => {
|
||||
lastSeek = video.currentTime;
|
||||
});
|
||||
|
||||
video.addEventListener("seeked", () => {
|
||||
if (video.paused || !rpcActive) return;
|
||||
|
||||
const elapsed = Math.floor(video.currentTime);
|
||||
const start = Math.floor(Date.now() / 1000) - elapsed;
|
||||
const end = start + Math.floor(video.duration);
|
||||
|
||||
sendRPC({
|
||||
startTimestamp: start,
|
||||
endTimestamp: end
|
||||
});
|
||||
});
|
||||
|
||||
function sendRPC({ startTimestamp, endTimestamp, paused = false } = {}) {
|
||||
fetch("/api/rpc", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
details: animeTitle,
|
||||
state: `Episode ${currentEpisode}`,
|
||||
mode: "watching",
|
||||
startTimestamp,
|
||||
endTimestamp,
|
||||
paused
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setLoading(message) {
|
||||
|
||||
@@ -6,6 +6,8 @@ let bookSlug = null;
|
||||
let allChapters = [];
|
||||
let filteredChapters = [];
|
||||
|
||||
let availableExtensions = [];
|
||||
|
||||
const chapterPagination = Object.create(PaginationManager);
|
||||
chapterPagination.init(12, () => renderChapterTable());
|
||||
|
||||
@@ -16,7 +18,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
async function init() {
|
||||
try {
|
||||
|
||||
const urlData = URLUtils.parseEntityPath('book');
|
||||
if (!urlData) {
|
||||
showError("Book Not Found");
|
||||
@@ -29,6 +30,7 @@ async function init() {
|
||||
|
||||
await loadBookMetadata();
|
||||
|
||||
await loadAvailableExtensions();
|
||||
await loadChapters();
|
||||
|
||||
await setupAddToListButton();
|
||||
@@ -39,11 +41,23 @@ async function init() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAvailableExtensions() {
|
||||
try {
|
||||
const res = await fetch('/api/extensions/book');
|
||||
const data = await res.json();
|
||||
availableExtensions = data.extensions || [];
|
||||
|
||||
setupProviderFilter();
|
||||
} catch (err) {
|
||||
console.error("Error fetching extensions:", err);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadBookMetadata() {
|
||||
const source = extensionName || 'anilist';
|
||||
const fetchUrl = `/api/book/${bookId}?source=${source}`;
|
||||
|
||||
const res = await fetch(fetchUrl, { headers: AuthUtils.getSimpleAuthHeaders() });
|
||||
const res = await fetch(fetchUrl);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.error || !data) {
|
||||
@@ -154,17 +168,27 @@ function updateCustomAddButton() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadChapters() {
|
||||
async function loadChapters(targetProvider = null) {
|
||||
const tbody = document.getElementById('chapters-body');
|
||||
if (!tbody) return;
|
||||
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center; padding: 2rem;">Searching extensions for chapters...</td></tr>';
|
||||
// Si no se pasa provider, intentamos pillar el del select o el primero disponible
|
||||
if (!targetProvider) {
|
||||
const select = document.getElementById('provider-filter');
|
||||
targetProvider = select ? select.value : (availableExtensions[0] || 'all');
|
||||
}
|
||||
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center; padding: 2rem;">Searching extension for chapters...</td></tr>';
|
||||
|
||||
try {
|
||||
const source = extensionName || 'anilist';
|
||||
const fetchUrl = `/api/book/${bookId}/chapters?source=${source}`;
|
||||
// Añadimos el query param 'provider' para que el backend filtre
|
||||
let fetchUrl = `/api/book/${bookId}/chapters?source=${source}`;
|
||||
if (targetProvider !== 'all') {
|
||||
fetchUrl += `&provider=${targetProvider}`;
|
||||
}
|
||||
|
||||
const res = await fetch(fetchUrl, { headers: AuthUtils.getSimpleAuthHeaders() });
|
||||
const res = await fetch(fetchUrl);
|
||||
const data = await res.json();
|
||||
|
||||
allChapters = data.chapters || [];
|
||||
@@ -175,18 +199,17 @@ async function loadChapters() {
|
||||
const totalEl = document.getElementById('total-chapters');
|
||||
|
||||
if (allChapters.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center; padding: 2rem;">No chapters found on loaded extensions.</td></tr>';
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center; padding: 2rem;">No chapters found.</td></tr>';
|
||||
if (totalEl) totalEl.innerText = "0 Found";
|
||||
return;
|
||||
}
|
||||
|
||||
if (totalEl) totalEl.innerText = `${allChapters.length} Found`;
|
||||
|
||||
setupProviderFilter();
|
||||
|
||||
setupReadButton();
|
||||
|
||||
chapterPagination.setTotalItems(filteredChapters.length);
|
||||
chapterPagination.reset();
|
||||
renderChapterTable();
|
||||
|
||||
} catch (err) {
|
||||
@@ -211,44 +234,31 @@ function applyChapterFilter() {
|
||||
|
||||
function setupProviderFilter() {
|
||||
const select = document.getElementById('provider-filter');
|
||||
if (!select) return;
|
||||
|
||||
const providers = [...new Set(allChapters.map(ch => ch.provider))];
|
||||
|
||||
if (providers.length === 0) return;
|
||||
if (!select || availableExtensions.length === 0) return;
|
||||
|
||||
select.style.display = 'inline-block';
|
||||
select.innerHTML = '<option value="all">All Providers</option>';
|
||||
select.innerHTML = '';
|
||||
|
||||
providers.forEach(prov => {
|
||||
const allOpt = document.createElement('option');
|
||||
allOpt.value = 'all';
|
||||
allOpt.innerText = 'Load All (Slower)';
|
||||
select.appendChild(allOpt);
|
||||
|
||||
availableExtensions.forEach(ext => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = prov;
|
||||
opt.innerText = prov;
|
||||
opt.value = ext;
|
||||
opt.innerText = ext.charAt(0).toUpperCase() + ext.slice(1);
|
||||
select.appendChild(opt);
|
||||
});
|
||||
|
||||
if (extensionName) {
|
||||
const extensionProvider = providers.find(
|
||||
p => p.toLowerCase() === extensionName.toLowerCase()
|
||||
);
|
||||
|
||||
if (extensionProvider) {
|
||||
select.value = extensionProvider;
|
||||
filteredChapters = allChapters.filter(ch => ch.provider === extensionProvider);
|
||||
}
|
||||
if (extensionName && availableExtensions.includes(extensionName)) {
|
||||
select.value = extensionName;
|
||||
} else if (availableExtensions.length > 0) {
|
||||
select.value = availableExtensions[0];
|
||||
}
|
||||
|
||||
select.onchange = (e) => {
|
||||
const selected = e.target.value;
|
||||
if (selected === 'all') {
|
||||
filteredChapters = [...allChapters];
|
||||
} else {
|
||||
filteredChapters = allChapters.filter(ch => ch.provider === selected);
|
||||
}
|
||||
|
||||
chapterPagination.reset();
|
||||
chapterPagination.setTotalItems(filteredChapters.length);
|
||||
renderChapterTable();
|
||||
select.onchange = () => {
|
||||
loadChapters(select.value);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -694,30 +694,102 @@ window.handleDeleteConfirmation = function(userId) {
|
||||
|
||||
closeModal();
|
||||
|
||||
if (user.has_password) {
|
||||
modalAniList.innerHTML = `
|
||||
<div class="modal-overlay"></div>
|
||||
<div class="modal-content" style="max-width:400px;">
|
||||
<div class="modal-header">
|
||||
<h2>Confirm Deletion</h2>
|
||||
<button class="modal-close" onclick="closeModal()">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<line x1="18" y1="6" x2="6" y2="18"></line>
|
||||
<line x1="6" y1="6" x2="18" y2="18"></line>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form id="deleteWithPasswordForm">
|
||||
<p style="margin-bottom:1.25rem; color:var(--color-text-secondary)">
|
||||
Enter your password to permanently delete
|
||||
<b>${user.username}</b>
|
||||
</p>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="deletePassword">Password</label>
|
||||
<div class="password-toggle-wrapper">
|
||||
<input
|
||||
type="password"
|
||||
id="deletePassword"
|
||||
required
|
||||
placeholder="Enter password"
|
||||
autofocus
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="password-toggle-btn"
|
||||
onclick="togglePasswordVisibility('deletePassword', this)"
|
||||
>
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn-secondary" onclick="closeModal()">
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" class="btn-disconnect">
|
||||
Delete Profile
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
`;
|
||||
modalAniList.classList.add('active');
|
||||
|
||||
document
|
||||
.getElementById('deleteWithPasswordForm')
|
||||
.addEventListener('submit', e => {
|
||||
e.preventDefault();
|
||||
const password = document.getElementById('deletePassword').value;
|
||||
handleConfirmedDeleteUser(userId, password);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
showConfirmationModal(
|
||||
'Confirm Deletion',
|
||||
`Are you absolutely sure you want to delete profile ${user.username}? This action cannot be undone.`,
|
||||
`Are you absolutely sure you want to delete profile ${user.username}?`,
|
||||
`handleConfirmedDeleteUser(${userId})`
|
||||
);
|
||||
};
|
||||
|
||||
window.handleConfirmedDeleteUser = async function(userId) {
|
||||
window.handleConfirmedDeleteUser = async function(userId, password = null) {
|
||||
closeModal();
|
||||
showUserToast('Deleting user...', 'info');
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/users/${userId}`, { method: 'DELETE' });
|
||||
const options = { method: 'DELETE' };
|
||||
|
||||
if (password) {
|
||||
options.headers = { 'Content-Type': 'application/json' };
|
||||
options.body = JSON.stringify({ password });
|
||||
}
|
||||
|
||||
const res = await fetch(`${API_BASE}/users/${userId}`, options);
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.json();
|
||||
throw new Error(error.error || 'Error deleting user');
|
||||
throw new Error(error.error);
|
||||
}
|
||||
|
||||
await loadUsers();
|
||||
showUserToast('User deleted successfully!', 'success');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
showUserToast('Error deleting user', 'error');
|
||||
showUserToast(err.message || 'Error deleting user', 'error');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -87,15 +87,16 @@ export async function getChapters(req: any, reply: FastifyReply) {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const source = req.query.source || 'anilist';
|
||||
const provider = req.query.provider;
|
||||
|
||||
const isExternal = source !== 'anilist';
|
||||
return await booksService.getChaptersForBook(id, isExternal);
|
||||
} catch {
|
||||
return await booksService.getChaptersForBook(id, isExternal, provider);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return { chapters: [] };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function getChapterContent(req: any, reply: FastifyReply) {
|
||||
try {
|
||||
const { bookId, chapter, provider } = req.params;
|
||||
|
||||
@@ -168,20 +168,39 @@ export async function deleteUser(req: FastifyRequest, reply: FastifyReply) {
|
||||
const { id } = req.params as { id: string };
|
||||
const userId = parseInt(id, 10);
|
||||
|
||||
const body = (req.body ?? {}) as { password?: string };
|
||||
const password = body.password;
|
||||
|
||||
if (!userId || isNaN(userId)) {
|
||||
return reply.code(400).send({ error: "Invalid user id" });
|
||||
}
|
||||
|
||||
const result = await userService.deleteUser(userId);
|
||||
|
||||
if (result && result.changes > 0) {
|
||||
return { success: true, message: "User deleted successfully" };
|
||||
} else {
|
||||
const user = await userService.getUserById(userId);
|
||||
if (!user) {
|
||||
return reply.code(404).send({ error: "User not found" });
|
||||
}
|
||||
|
||||
if (user.has_password) {
|
||||
if (!password) {
|
||||
return reply.code(401).send({ error: "Password required" });
|
||||
}
|
||||
|
||||
const isValid = await userService.verifyPassword(userId, password);
|
||||
if (!isValid) {
|
||||
return reply.code(401).send({ error: "Incorrect password" });
|
||||
}
|
||||
}
|
||||
|
||||
const result = await userService.deleteUser(userId);
|
||||
|
||||
if (result.changes > 0) {
|
||||
return reply.send({ success: true });
|
||||
}
|
||||
|
||||
return reply.code(500).send({ error: "Failed to delete user" });
|
||||
|
||||
} catch (err) {
|
||||
console.error("Delete User Error:", (err as Error).message);
|
||||
console.error("Delete User Error:", err);
|
||||
return reply.code(500).send({ error: "Failed to delete user" });
|
||||
}
|
||||
}
|
||||
@@ -246,16 +265,17 @@ export async function changePassword(req: FastifyRequest, reply: FastifyReply) {
|
||||
return reply.code(404).send({ error: "User not found" });
|
||||
}
|
||||
|
||||
// Si el usuario tiene contraseña actual, debe proporcionar la contraseña actual
|
||||
if (user.has_password && currentPassword) {
|
||||
const isValid = await userService.verifyPassword(userId, currentPassword);
|
||||
if (user.has_password) {
|
||||
if (!currentPassword) {
|
||||
return reply.code(401).send({ error: "Current password required" });
|
||||
}
|
||||
|
||||
const isValid = await userService.verifyPassword(userId, currentPassword);
|
||||
if (!isValid) {
|
||||
return reply.code(401).send({ error: "Current password is incorrect" });
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar la contraseña (null para eliminarla, string para establecerla)
|
||||
await userService.updateUser(userId, { password: newPassword });
|
||||
|
||||
return reply.send({
|
||||
|
||||
@@ -6,6 +6,8 @@ let bookSlug = null;
|
||||
let allChapters = [];
|
||||
let filteredChapters = [];
|
||||
|
||||
let availableExtensions = [];
|
||||
|
||||
const chapterPagination = Object.create(PaginationManager);
|
||||
chapterPagination.init(12, () => renderChapterTable());
|
||||
|
||||
@@ -16,7 +18,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
async function init() {
|
||||
try {
|
||||
|
||||
const urlData = URLUtils.parseEntityPath('book');
|
||||
if (!urlData) {
|
||||
showError("Book Not Found");
|
||||
@@ -29,6 +30,7 @@ async function init() {
|
||||
|
||||
await loadBookMetadata();
|
||||
|
||||
await loadAvailableExtensions();
|
||||
await loadChapters();
|
||||
|
||||
await setupAddToListButton();
|
||||
@@ -39,11 +41,23 @@ async function init() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAvailableExtensions() {
|
||||
try {
|
||||
const res = await fetch('/api/extensions/book');
|
||||
const data = await res.json();
|
||||
availableExtensions = data.extensions || [];
|
||||
|
||||
setupProviderFilter();
|
||||
} catch (err) {
|
||||
console.error("Error fetching extensions:", err);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadBookMetadata() {
|
||||
const source = extensionName || 'anilist';
|
||||
const fetchUrl = `/api/book/${bookId}?source=${source}`;
|
||||
|
||||
const res = await fetch(fetchUrl, { headers: AuthUtils.getSimpleAuthHeaders() });
|
||||
const res = await fetch(fetchUrl);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.error || !data) {
|
||||
@@ -154,17 +168,27 @@ function updateCustomAddButton() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadChapters() {
|
||||
async function loadChapters(targetProvider = null) {
|
||||
const tbody = document.getElementById('chapters-body');
|
||||
if (!tbody) return;
|
||||
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center; padding: 2rem;">Searching extensions for chapters...</td></tr>';
|
||||
// Si no se pasa provider, intentamos pillar el del select o el primero disponible
|
||||
if (!targetProvider) {
|
||||
const select = document.getElementById('provider-filter');
|
||||
targetProvider = select ? select.value : (availableExtensions[0] || 'all');
|
||||
}
|
||||
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center; padding: 2rem;">Searching extension for chapters...</td></tr>';
|
||||
|
||||
try {
|
||||
const source = extensionName || 'anilist';
|
||||
const fetchUrl = `/api/book/${bookId}/chapters?source=${source}`;
|
||||
// Añadimos el query param 'provider' para que el backend filtre
|
||||
let fetchUrl = `/api/book/${bookId}/chapters?source=${source}`;
|
||||
if (targetProvider !== 'all') {
|
||||
fetchUrl += `&provider=${targetProvider}`;
|
||||
}
|
||||
|
||||
const res = await fetch(fetchUrl, { headers: AuthUtils.getSimpleAuthHeaders() });
|
||||
const res = await fetch(fetchUrl);
|
||||
const data = await res.json();
|
||||
|
||||
allChapters = data.chapters || [];
|
||||
@@ -175,18 +199,17 @@ async function loadChapters() {
|
||||
const totalEl = document.getElementById('total-chapters');
|
||||
|
||||
if (allChapters.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center; padding: 2rem;">No chapters found on loaded extensions.</td></tr>';
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center; padding: 2rem;">No chapters found.</td></tr>';
|
||||
if (totalEl) totalEl.innerText = "0 Found";
|
||||
return;
|
||||
}
|
||||
|
||||
if (totalEl) totalEl.innerText = `${allChapters.length} Found`;
|
||||
|
||||
setupProviderFilter();
|
||||
|
||||
setupReadButton();
|
||||
|
||||
chapterPagination.setTotalItems(filteredChapters.length);
|
||||
chapterPagination.reset();
|
||||
renderChapterTable();
|
||||
|
||||
} catch (err) {
|
||||
@@ -211,44 +234,31 @@ function applyChapterFilter() {
|
||||
|
||||
function setupProviderFilter() {
|
||||
const select = document.getElementById('provider-filter');
|
||||
if (!select) return;
|
||||
|
||||
const providers = [...new Set(allChapters.map(ch => ch.provider))];
|
||||
|
||||
if (providers.length === 0) return;
|
||||
if (!select || availableExtensions.length === 0) return;
|
||||
|
||||
select.style.display = 'inline-block';
|
||||
select.innerHTML = '<option value="all">All Providers</option>';
|
||||
select.innerHTML = '';
|
||||
|
||||
providers.forEach(prov => {
|
||||
const allOpt = document.createElement('option');
|
||||
allOpt.value = 'all';
|
||||
allOpt.innerText = 'Load All (Slower)';
|
||||
select.appendChild(allOpt);
|
||||
|
||||
availableExtensions.forEach(ext => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = prov;
|
||||
opt.innerText = prov;
|
||||
opt.value = ext;
|
||||
opt.innerText = ext.charAt(0).toUpperCase() + ext.slice(1);
|
||||
select.appendChild(opt);
|
||||
});
|
||||
|
||||
if (extensionName) {
|
||||
const extensionProvider = providers.find(
|
||||
p => p.toLowerCase() === extensionName.toLowerCase()
|
||||
);
|
||||
|
||||
if (extensionProvider) {
|
||||
select.value = extensionProvider;
|
||||
filteredChapters = allChapters.filter(ch => ch.provider === extensionProvider);
|
||||
}
|
||||
if (extensionName && availableExtensions.includes(extensionName)) {
|
||||
select.value = extensionName;
|
||||
} else if (availableExtensions.length > 0) {
|
||||
select.value = availableExtensions[0];
|
||||
}
|
||||
|
||||
select.onchange = (e) => {
|
||||
const selected = e.target.value;
|
||||
if (selected === 'all') {
|
||||
filteredChapters = [...allChapters];
|
||||
} else {
|
||||
filteredChapters = allChapters.filter(ch => ch.provider === selected);
|
||||
}
|
||||
|
||||
chapterPagination.reset();
|
||||
chapterPagination.setTotalItems(filteredChapters.length);
|
||||
renderChapterTable();
|
||||
select.onchange = () => {
|
||||
loadChapters(select.value);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -694,30 +694,102 @@ window.handleDeleteConfirmation = function(userId) {
|
||||
|
||||
closeModal();
|
||||
|
||||
if (user.has_password) {
|
||||
modalAniList.innerHTML = `
|
||||
<div class="modal-overlay"></div>
|
||||
<div class="modal-content" style="max-width:400px;">
|
||||
<div class="modal-header">
|
||||
<h2>Confirm Deletion</h2>
|
||||
<button class="modal-close" onclick="closeModal()">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<line x1="18" y1="6" x2="6" y2="18"></line>
|
||||
<line x1="6" y1="6" x2="18" y2="18"></line>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form id="deleteWithPasswordForm">
|
||||
<p style="margin-bottom:1.25rem; color:var(--color-text-secondary)">
|
||||
Enter your password to permanently delete
|
||||
<b>${user.username}</b>
|
||||
</p>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="deletePassword">Password</label>
|
||||
<div class="password-toggle-wrapper">
|
||||
<input
|
||||
type="password"
|
||||
id="deletePassword"
|
||||
required
|
||||
placeholder="Enter password"
|
||||
autofocus
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="password-toggle-btn"
|
||||
onclick="togglePasswordVisibility('deletePassword', this)"
|
||||
>
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn-secondary" onclick="closeModal()">
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" class="btn-disconnect">
|
||||
Delete Profile
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
`;
|
||||
modalAniList.classList.add('active');
|
||||
|
||||
document
|
||||
.getElementById('deleteWithPasswordForm')
|
||||
.addEventListener('submit', e => {
|
||||
e.preventDefault();
|
||||
const password = document.getElementById('deletePassword').value;
|
||||
handleConfirmedDeleteUser(userId, password);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
showConfirmationModal(
|
||||
'Confirm Deletion',
|
||||
`Are you absolutely sure you want to delete profile ${user.username}? This action cannot be undone.`,
|
||||
`Are you absolutely sure you want to delete profile ${user.username}?`,
|
||||
`handleConfirmedDeleteUser(${userId})`
|
||||
);
|
||||
};
|
||||
|
||||
window.handleConfirmedDeleteUser = async function(userId) {
|
||||
window.handleConfirmedDeleteUser = async function(userId, password = null) {
|
||||
closeModal();
|
||||
showUserToast('Deleting user...', 'info');
|
||||
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/users/${userId}`, { method: 'DELETE' });
|
||||
const options = { method: 'DELETE' };
|
||||
|
||||
if (password) {
|
||||
options.headers = { 'Content-Type': 'application/json' };
|
||||
options.body = JSON.stringify({ password });
|
||||
}
|
||||
|
||||
const res = await fetch(`${API_BASE}/users/${userId}`, options);
|
||||
|
||||
if (!res.ok) {
|
||||
const error = await res.json();
|
||||
throw new Error(error.error || 'Error deleting user');
|
||||
throw new Error(error.error);
|
||||
}
|
||||
|
||||
await loadUsers();
|
||||
showUserToast('User deleted successfully!', 'success');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
showUserToast('Error deleting user', 'error');
|
||||
showUserToast(err.message || 'Error deleting user', 'error');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user