mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 10:22:29 +08:00
Merge branch 'develop' into left-pane
This commit is contained in:
commit
501fab2736
@ -38,7 +38,7 @@
|
||||
"@playwright/test": "1.52.0",
|
||||
"@stylistic/eslint-plugin": "4.2.0",
|
||||
"@types/express": "5.0.1",
|
||||
"@types/node": "22.15.18",
|
||||
"@types/node": "22.15.19",
|
||||
"@types/yargs": "17.0.33",
|
||||
"@vitest/coverage-v8": "3.1.3",
|
||||
"eslint": "9.27.0",
|
||||
|
@ -104,7 +104,6 @@
|
||||
"sanitize-html": "2.17.0",
|
||||
"sax": "1.4.1",
|
||||
"serve-favicon": "2.5.0",
|
||||
"session-file-store": "1.5.0",
|
||||
"stream-throttle": "0.1.3",
|
||||
"strip-bom": "5.0.0",
|
||||
"striptags": "3.2.0",
|
||||
|
@ -4,7 +4,6 @@ import favicon from "serve-favicon";
|
||||
import cookieParser from "cookie-parser";
|
||||
import helmet from "helmet";
|
||||
import compression from "compression";
|
||||
import sessionParser from "./routes/session_parser.js";
|
||||
import config from "./services/config.js";
|
||||
import utils, { getResourceDir } from "./services/utils.js";
|
||||
import assets from "./routes/assets.js";
|
||||
@ -111,6 +110,8 @@ export default async function buildApp() {
|
||||
app.use(`/manifest.webmanifest`, express.static(path.join(publicAssetsDir, "manifest.webmanifest")));
|
||||
app.use(`/robots.txt`, express.static(path.join(publicAssetsDir, "robots.txt")));
|
||||
app.use(`/icon.png`, express.static(path.join(publicAssetsDir, "icon.png")));
|
||||
|
||||
const sessionParser = (await import("./routes/session_parser.js")).default;
|
||||
app.use(sessionParser);
|
||||
app.use(favicon(path.join(assetsDir, "icon.ico")));
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
id TEXT PRIMARY KEY,
|
||||
data TEXT,
|
||||
expires INTEGER
|
||||
);
|
@ -187,3 +187,9 @@ CREATE TABLE IF NOT EXISTS "embedding_providers" (
|
||||
"dateModified" TEXT NOT NULL,
|
||||
"utcDateModified" TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
id TEXT PRIMARY KEY,
|
||||
data TEXT,
|
||||
expires INTEGER
|
||||
);
|
||||
|
@ -1,10 +1,55 @@
|
||||
import session from "express-session";
|
||||
import sessionFileStore from "session-file-store";
|
||||
import sql from "../services/sql.js";
|
||||
import session, { Store } from "express-session";
|
||||
import sessionSecret from "../services/session_secret.js";
|
||||
import dataDir from "../services/data_dir.js";
|
||||
import config from "../services/config.js";
|
||||
import log from "../services/log.js";
|
||||
|
||||
const FileStore = sessionFileStore(session);
|
||||
class SQLiteSessionStore extends Store {
|
||||
|
||||
get(sid: string, callback: (err: any, session?: session.SessionData | null) => void): void {
|
||||
try {
|
||||
const data = sql.getValue<string>(/*sql*/`SELECT data FROM sessions WHERE id = ?`, sid);
|
||||
let session = null;
|
||||
if (data) {
|
||||
session = JSON.parse(data);
|
||||
}
|
||||
return callback(null, session);
|
||||
} catch (e: unknown) {
|
||||
log.error(e);
|
||||
return callback(e);
|
||||
}
|
||||
}
|
||||
|
||||
set(id: string, session: session.SessionData, callback?: (err?: any) => void): void {
|
||||
try {
|
||||
const expires = session.cookie?.expires
|
||||
? new Date(session.cookie.expires).getTime()
|
||||
: Date.now() + 3600000; // fallback to 1 hour
|
||||
const data = JSON.stringify(session);
|
||||
|
||||
sql.upsert("sessions", "id", {
|
||||
id,
|
||||
expires,
|
||||
data
|
||||
});
|
||||
callback?.();
|
||||
} catch (e) {
|
||||
log.error(e);
|
||||
return callback?.(e);
|
||||
}
|
||||
}
|
||||
|
||||
destroy(sid: string, callback?: (err?: any) => void): void {
|
||||
try {
|
||||
sql.execute(/*sql*/`DELETE FROM sessions WHERE id = ?`, sid);
|
||||
callback?.();
|
||||
} catch (e) {
|
||||
log.error(e);
|
||||
callback?.(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const sessionParser = session({
|
||||
secret: sessionSecret,
|
||||
@ -16,10 +61,14 @@ const sessionParser = session({
|
||||
maxAge: config.Session.cookieMaxAge * 1000 // needs value in milliseconds
|
||||
},
|
||||
name: "trilium.sid",
|
||||
store: new FileStore({
|
||||
ttl: config.Session.cookieMaxAge,
|
||||
path: `${dataDir.TRILIUM_DATA_DIR}/sessions`
|
||||
})
|
||||
store: new SQLiteSessionStore()
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
// Clean up expired sesions.
|
||||
const now = Date.now();
|
||||
const result = sql.execute(/*sql*/`DELETE FROM sessions WHERE expires < ?`, now);
|
||||
console.log("Cleaning up expired sessions: ", result.changes);
|
||||
}, 60 * 60 * 1000);
|
||||
|
||||
export default sessionParser;
|
||||
|
@ -3,7 +3,7 @@ import build from "./build.js";
|
||||
import packageJson from "../../package.json" with { type: "json" };
|
||||
import dataDir from "./data_dir.js";
|
||||
|
||||
const APP_DB_VERSION = 230;
|
||||
const APP_DB_VERSION = 231;
|
||||
const SYNC_VERSION = 35;
|
||||
const CLIPPER_PROTOCOL_VERSION = "1.0";
|
||||
|
||||
|
@ -69,7 +69,7 @@ function info(message: string | Error) {
|
||||
log(message);
|
||||
}
|
||||
|
||||
function error(message: string | Error) {
|
||||
function error(message: string | Error | unknown) {
|
||||
log(`ERROR: ${message}`);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import sessionParser from "./routes/session_parser.js";
|
||||
import fs from "fs";
|
||||
import http from "http";
|
||||
import https from "https";
|
||||
@ -79,6 +77,7 @@ async function startTrilium() {
|
||||
|
||||
const httpServer = startHttpServer(app);
|
||||
|
||||
const sessionParser = (await import("./routes/session_parser.js")).default;
|
||||
ws.init(httpServer, sessionParser as any); // TODO: Not sure why session parser is incompatible.
|
||||
|
||||
if (utils.isElectron) {
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
* [Inconsistent Find and Replace Behavior in Large Code Notes](https://github.com/TriliumNext/Notes/issues/1826) by @SiriusXT
|
||||
* [Incorrect import of multiple inline math](https://github.com/TriliumNext/Notes/pull/1906) by @SiriusXT
|
||||
* [Random EPERM: operation not permitted on Windows](https://github.com/TriliumNext/Notes/issues/249)
|
||||
|
||||
## ✨ Improvements
|
||||
|
||||
@ -40,7 +41,8 @@
|
||||
* [Added support for opening and activating a note in a new tab using Ctrl+Shift+click on notes in the launcher pane, note tree, or note images](https://github.com/TriliumNext/Notes/pull/1854) by @SiriusXT
|
||||
* [Style and footnote improvements](https://github.com/TriliumNext/Notes/pull/1913) by @SiriusXT
|
||||
* Backend log: disable some editor features in order to increase performance for large logs (syntax highlighting, folding, etc.).
|
||||
* [Collapsible table of contents](https://github.com/TriliumNext/Notes/pull/1954) by @SriiusXT
|
||||
* [Collapsible table of contents](https://github.com/TriliumNext/Notes/pull/1954) by @SiriusXT
|
||||
* Sessions (logins) are no longer stored as files in the data directory, but as entries in the database. This improves the session reliability on Windows platforms.
|
||||
|
||||
## 📖 Documentation
|
||||
|
||||
|
@ -46,7 +46,7 @@
|
||||
"@swc/helpers": "~0.5.11",
|
||||
"@triliumnext/server": "workspace:*",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/node": "22.15.18",
|
||||
"@types/node": "22.15.19",
|
||||
"@vitest/coverage-v8": "^3.0.5",
|
||||
"@vitest/ui": "^3.0.0",
|
||||
"chalk": "5.4.1",
|
||||
|
355
pnpm-lock.yaml
generated
355
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user