diff --git a/SharpbinV3.Client/.vscode/settings.json b/SharpbinV3.Client/.vscode/settings.json index 1935b91..2488d0b 100644 --- a/SharpbinV3.Client/.vscode/settings.json +++ b/SharpbinV3.Client/.vscode/settings.json @@ -2,5 +2,5 @@ "files.associations": { "*.css": "tailwindcss" }, - "tailwindCSS.experimental.configFile": "src/routes/layout.css", + "tailwindCSS.experimental.configFile": "src/routes/layout.css" } diff --git a/SharpbinV3.Client/package-lock.json b/SharpbinV3.Client/package-lock.json index 881313b..cc7011f 100644 --- a/SharpbinV3.Client/package-lock.json +++ b/SharpbinV3.Client/package-lock.json @@ -22,6 +22,7 @@ "prettier": "^3.7.4", "prettier-plugin-svelte": "^3.4.0", "prettier-plugin-tailwindcss": "^0.7.2", + "shiki": "^3.20.0", "svelte": "^5.45.6", "svelte-check": "^4.3.4", "tailwindcss": "^4.1.17", @@ -1067,6 +1068,80 @@ "win32" ] }, + "node_modules/@shikijs/core": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-3.20.0.tgz", + "integrity": "sha512-f2ED7HYV4JEk827mtMDwe/yQ25pRiXZmtHjWF8uzZKuKiEsJR7Ce1nuQ+HhV9FzDcbIo4ObBCD9GPTzNuy9S1g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.20.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4", + "hast-util-to-html": "^9.0.5" + } + }, + "node_modules/@shikijs/engine-javascript": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-3.20.0.tgz", + "integrity": "sha512-OFx8fHAZuk7I42Z9YAdZ95To6jDePQ9Rnfbw9uSRTSbBhYBp1kEOKv/3jOimcj3VRUKusDYM6DswLauwfhboLg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.20.0", + "@shikijs/vscode-textmate": "^10.0.2", + "oniguruma-to-es": "^4.3.4" + } + }, + "node_modules/@shikijs/engine-oniguruma": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.20.0.tgz", + "integrity": "sha512-Yx3gy7xLzM0ZOjqoxciHjA7dAt5tyzJE3L4uQoM83agahy+PlW244XJSrmJRSBvGYELDhYXPacD4R/cauV5bzQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.20.0", + "@shikijs/vscode-textmate": "^10.0.2" + } + }, + "node_modules/@shikijs/langs": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.20.0.tgz", + "integrity": "sha512-le+bssCxcSHrygCWuOrYJHvjus6zhQ2K7q/0mgjiffRbkhM4o1EWu2m+29l0yEsHDbWaWPNnDUTRVVBvBBeKaA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.20.0" + } + }, + "node_modules/@shikijs/themes": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.20.0.tgz", + "integrity": "sha512-U1NSU7Sl26Q7ErRvJUouArxfM2euWqq1xaSrbqMu2iqa+tSp0D1Yah8216sDYbdDHw4C8b75UpE65eWorm2erQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "3.20.0" + } + }, + "node_modules/@shikijs/types": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.20.0.tgz", + "integrity": "sha512-lhYAATn10nkZcBQ0BlzSbJA3wcmL5MXUUF8d2Zzon6saZDlToKaiRX60n2+ZaHJCmXEcZRWNzn+k9vplr8Jhsw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" + } + }, + "node_modules/@shikijs/vscode-textmate": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.0.2.tgz", + "integrity": "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==", + "dev": true, + "license": "MIT" + }, "node_modules/@standard-schema/spec": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", @@ -1458,6 +1533,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/hast": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz", + "integrity": "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "*" + } + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -1465,6 +1550,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/mdast": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", + "integrity": "sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "*" + } + }, "node_modules/@types/node": { "version": "22.19.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.3.tgz", @@ -1475,6 +1570,13 @@ "undici-types": "~6.21.0" } }, + "node_modules/@types/unist": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", + "integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==", + "dev": true, + "license": "MIT" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.50.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.50.1.tgz", @@ -1731,6 +1833,13 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@ungap/structured-clone": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.0.tgz", + "integrity": "sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g==", + "dev": true, + "license": "ISC" + }, "node_modules/acorn": { "version": "8.15.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", @@ -1842,6 +1951,17 @@ "node": ">=6" } }, + "node_modules/ccount": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz", + "integrity": "sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -1859,6 +1979,28 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/character-entities-html4": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/character-entities-html4/-/character-entities-html4-2.1.0.tgz", + "integrity": "sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/character-entities-legacy": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-3.0.0.tgz", + "integrity": "sha512-RpPp0asT/6ufRm//AJVwpViZbGM/MkjQFxJccQRHmISF/22NBtsHqAWmL+/pmkPWoIUJdWyeVleTl1wydHATVQ==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/chokidar": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", @@ -1905,6 +2047,17 @@ "dev": true, "license": "MIT" }, + "node_modules/comma-separated-tokens": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", + "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -1985,6 +2138,16 @@ "node": ">=0.10.0" } }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", @@ -2002,6 +2165,20 @@ "dev": true, "license": "MIT" }, + "node_modules/devlop": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/devlop/-/devlop-1.1.0.tgz", + "integrity": "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==", + "dev": true, + "license": "MIT", + "dependencies": { + "dequal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/enhanced-resolve": { "version": "5.18.4", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.18.4.tgz", @@ -2440,6 +2617,55 @@ "node": ">=8" } }, + "node_modules/hast-util-to-html": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/hast-util-to-html/-/hast-util-to-html-9.0.5.tgz", + "integrity": "sha512-OguPdidb+fbHQSU4Q4ZiLKnzWo8Wwsf5bZfbvu7//a9oTYoqD/fWpe96NuHkoS9h0ccGOTe0C4NGXdtS0iObOw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/unist": "^3.0.0", + "ccount": "^2.0.0", + "comma-separated-tokens": "^2.0.0", + "hast-util-whitespace": "^3.0.0", + "html-void-elements": "^3.0.0", + "mdast-util-to-hast": "^13.0.0", + "property-information": "^7.0.0", + "space-separated-tokens": "^2.0.0", + "stringify-entities": "^4.0.0", + "zwitch": "^2.0.4" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-whitespace": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz", + "integrity": "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/html-void-elements": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/html-void-elements/-/html-void-elements-3.0.0.tgz", + "integrity": "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -2913,6 +3139,122 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/mdast-util-to-hast": { + "version": "13.2.1", + "resolved": "https://registry.npmjs.org/mdast-util-to-hast/-/mdast-util-to-hast-13.2.1.tgz", + "integrity": "sha512-cctsq2wp5vTsLIcaymblUriiTcZd0CwWtCbLvrOzYCDZoWyMNV8sZ7krj09FSnsiJi3WVsHLM4k6Dq/yaPyCXA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "@ungap/structured-clone": "^1.0.0", + "devlop": "^1.0.0", + "micromark-util-sanitize-uri": "^2.0.0", + "trim-lines": "^3.0.0", + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0", + "vfile": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/micromark-util-character": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.1.tgz", + "integrity": "sha512-wv8tdUTJ3thSFFFJKtpYKOYiGP2+v96Hvk4Tu8KpCAsTMs6yi+nVmGh1syvSCsaxz45J6Jbw+9DD6g97+NV67Q==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-encode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-encode/-/micromark-util-encode-2.0.1.tgz", + "integrity": "sha512-c3cVx2y4KqUnwopcO9b/SCdo2O67LwJJ/UyqGfbigahfegL9myoEFoDYZgkT7f36T0bLrM9hZTAaAyH+PCAXjw==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/micromark-util-sanitize-uri": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-sanitize-uri/-/micromark-util-sanitize-uri-2.0.1.tgz", + "integrity": "sha512-9N9IomZ/YuGGZZmQec1MbgxtlgougxTodVwDzzEouPKo3qFWvymFHWcnDi2vzV1ff6kas9ucW+o3yzJK9YB1AQ==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-character": "^2.0.0", + "micromark-util-encode": "^2.0.0", + "micromark-util-symbol": "^2.0.0" + } + }, + "node_modules/micromark-util-symbol": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-symbol/-/micromark-util-symbol-2.0.1.tgz", + "integrity": "sha512-vs5t8Apaud9N28kgCrRUdEed4UJ+wWNvicHLPxCa9ENlYuAY31M0ETy5y1vA33YoNPDFTghEbnh6efaE8h4x0Q==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/micromark-util-types": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/micromark-util-types/-/micromark-util-types-2.0.2.tgz", + "integrity": "sha512-Yw0ECSpJoViF1qTU4DC6NwtC4aWGt1EkzaQB8KPPyCRR8z9TWeV0HbEFGTO+ZY1wB22zmxnJqhPyTpOVCpeHTA==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -2979,6 +3321,25 @@ "dev": true, "license": "MIT" }, + "node_modules/oniguruma-parser": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/oniguruma-parser/-/oniguruma-parser-0.12.1.tgz", + "integrity": "sha512-8Unqkvk1RYc6yq2WBYRj4hdnsAxVze8i7iPfQr8e4uSP3tRv0rpZcbGUDvxfQQcdwHt/e9PrMvGCsa8OqG9X3w==", + "dev": true, + "license": "MIT" + }, + "node_modules/oniguruma-to-es": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/oniguruma-to-es/-/oniguruma-to-es-4.3.4.tgz", + "integrity": "sha512-3VhUGN3w2eYxnTzHn+ikMI+fp/96KoRSVK9/kMTcFqj1NRDh2IhQCKvYxDnWePKRXY/AqH+Fuiyb7VHSzBjHfA==", + "dev": true, + "license": "MIT", + "dependencies": { + "oniguruma-parser": "^0.12.1", + "regex": "^6.0.1", + "regex-recursion": "^6.0.2" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -3335,6 +3696,17 @@ } } }, + "node_modules/property-information": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-7.1.0.tgz", + "integrity": "sha512-TwEZ+X+yCJmYfL7TPUOcvBZ4QfoT5YenQiJuX//0th53DE6w0xxLEtfK3iyryQFddXuvkIk51EEgrJQ0WJkOmQ==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -3359,6 +3731,33 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/regex/-/regex-6.1.0.tgz", + "integrity": "sha512-6VwtthbV4o/7+OaAF9I5L5V3llLEsoPyq9P1JVXkedTP33c7MfCG0/5NOPcSJn0TzXcG9YUrR0gQSWioew3LDg==", + "dev": true, + "license": "MIT", + "dependencies": { + "regex-utilities": "^2.3.0" + } + }, + "node_modules/regex-recursion": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/regex-recursion/-/regex-recursion-6.0.2.tgz", + "integrity": "sha512-0YCaSCq2VRIebiaUviZNs0cBz1kg5kVS2UKUfNIx8YVs1cN3AV7NTctO5FOKBA+UT2BPJIWZauYHPqJODG50cg==", + "dev": true, + "license": "MIT", + "dependencies": { + "regex-utilities": "^2.3.0" + } + }, + "node_modules/regex-utilities": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/regex-utilities/-/regex-utilities-2.3.0.tgz", + "integrity": "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng==", + "dev": true, + "license": "MIT" + }, "node_modules/resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", @@ -3467,6 +3866,23 @@ "node": ">=8" } }, + "node_modules/shiki": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-3.20.0.tgz", + "integrity": "sha512-kgCOlsnyWb+p0WU+01RjkCH+eBVsjL1jOwUYWv0YDWkM2/A46+LDKVs5yZCUXjJG6bj4ndFoAg5iLIIue6dulg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/core": "3.20.0", + "@shikijs/engine-javascript": "3.20.0", + "@shikijs/engine-oniguruma": "3.20.0", + "@shikijs/langs": "3.20.0", + "@shikijs/themes": "3.20.0", + "@shikijs/types": "3.20.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" + } + }, "node_modules/sirv": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/sirv/-/sirv-3.0.2.tgz", @@ -3492,6 +3908,32 @@ "node": ">=0.10.0" } }, + "node_modules/space-separated-tokens": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", + "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/stringify-entities": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz", + "integrity": "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg==", + "dev": true, + "license": "MIT", + "dependencies": { + "character-entities-html4": "^2.0.0", + "character-entities-legacy": "^3.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -3647,6 +4089,17 @@ "node": ">=6" } }, + "node_modules/trim-lines": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", + "integrity": "sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/ts-api-utils": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.2.0.tgz", @@ -3718,6 +4171,79 @@ "dev": true, "license": "MIT" }, + "node_modules/unist-util-is": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.1.tgz", + "integrity": "sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-position": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/unist-util-position/-/unist-util-position-5.0.0.tgz", + "integrity": "sha512-fucsC7HjXvkB5R3kTCO7kUjRdrS0BJt3M/FPxmHMBOm8JQi2BsHAHFsy27E0EolP8rp0NzXsJ+jNPyDWvOJZPA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-stringify-position": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", + "integrity": "sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-visit": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", + "integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0", + "unist-util-visit-parents": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/unist-util-visit-parents": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.2.tgz", + "integrity": "sha512-goh1s1TBrqSqukSc8wrjwWhL0hiJxgA8m4kFxGlQ+8FYQ3C/m11FcTs4YYem7V664AhHVvgoQLk890Ssdsr2IQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -3735,6 +4261,36 @@ "dev": true, "license": "MIT" }, + "node_modules/vfile": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz", + "integrity": "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "vfile-message": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/vfile-message": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-4.0.3.tgz", + "integrity": "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-stringify-position": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/vite": { "version": "7.3.0", "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.0.tgz", @@ -3856,22 +4412,6 @@ "node": ">=0.10.0" } }, - "node_modules/yaml": { - "version": "2.8.2", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.2.tgz", - "integrity": "sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A==", - "extraneous": true, - "license": "ISC", - "bin": { - "yaml": "bin.mjs" - }, - "engines": { - "node": ">= 14.6" - }, - "funding": { - "url": "https://github.com/sponsors/eemeli" - } - }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -3891,6 +4431,17 @@ "integrity": "sha512-B58NGBEoc8Y9MWWCQGl/gq9xBCe4IiKM0a2x7GZdQKOW5Exr8S1W24J6OgM1njK8xCRGvAJIL/MxXHf6SkmQKQ==", "dev": true, "license": "MIT" + }, + "node_modules/zwitch": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", + "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } } } } diff --git a/SharpbinV3.Client/package.json b/SharpbinV3.Client/package.json index c432e65..718e4db 100644 --- a/SharpbinV3.Client/package.json +++ b/SharpbinV3.Client/package.json @@ -28,6 +28,7 @@ "prettier": "^3.7.4", "prettier-plugin-svelte": "^3.4.0", "prettier-plugin-tailwindcss": "^0.7.2", + "shiki": "^3.20.0", "svelte": "^5.45.6", "svelte-check": "^4.3.4", "tailwindcss": "^4.1.17", diff --git a/SharpbinV3.Client/src/app.html b/SharpbinV3.Client/src/app.html index f273cc5..442b0f2 100644 --- a/SharpbinV3.Client/src/app.html +++ b/SharpbinV3.Client/src/app.html @@ -3,6 +3,14 @@ + + %sveltekit.head% diff --git a/SharpbinV3.Client/src/lib/consts.ts b/SharpbinV3.Client/src/lib/consts.ts new file mode 100644 index 0000000..2daac53 --- /dev/null +++ b/SharpbinV3.Client/src/lib/consts.ts @@ -0,0 +1,74 @@ +export const displayNames: Record = { + plaintext: 'Plain Text', + abap: 'ABAP', + 'actionscript-3': 'ActionScript 3', + apl: 'APL', + applescript: 'AppleScript', + ara: 'ARA', + awk: 'AWK', + bibtex: 'BibTeX', + cmake: 'CMake', + cobol: 'COBOL', + codeql: 'CodeQL', + coffee: 'CoffeeScript', + cpp: 'C++', + csharp: 'C#', + css: 'CSS', + cue: 'CUE', + 'dream-maker': 'Dream Maker', + erb: 'ERB', + fsharp: 'F#', + gdresource: 'Godot Resource', + gdscript: 'GDScript', + gdshader: 'Godot Shader', + 'git-commit': 'Git Commit', + 'git-rebase': 'Git Rebase', + glsl: 'GLSL', + graphql: 'GraphQL', + hcl: 'HCL', + hjson: 'HJSON', + hlsl: 'HLSL', + html: 'HTML', + ini: 'INI', + javascript: 'JavaScript', + json: 'JSON', + json5: 'JSON5', + jsonc: 'JSONC', + jssm: 'JSSM', + jsx: 'JSX', + latex: 'LaTeX', + matlab: 'MATLAB', + mdx: 'MDX', + 'objective-c': 'Objective-C', + 'objective-cpp': 'Objective-C++', + ocaml: 'OCaml', + php: 'PHP', + plsql: 'PL/SQL', + postcss: 'PostCSS', + powerquery: 'Power Query', + purescript: 'PureScript', + riscv: 'RISC-V', + rst: 'reStructuredText', + sas: 'SAS', + scss: 'SCSS', + shaderlab: 'ShaderLab', + sparql: 'SPARQL', + sql: 'SQL', + 'ssh-config': 'SSH Config', + 'system-verilog': 'SystemVerilog', + tasl: 'TASL', + tex: 'TeX', + toml: 'TOML', + tsx: 'TSX', + typescript: 'TypeScript', + vb: 'VB', + vhdl: 'VHDL', + viml: 'VimL', + wasm: 'WebAssembly', + xml: 'XML', + xsl: 'XSL', + yaml: 'YAML', + zenscript: 'ZenScript' +}; +// only include langs that need special display names +// e.g. cpp -> C++ or toml -> TOML, langs like java are automatically capitalized diff --git a/SharpbinV3.Client/src/lib/shiki.ts b/SharpbinV3.Client/src/lib/shiki.ts new file mode 100644 index 0000000..a9d27d2 --- /dev/null +++ b/SharpbinV3.Client/src/lib/shiki.ts @@ -0,0 +1,23 @@ +import { createHighlighter } from 'shiki'; + +import type { Highlighter } from 'shiki'; +let highlighterPromise: Promise | null = null; + +async function loadHighlighter() { + const res = await fetch('http://localhost:5050/api/paste/create/options'); + if (!res.ok) throw new Error('Failed to fetch paste options'); + + const data = await res.json(); + + return createHighlighter({ + themes: ['github-dark', 'github-light'], + langs: data.syntaxes + }); +} + +export function getShiki() { + if (!highlighterPromise) { + highlighterPromise = loadHighlighter(); + } + return highlighterPromise; +} diff --git a/SharpbinV3.Client/src/routes/+page.server.ts b/SharpbinV3.Client/src/routes/+page.server.ts new file mode 100644 index 0000000..2580488 --- /dev/null +++ b/SharpbinV3.Client/src/routes/+page.server.ts @@ -0,0 +1,7 @@ +import type { PageServerLoad } from './$types'; + +export const load: PageServerLoad = async ({ fetch }) => { + const res = await fetch('/api/paste/create/options'); + const options = await res.json(); + return { options }; +}; diff --git a/SharpbinV3.Client/src/routes/+page.svelte b/SharpbinV3.Client/src/routes/+page.svelte index cc88df0..50dc595 100644 --- a/SharpbinV3.Client/src/routes/+page.svelte +++ b/SharpbinV3.Client/src/routes/+page.svelte @@ -1,2 +1,142 @@ -

Welcome to SvelteKit

-

Visit svelte.dev/docs/kit to read the documentation

+ + +
+
+

Create a Paste

+
+ + + + + {#if selectedVisibility === 2} + + {/if} + +
+
+
diff --git a/SharpbinV3.Client/src/routes/[id]/+page.server.ts b/SharpbinV3.Client/src/routes/[id]/+page.server.ts new file mode 100644 index 0000000..f71e5f1 --- /dev/null +++ b/SharpbinV3.Client/src/routes/[id]/+page.server.ts @@ -0,0 +1,30 @@ +import type { PageServerLoad } from './$types'; +import { getShiki } from '$lib/shiki'; + +export const load: PageServerLoad = async ({ params, fetch }) => { + const { id } = params; + + const paste = await fetch(`/api/paste/${id}`); + if (paste.status === 404) { + return { + status: 404, + error: { message: 'Paste not found' } + }; + } + const pasteData = await paste.json(); + const pasteContent = await fetch(`/api/paste/raw/${id}`); + const pasteOptions = await fetch('/api/paste/create/options'); + const options = await pasteOptions.json(); + const content = await pasteContent.text(); + + let highlighted = ''; + if (pasteData && content) { + const shiki = await getShiki(); + highlighted = shiki.codeToHtml(content, { + lang: pasteData.syntax || 'plaintext', + theme: 'github-dark' + }); + } + + return { paste: pasteData, content, options, highlighted }; +}; diff --git a/SharpbinV3.Client/src/routes/[id]/+page.svelte b/SharpbinV3.Client/src/routes/[id]/+page.svelte new file mode 100644 index 0000000..81eaca5 --- /dev/null +++ b/SharpbinV3.Client/src/routes/[id]/+page.svelte @@ -0,0 +1,83 @@ + + +
+ {#if data.paste} +
+

{data.paste.title || 'Untitled Paste'}

+
+ {@html addLineNumbers(data.highlighted ?? '')} +
+
+ {:else} +

Paste not found

+

The paste you are looking for does not exist.

+ {/if} + +
diff --git a/SharpbinV3.Client/src/routes/layout.css b/SharpbinV3.Client/src/routes/layout.css index d4b5078..9b70ce7 100644 --- a/SharpbinV3.Client/src/routes/layout.css +++ b/SharpbinV3.Client/src/routes/layout.css @@ -1 +1,29 @@ @import 'tailwindcss'; + +* { + box-sizing: border-box; +} + +body, +h1, +h2, +h3, +p { + font-family: 'IBM Plex Sans', sans-serif; +} + +pre, +code, +textarea, +option, +select { + font-family: 'Fira Code', monospace; +} + +input[type='text'], +input[type='email'], +input[type='password'], +textarea, +select { + outline: none; +} diff --git a/SharpbinV3.Client/vite.config.ts b/SharpbinV3.Client/vite.config.ts index 19f844f..09e9bae 100644 --- a/SharpbinV3.Client/vite.config.ts +++ b/SharpbinV3.Client/vite.config.ts @@ -3,10 +3,10 @@ import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; export default defineConfig({ - plugins: [tailwindcss(), sveltekit()], - server: { - proxy: { - '/api': 'http://localhost:5050' - } - } + plugins: [tailwindcss(), sveltekit()], + server: { + proxy: { + '/api': 'http://localhost:5050' + } + } }); diff --git a/SharpbinV3/Controllers/PasteController.cs b/SharpbinV3/Controllers/PasteController.cs index 8605129..cf76a3f 100644 --- a/SharpbinV3/Controllers/PasteController.cs +++ b/SharpbinV3/Controllers/PasteController.cs @@ -1,17 +1,20 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using SharpbinV3.Server.Data.Entities; using SharpbinV3.Server.DTOs; using SharpbinV3.Server.Services; +using SharpbinV3.Server.Settings; namespace SharpbinV3.Server.Controllers { [Route("api/[controller]")] [ApiController] - public class PasteController(IPasteService pasteService, IUserService userService) : ControllerBase + public class PasteController(IPasteService pasteService, IUserService userService, IOptions options) : ControllerBase { private readonly IPasteService _pasteService = pasteService; private readonly IUserService _userService = userService; + private readonly PasteSettings _pasteSettings = options.Value; [HttpPost] [Route("create")] @@ -24,7 +27,7 @@ namespace SharpbinV3.Server.Controllers if (!await _pasteService.ValidateSyntax(syntax)) return BadRequest(new { message = "Invalid syntax." }); if (!await _pasteService.ValidateTitle(title)) - return BadRequest(new { message = "Invalid title. Must be less than 500 characters." }); + return BadRequest(new { message = $"Invalid title. Must be less than {_pasteSettings.MaxTitleLength} characters." }); string content = await new StreamReader(Request.Body).ReadToEndAsync(); var httpUser = HttpContext.User; @@ -40,7 +43,6 @@ namespace SharpbinV3.Server.Controllers paste.TrueSize, paste.ExpiresAt }); - } [HttpGet] [Route("{id}")] @@ -48,7 +50,6 @@ namespace SharpbinV3.Server.Controllers { var paste = await _pasteService.Get(id); if (paste == null) return NotFound(); - Console.WriteLine(paste.User); return Ok(new { paste.ID, @@ -124,6 +125,16 @@ namespace SharpbinV3.Server.Controllers paste.Visibility = request.Visibility.Value; if (request.ExpiresAt.HasValue) paste.ExpiresAt = request.ExpiresAt.Value; + + if (!await _pasteService.ValidateExpiresAt(paste.ExpiresAt)) + return BadRequest(new { message = "Invalid expiration time." }); + if (!await _pasteService.ValidateVisibility(paste.Visibility)) + return BadRequest(new { message = "Invalid visibility level. Must be between 0 and 2." }); + if (!await _pasteService.ValidateSyntax(paste.Syntax ?? "plaintext")) + return BadRequest(new { message = "Invalid syntax." }); + if (!await _pasteService.ValidateTitle(paste.Title ?? "")) + return BadRequest(new { message = $"Invalid title. Must be less than {_pasteSettings.MaxTitleLength} characters." }); + var newPaste = await _pasteService.Edit(paste); return Ok(new { @@ -143,5 +154,24 @@ namespace SharpbinV3.Server.Controllers } }); } + + [HttpGet] + [Route("create/options")] + public IActionResult GetCreatePasteOptions() + { + var options = new + { + syntaxes = _pasteSettings.ValidSyntaxLanguages, + visibilities = new[] + { + new { value = 0, displayName = "Public" }, + new { value = 1, displayName = "Unlisted" }, + new { value = 2, displayName = "Private" } + }, + maxTitleLength = _pasteSettings.MaxTitleLength, + maxPasteSize = _pasteSettings.MaxPasteSizeInBytes + }; + return Ok(options); + } } } diff --git a/SharpbinV3/DTOs/PasteMetadataUpdateRequest.cs b/SharpbinV3/DTOs/PasteMetadataUpdateRequest.cs index 9e0986f..1afaab4 100644 --- a/SharpbinV3/DTOs/PasteMetadataUpdateRequest.cs +++ b/SharpbinV3/DTOs/PasteMetadataUpdateRequest.cs @@ -1,10 +1,7 @@ -using System.ComponentModel.DataAnnotations; - -namespace SharpbinV3.Server.DTOs +namespace SharpbinV3.Server.DTOs { public class PasteMetadataUpdateRequest { - [StringLength(500)] public string? Title { get; set; } public string? Syntax { get; set; } public int? Visibility { get; set; } diff --git a/SharpbinV3/Migrations/20251125015039_Init.cs b/SharpbinV3/Migrations/20251125015039_Init.cs index ff51461..3fcd97f 100644 --- a/SharpbinV3/Migrations/20251125015039_Init.cs +++ b/SharpbinV3/Migrations/20251125015039_Init.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable diff --git a/SharpbinV3/Program.cs b/SharpbinV3/Program.cs index 6441d5b..0fbe568 100644 --- a/SharpbinV3/Program.cs +++ b/SharpbinV3/Program.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using SharpbinV3.Server.Data; using SharpbinV3.Server.Services; +using SharpbinV3.Server.Settings; using System.Text; using System.Threading.RateLimiting; @@ -72,6 +73,8 @@ namespace SharpbinV3.Server .AllowAnyHeader() .AllowAnyMethod()); }); + builder.Services.Configure(builder.Configuration.GetSection("PasteSettings")); + builder.Services.Configure(builder.Configuration.GetSection("JWTSettings")); var app = builder.Build(); app.UseRateLimiter(); diff --git a/SharpbinV3/Services/AuthService.cs b/SharpbinV3/Services/AuthService.cs index 7d103e0..56baf94 100644 --- a/SharpbinV3/Services/AuthService.cs +++ b/SharpbinV3/Services/AuthService.cs @@ -1,8 +1,10 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; using SharpbinV3.Server.Data; using SharpbinV3.Server.Data.Entities; using SharpbinV3.Server.DTOs; +using SharpbinV3.Server.Settings; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; @@ -10,10 +12,10 @@ using Bcrypt = BCrypt.Net.BCrypt; namespace SharpbinV3.Server.Services { - public sealed class AuthService(AppDbContext db, IConfiguration configuration) : IAuthService + public sealed class AuthService(AppDbContext db, IOptions options) : IAuthService { private readonly AppDbContext _db = db; - private readonly IConfiguration _configuration = configuration; + private readonly JWTSettings _jwtSettings = options.Value; public async Task CreateUser(string username, string password, string? email, string? displayName) { @@ -33,7 +35,7 @@ namespace SharpbinV3.Server.Services public async Task GenerateJWTToken(User user) { var jwtHandler = new JwtSecurityTokenHandler(); - var key = Encoding.ASCII.GetBytes(_configuration["JwtConfig:Secret"]!); + var key = Encoding.ASCII.GetBytes(_jwtSettings.SecretKey); var descriptor = new SecurityTokenDescriptor { @@ -43,8 +45,8 @@ namespace SharpbinV3.Server.Services new Claim("Roles", user.Roles != null ? string.Join(",", user.Roles) : "0"), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) ]), - Issuer = _configuration["JwtConfig:Issuer"], - Audience = _configuration["JwtConfig:Audience"], + Issuer = _jwtSettings.Issuer, + Audience = _jwtSettings.Audience, Expires = DateTime.UtcNow.AddMinutes(15), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; @@ -91,7 +93,7 @@ namespace SharpbinV3.Server.Services public async Task ValidateJWTToken(string token) { var jwtHandler = new JwtSecurityTokenHandler(); - var key = Encoding.ASCII.GetBytes(_configuration["JwtConfig:Secret"]!); + var key = Encoding.ASCII.GetBytes(_jwtSettings.SecretKey); try { jwtHandler.ValidateToken(token, new TokenValidationParameters @@ -113,7 +115,7 @@ namespace SharpbinV3.Server.Services public async Task RefreshJWTToken(string token, string refreshToken) { var jwtHandler = new JwtSecurityTokenHandler(); - var key = Encoding.ASCII.GetBytes(_configuration["JwtConfig:Secret"]!); + var key = Encoding.ASCII.GetBytes(_jwtSettings.SecretKey); try { var principal = jwtHandler.ValidateToken(token, new TokenValidationParameters @@ -121,9 +123,9 @@ namespace SharpbinV3.Server.Services ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(key), ValidateIssuer = true, - ValidIssuer = _configuration["JwtConfig:Issuer"], + ValidIssuer = _jwtSettings.Issuer, ValidateAudience = true, - ValidAudience = _configuration["JwtConfig:Audience"], + ValidAudience = _jwtSettings.Audience, ClockSkew = TimeSpan.Zero, ValidateLifetime = false }, out SecurityToken validatedToken); diff --git a/SharpbinV3/Services/PasteService.cs b/SharpbinV3/Services/PasteService.cs index bdd3c64..9b07920 100644 --- a/SharpbinV3/Services/PasteService.cs +++ b/SharpbinV3/Services/PasteService.cs @@ -1,41 +1,17 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; using SharpbinV3.Server.Data; using SharpbinV3.Server.Data.Entities; +using SharpbinV3.Server.Settings; using System.Text; namespace SharpbinV3.Server.Services { - public sealed class PasteService(AppDbContext db, ICompressionService cs) : IPasteService + public sealed class PasteService(AppDbContext db, ICompressionService cs, IOptions options) : IPasteService { private readonly AppDbContext _db = db; private readonly ICompressionService _cs = cs; - private readonly static string[] ValidSyntaxLanguages = - [ - "plaintext", - "autoHotkey", - "autoIt", - "bash", - "c", - "cpp", - "csharp", - "css", - "dart", - "html", - "java", - "javascript", - "json", - "lua", - "markdown", - "php", - "python", - "ruby", - "rust", - "sql", - "swift", - "typescript", - "toml", - "xml" - ]; + private readonly PasteSettings _pasteSettings = options.Value; public async Task Create(User? author, string content, string title, string syntax, int visibility, long expiresAt) { @@ -92,10 +68,10 @@ namespace SharpbinV3.Server.Services var result = await _db.SaveChangesAsync(); return result > 0; } - public async Task Get(string id) + public async Task Get(string id) { var paste = await _db.Pastes.Include(p => p.User).FirstOrDefaultAsync(p => p.ID == id); - return paste ?? throw new KeyNotFoundException("Paste not found"); + return paste ?? null; } public async Task> GetList(int offset, int count, bool publicOnly = false) { @@ -112,11 +88,11 @@ namespace SharpbinV3.Server.Services public async Task ValidateSyntax(string syntax) { - return await Task.FromResult(ValidSyntaxLanguages.Contains(syntax)); + return await Task.FromResult(_pasteSettings.ValidSyntaxLanguages.Contains(syntax)); } public async Task ValidateTitle(string title) { - return await Task.FromResult(title.Length <= 500); + return await Task.FromResult(title.Length <= _pasteSettings.MaxTitleLength); } public async Task ValidateVisibility(int visibility) { diff --git a/SharpbinV3/Settings/JWTSettings.cs b/SharpbinV3/Settings/JWTSettings.cs new file mode 100644 index 0000000..ec30802 --- /dev/null +++ b/SharpbinV3/Settings/JWTSettings.cs @@ -0,0 +1,9 @@ +namespace SharpbinV3.Server.Settings +{ + public class JWTSettings + { + public string SecretKey { get; set; } = Utilities.GenerateRandomString(64); + public string Issuer { get; set; } = "SharpbinV3"; + public string Audience { get; set; } = "SharpbinV3.Client"; + } +} diff --git a/SharpbinV3/Settings/PasteSettings.cs b/SharpbinV3/Settings/PasteSettings.cs new file mode 100644 index 0000000..045c647 --- /dev/null +++ b/SharpbinV3/Settings/PasteSettings.cs @@ -0,0 +1,9 @@ +namespace SharpbinV3.Server.Settings +{ + public class PasteSettings + { + public string[] ValidSyntaxLanguages { get; set; } = []; + public int MaxTitleLength { get; set; } = 500; + public int MaxPasteSizeInBytes { get; set; } = 1_048_576; // 1 MB + } +} diff --git a/SharpbinV3/appsettings.json b/SharpbinV3/appsettings.json index 300bdb4..c434afa 100644 --- a/SharpbinV3/appsettings.json +++ b/SharpbinV3/appsettings.json @@ -9,9 +9,165 @@ "DefaultConnection": "Data Source=sharpbin.db" }, "AllowedHosts": "*", - "JwtConfig": { + "JwtSettings": { "Secret": "", "Issuer": "SharpbinApi", "Audience": "SharpbinClient" + }, + "PasteSettings": { + "ValidSyntaxLanguages": [ + "plaintext", + "abap", + "actionscript-3", + "ada", + "apache", + "apex", + "apl", + "applescript", + "ara", + "asm", + "astro", + "awk", + "ballerina", + "bat", + "berry", + "bibtex", + "bicep", + "blade", + "c", + "cadence", + "clarity", + "clojure", + "cmake", + "cobol", + "codeql", + "coffee", + "cpp", + "crystal", + "csharp", + "css", + "cue", + "d", + "dart", + "diff", + "docker", + "dream-maker", + "elixir", + "elm", + "erb", + "erlang", + "fish", + "fsharp", + "gdresource", + "gdscript", + "gdshader", + "gherkin", + "git-commit", + "git-rebase", + "glsl", + "gnuplot", + "go", + "graphql", + "groovy", + "hack", + "haml", + "handlebars", + "haskell", + "hcl", + "hjson", + "hlsl", + "html", + "ini", + "java", + "javascript", + "jison", + "json", + "json5", + "jsonc", + "jsonnet", + "jssm", + "jsx", + "julia", + "kotlin", + "latex", + "less", + "liquid", + "lisp", + "logo", + "lua", + "makefile", + "markdown", + "marko", + "matlab", + "mdx", + "nginx", + "nim", + "nix", + "objective-c", + "objective-cpp", + "ocaml", + "pascal", + "perl", + "php", + "plsql", + "postcss", + "powerquery", + "powershell", + "prisma", + "prolog", + "proto", + "pug", + "puppet", + "purescript", + "python", + "r", + "raku", + "razor", + "reg", + "rel", + "riscv", + "rst", + "ruby", + "rust", + "sas", + "sass", + "scala", + "scheme", + "scss", + "shaderlab", + "shell", + "smalltalk", + "solidity", + "sparql", + "sql", + "ssh-config", + "stata", + "stylus", + "svelte", + "swift", + "system-verilog", + "tasl", + "tcl", + "tex", + "toml", + "tsx", + "turtle", + "twig", + "typescript", + "v", + "vb", + "verilog", + "vhdl", + "viml", + "vue", + "wasm", + "wenyan", + "xml", + "xsl", + "yaml", + "zenscript" + ], + "MaxPasteSizeBytes": 1048576, + "MaxTitleLength": 500 } }