refactored note_content_protected_fulltext.js and note_content_unprotected_fulltext.js into one class

This commit is contained in:
zadam 2022-05-11 21:33:41 +02:00
parent 963c18b8e4
commit 91d23c540a
6 changed files with 89 additions and 173 deletions

122
package-lock.json generated
View File

@ -19,8 +19,8 @@
"commonmark": "0.30.0", "commonmark": "0.30.0",
"cookie-parser": "1.4.6", "cookie-parser": "1.4.6",
"csurf": "1.11.0", "csurf": "1.11.0",
"dayjs": "1.11.1", "dayjs": "1.11.2",
"ejs": "3.1.7", "ejs": "3.1.8",
"electron-debug": "3.2.0", "electron-debug": "3.2.0",
"electron-dl": "3.3.1", "electron-dl": "3.3.1",
"electron-find": "1.0.7", "electron-find": "1.0.7",
@ -28,7 +28,7 @@
"express": "4.18.1", "express": "4.18.1",
"express-partial-content": "1.0.2", "express-partial-content": "1.0.2",
"express-rate-limit": "6.4.0", "express-rate-limit": "6.4.0",
"express-session": "1.17.2", "express-session": "1.17.3",
"fs-extra": "10.1.0", "fs-extra": "10.1.0",
"helmet": "5.0.2", "helmet": "5.0.2",
"html": "1.0.0", "html": "1.0.0",
@ -70,7 +70,7 @@
}, },
"devDependencies": { "devDependencies": {
"cross-env": "7.0.3", "cross-env": "7.0.3",
"electron": "16.2.4", "electron": "16.2.6",
"electron-builder": "23.0.3", "electron-builder": "23.0.3",
"electron-packager": "15.5.1", "electron-packager": "15.5.1",
"electron-rebuild": "3.2.7", "electron-rebuild": "3.2.7",
@ -79,7 +79,7 @@
"jsdoc": "3.6.10", "jsdoc": "3.6.10",
"lorem-ipsum": "2.0.4", "lorem-ipsum": "2.0.4",
"rcedit": "3.0.1", "rcedit": "3.0.1",
"webpack": "5.72.0", "webpack": "5.72.1",
"webpack-cli": "4.9.2" "webpack-cli": "4.9.2"
}, },
"optionalDependencies": { "optionalDependencies": {
@ -3200,9 +3200,9 @@
} }
}, },
"node_modules/dayjs": { "node_modules/dayjs": {
"version": "1.11.1", "version": "1.11.2",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.1.tgz", "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.2.tgz",
"integrity": "sha512-ER7EjqVAMkRRsxNCC5YqJ9d9VQYuWdGt7aiH2qA5R5wt8ZmWaP2dLUSIK6y/kVzLMlmh1Tvu5xUf4M/wdGJ5KA==" "integrity": "sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw=="
}, },
"node_modules/debug": { "node_modules/debug": {
"version": "4.3.3", "version": "4.3.3",
@ -3596,9 +3596,9 @@
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
}, },
"node_modules/ejs": { "node_modules/ejs": {
"version": "3.1.7", "version": "3.1.8",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.7.tgz", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
"integrity": "sha512-BIar7R6abbUxDA3bfXrO4DSgwo8I+fB5/1zgujl3HLLjwd6+9iOnrT+t3grn2qbk9vOgBubXOFwX2m9axoFaGw==", "integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
"dependencies": { "dependencies": {
"jake": "^10.8.5" "jake": "^10.8.5"
}, },
@ -3610,9 +3610,9 @@
} }
}, },
"node_modules/electron": { "node_modules/electron": {
"version": "16.2.4", "version": "16.2.6",
"resolved": "https://registry.npmjs.org/electron/-/electron-16.2.4.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-16.2.6.tgz",
"integrity": "sha512-A40aU+gh41EtyspwEBMSuy5KBB56Z8OYSDsqZK9Y8nJdVIFKDtp824x/jnU7N6zNnzVil6oDIFBMGp/hkFu6FQ==", "integrity": "sha512-FJLnIu318WNh1WigMmWqSidOPwipwym2Qi3Hs/YY6znquztf6ZJuaq/TdJJyHIJHld+znG0hSmq3VbyW5KUr9A==",
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"@electron/get": "^1.13.0", "@electron/get": "^1.13.0",
@ -4630,9 +4630,9 @@
} }
}, },
"node_modules/enhanced-resolve": { "node_modules/enhanced-resolve": {
"version": "5.9.2", "version": "5.9.3",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.9.2.tgz", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.9.3.tgz",
"integrity": "sha512-GIm3fQfwLJ8YZx2smuHpBKkXC1yOk+OBEmKckVyL0i/ea8mqDEykK3ld5dgH1QYPNyT/lIllxV2LULnxCHaHkA==", "integrity": "sha512-Bq9VSor+kjvW3f9/MiiR4eE3XYgOl7/rS8lnSxbRbF3kS0B2r+Y9w5krBWxZgDxASVZbdYrn5wT4j/Wb0J9qow==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"graceful-fs": "^4.2.4", "graceful-fs": "^4.2.4",
@ -4960,11 +4960,11 @@
} }
}, },
"node_modules/express-session": { "node_modules/express-session": {
"version": "1.17.2", "version": "1.17.3",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.2.tgz", "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
"integrity": "sha512-mPcYcLA0lvh7D4Oqr5aNJFMtBMKPLl++OKKxkHzZ0U0oDq1rpKBnkR5f5vCHR26VeArlTOEF9td4x5IjICksRQ==", "integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
"dependencies": { "dependencies": {
"cookie": "0.4.1", "cookie": "0.4.2",
"cookie-signature": "1.0.6", "cookie-signature": "1.0.6",
"debug": "2.6.9", "debug": "2.6.9",
"depd": "~2.0.0", "depd": "~2.0.0",
@ -4978,9 +4978,9 @@
} }
}, },
"node_modules/express-session/node_modules/cookie": { "node_modules/express-session/node_modules/cookie": {
"version": "0.4.1", "version": "0.4.2",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==", "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
"engines": { "engines": {
"node": ">= 0.6" "node": ">= 0.6"
} }
@ -6745,10 +6745,10 @@
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=" "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg="
}, },
"node_modules/json-parse-better-errors": { "node_modules/json-parse-even-better-errors": {
"version": "1.0.2", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
"integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==",
"dev": true "dev": true
}, },
"node_modules/json-schema": { "node_modules/json-schema": {
@ -10323,9 +10323,9 @@
} }
}, },
"node_modules/webpack": { "node_modules/webpack": {
"version": "5.72.0", "version": "5.72.1",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.0.tgz", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.1.tgz",
"integrity": "sha512-qmSmbspI0Qo5ld49htys8GY9XhS9CGqFoHTsOVAnjBdg0Zn79y135R+k4IR4rKK6+eKaabMhJwiVB7xw0SJu5w==", "integrity": "sha512-dXG5zXCLspQR4krZVR6QgajnZOjW2K/djHvdcRaDQvsjV9z9vaW6+ja5dZOYbqBBjF6kGXka/2ZyxNdc+8Jung==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@types/eslint-scope": "^3.7.3", "@types/eslint-scope": "^3.7.3",
@ -10337,13 +10337,13 @@
"acorn-import-assertions": "^1.7.6", "acorn-import-assertions": "^1.7.6",
"browserslist": "^4.14.5", "browserslist": "^4.14.5",
"chrome-trace-event": "^1.0.2", "chrome-trace-event": "^1.0.2",
"enhanced-resolve": "^5.9.2", "enhanced-resolve": "^5.9.3",
"es-module-lexer": "^0.9.0", "es-module-lexer": "^0.9.0",
"eslint-scope": "5.1.1", "eslint-scope": "5.1.1",
"events": "^3.2.0", "events": "^3.2.0",
"glob-to-regexp": "^0.4.1", "glob-to-regexp": "^0.4.1",
"graceful-fs": "^4.2.9", "graceful-fs": "^4.2.9",
"json-parse-better-errors": "^1.0.2", "json-parse-even-better-errors": "^2.3.1",
"loader-runner": "^4.2.0", "loader-runner": "^4.2.0",
"mime-types": "^2.1.27", "mime-types": "^2.1.27",
"neo-async": "^2.6.2", "neo-async": "^2.6.2",
@ -13413,9 +13413,9 @@
} }
}, },
"dayjs": { "dayjs": {
"version": "1.11.1", "version": "1.11.2",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.1.tgz", "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.2.tgz",
"integrity": "sha512-ER7EjqVAMkRRsxNCC5YqJ9d9VQYuWdGt7aiH2qA5R5wt8ZmWaP2dLUSIK6y/kVzLMlmh1Tvu5xUf4M/wdGJ5KA==" "integrity": "sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw=="
}, },
"debug": { "debug": {
"version": "4.3.3", "version": "4.3.3",
@ -13721,17 +13721,17 @@
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
}, },
"ejs": { "ejs": {
"version": "3.1.7", "version": "3.1.8",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.7.tgz", "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
"integrity": "sha512-BIar7R6abbUxDA3bfXrO4DSgwo8I+fB5/1zgujl3HLLjwd6+9iOnrT+t3grn2qbk9vOgBubXOFwX2m9axoFaGw==", "integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
"requires": { "requires": {
"jake": "^10.8.5" "jake": "^10.8.5"
} }
}, },
"electron": { "electron": {
"version": "16.2.4", "version": "16.2.6",
"resolved": "https://registry.npmjs.org/electron/-/electron-16.2.4.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-16.2.6.tgz",
"integrity": "sha512-A40aU+gh41EtyspwEBMSuy5KBB56Z8OYSDsqZK9Y8nJdVIFKDtp824x/jnU7N6zNnzVil6oDIFBMGp/hkFu6FQ==", "integrity": "sha512-FJLnIu318WNh1WigMmWqSidOPwipwym2Qi3Hs/YY6znquztf6ZJuaq/TdJJyHIJHld+znG0hSmq3VbyW5KUr9A==",
"requires": { "requires": {
"@electron/get": "^1.13.0", "@electron/get": "^1.13.0",
"@types/node": "^14.6.2", "@types/node": "^14.6.2",
@ -14503,9 +14503,9 @@
} }
}, },
"enhanced-resolve": { "enhanced-resolve": {
"version": "5.9.2", "version": "5.9.3",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.9.2.tgz", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.9.3.tgz",
"integrity": "sha512-GIm3fQfwLJ8YZx2smuHpBKkXC1yOk+OBEmKckVyL0i/ea8mqDEykK3ld5dgH1QYPNyT/lIllxV2LULnxCHaHkA==", "integrity": "sha512-Bq9VSor+kjvW3f9/MiiR4eE3XYgOl7/rS8lnSxbRbF3kS0B2r+Y9w5krBWxZgDxASVZbdYrn5wT4j/Wb0J9qow==",
"dev": true, "dev": true,
"requires": { "requires": {
"graceful-fs": "^4.2.4", "graceful-fs": "^4.2.4",
@ -14780,11 +14780,11 @@
"requires": {} "requires": {}
}, },
"express-session": { "express-session": {
"version": "1.17.2", "version": "1.17.3",
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.2.tgz", "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
"integrity": "sha512-mPcYcLA0lvh7D4Oqr5aNJFMtBMKPLl++OKKxkHzZ0U0oDq1rpKBnkR5f5vCHR26VeArlTOEF9td4x5IjICksRQ==", "integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
"requires": { "requires": {
"cookie": "0.4.1", "cookie": "0.4.2",
"cookie-signature": "1.0.6", "cookie-signature": "1.0.6",
"debug": "2.6.9", "debug": "2.6.9",
"depd": "~2.0.0", "depd": "~2.0.0",
@ -14795,9 +14795,9 @@
}, },
"dependencies": { "dependencies": {
"cookie": { "cookie": {
"version": "0.4.1", "version": "0.4.2",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==" "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA=="
}, },
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
@ -16110,10 +16110,10 @@
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=" "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg="
}, },
"json-parse-better-errors": { "json-parse-even-better-errors": {
"version": "1.0.2", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
"integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==",
"dev": true "dev": true
}, },
"json-schema": { "json-schema": {
@ -18906,9 +18906,9 @@
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==" "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g=="
}, },
"webpack": { "webpack": {
"version": "5.72.0", "version": "5.72.1",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.0.tgz", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.1.tgz",
"integrity": "sha512-qmSmbspI0Qo5ld49htys8GY9XhS9CGqFoHTsOVAnjBdg0Zn79y135R+k4IR4rKK6+eKaabMhJwiVB7xw0SJu5w==", "integrity": "sha512-dXG5zXCLspQR4krZVR6QgajnZOjW2K/djHvdcRaDQvsjV9z9vaW6+ja5dZOYbqBBjF6kGXka/2ZyxNdc+8Jung==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/eslint-scope": "^3.7.3", "@types/eslint-scope": "^3.7.3",
@ -18920,13 +18920,13 @@
"acorn-import-assertions": "^1.7.6", "acorn-import-assertions": "^1.7.6",
"browserslist": "^4.14.5", "browserslist": "^4.14.5",
"chrome-trace-event": "^1.0.2", "chrome-trace-event": "^1.0.2",
"enhanced-resolve": "^5.9.2", "enhanced-resolve": "^5.9.3",
"es-module-lexer": "^0.9.0", "es-module-lexer": "^0.9.0",
"eslint-scope": "5.1.1", "eslint-scope": "5.1.1",
"events": "^3.2.0", "events": "^3.2.0",
"glob-to-regexp": "^0.4.1", "glob-to-regexp": "^0.4.1",
"graceful-fs": "^4.2.9", "graceful-fs": "^4.2.9",
"json-parse-better-errors": "^1.0.2", "json-parse-even-better-errors": "^2.3.1",
"loader-runner": "^4.2.0", "loader-runner": "^4.2.0",
"mime-types": "^2.1.27", "mime-types": "^2.1.27",
"neo-async": "^2.6.2", "neo-async": "^2.6.2",

View File

@ -33,8 +33,8 @@
"commonmark": "0.30.0", "commonmark": "0.30.0",
"cookie-parser": "1.4.6", "cookie-parser": "1.4.6",
"csurf": "1.11.0", "csurf": "1.11.0",
"dayjs": "1.11.1", "dayjs": "1.11.2",
"ejs": "3.1.7", "ejs": "3.1.8",
"electron-debug": "3.2.0", "electron-debug": "3.2.0",
"electron-dl": "3.3.1", "electron-dl": "3.3.1",
"electron-find": "1.0.7", "electron-find": "1.0.7",
@ -43,7 +43,7 @@
"express": "4.18.1", "express": "4.18.1",
"express-partial-content": "1.0.2", "express-partial-content": "1.0.2",
"express-rate-limit": "6.4.0", "express-rate-limit": "6.4.0",
"express-session": "1.17.2", "express-session": "1.17.3",
"fs-extra": "10.1.0", "fs-extra": "10.1.0",
"helmet": "5.0.2", "helmet": "5.0.2",
"html": "1.0.0", "html": "1.0.0",
@ -82,7 +82,7 @@
}, },
"devDependencies": { "devDependencies": {
"cross-env": "7.0.3", "cross-env": "7.0.3",
"electron": "16.2.4", "electron": "16.2.6",
"electron-builder": "23.0.3", "electron-builder": "23.0.3",
"electron-packager": "15.5.1", "electron-packager": "15.5.1",
"electron-rebuild": "3.2.7", "electron-rebuild": "3.2.7",
@ -91,7 +91,7 @@
"jsdoc": "3.6.10", "jsdoc": "3.6.10",
"lorem-ipsum": "2.0.4", "lorem-ipsum": "2.0.4",
"rcedit": "3.0.1", "rcedit": "3.0.1",
"webpack": "5.72.0", "webpack": "5.72.1",
"webpack-cli": "4.9.2" "webpack-cli": "4.9.2"
}, },
"optionalDependencies": { "optionalDependencies": {

View File

@ -58,11 +58,8 @@ describe("Parser", () => {
expect(subs[0].constructor.name).toEqual("NoteFlatTextExp"); expect(subs[0].constructor.name).toEqual("NoteFlatTextExp");
expect(subs[0].tokens).toEqual(["hello", "hi"]); expect(subs[0].tokens).toEqual(["hello", "hi"]);
expect(subs[1].constructor.name).toEqual("NoteContentProtectedFulltextExp"); expect(subs[1].constructor.name).toEqual("NoteContentFulltextExp");
expect(subs[1].tokens).toEqual(["hello", "hi"]); expect(subs[1].tokens).toEqual(["hello", "hi"]);
expect(subs[2].constructor.name).toEqual("NoteContentUnprotectedFulltextExp");
expect(subs[2].tokens).toEqual(["hello", "hi"]);
}); });
it("simple label comparison", () => { it("simple label comparison", () => {

View File

@ -8,8 +8,7 @@ const protectedSessionService = require('../../protected_session');
const striptags = require('striptags'); const striptags = require('striptags');
const utils = require("../../utils"); const utils = require("../../utils");
// FIXME: create common subclass with NoteContentUnprotectedFulltextExp to avoid duplication class NoteContentFulltextExp extends Expression {
class NoteContentProtectedFulltextExp extends Expression {
constructor(operator, {tokens, raw, flatText}) { constructor(operator, {tokens, raw, flatText}) {
super(); super();
@ -24,28 +23,28 @@ class NoteContentProtectedFulltextExp extends Expression {
execute(inputNoteSet) { execute(inputNoteSet) {
const resultNoteSet = new NoteSet(); const resultNoteSet = new NoteSet();
if (!protectedSessionService.isProtectedSessionAvailable()) {
return resultNoteSet;
}
const sql = require('../../sql'); const sql = require('../../sql');
for (let {noteId, type, mime, content} of sql.iterateRows(` for (let {noteId, type, mime, content, isProtected} of sql.iterateRows(`
SELECT noteId, type, mime, content SELECT noteId, type, mime, content, isProtected
FROM notes JOIN note_contents USING (noteId) FROM notes JOIN note_contents USING (noteId)
WHERE type IN ('text', 'code', 'mermaid') AND isDeleted = 0 AND isProtected = 1`)) { WHERE type IN ('text', 'code', 'mermaid') AND isDeleted = 0`)) {
if (!inputNoteSet.hasNoteId(noteId) || !(noteId in becca.notes)) { if (!inputNoteSet.hasNoteId(noteId) || !(noteId in becca.notes)) {
continue; continue;
} }
try { if (isProtected) {
content = protectedSessionService.decryptString(content); if (!protectedSessionService.isProtectedSessionAvailable()) {
} continue;
catch (e) { }
log.info(`Cannot decrypt content of note ${noteId}`);
continue; try {
content = protectedSessionService.decryptString(content);
} catch (e) {
log.info(`Cannot decrypt content of note ${noteId}`);
continue;
}
} }
content = this.preprocessContent(content, type, mime); content = this.preprocessContent(content, type, mime);
@ -82,8 +81,9 @@ class NoteContentProtectedFulltextExp extends Expression {
content = content.replace(/ /g, ' '); content = content.replace(/ /g, ' ');
} }
return content;
return content.trim();
} }
} }
module.exports = NoteContentProtectedFulltextExp; module.exports = NoteContentFulltextExp;

View File

@ -1,75 +0,0 @@
"use strict";
const Expression = require('./expression');
const NoteSet = require('../note_set');
const becca = require('../../../becca/becca');
const striptags = require('striptags');
const utils = require("../../utils");
// FIXME: create common subclass with NoteContentProtectedFulltextExp to avoid duplication
class NoteContentUnprotectedFulltextExp extends Expression {
constructor(operator, {tokens, raw, flatText}) {
super();
if (operator !== '*=*') {
throw new Error(`Note content can be searched only with *=* operator`);
}
this.tokens = tokens;
this.raw = !!raw;
this.flatText = !!flatText;
}
execute(inputNoteSet) {
const resultNoteSet = new NoteSet();
const sql = require('../../sql');
for (let {noteId, type, mime, content} of sql.iterateRows(`
SELECT noteId, type, mime, content
FROM notes JOIN note_contents USING (noteId)
WHERE type IN ('text', 'code', 'mermaid') AND isDeleted = 0 AND isProtected = 0`)) {
if (!inputNoteSet.hasNoteId(noteId) || !(noteId in becca.notes)) {
continue;
}
content = this.preprocessContent(content, type, mime);
const nonMatchingToken = this.tokens.find(token =>
!content.includes(token) &&
(
// in case of default fulltext search we should consider both title, attrs and content
// so e.g. "hello world" should match when "hello" is in title and "world" in content
!this.flatText
|| !becca.notes[noteId].getFlatText().includes(token)
)
);
if (!nonMatchingToken) {
resultNoteSet.add(becca.notes[noteId]);
}
}
return resultNoteSet;
}
preprocessContent(content, type, mime) {
content = utils.normalize(content.toString());
if (type === 'text' && mime === 'text/html') {
if (!this.raw && content.length < 20000) { // striptags is slow for very large notes
// allow link to preserve URLs: https://github.com/zadam/trilium/issues/2412
content = striptags(content, ['a']);
// at least the closing tag can be easily stripped
content = content.replace(/<\/a>/ig, "");
}
content = content.replace(/&nbsp;/g, ' ');
}
return content;
}
}
module.exports = NoteContentUnprotectedFulltextExp;

View File

@ -12,8 +12,7 @@ const PropertyComparisonExp = require('../expressions/property_comparison');
const AttributeExistsExp = require('../expressions/attribute_exists'); const AttributeExistsExp = require('../expressions/attribute_exists');
const LabelComparisonExp = require('../expressions/label_comparison'); const LabelComparisonExp = require('../expressions/label_comparison');
const NoteFlatTextExp = require('../expressions/note_flat_text'); const NoteFlatTextExp = require('../expressions/note_flat_text');
const NoteContentProtectedFulltextExp = require('../expressions/note_content_protected_fulltext'); const NoteContentFulltextExp = require('../expressions/note_content_fulltext.js');
const NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext');
const OrderByAndLimitExp = require('../expressions/order_by_and_limit'); const OrderByAndLimitExp = require('../expressions/order_by_and_limit');
const AncestorExp = require("../expressions/ancestor"); const AncestorExp = require("../expressions/ancestor");
const buildComparator = require('./build_comparator'); const buildComparator = require('./build_comparator');
@ -32,8 +31,7 @@ function getFulltext(tokens, searchContext) {
if (!searchContext.fastSearch) { if (!searchContext.fastSearch) {
return new OrExp([ return new OrExp([
new NoteFlatTextExp(tokens), new NoteFlatTextExp(tokens),
new NoteContentProtectedFulltextExp('*=*', {tokens, flatText: true}), new NoteContentFulltextExp('*=*', {tokens, flatText: true})
new NoteContentUnprotectedFulltextExp('*=*', {tokens, flatText: true})
]); ]);
} }
else { else {
@ -140,10 +138,7 @@ function getExpression(tokens, searchContext, level = 0) {
i++; i++;
return new OrExp([ return new NoteContentFulltextExp(operator, {tokens: [tokens[i].token], raw });
new NoteContentUnprotectedFulltextExp(operator, {tokens: [tokens[i].token], raw }),
new NoteContentProtectedFulltextExp(operator, {tokens: [tokens[i].token], raw })
]);
} }
if (tokens[i].token === 'parents') { if (tokens[i].token === 'parents') {
@ -196,8 +191,7 @@ function getExpression(tokens, searchContext, level = 0) {
return new OrExp([ return new OrExp([
new PropertyComparisonExp(searchContext, 'title', '*=*', tokens[i].token), new PropertyComparisonExp(searchContext, 'title', '*=*', tokens[i].token),
new NoteContentProtectedFulltextExp('*=*', {tokens: [tokens[i].token]}), new NoteContentFulltextExp('*=*', {tokens: [tokens[i].token]})
new NoteContentUnprotectedFulltextExp('*=*', {tokens: [tokens[i].token]})
]); ]);
} }