From db309a2d4af6d816110b06875ba0df6979ce7c7e Mon Sep 17 00:00:00 2001 From: Lete114 Date: Tue, 20 Sep 2022 14:15:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=E4=B8=A5=E8=B0=A8=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E6=95=B0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 321 +++++++++++++++++++++++++++++-- package.json | 1 + src/client/view/submit.svelte | 75 +++++--- src/server/utils/commentUtils.js | 44 ++--- 4 files changed, 376 insertions(+), 65 deletions(-) diff --git a/package-lock.json b/package-lock.json index 543f4f6..fbbc2fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1043,6 +1043,11 @@ "through": ">=2.2.7 <3" } }, + "abab": { + "version": "2.0.6", + "resolved": "https://mirrors.cloud.tencent.com/npm/abab/-/abab-2.0.6.tgz", + "integrity": "sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==" + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -1051,8 +1056,28 @@ "acorn": { "version": "8.7.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", - "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", - "dev": true + "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==" + }, + "acorn-globals": { + "version": "6.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/acorn-globals/-/acorn-globals-6.0.0.tgz", + "integrity": "sha512-ZQl7LOWaF5ePqqcX4hLuv/bLXYQNfNWw2c0/yX/TsPRKamzHcTGQnlCjHT3TsmkOUVEPS3crCxiPfdzE/Trlhg==", + "requires": { + "acorn": "^7.1.1", + "acorn-walk": "^7.1.1" + }, + "dependencies": { + "acorn": { + "version": "7.4.1", + "resolved": "https://mirrors.cloud.tencent.com/npm/acorn/-/acorn-7.4.1.tgz", + "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==" + }, + "acorn-walk": { + "version": "7.2.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/acorn-walk/-/acorn-walk-7.2.0.tgz", + "integrity": "sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==" + } + } }, "acorn-jsx": { "version": "5.3.2", @@ -1486,6 +1511,11 @@ "fill-range": "^7.0.1" } }, + "browser-process-hrtime": { + "version": "1.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz", + "integrity": "sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==" + }, "browserslist": { "version": "4.20.3", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.20.3.tgz", @@ -2156,6 +2186,26 @@ "css-tree": "^1.1.2" } }, + "cssom": { + "version": "0.5.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/cssom/-/cssom-0.5.0.tgz", + "integrity": "sha512-iKuQcq+NdHqlAcwUY0o/HL69XQrUaQdMjmStJ8JFmUaiiQErlhrmuigkg/CU4E2J0IyUKUrMAgl36TvN67MqTw==" + }, + "cssstyle": { + "version": "2.3.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/cssstyle/-/cssstyle-2.3.0.tgz", + "integrity": "sha512-AZL67abkUzIuvcHqk7c09cezpGNcxUxU4Ioi/05xHk4DQeTkWmGYftIE6ctU6AEt+Gn4n1lDStOtj7FKycP71A==", + "requires": { + "cssom": "~0.3.6" + }, + "dependencies": { + "cssom": { + "version": "0.3.8", + "resolved": "https://mirrors.cloud.tencent.com/npm/cssom/-/cssom-0.3.8.tgz", + "integrity": "sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==" + } + } + }, "dargs": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/dargs/-/dargs-7.0.0.tgz", @@ -2170,6 +2220,16 @@ "assert-plus": "^1.0.0" } }, + "data-urls": { + "version": "3.0.2", + "resolved": "https://mirrors.cloud.tencent.com/npm/data-urls/-/data-urls-3.0.2.tgz", + "integrity": "sha512-Jy/tj3ldjZJo63sVAvg6LHt2mHvl4V6AgRAmNDtLdm7faqtsx+aJG42rsyCo9JCoRVKwPFzKlIPx3DIibwSIaQ==", + "requires": { + "abab": "^2.0.6", + "whatwg-mimetype": "^3.0.0", + "whatwg-url": "^11.0.0" + } + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -2202,6 +2262,11 @@ } } }, + "decimal.js": { + "version": "10.4.1", + "resolved": "https://mirrors.cloud.tencent.com/npm/decimal.js/-/decimal.js-10.4.1.tgz", + "integrity": "sha512-F29o+vci4DodHYT9UrR5IEbfBw9pE5eSapIJdTqXK5+6hq+t8VRxwQyKlW2i+KDKFkkJQRvFyI/QXD83h8LyQw==" + }, "decompress-response": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", @@ -2220,8 +2285,7 @@ "deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", - "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", - "dev": true + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==" }, "deepmerge": { "version": "4.2.2", @@ -2306,6 +2370,14 @@ "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", "dev": true }, + "domexception": { + "version": "4.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/domexception/-/domexception-4.0.0.tgz", + "integrity": "sha512-A2is4PLG+eeSfoTMA95/s4pvAoSo2mKtiM5jlHkAVewmiO8ISFTFKZjH7UAM1Atli/OT/7JHOrJRJiMKUZKYBw==", + "requires": { + "webidl-conversions": "^7.0.0" + } + }, "domhandler": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.3.1.tgz", @@ -2463,6 +2535,55 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "escodegen": { + "version": "2.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/escodegen/-/escodegen-2.0.0.tgz", + "integrity": "sha512-mmHKys/C8BFUGI+MAWNcSYoORYLMdPzjrknd2Vc+bUsjN5bXcr8EhrNB+UTqfL1y3I9c4fw2ihgtMPQLBRiQxw==", + "requires": { + "esprima": "^4.0.1", + "estraverse": "^5.2.0", + "esutils": "^2.0.2", + "optionator": "^0.8.1", + "source-map": "~0.6.1" + }, + "dependencies": { + "levn": { + "version": "0.3.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/levn/-/levn-0.3.0.tgz", + "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", + "requires": { + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2" + } + }, + "optionator": { + "version": "0.8.3", + "resolved": "https://mirrors.tencent.com/npm/optionator/-/optionator-0.8.3.tgz", + "integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==", + "requires": { + "deep-is": "~0.1.3", + "fast-levenshtein": "~2.0.6", + "levn": "~0.3.0", + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2", + "word-wrap": "~1.2.3" + } + }, + "prelude-ls": { + "version": "1.1.2", + "resolved": "https://mirrors.cloud.tencent.com/npm/prelude-ls/-/prelude-ls-1.1.2.tgz", + "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" + }, + "type-check": { + "version": "0.3.2", + "resolved": "https://mirrors.cloud.tencent.com/npm/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", + "requires": { + "prelude-ls": "~1.1.2" + } + } + } + }, "eslint": { "version": "8.16.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.16.0.tgz", @@ -2649,6 +2770,11 @@ "eslint-visitor-keys": "^3.3.0" } }, + "esprima": { + "version": "4.0.1", + "resolved": "https://mirrors.tencent.com/npm/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" + }, "esquery": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz", @@ -2670,8 +2796,7 @@ "estraverse": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", - "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", - "dev": true + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==" }, "estree-walker": { "version": "2.0.2", @@ -2682,8 +2807,7 @@ "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", - "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", - "dev": true + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==" }, "execa": { "version": "5.1.1", @@ -2725,8 +2849,7 @@ "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", - "dev": true + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, "fast-safe-stringify": { "version": "2.1.1", @@ -3187,6 +3310,14 @@ "lru-cache": "^6.0.0" } }, + "html-encoding-sniffer": { + "version": "3.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz", + "integrity": "sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==", + "requires": { + "whatwg-encoding": "^2.0.0" + } + }, "html-minifier": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/html-minifier/-/html-minifier-4.0.0.tgz", @@ -3484,6 +3615,11 @@ "integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4=", "dev": true }, + "is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://mirrors.cloud.tencent.com/npm/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==" + }, "is-property": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", @@ -3602,6 +3738,82 @@ "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, + "jsdom": { + "version": "19.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/jsdom/-/jsdom-19.0.0.tgz", + "integrity": "sha512-RYAyjCbxy/vri/CfnjUWJQQtZ3LKlLnDqj+9XLNnJPgEGeirZs3hllKR20re8LUZ6o1b1X4Jat+Qd26zmP41+A==", + "requires": { + "abab": "^2.0.5", + "acorn": "^8.5.0", + "acorn-globals": "^6.0.0", + "cssom": "^0.5.0", + "cssstyle": "^2.3.0", + "data-urls": "^3.0.1", + "decimal.js": "^10.3.1", + "domexception": "^4.0.0", + "escodegen": "^2.0.0", + "form-data": "^4.0.0", + "html-encoding-sniffer": "^3.0.0", + "http-proxy-agent": "^5.0.0", + "https-proxy-agent": "^5.0.0", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.0", + "parse5": "6.0.1", + "saxes": "^5.0.1", + "symbol-tree": "^3.2.4", + "tough-cookie": "^4.0.0", + "w3c-hr-time": "^1.0.2", + "w3c-xmlserializer": "^3.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^2.0.0", + "whatwg-mimetype": "^3.0.0", + "whatwg-url": "^10.0.0", + "ws": "^8.2.3", + "xml-name-validator": "^4.0.0" + }, + "dependencies": { + "@tootallnate/once": { + "version": "2.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/@tootallnate%2fonce/-/once-2.0.0.tgz", + "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==" + }, + "http-proxy-agent": { + "version": "5.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", + "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", + "requires": { + "@tootallnate/once": "2", + "agent-base": "6", + "debug": "4" + } + }, + "tough-cookie": { + "version": "4.1.2", + "resolved": "https://mirrors.cloud.tencent.com/npm/tough-cookie/-/tough-cookie-4.1.2.tgz", + "integrity": "sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==", + "requires": { + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" + } + }, + "universalify": { + "version": "0.2.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/universalify/-/universalify-0.2.0.tgz", + "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==" + }, + "whatwg-url": { + "version": "10.0.0", + "resolved": "https://mirrors.tencent.com/npm/whatwg-url/-/whatwg-url-10.0.0.tgz", + "integrity": "sha512-CLxxCmdUby142H5FZzn4D8ikO1cmypvXVQktsgosNy4a4BHrDHeciBBGZhb0bNoR5/MltoCatso+vFjjGx8t0w==", + "requires": { + "tr46": "^3.0.0", + "webidl-conversions": "^7.0.0" + } + } + } + }, "json-buffer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", @@ -5038,6 +5250,11 @@ "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" }, + "nwsapi": { + "version": "2.2.2", + "resolved": "https://mirrors.cloud.tencent.com/npm/nwsapi/-/nwsapi-2.2.2.tgz", + "integrity": "sha512-90yv+6538zuvUMnN+zCr8LuV6bPFdq50304114vJYJ8RDyK8D5O9Phpbd6SZWgI7PwzmmfN1upeOJlvybDSgCw==" + }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", @@ -5187,6 +5404,11 @@ "lines-and-columns": "^1.1.6" } }, + "parse5": { + "version": "6.0.1", + "resolved": "https://mirrors.tencent.com/npm/parse5/-/parse5-6.0.1.tgz", + "integrity": "sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==" + }, "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -5727,6 +5949,11 @@ "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", "integrity": "sha512-X/xY82scca2tau62i9mDyU9K+I+djTMUsvwf7xnUX5GLvVzgJybOJf4Y6o9Zx3oJK/LSXg5tTZBjwzqVPaPO2g==" }, + "querystringify": { + "version": "2.2.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" + }, "quick-lru": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", @@ -5950,6 +6177,11 @@ "integrity": "sha1-eZlTn8ngR6N5KPoZb44VY9q9Nt4=", "dev": true }, + "requires-port": { + "version": "1.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=" + }, "resolve": { "version": "1.22.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz", @@ -6271,6 +6503,14 @@ "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" }, + "saxes": { + "version": "5.0.1", + "resolved": "https://mirrors.cloud.tencent.com/npm/saxes/-/saxes-5.0.1.tgz", + "integrity": "sha512-5LBh1Tls8c9xgGjw3QrMwETmTMVk0oFgvrFSvWx62llR2hcEInrKNZ2GZCCuuy2lvWrdl5jhbpeqc5hRYKFOcw==", + "requires": { + "xmlchars": "^2.2.0" + } + }, "scss-tokenizer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/scss-tokenizer/-/scss-tokenizer-0.3.0.tgz", @@ -6799,6 +7039,11 @@ } } }, + "symbol-tree": { + "version": "3.2.4", + "resolved": "https://mirrors.cloud.tencent.com/npm/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==" + }, "tar": { "version": "6.1.11", "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz", @@ -7209,6 +7454,15 @@ } } }, + "url-parse": { + "version": "1.5.10", + "resolved": "https://mirrors.cloud.tencent.com/npm/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "requires": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "url-parse-lax": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", @@ -7265,11 +7519,40 @@ "extsprintf": "^1.2.0" } }, + "w3c-hr-time": { + "version": "1.0.2", + "resolved": "https://mirrors.cloud.tencent.com/npm/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz", + "integrity": "sha512-z8P5DvDNjKDoFIHK7q8r8lackT6l+jo/Ye3HOle7l9nICP9lf1Ci25fy9vHd0JOWewkIFzXIEig3TdKT7JQ5fQ==", + "requires": { + "browser-process-hrtime": "^1.0.0" + } + }, + "w3c-xmlserializer": { + "version": "3.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/w3c-xmlserializer/-/w3c-xmlserializer-3.0.0.tgz", + "integrity": "sha512-3WFqGEgSXIyGhOmAFtlicJNMjEps8b1MG31NCA0/vOF9+nKMUW1ckhi9cnNHmf88Rzw5V+dwIwsm2C7X8k9aQg==", + "requires": { + "xml-name-validator": "^4.0.0" + } + }, "webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==" }, + "whatwg-encoding": { + "version": "2.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/whatwg-encoding/-/whatwg-encoding-2.0.0.tgz", + "integrity": "sha512-p41ogyeMUrw3jWclHWTQg1k05DSVXPLcVxRTYsXUk+ZooOCZLcoYgPZ/HL/D/N+uQPOtcp1me1WhBEaX02mhWg==", + "requires": { + "iconv-lite": "0.6.3" + } + }, + "whatwg-mimetype": { + "version": "3.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz", + "integrity": "sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==" + }, "whatwg-url": { "version": "11.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz", @@ -7349,8 +7632,7 @@ "word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", - "dev": true + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==" }, "wrappy": { "version": "1.0.2", @@ -7369,12 +7651,22 @@ "typedarray-to-buffer": "^3.1.5" } }, + "ws": { + "version": "8.8.1", + "resolved": "https://mirrors.cloud.tencent.com/npm/ws/-/ws-8.8.1.tgz", + "integrity": "sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==" + }, "xdg-basedir": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", "integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==", "dev": true }, + "xml-name-validator": { + "version": "4.0.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/xml-name-validator/-/xml-name-validator-4.0.0.tgz", + "integrity": "sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw==" + }, "xml2js": { "version": "0.4.23", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", @@ -7389,6 +7681,11 @@ "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" }, + "xmlchars": { + "version": "2.2.0", + "resolved": "https://mirrors.cloud.tencent.com/npm/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==" + }, "xss": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/xss/-/xss-1.0.11.tgz", diff --git a/package.json b/package.json index eaf6ff7..b8cfe84 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "dotenv": "^10.0.0", "get-user-ip": "^1.0.0", "html-minifier": "^4.0.0", + "jsdom": "^19.0.0", "jsonwebtoken": "^8.5.1", "md5": "^2.3.0", "min-1px": "^1.0.0", diff --git a/src/client/view/submit.svelte b/src/client/view/submit.svelte index 2eb8be3..95189c8 100644 --- a/src/client/view/submit.svelte +++ b/src/client/view/submit.svelte @@ -15,12 +15,12 @@ export let cancel = false, pid = '', rid = '', - wordLimit = 0 - - let wordLimitContent = wordLimit.content - $: { - wordLimitContent = wordLimit.content - } + wordLimit = { + nick: 0, + mail: 0, + site: 0, + content: 0 + } // 普通变量 const textStr = 'text' @@ -72,6 +72,14 @@ content: { value: '', is: false } } + let wordLimitContent = wordLimit.content + let limitContentLen + $: { + wordLimitContent = wordLimit.content + const dom = new DOMParser().parseFromString(metas.content.value, 'text/html') + limitContentLen = dom.body.textContent.length + dom.body.querySelectorAll('img').length + } + onMount(() => { initInfo() getEmot() @@ -191,23 +199,46 @@ SaveInfo() } + // eslint-disable-next-line max-statements function MetasChange() { try { const { nick, mail, site, content } = metas - for (const [k, v] of Object.entries(metas)) { - const len = v.value.length - const word = wordLimit[k] - let condition = true - if (k === nickStr) condition = len > 1 - if (k === mailStr) condition = mailReg.test(v.value) - if (k === siteStr) condition = len === 0 ? true : isUrl(v.value) - if (k === contentStr) condition = len > 1 - - // 如果word的参数不为0,则判断输入框内容长度是否符合规定 - if (word) condition = condition && len <= word - - condition ? (metas[k].is = true) : (metas[k].is = false) + const { nick: nickWord, mail: mailWord, site: siteWord, content: contentWord } = wordLimit + const nickLen = nick.value.length + const mailLen = mail.value.length + const siteLen = site.value.length + const contentLen = content.value.length + + // 昵称 + if (nickLen > 1 && nickLen <= nickWord) { + metas.nick.is = true + } else { + metas.nick.is = false } + + // 邮箱 + if (mailLen <= mailWord && mailReg.test(mail.value)) { + metas.mail.is = true + } else { + metas.mail.is = false + } + + // 网站 + if (siteLen === 0 || siteLen <= siteWord && isUrl(site.value)) { + metas.site.is = true + } else if (siteLen !== 0) { + metas.site.is = false + } + + // 内容 + const dom = new DOMParser().parseFromString(content.value, 'text/html') + const textContent = dom.body.textContent.length + if (contentLen > 1 && textContent <= contentWord) { + metas.content.is = true + } else { + metas.content.is = false + } + isLegal = nick.is && mail.is && site.is && content.is } catch (error) { // eslint-disable-next-line no-console @@ -288,11 +319,9 @@ {#if wordLimitContent} - {metas.content.value.length} + {limitContentLen} {#if wordLimitContent} - wordLimitContent && 'D-text-number-illegal'} - >{'/ ' + wordLimitContent} - + wordLimitContent && 'D-text-number-illegal'}>{'/ ' + wordLimitContent} {/if} {/if} diff --git a/src/server/utils/commentUtils.js b/src/server/utils/commentUtils.js index a60f398..bb97330 100644 --- a/src/server/utils/commentUtils.js +++ b/src/server/utils/commentUtils.js @@ -1,5 +1,6 @@ const bcrypt = require('bcryptjs') const axios = require('axios') +const { JSDOM } = require('jsdom') const { Unique, XSS, SetAvatar, DeepClone, IndexHandler, VerifyParams, GetAvatar } = require('./index') /** @@ -40,41 +41,24 @@ function WordExceedsOutput(text, content, wordNumber) { /* eslint-disable max-statements */ function WordNumberExceed(configWordNumber, params) { // 自定义限制字数 - const { - nick: nickWordNumber, - mail: mailWordNumber, - site: siteWordNumber, - content: contentWordNumber - } = WordNumberLimit(configWordNumber) + const { nick: nickWord, mail: mailWord, site: siteWord, content: contentWord } = WordNumberLimit(configWordNumber) // 实际输入字数 const nick = params.nick.length const mail = params.mail.length const site = params.site.length - - // 去除规定的表情包表情包(img)标签 - // 进行字数判断是否超出指定范围 - /* eslint-disable max-len */ - const regImage = /(['"]?)([^'"]*)\1\/?/g - /* eslint-enable max-len */ - - const emot = params.content.match(regImage) - const emotLen = emot === null || emot === void 0 ? void 0 : emot.length - - const errorEmotStr = 'The number of emoji packs exceeds the specified range' - if (emotLen > 20) throw new Error(errorEmotStr) - - const content = params.content.replace(regImage, '').length - - const nickExceed = nickWordNumber && nick > nickWordNumber - const mailExceed = mailWordNumber && mail > mailWordNumber - const siteExceed = siteWordNumber && site > siteWordNumber - const contentExceed = contentWordNumber && content > contentWordNumber - - if (contentExceed) WordExceedsOutput('Content', content, contentWordNumber) - if (nickExceed) WordExceedsOutput('Nickname', nick, nickWordNumber) - if (mailExceed) WordExceedsOutput('Mail', mail, mailWordNumber) - if (siteExceed) WordExceedsOutput('Site', site, siteWordNumber) + const dom = new JSDOM(params.content) + const content = dom.window.document.body.textContent.length + dom.window.document.querySelectorAll('img').length + + const nickExceed = nickWord && nick > nickWord + const mailExceed = mailWord && mail > mailWord + const siteExceed = siteWord && site > siteWord + const contentExceed = contentWord && content > contentWord + + if (contentExceed) WordExceedsOutput('Content', content, contentWord) + if (nickExceed) WordExceedsOutput('Nickname', nick, nickWord) + if (mailExceed) WordExceedsOutput('Mail', mail, mailWord) + if (siteExceed) WordExceedsOutput('Site', site, siteWord) const condition = contentExceed || nickExceed || mailExceed || siteExceed From a5823487c7ee2dadee30101ca074b84683c4cd42 Mon Sep 17 00:00:00 2001 From: Lete114 Date: Tue, 20 Sep 2022 17:31:53 +0800 Subject: [PATCH 2/3] =?UTF-8?q?revert(textarea):=20contenteditable=20?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=20bug=20=E6=89=80=E4=BB=A5=E5=9B=9E=E6=BB=9A?= =?UTF-8?q?=E5=88=B0=E4=BB=A5=E5=89=8D=E7=9A=84=E8=AF=84=E8=AE=BA=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/view/submit.svelte | 151 +++++++++++++++++----------------- 1 file changed, 75 insertions(+), 76 deletions(-) diff --git a/src/client/view/submit.svelte b/src/client/view/submit.svelte index 95189c8..26b511c 100644 --- a/src/client/view/submit.svelte +++ b/src/client/view/submit.svelte @@ -1,5 +1,5 @@