chore(code): fix editorconfig for src/public

This commit is contained in:
Elian Doran 2024-12-22 15:42:15 +02:00
parent ae90ff2df4
commit b321d99076
No known key found for this signature in database
70 changed files with 589 additions and 590 deletions

View File

@ -16,7 +16,7 @@ bundleService.getWidgetBundlesByParent().then(async widgetBundles => {
// A dynamic import is required for layouts since they initialize components which require translations.
const DesktopLayout = (await import("./layouts/desktop_layout.js")).default;
appContext.setLayout(new DesktopLayout(widgetBundles));
appContext.setLayout(new DesktopLayout(widgetBundles));
appContext.start()
.catch((e) => {
toastService.showPersistent({
@ -47,16 +47,16 @@ if (utils.isElectron()) {
function initOnElectron() {
const electron = utils.dynamicRequire('electron');
electron.ipcRenderer.on('globalShortcut', async (event, actionName) => appContext.triggerCommand(actionName));
const electronRemote = utils.dynamicRequire("@electron/remote");
const currentWindow = electronRemote.getCurrentWindow();
const electronRemote = utils.dynamicRequire("@electron/remote");
const currentWindow = electronRemote.getCurrentWindow();
const style = window.getComputedStyle(document.body);
initTransparencyEffects(style, currentWindow);
if (options.get("nativeTitleBarVisible") !== "true") {
initTitleBarButtons(style, currentWindow);
}
}
}
function initTitleBarButtons(style, currentWindow) {
@ -68,7 +68,7 @@ function initTitleBarButtons(style, currentWindow) {
currentWindow.setTitleBarOverlay({ color, symbolColor });
}
};
applyWindowsOverlay();
// Register for changes to the native title bar colors.
@ -80,7 +80,7 @@ function initTitleBarButtons(style, currentWindow) {
const xOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-x-offset"), 10);
const yOffset = parseInt(style.getPropertyValue("--native-titlebar-darwin-y-offset"), 10);
currentWindow.setWindowButtonPosition({ x: xOffset, y: yOffset });
}
}
}
function initTransparencyEffects(style, currentWindow) {
@ -88,4 +88,4 @@ function initTransparencyEffects(style, currentWindow) {
const material = style.getPropertyValue("--background-material");
currentWindow.setBackgroundMaterial(material);
}
}
}

View File

@ -1,18 +1,18 @@
// TODO: Deduplicate with src/services/entity_changes_interface.ts
export interface EntityChange {
id?: number | null;
noteId?: string;
entityName: string;
entityId: string;
entity?: any;
positions?: Record<string, number>;
hash: string;
utcDateChanged?: string;
utcDateModified?: string;
utcDateCreated?: string;
isSynced: boolean | 1 | 0;
isErased: boolean | 1 | 0;
componentId?: string | null;
changeId?: string | null;
instanceId?: string | null;
}
id?: number | null;
noteId?: string;
entityName: string;
entityId: string;
entity?: any;
positions?: Record<string, number>;
hash: string;
utcDateChanged?: string;
utcDateModified?: string;
utcDateCreated?: string;
isSynced: boolean | 1 | 0;
isErased: boolean | 1 | 0;
componentId?: string | null;
changeId?: string | null;
instanceId?: string | null;
}

View File

@ -48,8 +48,8 @@ type RequireMethod = (moduleName: string) => any;
declare global {
interface Window {
logError(message: string);
logInfo(message: string);
logInfo(message: string);
process?: ElectronProcess;
glob?: CustomGlobals;
}
@ -75,10 +75,10 @@ declare global {
suggestion: (suggestion: Suggestion) => string | undefined
}
};
interface JQuery {
autocomplete: (action?: "close" | "open" | "destroy" | "val" | AutoCompleteConfig, args?: AutoCompleteArg[] | string) => JQuery<?>;
getSelectedNotePath(): string | undefined;
getSelectedNoteId(): string | null;
setSelectedNotePath(notePath: string | null | undefined);
@ -88,7 +88,7 @@ declare global {
}
var logError: (message: string, e?: Error) => void;
var logInfo: (message: string) => void;
var logInfo: (message: string) => void;
var glob: CustomGlobals;
var require: RequireMethod;
var __non_webpack_require__: RequireMethod | undefined;
@ -132,7 +132,7 @@ declare global {
interface MermaidLoader {
}
var mermaid: {
var mermaid: {
mermaidAPI: MermaidApi;
registerLayoutLoaders(loader: MermaidLoader);
parse(content: string, opts: {
@ -140,7 +140,7 @@ declare global {
}): {
config: {
layout: string;
}
}
}
};
var MERMAID_ELK: MermaidLoader;

View File

@ -111,4 +111,3 @@
.calendar-dropdown-widget .calendar-date:not(.calendar-date-active) {
cursor: pointer;
}

View File

@ -20,7 +20,7 @@
}
:root {
--submenu-opening-delay: 300ms;
--submenu-opening-delay: 300ms;
}
html {
@ -30,7 +30,7 @@ html {
body {
/* Fix for CKEditor block gutter icon "stretching" body and causing scrollbar to appear after pressing enter
on the last line of the editor. */
on the last line of the editor. */
position: fixed;
width: 100%;
height: 100%;
@ -38,7 +38,7 @@ body {
color: var(--main-text-color);
font-family: var(--main-font-family);
font-size: var(--main-font-size);
--native-titlebar-foreground: var(--main-text-color);
--native-titlebar-darwin-x-offset: 10;
--native-titlebar-darwin-y-offset: 12;
@ -1097,7 +1097,7 @@ body:not(.mobile) #launcher-pane.horizontal .dropdown-submenu > .dropdown-menu {
cursor: pointer;
border: none;
color: var(--launcher-pane-text-color);
background-color: var(--launcher-pane-background-color);
background-color: var(--launcher-pane-background-color);
}
#launcher-pane.vertical .launcher-button {
@ -1297,7 +1297,7 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container {
width: 24px;
height: 24px;
color: var(--launcher-pane-text-color);
margin: 8px 10px;
margin: 8px 10px;
font-size: 18px;
}
@ -1313,4 +1313,4 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container {
border-color: var(--hover-item-border-color);
background: var(--hover-item-background-color);
color: var(--hover-item-text-color);
}
}

View File

@ -100,4 +100,4 @@ body .todo-list input[type="checkbox"]:not(:checked):before {
.ck-content pre {
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6) !important;
}
}

View File

@ -1,6 +1,6 @@
/* Light theme is special since it's also baseline/default so when a theme does not define some variable then
value from this theme will be used. For this reason this theme uses "html" instead of ":root"
since it's less "specific" and thus serves as default */
value from this theme will be used. For this reason this theme uses "html" instead of ":root"
since it's less "specific" and thus serves as default */
html {
/* either light or dark, colored theme with darker tones are also dark, used e.g. for note map node colors */
--theme-style: light;

View File

@ -9,7 +9,7 @@
--native-titlebar-background: #00000000;
--main-background-color: #333;
--main-text-color: #ccc;
--main-text-color: #ccc;
--main-border-color: #454545;
--subtle-border-color: #313131;
--dropdown-border-color: #292929;
@ -81,7 +81,7 @@
--left-pane-item-action-button-hover-background: #ffffffad;
--left-pane-item-action-button-hover-shadow: 2px 2px 3px rgba(0, 0, 0, .15);
--left-pane-item-selected-action-button-hover-shadow: 2px 2px 10px rgba(0, 0, 0, .25);
--launcher-pane-background-color: #1a1a1a;
--launcher-pane-horizontal-background-color: #282828;
--launcher-pane-horizontal-border-color: rgb(22, 22, 22);
@ -145,8 +145,8 @@
--tooltip-shadow-color: rgba(0, 0, 0, 0.4);
}
/*
* Dark color scheme tweaks
/*
* Dark color scheme tweaks
*/
body ::-webkit-calendar-picker-indicator {
@ -167,4 +167,4 @@ body .todo-list input[type="checkbox"]:not(:checked):before {
.btn-close {
filter: invert(1);
}
}

View File

@ -1,5 +1,5 @@
/* Import the Next theme base style */
@import url(./theme-next/base.css);
@import url(./theme-next/base.css);
/*
* Color scheme
@ -7,7 +7,7 @@
:root {
--theme-style: light;
--native-titlebar-background: #ffffff00;
--main-background-color: white;
--main-text-color: black;
--main-border-color: #dbdbdb;
@ -16,33 +16,33 @@
--dropdown-shadow-opacity: .2;
--dropdown-item-icon-destructive-color: #ec5138;
--disabled-tooltip-icon-color: #004382;
--accented-background-color: #f5f5f5;
--accented-background-color: #f5f5f5;
--button-background-color: transparent;
--button-border-color: #ddd;
--button-text-color: black;
--button-border-radius: 5px;
--button-disabled-background-color: #ddd;
--button-disabled-text-color: black;
--primary-button-background-color: #6c757d;
--primary-button-text-color: white;
--primary-button-border-color: #6c757d;
--muted-text-color: #666;
--input-text-color: black;
--input-background-color: transparent;
--hover-item-text-color: black;
--hover-item-background-color: #0000001a;
--hover-item-border-color: transparent;
--active-item-text-color: var(--left-pane-text-color);
--active-item-background-color: #ddd;
--active-item-border-color: transparent;
--menu-text-color: #272727;
--menu-background-color: #ffffffd9;
--menu-item-icon-color: #727272;
@ -50,17 +50,17 @@
--menu-item-keyboard-shortcut-color: #666666a8;
--menu-item-arrow-color: #00000080;
--menu-item-delimiter-color: #00000030;
--modal-background-color: white;
--modal-backdrop-color: black;
--quick-search-background: #00000012;
--quick-search-color: #06060682;
--quick-search-hover-background: #00000020;
--quick-search-focus-border: #00000029;
--quick-search-focus-background: #ffffff80;
--quick-search-focus-color: #000;
--left-pane-collapsed-border-color: #0000000d;
--left-pane-background-color: #f2f2f2;
--left-pane-text-color: #383838;
@ -73,7 +73,7 @@
--left-pane-item-action-button-hover-background: white;
--left-pane-item-action-button-hover-shadow: 2px 2px 3px rgba(0, 0, 0, .15);
--left-pane-item-selected-action-button-hover-shadow: 2px 2px 10px rgba(0, 0, 0, .25);
--launcher-pane-background-color: #e8e8e8;
--launcher-pane-horizontal-background-color: #fafafa;
--launcher-pane-horizontal-border-color: rgba(0, 0, 0, 0.1);
@ -81,65 +81,65 @@
--launcher-pane-button-hover-color: black;
--launcher-pane-button-hover-background: white;
--launcher-pane-button-hover-shadow: 4px 4px 4px rgba(0, 0, 0, .075);
--protected-session-active-icon-color: #16b516;
--sync-status-error-pulse-color: #ff5528;
--root-background: var(--left-pane-background-color);
--gutter-color: transparent;
--gutter-hover-color: #bfbfbf;
--tab-close-button-hover-background: #c95a5a;
--tab-close-button-hover-color: white;
--active-tab-background-color: white;
--active-tab-hover-background-color: var(--active-tab-background-color);
--active-tab-text-color: black;
--active-tab-shadow: 3px 3px 6px rgba(0, 0, 0, .1), -1px -1px 3px rgba(0, 0, 0, .05);
--active-tab-dragging-shadow: var(--active-tab-shadow), 0 0 20px rgba(0, 0, 0, .1);
--inactive-tab-background-color: transparent;
--inactive-tab-hover-background-color: #00000016;
--inactive-tab-text-color: #4e4e4e;
--new-tab-button-background: #d8d8d8;
--new-tab-button-color: #3a3a3a;
--new-tab-button-shadow: 2px 2px 4px rgba(0, 0, 0, .2);
--new-tab-button-hover-background: white;
--new-tab-button-hover-color: black;
--right-pane-item-hover-background: #ececec;
--right-pane-item-hover-color: inherit;
--scrollbar-border-color: #ddd;
--scrollbar-background-color: #ddd;
--link-color: blue;
--mermaid-theme: default;
--mermaid-theme: default;
--code-block-box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.1), 0px 0px 2px rgba(0, 0, 0, 0.2);
--card-background-color: var(--accented-background-color);
--card-background-hover-color: #f9f9f9;
--card-background-press-color: #efefef;
--card-border-color: #eaeaea;
--card-shadow-color: rgba(0, 0, 0, 0.1);
--card-box-shadow: 0 0 12px var(--card-shadow-color);
--calendar-color: var(--menu-text-color);
--calendar-weekday-labels-color: var(--muted-text-color);
--calendar-day-hover-color: var(--hover-item-text-color);
--calendar-day-hover-background: var(--active-item-background-color);
--calendar-day-highlight-background: #80808024;
--timeline-bullet-color: #a5a5a5;
--timeline-bullet-hover-color: black;
--timeline-connector-color: #f1f1f1;
--timeline-connector-active-color: #ddd;
--timeline-connector-hover-blend-mode: multiply;
--tooltip-background-color: rgba(255, 255, 255, 0.85);
--tooltip-foreground-color: #000000ba;
--tooltip-shadow-color: rgba(0, 0, 0, .15);
}
}

View File

@ -1,7 +1,7 @@
/* Import the light color scheme.
/* Import the light color scheme.
* This is the base color scheme, always active and overridden by the dark
* color scheme stylesheet when necessary. */
@import url(./theme-next-light.css);
/* Import the dark color scheme when the system preference is set to dark mode */
@import url(./theme-next-dark.css) (prefers-color-scheme: dark);
@import url(./theme-next-dark.css) (prefers-color-scheme: dark);

View File

@ -1,7 +1,7 @@
/* Import the light color scheme.
/* Import the light color scheme.
* This is the base color scheme, always active and overridden by the dark
* color scheme stylesheet when necessary. */
@import url(./theme-light.css);
/* Import the dark color scheme when the system preference is set to dark mode */
@import url(./theme-dark.css) (prefers-color-scheme: dark);
@import url(./theme-dark.css) (prefers-color-scheme: dark);

View File

@ -15,7 +15,7 @@ function getAutocomplete(req: Request) {
}
const query = (req.query.query || "").trim();
const fastSearch = String(req.query.fastSearch).toLowerCase() === "false" ? false : true;
const activeNoteId = req.query.activeNoteId || 'none';
let results;
@ -49,18 +49,18 @@ function getRecentNotes(activeNoteId: string) {
}
const recentNotes = becca.getRecentNotesFromQuery(`
SELECT
recent_notes.*
FROM
SELECT
recent_notes.*
FROM
recent_notes
JOIN notes USING(noteId)
WHERE
WHERE
notes.isDeleted = 0
AND notes.noteId != ?
${extraCondition}
ORDER BY
ORDER BY
utcDateCreated DESC
LIMIT 200`, params);
LIMIT 200`, params);
return recentNotes.map(rn => {
const notePathArray = rn.notePath.split('/');

View File

@ -176,7 +176,7 @@ function saveToTmpDir(fileName: string, content: string | Buffer, entityType: st
if (typeof content === "string") {
fs.writeSync(tmpObj.fd, content);
} else {
fs.writeSync(tmpObj.fd, content);
fs.writeSync(tmpObj.fd, content);
}
fs.closeSync(tmpObj.fd);

View File

@ -107,7 +107,7 @@ function updateImage(req: Request) {
message: "Invalid image content."
};
}
imageService.updateImage(noteId, file.buffer, file.originalname);
return { uploaded: true };

View File

@ -219,9 +219,9 @@ function getDeleteNotesPreview(req: Request) {
brokenRelations = sql.getRows<AttributeRow>(`
SELECT attr.noteId, attr.name, attr.value
FROM attributes attr
JOIN param_list ON param_list.paramId = attr.value
JOIN param_list ON param_list.paramId = attr.value
WHERE attr.isDeleted = 0
AND attr.type = 'relation'`).filter(attr => attr.noteId && !noteIdsToBeDeleted.has(attr.noteId));
AND attr.type = 'relation'`).filter(attr => attr.noteId && !noteIdsToBeDeleted.has(attr.noteId));
}
return {

View File

@ -25,7 +25,7 @@ function getRecentChanges(req: Request) {
let recentChanges = [];
const revisionRows = sql.getRows<RecentChangeRow>(`
SELECT
SELECT
notes.noteId,
notes.isDeleted AS current_isDeleted,
notes.deleteId AS current_deleteId,
@ -34,7 +34,7 @@ function getRecentChanges(req: Request) {
revisions.title,
revisions.utcDateCreated AS utcDate,
revisions.dateCreated AS date
FROM
FROM
revisions
JOIN notes USING(noteId)`);

View File

@ -35,9 +35,9 @@ function getRevisionBlob(req: Request) {
function getRevisions(req: Request) {
return becca.getRevisionsFromQuery(`
SELECT revisions.*,
LENGTH(blobs.content) AS contentLength
LENGTH(blobs.content) AS contentLength
FROM revisions
JOIN blobs ON revisions.blobId = blobs.blobId
JOIN blobs ON revisions.blobId = blobs.blobId
WHERE revisions.noteId = ?
ORDER BY revisions.utcDateCreated DESC`, [req.params.noteId]);
}
@ -158,9 +158,9 @@ function getEditedNotesOnDate(req: Request) {
SELECT notes.*
FROM notes
WHERE noteId IN (
SELECT noteId FROM notes
SELECT noteId FROM notes
WHERE notes.dateCreated LIKE :date
OR notes.dateModified LIKE :date
OR notes.dateModified LIKE :date
UNION ALL
SELECT noteId FROM revisions
WHERE revisions.dateLastEdited LIKE :date

View File

@ -40,7 +40,7 @@ function execute(req: Request) {
const pivot = query.indexOf('\n');
query = pivot > 0 ? query.substr(pivot + 1).trim() : "";
}
if (!query) {
continue;
}

View File

@ -11,9 +11,9 @@ function getNoteSize(req: Request) {
LEFT JOIN notes ON notes.blobId = blobs.blobId AND notes.noteId = ? AND notes.isDeleted = 0
LEFT JOIN attachments ON attachments.blobId = blobs.blobId AND attachments.ownerId = ? AND attachments.isDeleted = 0
LEFT JOIN revisions ON revisions.blobId = blobs.blobId AND revisions.noteId = ?
WHERE notes.noteId IS NOT NULL
OR attachments.attachmentId IS NOT NULL
OR revisions.revisionId IS NOT NULL`, [noteId, noteId, noteId]);
WHERE notes.noteId IS NOT NULL
OR attachments.attachmentId IS NOT NULL
OR revisions.revisionId IS NOT NULL`, [noteId, noteId, noteId]);
const noteSize = Object.values(blobSizes).reduce((acc, blobSize) => acc + blobSize, 0);

View File

@ -103,7 +103,7 @@ function getChanged(req: Request) {
SELECT *
FROM entity_changes
WHERE isSynced = 1
AND id > ?
AND id > ?
ORDER BY id
LIMIT 1000`, [lastEntityChangeId]);
@ -130,11 +130,11 @@ function getChanged(req: Request) {
entityChanges: entityChangeRecords,
lastEntityChangeId,
outstandingPullCount: sql.getValue(`
SELECT COUNT(id)
FROM entity_changes
WHERE isSynced = 1
AND instanceId != ?
AND id > ?`, [clientInstanceId, lastEntityChangeId])
SELECT COUNT(id)
FROM entity_changes
WHERE isSynced = 1
AND instanceId != ?
AND id > ?`, [clientInstanceId, lastEntityChangeId])
};
}

View File

@ -18,22 +18,22 @@ const persistentCacheStatic = (root: string, options?: serveStatic.ServeStaticOp
async function register(app: express.Application) {
const srcRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
if (env.isDev()) {
const webpack = (await import("webpack")).default;
const webpackMiddleware = (await import("webpack-dev-middleware")).default;
const productionConfig = (await import("../../webpack.config.js")).default;
const webpack = (await import("webpack")).default;
const webpackMiddleware = (await import("webpack-dev-middleware")).default;
const productionConfig = (await import("../../webpack.config.js")).default;
const frontendCompiler = webpack({
const frontendCompiler = webpack({
mode: "development",
entry: productionConfig.entry,
module: productionConfig.module,
resolve: productionConfig.resolve,
devtool: productionConfig.devtool,
target: productionConfig.target
});
app.use(`/${assetPath}/app`, webpackMiddleware(frontendCompiler));
});
app.use(`/${assetPath}/app`, webpackMiddleware(frontendCompiler));
} else {
app.use(`/${assetPath}/app`, persistentCacheStatic(path.join(srcRoot, 'public/app')));
app.use(`/${assetPath}/app`, persistentCacheStatic(path.join(srcRoot, 'public/app')));
}
app.use(`/${assetPath}/app-dist`, persistentCacheStatic(path.join(srcRoot, 'public/app-dist')));
app.use(`/${assetPath}/fonts`, persistentCacheStatic(path.join(srcRoot, 'public/fonts')));
@ -56,19 +56,19 @@ async function register(app: express.Application) {
// KaTeX
app.use(
`/${assetPath}/node_modules/katex/dist/katex.min.js`,
persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/katex/dist/katex.min.js')));
`/${assetPath}/node_modules/katex/dist/katex.min.js`,
persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/katex/dist/katex.min.js')));
app.use(
`/${assetPath}/node_modules/katex/dist/contrib/mhchem.min.js`,
persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/katex/dist/contrib/mhchem.min.js')));
`/${assetPath}/node_modules/katex/dist/contrib/mhchem.min.js`,
persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/katex/dist/contrib/mhchem.min.js')));
app.use(
`/${assetPath}/node_modules/katex/dist/contrib/auto-render.min.js`,
persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/katex/dist/contrib/auto-render.min.js')));
`/${assetPath}/node_modules/katex/dist/contrib/auto-render.min.js`,
persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/katex/dist/contrib/auto-render.min.js')));
// expose the whole dist folder
app.use(`/node_modules/katex/dist/`,
express.static(path.join(srcRoot, '..', 'node_modules/katex/dist/')));
express.static(path.join(srcRoot, '..', 'node_modules/katex/dist/')));
app.use(`/${assetPath}/node_modules/katex/dist/`,
persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/katex/dist/')));
persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/katex/dist/')));
app.use(`/${assetPath}/node_modules/dayjs/`, persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/dayjs/')));
app.use(`/${assetPath}/node_modules/force-graph/dist/`, persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/force-graph/dist/')));
@ -98,9 +98,9 @@ async function register(app: express.Application) {
app.use(`/${assetPath}/node_modules/jsplumb/dist/`, persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/jsplumb/dist/')));
app.use(`/${assetPath}/node_modules/vanilla-js-wheel-zoom/dist/`, persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/vanilla-js-wheel-zoom/dist/')));
app.use(`/${assetPath}/node_modules/mark.js/dist/`, persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/mark.js/dist/')));
// Deprecated, https://www.npmjs.com/package/autocomplete.js?activeTab=readme
app.use(`/${assetPath}/node_modules/autocomplete.js/dist/`, persistentCacheStatic(path.join(srcRoot, '..', 'node_modules/autocomplete.js/dist/')));

View File

@ -10,7 +10,7 @@ import { Request, Response } from 'express';
function setupPage(req: Request, res: Response) {
if (sqlInit.isDbInitialized()) {
if (utils.isElectron()) {
handleElectronRedirect();
handleElectronRedirect();
} else {
res.redirect('.');
}

View File

@ -23,10 +23,10 @@ UPDATE attributes SET name = 'name', value = 'value' WHERE type = 'label' AND na
UPDATE attributes SET name = 'name' WHERE type = 'relation' AND name NOT IN (${builtinAttrNames});
UPDATE branches SET prefix = 'prefix' WHERE prefix IS NOT NULL AND prefix != 'recovered';
UPDATE options SET value = 'anonymized' WHERE name IN
('documentId', 'documentSecret', 'encryptedDataKey',
'passwordVerificationHash', 'passwordVerificationSalt',
'passwordDerivedKeySalt', 'username', 'syncServerHost', 'syncProxy')
AND value != '';
('documentId', 'documentSecret', 'encryptedDataKey',
'passwordVerificationHash', 'passwordVerificationSalt',
'passwordDerivedKeySalt', 'username', 'syncServerHost', 'syncProxy')
AND value != '';
VACUUM;
`;
@ -37,15 +37,15 @@ VACUUM;
function getLightAnonymizationScript() {
return `UPDATE blobs SET content = 'text' WHERE content IS NOT NULL AND blobId NOT IN (
SELECT blobId FROM notes WHERE mime IN ('application/javascript;env=backend', 'application/javascript;env=frontend')
UNION ALL
UNION ALL
SELECT blobId FROM revisions WHERE mime IN ('application/javascript;env=backend', 'application/javascript;env=frontend')
);
UPDATE options SET value = 'anonymized' WHERE name IN
('documentId', 'documentSecret', 'encryptedDataKey',
'passwordVerificationHash', 'passwordVerificationSalt',
'passwordDerivedKeySalt', 'username', 'syncServerHost', 'syncProxy')
AND value != '';`;
('documentId', 'documentSecret', 'encryptedDataKey',
'passwordVerificationHash', 'passwordVerificationSalt',
'passwordDerivedKeySalt', 'username', 'syncServerHost', 'syncProxy')
AND value != '';`;
}
async function createAnonymizedCopy(type: "full" | "light") {

View File

@ -14,4 +14,4 @@ export interface SetupStatusResponse {
export interface SetupSyncSeedResponse {
syncVersion: number;
options: OptionRow[]
}
}

View File

@ -48,7 +48,7 @@ function installLocalAppIcon() {
fs.writeFile(desktopFilePath, getDesktopFileContent(), function (err) {
if (err) {
log.error("Desktop icon installation to ~/.local/share/applications failed.");
log.error("Desktop icon installation to ~/.local/share/applications failed.");
}
});
}
@ -66,7 +66,7 @@ function escapePath(path: string) {
}
function getExePath() {
return path.resolve(resourceDir.ELECTRON_APP_ROOT_DIR, 'trilium');
return path.resolve(resourceDir.ELECTRON_APP_ROOT_DIR, 'trilium');
}
export default {

View File

@ -65,11 +65,11 @@ function getAttributeNames(type: string, nameLike: string) {
nameLike = nameLike.toLowerCase();
let names = sql.getColumn<string>(
`SELECT DISTINCT name
FROM attributes
WHERE isDeleted = 0
AND type = ?
AND name LIKE ?`, [type, `%${nameLike}%`]);
`SELECT DISTINCT name
FROM attributes
WHERE isDeleted = 0
AND type = ?
AND name LIKE ?`, [type, `%${nameLike}%`]);
for (const attr of BUILTIN_ATTRIBUTES) {
if (attr.type === type && attr.name.toLowerCase().includes(nameLike) && !names.includes(attr.name)) {

View File

@ -61,53 +61,53 @@ interface NoteAndBranch {
interface Api {
/**
* Note where the script started executing (entrypoint).
* As an analogy, in C this would be the file which contains the main() function of the current process.
*/
* Note where the script started executing (entrypoint).
* As an analogy, in C this would be the file which contains the main() function of the current process.
*/
startNote?: BNote | null;
/**
* Note where the script is currently executing. This comes into play when your script is spread in multiple code
* notes, the script starts in "startNote", but then through function calls may jump into another note (currentNote).
* A similar concept in C would be __FILE__
* Don't mix this up with the concept of active note.
*/
* Note where the script is currently executing. This comes into play when your script is spread in multiple code
* notes, the script starts in "startNote", but then through function calls may jump into another note (currentNote).
* A similar concept in C would be __FILE__
* Don't mix this up with the concept of active note.
*/
currentNote: BNote;
/**
* Entity whose event triggered this execution
*/
* Entity whose event triggered this execution
*/
originEntity?: AbstractBeccaEntity<any> | null;
/**
* Axios library for HTTP requests. See {@link https://axios-http.com} for documentation
* @deprecated use native (browser compatible) fetch() instead
*/
* Axios library for HTTP requests. See {@link https://axios-http.com} for documentation
* @deprecated use native (browser compatible) fetch() instead
*/
axios: typeof axios;
/**
* day.js library for date manipulation. See {@link https://day.js.org} for documentation
*/
* day.js library for date manipulation. See {@link https://day.js.org} for documentation
*/
dayjs: typeof dayjs;
/**
* xml2js library for XML parsing. See {@link https://github.com/Leonidas-from-XIV/node-xml2js} for documentation
*/
* xml2js library for XML parsing. See {@link https://github.com/Leonidas-from-XIV/node-xml2js} for documentation
*/
xml2js: typeof xml2js;
/**
* cheerio library for HTML parsing and manipulation. See {@link https://cheerio.js.org} for documentation
*/
* cheerio library for HTML parsing and manipulation. See {@link https://cheerio.js.org} for documentation
*/
cheerio: typeof cheerio;
/**
* Instance name identifies particular Trilium instance. It can be useful for scripts
* if some action needs to happen on only one specific instance.
*/
* Instance name identifies particular Trilium instance. It can be useful for scripts
* if some action needs to happen on only one specific instance.
*/
getInstanceName(): string | null;
getNote(noteId: string): BNote | null;
getBranch(branchId: string): BBranch | null;
getAttribute(attachmentId: string): BAttribute | null;
@ -118,78 +118,78 @@ interface Api {
getOption(optionName: string): BOption | null;
getOptions(): BOption[];
getAttribute(attributeId: string): BAttribute | null;
/**
* This is a powerful search method - you can search by attributes and their values, e.g.:
* "#dateModified =* MONTH AND #log". See {@link https://triliumnext.github.io/Docs/Wiki/search.html} for full documentation for all options
*/
* This is a powerful search method - you can search by attributes and their values, e.g.:
* "#dateModified =* MONTH AND #log". See {@link https://triliumnext.github.io/Docs/Wiki/search.html} for full documentation for all options
*/
searchForNotes(query: string, searchParams: SearchParams): BNote[];
/**
* This is a powerful search method - you can search by attributes and their values, e.g.:
* "#dateModified =* MONTH AND #log". See {@link https://triliumnext.github.io/Docs/Wiki/search.html} for full documentation for all options
*/
* This is a powerful search method - you can search by attributes and their values, e.g.:
* "#dateModified =* MONTH AND #log". See {@link https://triliumnext.github.io/Docs/Wiki/search.html} for full documentation for all options
*/
searchForNote(query: string, searchParams: SearchParams): BNote | null;
/**
* Retrieves notes with given label name & value
*
* @param name - attribute name
* @param value - attribute value
*/
* Retrieves notes with given label name & value
*
* @param name - attribute name
* @param value - attribute value
*/
getNotesWithLabel(name: string, value?: string): BNote[];
/**
* Retrieves first note with given label name & value
*
* @param name - attribute name
* @param value - attribute value
*/
* Retrieves first note with given label name & value
*
* @param name - attribute name
* @param value - attribute value
*/
getNoteWithLabel(name: string, value?: string): BNote | null;
/**
* If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch.
*
* @param prefix - if branch is created between note and parent note, set this prefix
*/
* If there's no branch between note and parent note, create one. Otherwise, do nothing. Returns the new or existing branch.
*
* @param prefix - if branch is created between note and parent note, set this prefix
*/
ensureNoteIsPresentInParent(noteId: string, parentNoteId: string, prefix: string): {
branch: BBranch | null
};
/**
* If there's a branch between note and parent note, remove it. Otherwise, do nothing.
*/
* If there's a branch between note and parent note, remove it. Otherwise, do nothing.
*/
ensureNoteIsAbsentFromParent(noteId: string, parentNoteId: string): void;
/**
* Based on the value, either create or remove branch between note and parent note.
*
* @param present - true if we want the branch to exist, false if we want it gone
* @param prefix - if branch is created between note and parent note, set this prefix
*/
* Based on the value, either create or remove branch between note and parent note.
*
* @param present - true if we want the branch to exist, false if we want it gone
* @param prefix - if branch is created between note and parent note, set this prefix
*/
toggleNoteInParent(present: true, noteId: string, parentNoteId: string, prefix: string): void;
/**
* Create text note. See also createNewNote() for more options.
*/
* Create text note. See also createNewNote() for more options.
*/
createTextNote(parentNoteId: string, title: string, content: string): NoteAndBranch;
/**
* Create data note - data in this context means object serializable to JSON. Created note will be of type 'code' and
* JSON MIME type. See also createNewNote() for more options.
*/
* Create data note - data in this context means object serializable to JSON. Created note will be of type 'code' and
* JSON MIME type. See also createNewNote() for more options.
*/
createDataNote(parentNoteId: string, title: string, content: {}): NoteAndBranch;
/**
* @returns object contains newly created entities note and branch
*/
* @returns object contains newly created entities note and branch
*/
createNewNote(params: NoteParams): NoteAndBranch;
/**
* @deprecated please use createTextNote() with similar API for simpler use cases or createNewNote() for more complex needs
* @param parentNoteId - create new note under this parent
* @returns object contains newly created entities note and branch
*/
* @deprecated please use createTextNote() with similar API for simpler use cases or createNewNote() for more complex needs
* @param parentNoteId - create new note under this parent
* @returns object contains newly created entities note and branch
*/
createNote(parentNoteId: string, title: string, content: string, extraOptions: Omit<NoteParams, "title" | "content" | "type" | "parentNoteId"> & {
/** should the note be JSON */
json?: boolean;
@ -200,37 +200,37 @@ interface Api {
logSpacedUpdates: Record<string, SpacedUpdate>;
/**
* Log given message to trilium logs and log pane in UI
*/
* Log given message to trilium logs and log pane in UI
*/
log(message: string): void;
/**
* Returns root note of the calendar.
*/
* Returns root note of the calendar.
*/
getRootCalendarNote(): BNote | null;
/**
* Returns day note for given date. If such note doesn't exist, it is created.
*
* @method
* @param date in YYYY-MM-DD format
* @param rootNote - specify calendar root note, normally leave empty to use the default calendar
*/
* Returns day note for given date. If such note doesn't exist, it is created.
*
* @method
* @param date in YYYY-MM-DD format
* @param rootNote - specify calendar root note, normally leave empty to use the default calendar
*/
getDayNote(date: string, rootNote?: BNote): BNote | null;
/**
* Returns today's day note. If such note doesn't exist, it is created.
*
* @param rootNote specify calendar root note, normally leave empty to use the default calendar
*/
* Returns today's day note. If such note doesn't exist, it is created.
*
* @param rootNote specify calendar root note, normally leave empty to use the default calendar
*/
getTodayNote(rootNote?: BNote): BNote | null;
/**
* Returns note for the first date of the week of the given date.
*
* @param date in YYYY-MM-DD format
* @param rootNote - specify calendar root note, normally leave empty to use the default calendar
*/
* Returns note for the first date of the week of the given date.
*
* @param date in YYYY-MM-DD format
* @param rootNote - specify calendar root note, normally leave empty to use the default calendar
*/
getWeekNote(date: string, options: {
// TODO: Deduplicate type with date_notes.ts once ES modules are added.
/** either "monday" (default) or "sunday" */
@ -238,90 +238,90 @@ interface Api {
}, rootNote: BNote): BNote | null;
/**
* Returns month note for given date. If such a note doesn't exist, it is created.
*
* @param date in YYYY-MM format
* @param rootNote - specify calendar root note, normally leave empty to use the default calendar
*/
* Returns month note for given date. If such a note doesn't exist, it is created.
*
* @param date in YYYY-MM format
* @param rootNote - specify calendar root note, normally leave empty to use the default calendar
*/
getMonthNote(date: string, rootNote: BNote): BNote | null;
/**
* Returns year note for given year. If such a note doesn't exist, it is created.
*
* @param year in YYYY format
* @param rootNote - specify calendar root note, normally leave empty to use the default calendar
*/
* Returns year note for given year. If such a note doesn't exist, it is created.
*
* @param year in YYYY format
* @param rootNote - specify calendar root note, normally leave empty to use the default calendar
*/
getYearNote(year: string, rootNote?: BNote): BNote | null;
/**
* Sort child notes of a given note.
*/
* Sort child notes of a given note.
*/
sortNotes(parentNoteId: string, sortConfig: {
/** 'title', 'dateCreated', 'dateModified' or a label name
* See {@link https://triliumnext.github.io/Docs/Wiki/sorting.html} for details. */
* See {@link https://triliumnext.github.io/Docs/Wiki/sorting.html} for details. */
sortBy?: string;
reverse?: boolean;
foldersFirst?: boolean;
}): void;
/**
* This method finds note by its noteId and prefix and either sets it to the given parentNoteId
* or removes the branch (if parentNoteId is not given).
*
* This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix.
*
* @deprecated this method is pretty confusing and serves specialized purpose only
*/
* This method finds note by its noteId and prefix and either sets it to the given parentNoteId
* or removes the branch (if parentNoteId is not given).
*
* This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix.
*
* @deprecated this method is pretty confusing and serves specialized purpose only
*/
setNoteToParent(noteId: string, prefix: string, parentNoteId: string | null): void;
/**
* This functions wraps code which is supposed to be running in transaction. If transaction already
* exists, then we'll use that transaction.
*
* @param func
* @returns result of func callback
*/
* This functions wraps code which is supposed to be running in transaction. If transaction already
* exists, then we'll use that transaction.
*
* @param func
* @returns result of func callback
*/
transactional(func: () => void): any;
/**
* Return randomly generated string of given length. This random string generation is NOT cryptographically secure.
*
* @param length of the string
* @returns random string
*/
* Return randomly generated string of given length. This random string generation is NOT cryptographically secure.
*
* @param length of the string
* @returns random string
*/
randomString(length: number): string;
/**
* @param to escape
* @returns escaped string
*/
* @param to escape
* @returns escaped string
*/
escapeHtml(string: string): string;
/**
* @param string to unescape
* @returns unescaped string
*/
* @param string to unescape
* @returns unescaped string
*/
unescapeHtml(string: string): string;
/**
* sql
* @type {module:sql}
*/
* sql
* @type {module:sql}
*/
sql: any;
getAppInfo(): typeof appInfo;
/**
* Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.
*/
* Creates a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.
*/
createOrUpdateLauncher(opts: {
/** id of the launcher, only alphanumeric at least 6 characters long */
id: string;
/** one of
* - "note" - activating the launcher will navigate to the target note (specified in targetNoteId param)
* - "script" - activating the launcher will execute the script (specified in scriptNoteId param)
* - "customWidget" - the launcher will be rendered with a custom widget (specified in widgetNoteId param)
*/
* - "note" - activating the launcher will navigate to the target note (specified in targetNoteId param)
* - "script" - activating the launcher will execute the script (specified in scriptNoteId param)
* - "customWidget" - the launcher will be rendered with a custom widget (specified in widgetNoteId param)
*/
type: "note" | "script" | "customWidget";
title: string;
/** if true, will be created in the "Visible launchers", otherwise in "Available launchers" */
@ -339,44 +339,44 @@ interface Api {
}): { note: BNote };
/**
* @param format - either 'html' or 'markdown'
*/
* @param format - either 'html' or 'markdown'
*/
exportSubtreeToZipFile(noteId: string, format: "markdown" | "html", zipFilePath: string): Promise<void>;
/**
* Executes given anonymous function on the frontend(s).
* Internally, this serializes the anonymous function into string and sends it to frontend(s) via WebSocket.
* Note that there can be multiple connected frontend instances (e.g. in different tabs). In such case, all
* instances execute the given function.
*
* @param script - script to be executed on the frontend
* @param params - list of parameters to the anonymous function to be sent to frontend
* @returns no return value is provided.
*/
* Executes given anonymous function on the frontend(s).
* Internally, this serializes the anonymous function into string and sends it to frontend(s) via WebSocket.
* Note that there can be multiple connected frontend instances (e.g. in different tabs). In such case, all
* instances execute the given function.
*
* @param script - script to be executed on the frontend
* @param params - list of parameters to the anonymous function to be sent to frontend
* @returns no return value is provided.
*/
runOnFrontend(script: () => void | string, params: []): void;
/**
* Sync process can make data intermittently inconsistent. Scripts which require strong data consistency
* can use this function to wait for a possible sync process to finish and prevent new sync process from starting
* while it is running.
*
* Because this is an async process, the inner callback doesn't have automatic transaction handling, so in case
* you need to make some DB changes, you need to surround your call with api.transactional(...)
*
* @param callback - function to be executed while sync process is not running
* @returns resolves once the callback is finished (callback is awaited)
*/
* Sync process can make data intermittently inconsistent. Scripts which require strong data consistency
* can use this function to wait for a possible sync process to finish and prevent new sync process from starting
* while it is running.
*
* Because this is an async process, the inner callback doesn't have automatic transaction handling, so in case
* you need to make some DB changes, you need to surround your call with api.transactional(...)
*
* @param callback - function to be executed while sync process is not running
* @returns resolves once the callback is finished (callback is awaited)
*/
runOutsideOfSync(callback: () => void): Promise<void>;
/**
* @param backupName - If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file
* @returns resolves once the backup is finished
*/
* @param backupName - If the backupName is e.g. "now", then the backup will be written to "backup-now.db" file
* @returns resolves once the backup is finished
*/
backupNow(backupName: string): Promise<string>;
/**
* This object contains "at your risk" and "no BC guarantees" objects for advanced use cases.
*/
/**
* This object contains "at your risk" and "no BC guarantees" objects for advanced use cases.
*/
__private: {
/** provides access to the backend in-memory object graph, see {@link Becca} */
becca: Becca;
@ -392,9 +392,9 @@ interface Api {
*/
function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
this.startNote = apiParams.startNote;
this.currentNote = currentNote;
this.originEntity = apiParams.originEntity;
for (const key in apiParams) {
@ -416,7 +416,7 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
this.getOption = optionName => becca.getOption(optionName);
this.getOptions = () => optionsService.getOptions();
this.getAttribute = attributeId => becca.getAttribute(attributeId);
this.searchForNotes = (query, searchParams = {}) => {
if (searchParams.includeArchivedNotes === undefined) {
searchParams.includeArchivedNotes = true;
@ -432,14 +432,14 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
return becca.getNotes(noteIds);
};
this.searchForNote = (query, searchParams = {}) => {
const notes = this.searchForNotes(query, searchParams);
return notes.length > 0 ? notes[0] : null;
};
this.getNotesWithLabel = attributeService.getNotesWithLabel;
this.getNotesWithLabel = attributeService.getNotesWithLabel;
this.getNoteWithLabel = attributeService.getNoteWithLabel;
this.ensureNoteIsPresentInParent = cloningService.ensureNoteIsPresentInParent;
this.ensureNoteIsAbsentFromParent = cloningService.ensureNoteIsAbsentFromParent;
@ -458,9 +458,9 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
type: 'code',
mime: 'application/json'
});
this.createNewNote = noteService.createNewNote;
this.createNote = (parentNoteId, title, content = "", _extraOptions = {}) => {
const parentNote = becca.getNote(parentNoteId);
if (!parentNote) {
@ -507,7 +507,7 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
this.logMessages = {};
this.logSpacedUpdates = {};
this.log = message => {
log.info(message);
@ -555,7 +555,7 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
this.sql = sql;
this.getAppInfo = () => appInfo;
this.createOrUpdateLauncher = opts => {
if (!opts.id) { throw new Error("ID is a mandatory parameter for api.createOrUpdateLauncher(opts)"); }
if (!opts.id.match(/[a-z0-9]{6,1000}/i)) { throw new Error(`ID must be an alphanumeric string at least 6 characters long.`); }
@ -650,10 +650,10 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
});
}
};
this.runOutsideOfSync = syncMutex.doExclusively;
this.backupNow = backupService.backupNow;
this.__private = {
becca
}

View File

@ -8,4 +8,4 @@ export interface ApiParams {
pathParams?: string[],
req?: Request,
res?: Response
}
}

View File

@ -2,4 +2,4 @@ export interface Blob {
blobId: string;
content: string | Buffer;
utcDateModified: string;
}
}

View File

@ -1,6 +1,6 @@
/**
* @module
*
*
* Manages the server-side functionality of the code blocks feature, mostly for obtaining the available themes for syntax highlighting.
*/
@ -23,11 +23,11 @@ interface ColorTheme {
/**
* Returns all the supported syntax highlighting themes for code blocks, in groups.
*
*
* The return value is an object where the keys represent groups in their human-readable name (e.g. "Light theme")
* and the values are an array containing the information about every theme. There is also a special group with no
* title (empty string) which should be displayed at the top of the listing pages, without a group.
*
*
* @returns the supported themes, grouped.
*/
export function listSyntaxHighlightingThemes() {
@ -55,9 +55,9 @@ function getStylesDirectory() {
/**
* Reads all the predefined themes by listing all minified CSSes from a given directory.
*
*
* The theme names are mapped against a known list in order to provide more descriptive names such as "Visual Studio 2015 (Dark)" instead of "vs2015".
*
*
* @param path the path to read from. Usually this is the highlight.js `styles` directory.
* @returns the list of themes.
*/
@ -65,13 +65,13 @@ function readThemesFromFileSystem(path: string): ColorTheme[] {
return fs.readdirSync(path)
.filter((el) => el.endsWith(".min.css"))
.map((name) => {
const nameWithoutExtension = name.replace(".min.css", "");
const nameWithoutExtension = name.replace(".min.css", "");
let title = nameWithoutExtension.replace(/-/g, " ");
if (title in themeNames) {
title = (themeNames as Record<string, string>)[title];
}
return {
val: `default:${nameWithoutExtension}`,
title: title
@ -82,7 +82,7 @@ function readThemesFromFileSystem(path: string): ColorTheme[] {
/**
* Groups a list of themes by dark or light themes. This is done simply by checking whether "Dark" is present in the given theme, otherwise it's considered a light theme.
* This generally only works if the theme has a known human-readable name (see {@link #readThemesFromFileSystem()})
*
*
* @param listOfThemes the list of themes to be grouped.
* @returns the grouped themes by light or dark.
*/
@ -102,4 +102,4 @@ function groupThemesByLightOrDark(listOfThemes: ColorTheme[]) {
output[t("code_block.theme_group_light")] = lightThemes;
output[t("code_block.theme_group_dark")] = darkThemes;
return output;
}
}

View File

@ -72,4 +72,4 @@
"vs2015": "Visual Studio 2015 (Dark)",
"xcode": "Xcode (Light)",
"xt256": "xt256 (Dark)"
}
}

View File

@ -23,12 +23,12 @@ class ConsistencyChecks {
private autoFix: boolean;
private unrecoveredConsistencyErrors: boolean;
private fixedIssues: boolean;
private fixedIssues: boolean;
private reloadNeeded: boolean;
/**
* @param autoFix - automatically fix all encountered problems. False is only for debugging during development (fail fast)
*/
* @param autoFix - automatically fix all encountered problems. False is only for debugging during development (fail fast)
*/
constructor(autoFix: boolean) {
this.autoFix = autoFix;
this.unrecoveredConsistencyErrors = false;
@ -138,9 +138,9 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT branchId, branches.noteId
FROM branches
LEFT JOIN notes USING (noteId)
LEFT JOIN notes USING (noteId)
WHERE branches.isDeleted = 0
AND notes.noteId IS NULL`,
AND notes.noteId IS NULL`,
({branchId, noteId}) => {
if (this.autoFix) {
const branch = becca.getBranch(branchId);
@ -160,10 +160,10 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT branchId, branches.parentNoteId AS parentNoteId
FROM branches
LEFT JOIN notes ON notes.noteId = branches.parentNoteId
LEFT JOIN notes ON notes.noteId = branches.parentNoteId
WHERE branches.isDeleted = 0
AND branches.noteId != 'root'
AND notes.noteId IS NULL`,
AND branches.noteId != 'root'
AND notes.noteId IS NULL`,
({branchId, parentNoteId}) => {
if (this.autoFix) {
// Delete the old branch and recreate it with root as parent.
@ -205,9 +205,9 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT attributeId, attributes.noteId
FROM attributes
LEFT JOIN notes USING (noteId)
LEFT JOIN notes USING (noteId)
WHERE attributes.isDeleted = 0
AND notes.noteId IS NULL`,
AND notes.noteId IS NULL`,
({attributeId, noteId}) => {
if (this.autoFix) {
const attribute = becca.getAttribute(attributeId);
@ -227,10 +227,10 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT attributeId, attributes.value AS noteId
FROM attributes
LEFT JOIN notes ON notes.noteId = attributes.value
LEFT JOIN notes ON notes.noteId = attributes.value
WHERE attributes.isDeleted = 0
AND attributes.type = 'relation'
AND notes.noteId IS NULL`,
AND attributes.type = 'relation'
AND notes.noteId IS NULL`,
({attributeId, noteId}) => {
if (this.autoFix) {
const attribute = becca.getAttribute(attributeId);
@ -255,7 +255,7 @@ class ConsistencyChecks {
UNION ALL
SELECT revisionId FROM revisions
)
AND attachments.isDeleted = 0`,
AND attachments.isDeleted = 0`,
({attachmentId, ownerId}) => {
if (this.autoFix) {
const attachment = becca.getAttachment(attachmentId);
@ -282,11 +282,11 @@ class ConsistencyChecks {
// another check might create missing branch
this.findAndFixIssues(`
SELECT branchId,
noteId
noteId
FROM branches
JOIN notes USING (noteId)
JOIN notes USING (noteId)
WHERE notes.isDeleted = 1
AND branches.isDeleted = 0`,
AND branches.isDeleted = 0`,
({branchId, noteId}) => {
if (this.autoFix) {
const branch = becca.getBranch(branchId);
@ -303,11 +303,11 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT branchId,
parentNoteId
parentNoteId
FROM branches
JOIN notes AS parentNote ON parentNote.noteId = branches.parentNoteId
JOIN notes AS parentNote ON parentNote.noteId = branches.parentNoteId
WHERE parentNote.isDeleted = 1
AND branches.isDeleted = 0
AND branches.isDeleted = 0
`, ({branchId, parentNoteId}) => {
if (this.autoFix) {
const branch = becca.getBranch(branchId);
@ -327,9 +327,9 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT DISTINCT notes.noteId
FROM notes
LEFT JOIN branches ON notes.noteId = branches.noteId AND branches.isDeleted = 0
LEFT JOIN branches ON notes.noteId = branches.noteId AND branches.isDeleted = 0
WHERE notes.isDeleted = 0
AND branches.branchId IS NULL
AND branches.branchId IS NULL
`, ({noteId}) => {
if (this.autoFix) {
const branch = new BBranch({
@ -349,21 +349,21 @@ class ConsistencyChecks {
// there should be a unique relationship between note and its parent
this.findAndFixIssues(`
SELECT noteId,
parentNoteId
parentNoteId
FROM branches
WHERE branches.isDeleted = 0
GROUP BY branches.parentNoteId,
branches.noteId
branches.noteId
HAVING COUNT(1) > 1`,
({noteId, parentNoteId}) => {
if (this.autoFix) {
const branchIds = sql.getColumn<string>(
`SELECT branchId
FROM branches
WHERE noteId = ?
and parentNoteId = ?
and isDeleted = 0
ORDER BY utcDateModified`, [noteId, parentNoteId]);
FROM branches
WHERE noteId = ?
and parentNoteId = ?
and isDeleted = 0
ORDER BY utcDateModified`, [noteId, parentNoteId]);
const branches = branchIds.map(branchId => becca.getBranch(branchId));
@ -393,11 +393,11 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT attachmentId,
attachments.ownerId AS noteId
attachments.ownerId AS noteId
FROM attachments
JOIN notes ON notes.noteId = attachments.ownerId
JOIN notes ON notes.noteId = attachments.ownerId
WHERE notes.isDeleted = 1
AND attachments.isDeleted = 0`,
AND attachments.isDeleted = 0`,
({attachmentId, noteId}) => {
if (this.autoFix) {
const attachment = becca.getAttachment(attachmentId);
@ -420,7 +420,7 @@ class ConsistencyChecks {
SELECT noteId, type
FROM notes
WHERE isDeleted = 0
AND type NOT IN (${noteTypesStr})`,
AND type NOT IN (${noteTypesStr})`,
({noteId, type}) => {
if (this.autoFix) {
const note = becca.getNote(noteId);
@ -439,7 +439,7 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT notes.noteId, notes.isProtected, notes.type, notes.mime
FROM notes
LEFT JOIN blobs USING (blobId)
LEFT JOIN blobs USING (blobId)
WHERE blobs.blobId IS NULL
AND notes.isDeleted = 0`,
({noteId, isProtected, type, mime}) => {
@ -494,10 +494,10 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT notes.noteId, notes.type, notes.mime
FROM notes
JOIN blobs USING (blobId)
JOIN blobs USING (blobId)
WHERE isDeleted = 0
AND isProtected = 0
AND content IS NULL`,
AND isProtected = 0
AND content IS NULL`,
({noteId, type, mime}) => {
if (this.autoFix) {
const note = becca.getNote(noteId);
@ -520,7 +520,7 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT revisions.revisionId, blobs.blobId
FROM revisions
LEFT JOIN blobs USING (blobId)
LEFT JOIN blobs USING (blobId)
WHERE blobs.blobId IS NULL`,
({revisionId, blobId}) => {
if (this.autoFix) {
@ -537,7 +537,7 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT attachments.attachmentId, blobs.blobId
FROM attachments
LEFT JOIN blobs USING (blobId)
LEFT JOIN blobs USING (blobId)
WHERE blobs.blobId IS NULL`,
({attachmentId, blobId}) => {
if (this.autoFix) {
@ -554,17 +554,17 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT parentNoteId
FROM branches
JOIN notes ON notes.noteId = branches.parentNoteId
JOIN notes ON notes.noteId = branches.parentNoteId
WHERE notes.isDeleted = 0
AND notes.type == 'search'
AND branches.isDeleted = 0`,
AND notes.type == 'search'
AND branches.isDeleted = 0`,
({parentNoteId}) => {
if (this.autoFix) {
const branchIds = sql.getColumn<string>(`
SELECT branchId
FROM branches
WHERE isDeleted = 0
AND parentNoteId = ?`, [parentNoteId]);
AND parentNoteId = ?`, [parentNoteId]);
const branches = branchIds.map(branchId => becca.getBranch(branchId));
@ -594,8 +594,8 @@ class ConsistencyChecks {
SELECT attributeId
FROM attributes
WHERE isDeleted = 0
AND type = 'relation'
AND value = ''`,
AND type = 'relation'
AND value = ''`,
({attributeId}) => {
if (this.autoFix) {
const relation = becca.getAttribute(attributeId);
@ -612,11 +612,11 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT attributeId,
type
type
FROM attributes
WHERE isDeleted = 0
AND type != 'label'
AND type != 'relation'`,
AND type != 'label'
AND type != 'relation'`,
({attributeId, type}) => {
if (this.autoFix) {
const attribute = becca.getAttribute(attributeId);
@ -634,11 +634,11 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT attributeId,
attributes.noteId
attributes.noteId
FROM attributes
JOIN notes ON attributes.noteId = notes.noteId
WHERE attributes.isDeleted = 0
AND notes.isDeleted = 1`,
AND notes.isDeleted = 1`,
({attributeId, noteId}) => {
if (this.autoFix) {
const attribute = becca.getAttribute(attributeId);
@ -655,12 +655,12 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT attributeId,
attributes.value AS targetNoteId
attributes.value AS targetNoteId
FROM attributes
JOIN notes ON attributes.value = notes.noteId
WHERE attributes.type = 'relation'
AND attributes.isDeleted = 0
AND notes.isDeleted = 1`,
AND attributes.isDeleted = 0
AND notes.isDeleted = 1`,
({attributeId, targetNoteId}) => {
if (this.autoFix) {
const attribute = becca.getAttribute(attributeId);
@ -680,7 +680,7 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT ${key} as entityId
FROM ${entityName}
LEFT JOIN entity_changes ec ON ec.entityName = '${entityName}' AND ec.entityId = ${entityName}.${key}
LEFT JOIN entity_changes ec ON ec.entityName = '${entityName}' AND ec.entityId = ${entityName}.${key}
WHERE ec.id IS NULL`,
({entityId}) => {
const entityRow = sql.getRow<EntityChange>(`SELECT * FROM ${entityName} WHERE ${key} = ?`, [entityId]);
@ -703,12 +703,12 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT id, entityId
FROM entity_changes
LEFT JOIN ${entityName} ON entityId = ${entityName}.${key}
FROM entity_changes
LEFT JOIN ${entityName} ON entityId = ${entityName}.${key}
WHERE
entity_changes.isErased = 0
AND entity_changes.entityName = '${entityName}'
AND ${entityName}.${key} IS NULL`,
entity_changes.isErased = 0
AND entity_changes.entityName = '${entityName}'
AND ${entityName}.${key} IS NULL`,
({id, entityId}) => {
if (this.autoFix) {
sql.execute("DELETE FROM entity_changes WHERE entityName = ? AND entityId = ?", [entityName, entityId]);
@ -721,11 +721,11 @@ class ConsistencyChecks {
this.findAndFixIssues(`
SELECT id, entityId
FROM entity_changes
JOIN ${entityName} ON entityId = ${entityName}.${key}
FROM entity_changes
JOIN ${entityName} ON entityId = ${entityName}.${key}
WHERE
entity_changes.isErased = 1
AND entity_changes.entityName = '${entityName}'`,
entity_changes.isErased = 1
AND entity_changes.entityName = '${entityName}'`,
({id, entityId}) => {
if (this.autoFix) {
sql.execute(`DELETE FROM ${entityName} WHERE ${key} = ?`, [entityId]);

View File

@ -18,12 +18,12 @@ function getEntityHashes() {
const hashRows = sql.disableSlowQueryLogging(
() => sql.getRawRows<HashRow>(`
SELECT entityName,
entityId,
hash,
isErased
entityId,
hash,
isErased
FROM entity_changes
WHERE isSynced = 1
AND entityName != 'note_reordering'`)
AND entityName != 'note_reordering'`)
);
// sorting is faster in memory

View File

@ -29,7 +29,7 @@ function changePassword(currentPassword: string, newPassword: string) {
optionService.setOption('passwordDerivedKeySalt', utils.randomSecureToken(32));
const newPasswordVerificationKey = utils.toBase64(myScryptService.getVerificationHash(newPassword));
if (decryptedDataKey) {
// TODO: what should happen if the decrypted data key is null?
passwordEncryptionService.setDataKey(newPassword, decryptedDataKey);

View File

@ -39,9 +39,9 @@ function putEntityChange(origEntityChange: EntityChange) {
ec.isErased = ec.isErased ? 1 : 0;
ec.id = sql.replace("entity_changes", ec);
if (ec.id) {
maxEntityChangeId = Math.max(maxEntityChangeId, ec.id);
}
if (ec.id) {
maxEntityChangeId = Math.max(maxEntityChangeId, ec.id);
}
cls.putEntityChange(ec);
}
@ -95,7 +95,7 @@ function addEntityChangesForSector(entityName: string, sector: string) {
function addEntityChangesForDependingEntity(sector: string, tableName: string, primaryKeyColumn: string) {
// problem in blobs might be caused by problem in entity referencing the blob
const dependingEntityChanges = sql.getRows<EntityChange>(`
SELECT dep_change.*
SELECT dep_change.*
FROM entity_changes orig_sector
JOIN ${tableName} ON ${tableName}.blobId = orig_sector.entityId
JOIN entity_changes dep_change ON dep_change.entityName = '${tableName}' AND dep_change.entityId = ${tableName}.${primaryKeyColumn}
@ -110,11 +110,11 @@ function addEntityChangesForDependingEntity(sector: string, tableName: string, p
function cleanupEntityChangesForMissingEntities(entityName: string, entityPrimaryKey: string) {
sql.execute(`
DELETE
FROM entity_changes
WHERE
DELETE
FROM entity_changes
WHERE
isErased = 0
AND entityName = '${entityName}'
AND entityName = '${entityName}'
AND entityId NOT IN (SELECT ${entityPrimaryKey} FROM ${entityName})`);
}

View File

@ -1,27 +1,27 @@
export interface EntityChange {
id?: number | null;
noteId?: string;
entityName: string;
entityId: string;
entity?: any;
positions?: Record<string, number>;
hash: string;
utcDateChanged?: string;
utcDateModified?: string;
utcDateCreated?: string;
isSynced: boolean | 1 | 0;
isErased: boolean | 1 | 0;
componentId?: string | null;
changeId?: string | null;
instanceId?: string | null;
id?: number | null;
noteId?: string;
entityName: string;
entityId: string;
entity?: any;
positions?: Record<string, number>;
hash: string;
utcDateChanged?: string;
utcDateModified?: string;
utcDateCreated?: string;
isSynced: boolean | 1 | 0;
isErased: boolean | 1 | 0;
componentId?: string | null;
changeId?: string | null;
instanceId?: string | null;
}
export interface EntityRow {
isDeleted?: boolean;
content?: Buffer | string;
isDeleted?: boolean;
content?: Buffer | string;
}
export interface EntityChangeRecord {
entityChange: EntityChange;
entity?: EntityRow;
entityChange: EntityChange;
entity?: EntityRow;
}

View File

@ -4,4 +4,4 @@ function isDev() {
export default {
isDev
};
};

View File

@ -100,9 +100,9 @@ function eraseUnusedBlobs() {
LEFT JOIN notes ON notes.blobId = blobs.blobId
LEFT JOIN attachments ON attachments.blobId = blobs.blobId
LEFT JOIN revisions ON revisions.blobId = blobs.blobId
WHERE notes.noteId IS NULL
AND attachments.attachmentId IS NULL
AND revisions.revisionId IS NULL`);
WHERE notes.noteId IS NULL
AND attachments.attachmentId IS NULL
AND revisions.revisionId IS NULL`);
if (unusedBlobIds.length === 0) {
return;
@ -181,7 +181,7 @@ export function startScheduledCleanup() {
// first cleanup kickoff 5 minutes after startup
setTimeout(cls.wrap(() => eraseDeletedEntities()), 5 * 60 * 1000);
setTimeout(cls.wrap(() => eraseScheduledAttachments()), 6 * 60 * 1000);
setInterval(cls.wrap(() => eraseDeletedEntities()), 4 * 3600 * 1000);
setInterval(cls.wrap(() => eraseScheduledAttachments()), 3600 * 1000);
});

View File

@ -8,25 +8,25 @@ let instance: TurndownService | null = null;
const fencedCodeBlockFilter: TurndownService.Rule = {
filter: function (node, options) {
return (
options.codeBlockStyle === 'fenced' &&
node.nodeName === 'PRE' &&
node.firstChild !== null &&
node.firstChild.nodeName === 'CODE'
options.codeBlockStyle === 'fenced' &&
node.nodeName === 'PRE' &&
node.firstChild !== null &&
node.firstChild.nodeName === 'CODE'
)
},
replacement: function (content, node, options) {
if (!node.firstChild || !("getAttribute" in node.firstChild) || typeof node.firstChild.getAttribute !== "function") {
return content;
return content;
}
const className = node.firstChild.getAttribute('class') || ''
const language = rewriteLanguageTag((className.match(/language-(\S+)/) || [null, ''])[1]);
return (
'\n\n' + options.fence + language + '\n' +
node.firstChild.textContent +
'\n' + options.fence + '\n\n'
'\n\n' + options.fence + language + '\n' +
node.firstChild.textContent +
'\n' + options.fence + '\n\n'
)
}
};
@ -34,7 +34,7 @@ const fencedCodeBlockFilter: TurndownService.Rule = {
function toMarkdown(content: string) {
if (instance === null) {
instance = new TurndownService({ codeBlockStyle: 'fenced' });
// Filter is heavily based on: https://github.com/mixmark-io/turndown/issues/274#issuecomment-458730974
// Filter is heavily based on: https://github.com/mixmark-io/turndown/issues/274#issuecomment-458730974
instance.addRule('fencedCodeBlock', fencedCodeBlockFilter);
instance.use(turndownPluginGfm.gfm);
}
@ -44,7 +44,7 @@ function toMarkdown(content: string) {
function rewriteLanguageTag(source: string) {
if (!source) {
return source;
return source;
}
if (source === "text-x-trilium-auto") {

View File

@ -63,7 +63,7 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h
if (fileName.length > 30) {
// We use regex to match the extension to preserve multiple dots in extensions (e.g. .tar.gz).
let match = fileName.match(/(\.[a-zA-Z0-9_.!#-]+)$/);
let ext = match ? match[0] : '';
let ext = match ? match[0] : '';
// Crop the extension if extension length exceeds 30
const croppedExt = ext.slice(-30);
// Crop the file name section and append the cropped extension
@ -324,9 +324,9 @@ async function exportToZip(taskContext: TaskContext, branch: BBranch, format: "h
</head>
<body>
<div class="content">
<h1 data-trilium-h1>${htmlTitle}</h1>
<div class="ck-content">${content}</div>
<h1 data-trilium-h1>${htmlTitle}</h1>
<div class="ck-content">${content}</div>
</div>
</body>
</html>`;

View File

@ -281,7 +281,7 @@ interface CheckHiddenExtraOpts {
restoreNames?: boolean;
}
function checkHiddenSubtree(force = false, extraOpts: CheckHiddenExtraOpts = {}) {
function checkHiddenSubtree(force = false, extraOpts: CheckHiddenExtraOpts = {}) {
if (!force && !migrationService.isDbUpToDate()) {
// on-delete hook might get triggered during some future migration and cause havoc
log.info("Will not check hidden subtree until migration is finished.");

View File

@ -6,8 +6,8 @@ function getHost() {
if (envHost && !utils.isElectron) {
return envHost;
}
return config['Network']['host'] || '0.0.0.0';
}
export default getHost();
export default getHost();

View File

@ -11,19 +11,19 @@ export async function initializeTranslations() {
// Initialize translations
await i18next.use(Backend).init({
lng: getCurrentLanguage(),
fallbackLng: "en",
ns: "server",
backend: {
loadPath: join(resourceDir, "translations/{{lng}}/{{ns}}.json")
}
lng: getCurrentLanguage(),
fallbackLng: "en",
ns: "server",
backend: {
loadPath: join(resourceDir, "translations/{{lng}}/{{ns}}.json")
}
});
}
function getCurrentLanguage() {
let language;
if (sql_init.isDbInitialized()) {
language = options.getOptionOrNull("locale");
language = options.getOptionOrNull("locale");
}
if (!language) {

View File

@ -208,7 +208,7 @@ async function resize(buffer: Buffer, quality: number) {
const start = Date.now();
const image = await Jimp.read(buffer);
const image = await Jimp.read(buffer);
if (image.bitmap.width > image.bitmap.height && image.bitmap.width > imageMaxWidthHeight) {
image.resize({ w: imageMaxWidthHeight });

View File

@ -2,4 +2,4 @@ export interface File {
originalname: string;
mimetype: string;
buffer: string | Buffer;
}
}

View File

@ -240,8 +240,8 @@ function importEnex(taskContext: TaskContext, file: File, parentNote: BNote): Pr
function updateDates(note: BNote, utcDateCreated?: string, utcDateModified?: string) {
// it's difficult to force custom dateCreated and dateModified to Note entity, so we do it post-creation with SQL
sql.execute(`
UPDATE notes
SET dateCreated = ?,
UPDATE notes
SET dateCreated = ?,
utcDateCreated = ?,
dateModified = ?,
utcDateModified = ?
@ -314,7 +314,7 @@ function importEnex(taskContext: TaskContext, file: File, parentNote: BNote): Pr
if (typeof resource.content !== "string") {
throw new Error("Missing or wrong content type for resource.");
}
const resourceNote = noteService.createNewNote({
parentNoteId: noteEntity.noteId,
title: resource.title,

View File

@ -114,4 +114,4 @@ export default {
getMime,
getType,
normalizeMimeType
};
};

View File

@ -160,9 +160,9 @@ function importHtml(taskContext: TaskContext, file: File, parentNote: BNote) {
if (taskContext?.data?.safeImport) {
content = htmlSanitizer.sanitize(content);
}
}
const {note} = noteService.createNewNote({
parentNoteId: parentNote.noteId,
title,
@ -171,9 +171,9 @@ function importHtml(taskContext: TaskContext, file: File, parentNote: BNote) {
mime: 'text/html',
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
});
taskContext.increaseProgressCount();
return note;
}

View File

@ -13,7 +13,7 @@ function getDefaultKeyboardActions() {
if (!t("keyboard_actions.note-navigation")) {
throw new Error("Keyboard actions loaded before translations.");
}
const DEFAULT_KEYBOARD_ACTIONS: KeyboardShortcut[] = [
{
separator: t("keyboard_actions.note-navigation")
@ -76,8 +76,8 @@ function getDefaultKeyboardActions() {
description: t("keyboard_actions.sort-child-notes"),
scope: "note-tree"
},
{
separator: t("keyboard_actions.creating-and-moving-notes")
},
@ -149,11 +149,11 @@ function getDefaultKeyboardActions() {
defaultShortcuts: ["CommandOrControl+Shift+X"],
scope: "window"
},
{
separator: t("keyboard_actions.note-clipboard")
},
{
actionName: "copyNotesToClipboard",
defaultShortcuts: ["CommandOrControl+C"],
@ -196,8 +196,8 @@ function getDefaultKeyboardActions() {
description: t("keyboard_actions.duplicate-subtree"),
scope: "note-tree"
},
{
separator: t("keyboard_actions.tabs-and-windows")
},
@ -303,8 +303,8 @@ function getDefaultKeyboardActions() {
description: t("keyboard_actions.last-tab"),
scope: "window"
},
{
separator: t("keyboard_actions.dialogs")
},
@ -350,12 +350,12 @@ function getDefaultKeyboardActions() {
description: t("keyboard_actions.show-help"),
scope: "window"
},
{
separator: t("keyboard_actions.text-note-operations")
},
{
actionName: "addLinkToText",
defaultShortcuts: ["CommandOrControl+L"],
@ -398,11 +398,11 @@ function getDefaultKeyboardActions() {
description: t("keyboard_actions.edit-readonly-note"),
scope: "window"
},
{
separator: t("keyboard_actions.attributes-labels-and-relations")
},
{
actionName: "addNewLabel",
defaultShortcuts: ["Alt+L"],
@ -415,11 +415,11 @@ function getDefaultKeyboardActions() {
description: t("keyboard_actions.create-new-relation"),
scope: "window"
},
{
separator: t("keyboard_actions.ribbon-tabs")
},
{
actionName: "toggleRibbonTabClassicEditor",
defaultShortcuts: [],
@ -492,11 +492,11 @@ function getDefaultKeyboardActions() {
description: t("keyboard_actions.toggle-similar-notes"),
scope: "window"
},
{
separator: t("keyboard_actions.other")
},
{
actionName: "toggleRightPane",
defaultShortcuts: [],
@ -601,10 +601,10 @@ function getDefaultKeyboardActions() {
];
/*
* Apply macOS-specific tweaks.
*/
* Apply macOS-specific tweaks.
*/
const platformModifier = isMac ? 'Meta' : 'Ctrl';
for (const action of DEFAULT_KEYBOARD_ACTIONS) {
if (action.defaultShortcuts) {
action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("CommandOrControl", platformModifier));

View File

@ -5,16 +5,16 @@ export interface KeyboardShortcut {
defaultShortcuts?: string[];
effectiveShortcuts?: string[];
/**
* Scope here means on which element the keyboard shortcuts are attached - this means that for the shortcut to work,
* the focus has to be inside the element.
*
* So e.g. shortcuts with "note-tree" scope work only when the focus is in note tree.
* This allows to have the same shortcut have different actions attached based on the context
* e.g. CTRL-C in note tree does something a bit different from CTRL-C in the text editor.
*/
* Scope here means on which element the keyboard shortcuts are attached - this means that for the shortcut to work,
* the focus has to be inside the element.
*
* So e.g. shortcuts with "note-tree" scope work only when the focus is in note tree.
* This allows to have the same shortcut have different actions attached based on the context
* e.g. CTRL-C in note tree does something a bit different from CTRL-C in the text editor.
*/
scope?: "window" | "note-tree" | "text-detail" | "code-detail";
}
export interface KeyboardShortcutWithRequiredActionName extends KeyboardShortcut {
actionName: string;
}
}

View File

@ -75,8 +75,8 @@ async function migrate() {
await executeMigration(mig);
sql.execute(`UPDATE options
SET value = ?
WHERE name = ?`, [mig.dbVersion.toString(), "dbVersion"]);
SET value = ?
WHERE name = ?`, [mig.dbVersion.toString(), "dbVersion"]);
log.info(`Migration to version ${mig.dbVersion} has been successful.`);
} catch (e: any) {

View File

@ -24,4 +24,4 @@ export interface NoteParams {
utcDateCreated?: string;
ignoreForbiddenParents?: boolean;
target?: "into";
}
}

View File

@ -490,7 +490,7 @@ async function downloadImage(noteId: string, imageUrl: string) {
const title = path.basename(parsedUrl.pathname || "");
const attachment = imageService.saveImageToAttachment(noteId, imageBuffer, title, true, true);
if (attachment.attachmentId) {
imageUrlToAttachmentIdMapping[imageUrl] = attachment.attachmentId;
} else {
@ -810,11 +810,11 @@ function undeleteBranch(branchId: string, deleteId: string, taskContext: TaskCon
noteEntity.save();
const attributeRows = sql.getRows<AttributeRow>(`
SELECT * FROM attributes
WHERE isDeleted = 1
AND deleteId = ?
AND (noteId = ?
OR (type = 'relation' AND value = ?))`, [deleteId, noteRow.noteId, noteRow.noteId]);
SELECT * FROM attributes
WHERE isDeleted = 1
AND deleteId = ?
AND (noteId = ?
OR (type = 'relation' AND value = ?))`, [deleteId, noteRow.noteId, noteRow.noteId]);
for (const attributeRow of attributeRows) {
// relation might point to a note which hasn't been undeleted yet and would thus throw up
@ -824,8 +824,8 @@ function undeleteBranch(branchId: string, deleteId: string, taskContext: TaskCon
const attachmentRows = sql.getRows<AttachmentRow>(`
SELECT * FROM attachments
WHERE isDeleted = 1
AND deleteId = ?
AND ownerId = ?`, [deleteId, noteRow.noteId]);
AND deleteId = ?
AND ownerId = ?`, [deleteId, noteRow.noteId]);
for (const attachmentRow of attachmentRows) {
new BAttachment(attachmentRow).save();
@ -835,8 +835,8 @@ function undeleteBranch(branchId: string, deleteId: string, taskContext: TaskCon
SELECT branches.branchId
FROM branches
WHERE branches.isDeleted = 1
AND branches.deleteId = ?
AND branches.parentNoteId = ?`, [deleteId, noteRow.noteId]);
AND branches.deleteId = ?
AND branches.parentNoteId = ?`, [deleteId, noteRow.noteId]);
for (const childBranchId of childBranchIds) {
undeleteBranch(childBranchId, deleteId, taskContext);
@ -853,9 +853,9 @@ function getUndeletedParentBranchIds(noteId: string, deleteId: string) {
FROM branches
JOIN notes AS parentNote ON parentNote.noteId = branches.parentNoteId
WHERE branches.noteId = ?
AND branches.isDeleted = 1
AND branches.deleteId = ?
AND parentNote.isDeleted = 0`, [noteId, deleteId]);
AND branches.isDeleted = 1
AND branches.deleteId = ?
AND parentNote.isDeleted = 0`, [noteId, deleteId]);
}
function scanForLinks(note: BNote, content: string | Buffer) {
@ -941,7 +941,7 @@ function duplicateSubtreeWithoutRoot(origNoteId: string, newNoteId: string) {
if (origNote == null) {
throw new Error("Unable to find note to duplicate.");
}
const noteIdMapping = getNoteIdMapping(origNote);
for (const childBranch of origNote.getChildBranches()) {
if (childBranch) {

View File

@ -1,12 +1,12 @@
/**
* @module
*
*
* Options are key-value pairs that are used to store information such as user preferences (for example
* the current theme, sync server information), but also information about the state of the application.
*
*
* Although options internally are represented as strings, their value can be interpreted as a number or
* boolean by calling the appropriate methods from this service (e.g. {@link #getOptionInt}).\
*
*
* Generally options are shared across multiple instances of the application via the sync mechanism,
* however it is possible to have options that are local to an instance. For example, the user can select
* a theme on a device and it will not affect other devices.
@ -90,7 +90,7 @@ function setOption(name: string, value: string | number | boolean) {
/**
* Creates a new option in the database, with the given name, value and whether it should be synced.
*
*
* @param name the name of the option to be created.
* @param value the value of the option, as a string. It can then be interpreted as other types such as a number of boolean.
* @param isSynced `true` if the value should be synced across multiple instances (e.g. locale) or `false` if it should be local-only (e.g. theme).

View File

@ -26,17 +26,17 @@ interface NotSyncedOpts {
interface DefaultOption {
name: string;
/**
* The value to initialize the option with, if the option is not already present in the database.
*
* If a function is passed in instead, the function is called if the option does not exist (with access to the current options) and the return value is used instead. Useful to migrate a new option with a value depending on some other option that might be initialized.
*/
* The value to initialize the option with, if the option is not already present in the database.
*
* If a function is passed in instead, the function is called if the option does not exist (with access to the current options) and the return value is used instead. Useful to migrate a new option with a value depending on some other option that might be initialized.
*/
value: string | ((options: OptionMap) => string);
isSynced: boolean;
}
/**
* Initializes the default options for new databases only.
*
*
* @param initialized `true` if the database has been fully initialized (i.e. a new database was created), or `false` if the database is created for sync.
* @param opts additional options to be initialized, for example the sync configuration.
*/
@ -56,10 +56,10 @@ async function initNotSyncedOptions(initialized: boolean, opts: NotSyncedOpts =
optionService.createOption('initialized', initialized ? 'true' : 'false', false);
optionService.createOption('lastSyncedPull', '0', false);
optionService.createOption('lastSyncedPush', '0', false);
optionService.createOption('lastSyncedPush', '0', false);
optionService.createOption('theme', 'next', false);
optionService.createOption('syncServerHost', opts.syncServerHost || '', false);
optionService.createOption('syncServerTimeout', '120000', false);
optionService.createOption('syncProxy', opts.syncProxy || '', false);
@ -155,7 +155,7 @@ const defaultOptions: DefaultOption[] = [
/**
* Initializes the options, by checking which options from {@link #allDefaultOptions()} are missing and registering them. It will also check some environment variables such as safe mode, to make any necessary adjustments.
*
*
* This method is called regardless of whether a new database is created, or an existing database is used.
*/
function initStartupOptions() {

View File

@ -29,13 +29,13 @@ interface Request {
end(payload?: string): void;
}
interface Client {
interface Client {
request(opts: ClientOpts): Request;
}
async function exec<T>(opts: ExecOpts): Promise<T> {
const client = getClient(opts);
// hack for cases where electron.net does not work, but we don't want to set proxy
if (opts.proxy === 'noproxy') {
opts.proxy = null;

View File

@ -17,4 +17,4 @@ export interface ExecOpts {
},
timeout: number;
body?: string | {};
}
}

View File

@ -27,7 +27,7 @@ function executeNote(note: BNote, apiParams: ApiParams) {
if (!bundle) {
throw new Error("Unable to determine bundle.");
}
return executeBundle(bundle, apiParams);
}

View File

@ -12,7 +12,7 @@ class ScriptContext {
notes: {};
apis: {};
allNotes: BNote[];
constructor(allNotes: BNote[], apiParams: ApiParams) {
this.allNotes = allNotes;
this.modules = {};

View File

@ -3,9 +3,9 @@
import BNote from "../../becca/entities/bnote.js";
class NoteSet {
private noteIdSet: Set<string>;
notes: BNote[];
sorted: boolean;

View File

@ -4,7 +4,7 @@ import hoistedNoteService from "../hoisted_note.js";
import { SearchParams } from './services/types.js';
class SearchContext {
fastSearch: boolean;
includeArchivedNotes: boolean;
includeHiddenNotes: boolean;

View File

@ -42,8 +42,8 @@ class SearchResult {
else if (normalizedTitle.startsWith(normalizedQuery)) {
this.score += 500; // Increased to give more weight to prefix matches
}
else if (normalizedTitle.includes(` ${normalizedQuery} `) ||
normalizedTitle.startsWith(`${normalizedQuery} `) ||
else if (normalizedTitle.includes(` ${normalizedQuery} `) ||
normalizedTitle.startsWith(`${normalizedQuery} `) ||
normalizedTitle.endsWith(` ${normalizedQuery}`)) {
this.score += 300; // Increased to better distinguish word matches
}

View File

@ -88,7 +88,7 @@ async function setupSyncFromSyncServer(syncServerHost: string, syncProxy: string
}
await sqlInit.createDatabaseForSync(resp.options, syncServerHost, syncProxy);
triggerSync();
return { result: 'success' };

View File

@ -19,7 +19,7 @@ let statementCache: Record<string, Statement> = {};
function buildDatabase() {
if (process.env.TRILIUM_INTEGRATION_TEST === "memory") {
return buildIntegrationTestDatabase();
return buildIntegrationTestDatabase();
}
return new Database(dataDir.DOCUMENT_PATH);
@ -95,8 +95,8 @@ function upsert<T extends {}>(tableName: string, primaryKey: string, rec: T) {
const updateMarks = keys.map(colName => `${colName} = @${colName}`).join(", ");
const query = `INSERT INTO ${tableName} (${columns}) VALUES (${questionMarks})
ON CONFLICT (${primaryKey}) DO UPDATE SET ${updateMarks}`;
const query = `INSERT INTO ${tableName} (${columns}) VALUES (${questionMarks})
ON CONFLICT (${primaryKey}) DO UPDATE SET ${updateMarks}`;
for (const idx in rec) {
if (rec[idx] === true || rec[idx] === false) {
@ -345,60 +345,60 @@ export default {
replace,
/**
* Get single value from the given query - first column from first returned row.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns single value
*/
* Get single value from the given query - first column from first returned row.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns single value
*/
getValue,
/**
* Get first returned row.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns - map of column name to column value
*/
* Get first returned row.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns - map of column name to column value
*/
getRow,
getRowOrNull,
/**
* Get all returned rows.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns - array of all rows, each row is a map of column name to column value
*/
* Get all returned rows.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns - array of all rows, each row is a map of column name to column value
*/
getRows,
getRawRows,
iterateRows,
getManyRows,
/**
* Get a map of first column mapping to second column.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns - map of first column to second column
*/
* Get a map of first column mapping to second column.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns - map of first column to second column
*/
getMap,
/**
* Get a first column in an array.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns array of first column of all returned rows
*/
* Get a first column in an array.
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
* @returns array of first column of all returned rows
*/
getColumn,
/**
* Execute SQL
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
*/
* Execute SQL
*
* @param query - SQL query with ? used as parameter placeholder
* @param params - array of params if needed
*/
execute,
executeMany,
executeScript,

View File

@ -22,7 +22,7 @@ const dbReady = utils.deferred<void>();
function schemaExists() {
return !!sql.getValue(`SELECT name FROM sqlite_master
WHERE type = 'table' AND name = 'options'`);
WHERE type = 'table' AND name = 'options'`);
}
function isDbInitialized() {
@ -87,7 +87,7 @@ async function createInitialDatabase() {
isExpanded: true,
notePosition: 10
}).save();
optionsInitService.initDocumentOptions();
optionsInitService.initNotSyncedOptions(true, {});
optionsInitService.initStartupOptions();
@ -131,7 +131,7 @@ async function createDatabaseForSync(options: OptionRow[], syncServerHost = '',
// We have to import async since options init requires keyboard actions which require translations.
const optionsInitService = (await import("./options_init.js")).default;
sql.transactional(() => {
sql.executeScript(schema);
@ -171,22 +171,22 @@ function initializeDb() {
cls.init(initDbConnection);
log.info(`DB size: ${getDbSize()} KB`);
dbReady.then(() => {
if (config.General && config.General.noBackup === true) {
log.info("Disabling scheduled backups.");
return;
}
setInterval(() => backup.regularBackup(), 4 * 60 * 60 * 1000);
// kickoff first backup soon after start up
setTimeout(() => backup.regularBackup(), 5 * 60 * 1000);
// optimize is usually inexpensive no-op, so running it semi-frequently is not a big deal
setTimeout(() => optimize(), 60 * 60 * 1000);
setInterval(() => optimize(), 10 * 60 * 60 * 1000);
});
}

View File

@ -153,7 +153,7 @@ async function doLogin(): Promise<SyncContext> {
return syncContext;
}
async function pullChanges(syncContext: SyncContext) {
async function pullChanges(syncContext: SyncContext) {
while (true) {
const lastSyncedPull = getLastSyncedPull();
const logMarkerId = utils.randomString(10); // to easily pair sync events between client and server logs

View File

@ -14,7 +14,7 @@ class TaskContext {
private lastSentCountTs: number;
data: TaskData | null;
noteDeletionHandlerTriggered: boolean;
constructor(taskId: string, taskType: string | null = null, data: {} | null = {}) {
this.taskId = taskId;
this.taskType = taskType;

View File

@ -272,14 +272,14 @@ function timeLimit<T>(promise: Promise<T>, limitMs: number, errorMessage?: strin
}
interface DeferredPromise<T> extends Promise<T> {
resolve: (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void
resolve: (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void
}
function deferred<T>(): DeferredPromise<T> {
return (() => {
let resolve!: (value: T | PromiseLike<T>) => void;
let reject!: (reason?: any) => void;
let reject!: (reason?: any) => void;
let promise = new Promise<T>((res, rej) => {
resolve = res;
@ -321,7 +321,7 @@ function isString(x: any) {
/**
* Returns the directory for resources. On Electron builds this corresponds to the `resources` subdirectory inside the distributable package.
* On development builds, this simply refers to the root directory of the application.
*
*
* @returns the resource dir.
*/
export function getResourceDir() {
@ -329,7 +329,7 @@ export function getResourceDir() {
return process.resourcesPath;
} else {
return join(dirname(fileURLToPath(import.meta.url)), "..", "..");
}
}
}
export default {

View File

@ -58,7 +58,7 @@ async function createMainWindow(app: App) {
}
]);
}
const windowStateKeeper = (await import('electron-window-state')).default; // should not be statically imported
const mainWindowState = windowStateKeeper({
@ -71,7 +71,7 @@ async function createMainWindow(app: App) {
const { BrowserWindow } = (await import('electron')); // should not be statically imported
mainWindow = new BrowserWindow({
x: mainWindowState.x,
@ -84,7 +84,7 @@ async function createMainWindow(app: App) {
contextIsolation: false,
spellcheck: spellcheckEnabled,
webviewTag: true
},
},
icon: getIcon(),
...getWindowExtraOpts()
});
@ -99,7 +99,7 @@ async function createMainWindow(app: App) {
app.on('second-instance', (event, commandLine) => {
if (commandLine.includes('--new-window')) {
createExtraWindow("");
createExtraWindow("");
} else if (mainWindow) {
// Someone tried to run a second instance, we should focus our window.
// see www.ts "requestSingleInstanceLock" for the rest of this logic with explanation
@ -146,7 +146,7 @@ function configureWebContents(webContents: WebContents, spellcheckEnabled: boole
async function openExternal() {
(await import('electron')).shell.openExternal(details.url);
}
openExternal();
return { action: 'deny' }
});

View File

@ -35,12 +35,12 @@ interface Message {
shrinkImages?: boolean
} | null,
lastSyncedPush?: number | null,
progressCount?: number;
taskId?: string;
taskType?: string | null;
message?: string;
reason?: string;
reason?: string;
result?: string | Record<string, string | undefined>;
script?: string;