diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..c9caa9a --- /dev/null +++ b/LICENCE @@ -0,0 +1,30 @@ +Copyright (c) 2021-2024, flashwave +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the disclaimer +below) provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY +THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4d010a7 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Uiharu + +Uiharu is a service that looks up metadata for a given URL. + +It runs on the [Deno](https://deno.com/) Javascript runtime and requires a [Memcached](https://www.memcached.org/) server for caching. +HTML wrangling is done using the [Cheerio](https://github.com/cheeriojs/cheerio) library. diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..7b19394 --- /dev/null +++ b/deno.lock @@ -0,0 +1,28 @@ +{ + "version": "4", + "specifiers": { + "jsr:@std/fs@*": "1.0.5", + "jsr:@std/path@*": "1.0.7", + "jsr:@std/path@^1.0.7": "1.0.7" + }, + "jsr": { + "@std/fs@1.0.5": { + "integrity": "41806ad6823d0b5f275f9849a2640d87e4ef67c51ee1b8fb02426f55e02fd44e", + "dependencies": [ + "jsr:@std/path@^1.0.7" + ] + }, + "@std/path@1.0.7": { + "integrity": "76a689e07f0e15dcc6002ec39d0866797e7156629212b28f27179b8a5c3b33a1" + } + }, + "workspace": { + "packageJson": { + "dependencies": [ + "npm:cheerio@1", + "npm:express@^5.0.1", + "npm:memcache-client@^1.0.5" + ] + } + } +} diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..344f813 --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,9 @@ +module.exports = { + apps: [ + { + script: './uiharu.ts', + interpreter: 'deno', + interpreterArgs: 'run --allow-net --allow-read --allow-run --allow-env', + }, + ], +}; diff --git a/extract.mjs b/extract.mjs deleted file mode 100644 index 73ce1cc..0000000 --- a/extract.mjs +++ /dev/null @@ -1,75 +0,0 @@ -import * as cheerio from 'cheerio'; - -const readStdIn = () => { - return new Promise((resolve, reject) => { - let stdIn = ''; - - process.stdin.on('data', data => stdIn += data); - process.stdin.on('end', () => resolve(stdIn)); - process.stdin.on('error', err => reject(err)); - }); -}; - -const $ = cheerio.load(await readStdIn()); -const info = { - title: '', - metaTitle: '', - desc: '', - siteName: '', - image: '', - colour: '', - type: 'website', -}; - -const titleTag = $('title').first(); -if(titleTag.length > 0) - info.title = titleTag.text().trim(); - -const metaTags = $('meta'); -for(const elemInfo of metaTags) { - const elem = $(elemInfo); - - const nameAttr = (elem.attr('name') ?? elem.attr('property') ?? '').trim(); - if(nameAttr === '') - continue; - - const valueAttr = (elem.attr('value') ?? elem.attr('content') ?? '').trim(); - - switch(nameAttr) { - case 'og:title': - case 'twitter:title': - if(info.metaTitle === '' || valueAttr.length > info.metaTitle.length) - info.metaTitle = valueAttr; - break; - - case 'description': - case 'og:description': - case 'twitter:description': - if(info.desc === '' || valueAttr.length > info.desc.length) - info.desc = valueAttr; - break; - - case 'og:site_name': - if(info.siteName === '') - info.siteName = valueAttr; - break; - - case 'og:image': - case 'twitter:image': - if(info.image === '') - info.image = valueAttr; - break; - - case 'theme-color': - if(info.colour === '') - info.colour = valueAttr; - break; - - case 'og:type': - if(info.type === '') - info.type = `website:${valueAttr}`; - break; - } -} - -console.log(JSON.stringify(info)); diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index b52159f..0000000 --- a/package-lock.json +++ /dev/null @@ -1,1237 +0,0 @@ -{ - "name": "uiharu.edgii.net", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "dependencies": { - "cheerio": "^1.0.0", - "express": "^5.0.1", - "memcache-client": "^1.0.5" - } - }, - "node_modules/accepts": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", - "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", - "license": "MIT", - "dependencies": { - "mime-types": "^3.0.0", - "negotiator": "^1.0.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/array-flatten": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-3.0.0.tgz", - "integrity": "sha512-zPMVc3ZYlGLNk4mpK1NzP2wg0ml9t7fUgDsayR5Y5rSzxQilzR9FGu/EH2jQOcKSAeAfWeylyW8juy3OkWRvNA==", - "license": "MIT" - }, - "node_modules/body-parser": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.0.1.tgz", - "integrity": "sha512-PagxbjvuPH6tv0f/kdVbFGcb79D236SLcDTs6DrQ7GizJ88S1UWP4nMXFEo/I4fdhGRGabvFfFjVGm3M7U8JwA==", - "license": "MIT", - "dependencies": { - "bytes": "3.1.2", - "content-type": "~1.0.5", - "debug": "3.1.0", - "destroy": "1.2.0", - "http-errors": "2.0.0", - "iconv-lite": "0.5.2", - "on-finished": "2.4.1", - "qs": "6.13.0", - "raw-body": "^3.0.0", - "type-is": "~1.6.18", - "unpipe": "1.0.0" - }, - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/body-parser/node_modules/debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/body-parser/node_modules/iconv-lite": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.2.tgz", - "integrity": "sha512-kERHXvpSaB4aU3eANwidg79K8FlrN77m8G9V+0vOR3HYaRifrlwMEpT7ZBJqLSEIHnEgJTHcWK82wwLwwKwtag==", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/body-parser/node_modules/media-typer": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/body-parser/node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/body-parser/node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/body-parser/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT" - }, - "node_modules/body-parser/node_modules/type-is": { - "version": "1.6.18", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", - "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", - "license": "MIT", - "dependencies": { - "media-typer": "0.3.0", - "mime-types": "~2.1.24" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/boolbase": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", - "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==", - "license": "ISC" - }, - "node_modules/bytes": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", - "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/call-bind": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", - "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", - "license": "MIT", - "dependencies": { - "es-define-property": "^1.0.0", - "es-errors": "^1.3.0", - "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.4", - "set-function-length": "^1.2.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/cheerio": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0.tgz", - "integrity": "sha512-quS9HgjQpdaXOvsZz82Oz7uxtXiy6UIsIQcpBj7HRw2M63Skasm9qlDocAM7jNuaxdhpPU7c4kJN+gA5MCu4ww==", - "license": "MIT", - "dependencies": { - "cheerio-select": "^2.1.0", - "dom-serializer": "^2.0.0", - "domhandler": "^5.0.3", - "domutils": "^3.1.0", - "encoding-sniffer": "^0.2.0", - "htmlparser2": "^9.1.0", - "parse5": "^7.1.2", - "parse5-htmlparser2-tree-adapter": "^7.0.0", - "parse5-parser-stream": "^7.1.2", - "undici": "^6.19.5", - "whatwg-mimetype": "^4.0.0" - }, - "engines": { - "node": ">=18.17" - }, - "funding": { - "url": "https://github.com/cheeriojs/cheerio?sponsor=1" - } - }, - "node_modules/cheerio-select": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cheerio-select/-/cheerio-select-2.1.0.tgz", - "integrity": "sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==", - "license": "BSD-2-Clause", - "dependencies": { - "boolbase": "^1.0.0", - "css-select": "^5.1.0", - "css-what": "^6.1.0", - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3", - "domutils": "^3.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/fb55" - } - }, - "node_modules/content-disposition": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.0.tgz", - "integrity": "sha512-Au9nRL8VNUut/XSzbQA38+M78dzP4D+eqg3gfJHMIHHYa3bg067xj1KxMUWj+VULbiZMowKngFFbKczUrNJ1mg==", - "license": "MIT", - "dependencies": { - "safe-buffer": "5.2.1" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/content-type": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", - "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/cookie": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", - "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/cookie-signature": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.1.tgz", - "integrity": "sha512-78KWk9T26NhzXtuL26cIJ8/qNHANyJ/ZYrmEXFzUmhZdjpBv+DlWlOANRTGBt48YcyslsLrj0bMLFTmXvLRCOw==", - "license": "MIT", - "engines": { - "node": ">=6.6.0" - } - }, - "node_modules/css-select": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", - "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", - "license": "BSD-2-Clause", - "dependencies": { - "boolbase": "^1.0.0", - "css-what": "^6.1.0", - "domhandler": "^5.0.2", - "domutils": "^3.0.1", - "nth-check": "^2.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/fb55" - } - }, - "node_modules/css-what": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", - "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==", - "license": "BSD-2-Clause", - "engines": { - "node": ">= 6" - }, - "funding": { - "url": "https://github.com/sponsors/fb55" - } - }, - "node_modules/debug": { - "version": "4.3.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", - "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", - "license": "MIT", - "dependencies": { - "ms": "2.1.2" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/define-data-property": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", - "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", - "license": "MIT", - "dependencies": { - "es-define-property": "^1.0.0", - "es-errors": "^1.3.0", - "gopd": "^1.0.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/depd": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", - "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/destroy": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", - "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", - "license": "MIT", - "engines": { - "node": ">= 0.8", - "npm": "1.2.8000 || >= 1.4.16" - } - }, - "node_modules/dom-serializer": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", - "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", - "license": "MIT", - "dependencies": { - "domelementtype": "^2.3.0", - "domhandler": "^5.0.2", - "entities": "^4.2.0" - }, - "funding": { - "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" - } - }, - "node_modules/domelementtype": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", - "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/fb55" - } - ], - "license": "BSD-2-Clause" - }, - "node_modules/domhandler": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", - "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", - "license": "BSD-2-Clause", - "dependencies": { - "domelementtype": "^2.3.0" - }, - "engines": { - "node": ">= 4" - }, - "funding": { - "url": "https://github.com/fb55/domhandler?sponsor=1" - } - }, - "node_modules/domutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz", - "integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==", - "license": "BSD-2-Clause", - "dependencies": { - "dom-serializer": "^2.0.0", - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3" - }, - "funding": { - "url": "https://github.com/fb55/domutils?sponsor=1" - } - }, - "node_modules/ee-first": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", - "license": "MIT" - }, - "node_modules/encodeurl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", - "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/encoding-sniffer": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/encoding-sniffer/-/encoding-sniffer-0.2.0.tgz", - "integrity": "sha512-ju7Wq1kg04I3HtiYIOrUrdfdDvkyO9s5XM8QAj/bN61Yo/Vb4vgJxy5vi4Yxk01gWHbrofpPtpxM8bKger9jhg==", - "license": "MIT", - "dependencies": { - "iconv-lite": "^0.6.3", - "whatwg-encoding": "^3.1.1" - }, - "funding": { - "url": "https://github.com/fb55/encoding-sniffer?sponsor=1" - } - }, - "node_modules/entities": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", - "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", - "license": "BSD-2-Clause", - "engines": { - "node": ">=0.12" - }, - "funding": { - "url": "https://github.com/fb55/entities?sponsor=1" - } - }, - "node_modules/es-define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", - "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", - "license": "MIT", - "dependencies": { - "get-intrinsic": "^1.2.4" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-errors": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", - "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/escape-html": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", - "license": "MIT" - }, - "node_modules/etag": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/express": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/express/-/express-5.0.1.tgz", - "integrity": "sha512-ORF7g6qGnD+YtUG9yx4DFoqCShNMmUKiXuT5oWMHiOvt/4WFbHC6yCwQMTSBMno7AqntNCAzzcnnjowRkTL9eQ==", - "license": "MIT", - "dependencies": { - "accepts": "^2.0.0", - "body-parser": "^2.0.1", - "content-disposition": "^1.0.0", - "content-type": "~1.0.4", - "cookie": "0.7.1", - "cookie-signature": "^1.2.1", - "debug": "4.3.6", - "depd": "2.0.0", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "^2.0.0", - "fresh": "2.0.0", - "http-errors": "2.0.0", - "merge-descriptors": "^2.0.0", - "methods": "~1.1.2", - "mime-types": "^3.0.0", - "on-finished": "2.4.1", - "once": "1.4.0", - "parseurl": "~1.3.3", - "proxy-addr": "~2.0.7", - "qs": "6.13.0", - "range-parser": "~1.2.1", - "router": "^2.0.0", - "safe-buffer": "5.2.1", - "send": "^1.1.0", - "serve-static": "^2.1.0", - "setprototypeof": "1.2.0", - "statuses": "2.0.1", - "type-is": "^2.0.0", - "utils-merge": "1.0.1", - "vary": "~1.1.2" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/finalhandler": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.0.0.tgz", - "integrity": "sha512-MX6Zo2adDViYh+GcxxB1dpO43eypOGUOL12rLCOTMQv/DfIbpSJUy4oQIIZhVZkH9e+bZWKMon0XHFEju16tkQ==", - "license": "MIT", - "dependencies": { - "debug": "2.6.9", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "on-finished": "2.4.1", - "parseurl": "~1.3.3", - "statuses": "2.0.1", - "unpipe": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/finalhandler/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/finalhandler/node_modules/encodeurl": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/finalhandler/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT" - }, - "node_modules/forwarded": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", - "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/fresh": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", - "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/function-bind": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", - "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-intrinsic": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", - "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "function-bind": "^1.1.2", - "has-proto": "^1.0.1", - "has-symbols": "^1.0.3", - "hasown": "^2.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/gopd": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", - "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", - "license": "MIT", - "dependencies": { - "get-intrinsic": "^1.1.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-property-descriptors": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", - "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", - "license": "MIT", - "dependencies": { - "es-define-property": "^1.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-proto": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", - "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-symbols": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/hasown": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", - "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", - "license": "MIT", - "dependencies": { - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/htmlparser2": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-9.1.0.tgz", - "integrity": "sha512-5zfg6mHUoaer/97TxnGpxmbR7zJtPwIYFMZ/H5ucTlPZhKvtum05yiPK3Mgai3a0DyVxv7qYqoweaEd2nrYQzQ==", - "funding": [ - "https://github.com/fb55/htmlparser2?sponsor=1", - { - "type": "github", - "url": "https://github.com/sponsors/fb55" - } - ], - "license": "MIT", - "dependencies": { - "domelementtype": "^2.3.0", - "domhandler": "^5.0.3", - "domutils": "^3.1.0", - "entities": "^4.5.0" - } - }, - "node_modules/http-errors": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", - "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", - "license": "MIT", - "dependencies": { - "depd": "2.0.0", - "inherits": "2.0.4", - "setprototypeof": "1.2.0", - "statuses": "2.0.1", - "toidentifier": "1.0.1" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "license": "ISC" - }, - "node_modules/ipaddr.js": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", - "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", - "license": "MIT", - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/is-promise": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", - "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", - "license": "MIT" - }, - "node_modules/lodash.defaults": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", - "integrity": "sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==", - "license": "MIT" - }, - "node_modules/media-typer": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", - "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/memcache-client": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/memcache-client/-/memcache-client-1.0.5.tgz", - "integrity": "sha512-hUADvh+Cju3eNZ5AWGfNhdI/Y4251pc8Hxq+6RryiVNzMeEnXKQ2z+gyBBAPY4SZnC1nOtp2MJUSsnCWB9t6lg==", - "license": "Apache-2.0", - "dependencies": { - "lodash.defaults": "4.2.0", - "memcache-parser": "^1.0.0", - "optional-require": "1.1.8", - "tslib": "2.1.0" - } - }, - "node_modules/memcache-parser": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/memcache-parser/-/memcache-parser-1.0.1.tgz", - "integrity": "sha512-F5TjjHKUNMCWTVfiJD+7M9ecNbBdnK6xifYZ1WL8PoQ/dP9sB37VQV8hPtyuUqJJFj76qY70Ezj9saQ0gw2FJg==", - "license": "Apache-2.0", - "engines": { - "node": ">=4" - } - }, - "node_modules/merge-descriptors": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", - "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-db": { - "version": "1.53.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.53.0.tgz", - "integrity": "sha512-oHlN/w+3MQ3rba9rqFr6V/ypF10LSkdwUysQL7GkXoTgIWeV+tcXGA852TBxH+gsh8UWoyhR1hKcoMJTuWflpg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.0.tgz", - "integrity": "sha512-XqoSHeCGjVClAmoGFG3lVFqQFRIrTVw2OH3axRqAcfaw+gHWIfnASS92AV+Rl/mk0MupgZTRHQOjxY6YVnzK5w==", - "license": "MIT", - "dependencies": { - "mime-db": "^1.53.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "license": "MIT" - }, - "node_modules/negotiator": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", - "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/nth-check": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", - "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", - "license": "BSD-2-Clause", - "dependencies": { - "boolbase": "^1.0.0" - }, - "funding": { - "url": "https://github.com/fb55/nth-check?sponsor=1" - } - }, - "node_modules/object-inspect": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", - "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/on-finished": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", - "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", - "license": "MIT", - "dependencies": { - "ee-first": "1.1.1" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "license": "ISC", - "dependencies": { - "wrappy": "1" - } - }, - "node_modules/optional-require": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz", - "integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==", - "license": "Apache-2.0", - "dependencies": { - "require-at": "^1.0.6" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/parse5": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.2.0.tgz", - "integrity": "sha512-ZkDsAOcxsUMZ4Lz5fVciOehNcJ+Gb8gTzcA4yl3wnc273BAybYWrQ+Ks/OjCjSEpjvQkDSeZbybK9qj2VHHdGA==", - "license": "MIT", - "dependencies": { - "entities": "^4.5.0" - }, - "funding": { - "url": "https://github.com/inikulin/parse5?sponsor=1" - } - }, - "node_modules/parse5-htmlparser2-tree-adapter": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.1.0.tgz", - "integrity": "sha512-ruw5xyKs6lrpo9x9rCZqZZnIUntICjQAd0Wsmp396Ul9lN/h+ifgVV1x1gZHi8euej6wTfpqX8j+BFQxF0NS/g==", - "license": "MIT", - "dependencies": { - "domhandler": "^5.0.3", - "parse5": "^7.0.0" - }, - "funding": { - "url": "https://github.com/inikulin/parse5?sponsor=1" - } - }, - "node_modules/parse5-parser-stream": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/parse5-parser-stream/-/parse5-parser-stream-7.1.2.tgz", - "integrity": "sha512-JyeQc9iwFLn5TbvvqACIF/VXG6abODeB3Fwmv/TGdLk2LfbWkaySGY72at4+Ty7EkPZj854u4CrICqNk2qIbow==", - "license": "MIT", - "dependencies": { - "parse5": "^7.0.0" - }, - "funding": { - "url": "https://github.com/inikulin/parse5?sponsor=1" - } - }, - "node_modules/parseurl": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/path-to-regexp": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", - "integrity": "sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==", - "license": "MIT", - "engines": { - "node": ">=16" - } - }, - "node_modules/proxy-addr": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", - "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", - "license": "MIT", - "dependencies": { - "forwarded": "0.2.0", - "ipaddr.js": "1.9.1" - }, - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/qs": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", - "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", - "license": "BSD-3-Clause", - "dependencies": { - "side-channel": "^1.0.6" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/range-parser": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", - "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/raw-body": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.0.tgz", - "integrity": "sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g==", - "license": "MIT", - "dependencies": { - "bytes": "3.1.2", - "http-errors": "2.0.0", - "iconv-lite": "0.6.3", - "unpipe": "1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/require-at": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz", - "integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==", - "license": "Apache-2.0", - "engines": { - "node": ">=4" - } - }, - "node_modules/router": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/router/-/router-2.0.0.tgz", - "integrity": "sha512-dIM5zVoG8xhC6rnSN8uoAgFARwTE7BQs8YwHEvK0VCmfxQXMaOuA1uiR1IPwsW7JyK5iTt7Od/TC9StasS2NPQ==", - "license": "MIT", - "dependencies": { - "array-flatten": "3.0.0", - "is-promise": "4.0.0", - "methods": "~1.1.2", - "parseurl": "~1.3.3", - "path-to-regexp": "^8.0.0", - "setprototypeof": "1.2.0", - "utils-merge": "1.0.1" - }, - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, - "node_modules/safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "license": "MIT" - }, - "node_modules/send": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/send/-/send-1.1.0.tgz", - "integrity": "sha512-v67WcEouB5GxbTWL/4NeToqcZiAWEq90N888fczVArY8A79J0L4FD7vj5hm3eUMua5EpoQ59wa/oovY6TLvRUA==", - "license": "MIT", - "dependencies": { - "debug": "^4.3.5", - "destroy": "^1.2.0", - "encodeurl": "^2.0.0", - "escape-html": "^1.0.3", - "etag": "^1.8.1", - "fresh": "^0.5.2", - "http-errors": "^2.0.0", - "mime-types": "^2.1.35", - "ms": "^2.1.3", - "on-finished": "^2.4.1", - "range-parser": "^1.2.1", - "statuses": "^2.0.1" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/send/node_modules/fresh": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/send/node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/send/node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/send/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "license": "MIT" - }, - "node_modules/serve-static": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.1.0.tgz", - "integrity": "sha512-A3We5UfEjG8Z7VkDv6uItWw6HY2bBSBJT1KtVESn6EOoOr2jAxNhxWCLY3jDE2WcuHXByWju74ck3ZgLwL8xmA==", - "license": "MIT", - "dependencies": { - "encodeurl": "^2.0.0", - "escape-html": "^1.0.3", - "parseurl": "^1.3.3", - "send": "^1.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/set-function-length": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", - "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", - "license": "MIT", - "dependencies": { - "define-data-property": "^1.1.4", - "es-errors": "^1.3.0", - "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.4", - "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/setprototypeof": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", - "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", - "license": "ISC" - }, - "node_modules/side-channel": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", - "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.7", - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.4", - "object-inspect": "^1.13.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/statuses": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", - "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/toidentifier": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", - "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", - "license": "MIT", - "engines": { - "node": ">=0.6" - } - }, - "node_modules/tslib": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz", - "integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==", - "license": "0BSD" - }, - "node_modules/type-is": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.0.tgz", - "integrity": "sha512-gd0sGezQYCbWSbkZr75mln4YBidWUN60+devscpLF5mtRDUpiaTvKpBNrdaCvel1NdR2k6vclXybU5fBd2i+nw==", - "license": "MIT", - "dependencies": { - "content-type": "^1.0.5", - "media-typer": "^1.1.0", - "mime-types": "^3.0.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/undici": { - "version": "6.20.1", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.20.1.tgz", - "integrity": "sha512-AjQF1QsmqfJys+LXfGTNum+qw4S88CojRInG/6t31W/1fk6G59s92bnAvGz5Cmur+kQv2SURXEvvudLmbrE8QA==", - "license": "MIT", - "engines": { - "node": ">=18.17" - } - }, - "node_modules/unpipe": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/utils-merge": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", - "license": "MIT", - "engines": { - "node": ">= 0.4.0" - } - }, - "node_modules/vary": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/whatwg-encoding": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", - "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", - "license": "MIT", - "dependencies": { - "iconv-lite": "0.6.3" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/whatwg-mimetype": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", - "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", - "license": "MIT", - "engines": { - "node": ">=18" - } - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "license": "ISC" - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index c04dbdf..0000000 --- a/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "dependencies": { - "cheerio": "^1.0.0", - "express": "^5.0.1", - "memcache-client": "^1.0.5" - } -} diff --git a/uiharu.js b/uiharu.js deleted file mode 100644 index e57d339..0000000 --- a/uiharu.js +++ /dev/null @@ -1,77 +0,0 @@ -const express = require('express'); -const fs = require('fs'); -const memcache = require('memcache-client'); -const { join: pathJoin } = require('path'); - -// todo: these should not be hardcoded lol -const port = 3009; -const memcacheServer = "localhost:11211"; -const allowedOrigins = [ - 'edgii.net', - 'chat.edgii.net', - 'sockchat.edgii.net', - 'ajaxchat.edgii.net', -]; - -const app = express(); -const isDebug = fs.existsSync(pathJoin(__dirname, '.debug')); -const cache = new memcache.MemcacheClient({ server: memcacheServer }); - -const handleMetadata = (res, req, url) => { - // -}; - -app.use((req, res, next) => { - res.set('X-Powered-By', 'Uiharu'); - - const origin = req.get('origin'); - if(origin !== undefined) { - const originObj = new URL(origin); - if(!allowedOrigins.includes(originObj.host)) { - res.status(403).end(); - return; - } - - res.set('Access-Control-Allow-Origin', origin); - res.set('Vary', 'Origin'); - } - - if(req.method === 'OPTIONS') - res.set('Access-Control-Allow-Methods', 'OPTIONS, GET, POST'); - - next(); -}); - -app.use(express.static('public')); - -app.get('/metadata', (req, res) => { - res.status(501).send('Not Implemented'); -}); - -app.post('/metadata', (req, res) => { - res.status(501).send('Not Implemented'); -}); - -app.get('/metadata/batch', (req, res) => { - res.type('application/json') - .send('{"took":0,"results":[]}') - .end(); -}); - -app.post('/metadata/batch', (req, res) => { - res.type('application/json') - .send('{"took":0,"results":[]}') - .end(); -}); - -app.get('/metadata/thumb/audio', (req, res) => { - res.status(501).send('Not Implemented'); -}); - -app.get('/metadata/thumb/video', (req, res) => { - res.status(501).send('Not Implemented'); -}); - -app.listen(port, () => { - console.log(`Uiharu listening to port ${port}!`); -}); diff --git a/uiharu.ts b/uiharu.ts new file mode 100644 index 0000000..208b9ac --- /dev/null +++ b/uiharu.ts @@ -0,0 +1,665 @@ +import * as cheerio from 'npm:cheerio@^1.0.0'; +import { MemcacheClient } from 'npm:memcache-client@^1.0.5'; +import { existsSync } from "jsr:@std/fs"; +import { basename, join as pathJoin } from "jsr:@std/path"; +import { normalize as pathNormalize } from "jsr:@std/path/normalize"; +import { encodeBase64Url } from "jsr:@std/encoding/base64url"; +import { brotliCompressSync, brotliDecompressSync } from "node:zlib"; +import { parseMediaType } from "jsr:@std/media-types"; +import { Color } from "https://deno.land/x/color@v0.3.0/mod.ts"; + +// todo: these should not be hardcoded lol +const port: Number = 3009; +const memcacheServer: String = "127.0.0.1:11211"; +const allowedOrigins: String[] = [ + 'edgii.net', + 'chat.edgii.net', + 'sockchat.edgii.net', + 'ajaxchat.edgii.net', +]; +const allowOEmbed: String[] = [ // copied from wordpress source sorta + '.youtube.com', + '.youtu.be', + '.vimeo.com', + '.dailymotion.com', + '.dai.ly', + '.flickr.com', + '.flic.kr', + '.smugmug.com', + '.scribd.com', + '.wordpress.tv', + '.crowdsignal.net', + '.polldaddy.com', + '.poll.fm', + '.survey.fm', + '.twitter.com', + '.soundcloud.com', + '.spotify.com', + '.imgur.com', + '.issuu.com', + '.mixcloud.com', + '.ted.com', + '.animoto.com', + '.video214.com', + '.tumblr.com', + '.kickstarter.com', + '.kck.st', + '.cloudup.com', + '.reverbnation.com', + '.videopress.com', + '.reddit.com', + '.speakerdeck.com', + '.screencast.com', + '.amazon.com', + '.amazon.com.mx', + '.amazon.com.br', + '.amazon.ca', + '.amazon.co.uk', + '.amazon.de', + '.amazon.fr', + '.amazon.it', + '.amazon.es', + '.amazon.in', + '.amazon.nl', + '.amazon.ru', + '.amazon.co.jp', + '.amazon.com.au', + '.amazon.cn', + '.a.co', + '.amzn.to', + '.amzn.eu', + '.amzn.in', + '.amzn.asia', + '.z.cn', + '.somecards.com', + '.some.ly', + '.tiktok.com', + '.pinterest.com', + '.pinterest.com.au', + '.pinterest.com.mx', + '.wolframcloud.com', + '.pca.st', + '.anghami.com', + '.bsky.app', + '.apple.com', +]; + +const isDebug: Boolean = existsSync(pathJoin(import.meta.dirname, '.debug')); +const cache: MemcacheClient = new MemcacheClient({ + server: memcacheServer, + compressor: { + // fuck it lol + compressSync: buffer => buffer, + decompressSync: buffer => buffer, + }, +}); + +const readableStreamToString = async (stream?: ReadableStream): string => { + if(stream === null) + return ''; + + const reader = stream.getReader(); + const decoder = new TextDecoder; + let result = ''; + + for(;;) { + const { done, value } = await reader.read(); + if(done) break; + result += decoder.decode(value, { stream: true }); + } + + result += decoder.decode(); + + return result; +}; + +const isAllowedOEmbedDomain = (domain: string): Boolean => { + if(!domain.startsWith('.')) + domain = '.' + domain; + + for(const suffix of allowOEmbed) + if(domain.endsWith(suffix)) + return true; + + return false; +}; + +const extractHtmlMetaData = (html) => { + const values = {}; + + const titleTag = html('title')?.first()?.text().trim() ?? ''; + if(titleTag.length > 0) + values.title = titleTag; + + const metaDescriptionTag = html('meta[name="description"]').first()?.attr('content')?.trim() ?? ''; + if(metaDescriptionTag.length > 0) + values.description = metaDescriptionTag; + + const metaThumbnailTag = html('meta[name="thumbnail"]').first()?.attr('content')?.trim() ?? ''; + if(metaThumbnailTag.length > 0) + values.thumbnail = metaThumbnailTag; + + const metaThemeColorTag = html('meta[name="theme-color"]').first()?.attr('content')?.trim() ?? ''; + if(metaThemeColorTag.length > 0) + values.theme_color = Color.string(metaThemeColorTag).hex(); + + const linkImageSrcTag = html('link[rel="image_src"]').first()?.attr('href')?.trim() ?? ''; + if(linkImageSrcTag.length > 0) + values.image = linkImageSrcTag; + + const linkCanonicalTag = html('link[rel="canonical"]').first()?.attr('href')?.trim() ?? ''; + if(linkCanonicalTag.length > 0) + values.canonical_url = linkCanonicalTag; + + return values; +}; + +const extractOpenGraphData = (html) => { + const values = {}; + + // this is hateful + const properties = { + 'url': { type: 'url' }, + 'type': { type: 'str' }, + 'title': { type: 'str' }, + 'locale': { type: 'str' }, + 'locale:alternate': { type: 'str', array: 'locales' }, + 'description': { type: 'str' }, + 'determiner': { type: 'str' }, + 'site_name': { type: 'str' }, + + 'image': { alias: 'image:url', array: 'images' }, + 'image:url': { of: 'image', type: 'url' }, + 'image:secure_url': { of: 'image', type: 'url', protos: ['https:'] }, + 'image:type': { of: 'image', type: 'mime' }, + 'image:width': { of: 'image', type: 'int' }, + 'image:height': { of: 'image', type: 'int' }, + 'image:alt': { of: 'image', type: 'string' }, + + 'video': { alias: 'video:url', array: 'videos' }, + 'video:url': { of: 'video', type: 'url' }, + 'video:secure_url': { of: 'video', type: 'url', protos: ['https:'] }, + 'video:type': { of: 'video', type: 'mime' }, + 'video:width': { of: 'video', type: 'int' }, + 'video:height': { of: 'video', type: 'int' }, + 'video:tag': { of: 'video', type: 'str', array: 'tags' }, + + 'audio': { alias: 'audio:url', array: 'audios' }, + 'audio:url': { of: 'audio', type: 'url' }, + 'audio:secure_url': { of: 'audio', type: 'url', protos: ['https:'] }, + 'audio:type': { of: 'audio', type: 'mime' }, + }; + + const tags = html('meta[property^="og:"]'); + for(const tagInfo of tags) { + const tag = html(tagInfo); + + let name = (tag.attr('property')?.trim() ?? '').substring(3); + if(!(name in properties)) + continue; + + let value = tag.attr('content')?.trim() ?? ''; + + let propInfo = properties[name]; + let target = values; + + if(propInfo.alias) { + name = propInfo.alias; + propInfo = properties[name]; + } + + if(propInfo.of) { + name = name.substring(propInfo.of.length + 1); + const objInfo = properties[propInfo.of]; + + if(objInfo.array) { + if(objInfo.array in target) + target = target[objInfo.array]; + else + target = target[objInfo.array] = []; + + const lastItem = target[target.length - 1]; + if(lastItem === undefined || name in lastItem) { + const newItem = {}; + target.push(newItem); + target = newItem; + } else + target = lastItem; + } else { + if(!(name in target)) + target[name] = {}; + + target = target[name]; + } + } + + if(propInfo.array) { + if(propInfo.array in target) + target = target[propInfo.array]; + else + target = target[propInfo.array] = []; + } else if(name in target) + continue; + + if(propInfo.type === 'int') + value = parseInt(value); + else { + if(propInfo.type === 'mime') { + // world's most naive validation + if(value.indexOf('/') < 0) + value = undefined; + } else if(propInfo.type === 'url') { + try { + const protos = propInfo.protos ?? ['https:', 'http:']; + if(!protos.includes(new URL(value).protocol)) + value = undefined; + } catch(ex) { + console.error(ex); + value = undefined; + } + } else if(propInfo.type !== 'str') + value = undefined; + } + + if(value) { + if(propInfo.array) + target.push(value); + else + target[name] = value; + } + } + + return values; +}; + +const extractTwitterData = (html) => { + const values = {}; + const properties = [ + 'card', + 'site', + 'site:id', + 'creator', + 'creator:id', + 'description', + 'title', + 'image', + 'image:alt', + 'player', + 'player:width', + 'player:height', + 'player:stream', + ]; + + for(const property of properties) { + const tag = html(`meta[name="twitter:${property}"]`)?.first()?.attr('content')?.trim() ?? ''; + if(tag.length > 0) + values[property.replace(':', '_')] = tag; + } + + return values; +}; + +const extractLinkedData = (html) => { + const values = []; + + const tags = html('script[type="application/ld+json"]'); + for(const tagInfo of tags) + try { + values.push(JSON.parse(html(tagInfo).text().trim())); + } catch(ex) { + console.error(ex); + } + + return values; +}; + +const extractOEmbedData = async (html, url: string, urlInfo: URL) => { + // TODO: this should also support header discovery + + let oEmbedUrl: string = ''; + + // idk how long i'll bother with this for + if(urlInfo.host === 'x.com' || urlInfo.host === 'twitter.com') + oEmbedUrl = `https://publish.twitter.com/oembed?dnt=true&omit_script=true&url=${encodeURIComponent(url)}`; + else + oEmbedUrl = html('link[rel="alternate"][type="application/json+oembed"]').first()?.attr('href')?.trim() ?? ''; + + if(oEmbedUrl === '') + return {}; + + try { + return (await fetch(oEmbedUrl)).json(); + } catch(ex) { + console.error(ex); + return {}; + } +}; + +const extractMetadata = async (url: string, urlInfo: URL) => { + const data = await fetch(url); + const contentTypeRaw = data.headers.get('content-type') ?? ''; + const contentType = parseMediaType(contentTypeRaw); + + const info = {}; + const addInfoOrDont = (prop, value) => { + if(value !== null && value !== undefined) + info[prop] = value; + }; + + if(contentTypeRaw) + info.media_type = contentType[0]; + + if(['text/html', 'application/xhtml+xml'].includes(contentType[0])) { + const html = cheerio.load(await readableStreamToString(data.body)); + + const metaData = extractHtmlMetaData(html); + const ogData = extractOpenGraphData(html); + const twitterData = extractTwitterData(html); + + addInfoOrDont('url', ogData.url ?? metaData.canonical_url ?? url); + addInfoOrDont('title', ogData.title ?? twitterData.title ?? metaData.title); + addInfoOrDont('site_name', ogData.site_name); + addInfoOrDont('description', ogData.description ?? twitterData.description ?? metaData.description); + addInfoOrDont('color', metaData.theme_color); + + if(ogData.images?.length > 0) { + const image = ogData.images[0]; + info.image = info.image_url = image.secure_url ?? image.url; + if(image.width > 0) + info.image_width = image.width; + if(image.height > 0) + info.image_height = image.height; + if(image.type) + info.image_type = image.type; + if(image.alt) + info.image_alt = image.alt; + if(info.image_width > 0) + info.width = info.image_width; + if(info.image_height > 0) + info.height = info.image_height; + } else { + addInfoOrDont('image_url', twitterData.image ?? metaData.image ?? metaData.thumbnail); + addInfoOrDont('image_alt', twitterData.image_alt); + if(info.image_url) + info.image = info.image_url; + } + + if(ogData.audios?.length > 0) { + const audio = ogData.audios[0]; + info.audio_url = audio.secure_url ?? audio.url; + if(audio.type) + info.audio_type = audio.type; + } + + if(ogData.videos?.length > 0) { + const video = ogData.videos[0]; + info.video_url = video.secure_url ?? video.url; + if(video.width > 0) + info.video_width = video.width; + if(video.height > 0) + info.video_height = video.height; + if(video.type) + info.video_type = video.type; + if(video.tags?.length > 0) + info.video_tags = video.tags; + if(info.video_width > 0) + info.width = info.video_width; + if(info.video_height > 0) + info.height = info.video_height; + } else { + addInfoOrDont('video_url', twitterData.player); + addInfoOrDont('video_width', twitterData.player_width); + addInfoOrDont('video_height', twitterData.player_height); + if(info.video_width > 0) + info.width = info.video_width; + if(info.video_height > 0) + info.height = info.video_height; + } + + const linkedDatas = extractLinkedData(html); + if(linkedDatas.length > 0) + info.lds = linkedDatas; + + if(isAllowedOEmbedDomain(urlInfo.host)) { + const oEmbedData = await extractOEmbedData(html, url, urlInfo); + if(oEmbedData.version) + info.oembed = oEmbedData; + } + } else { + info.url = url; + info.title = decodeURIComponent(basename(urlInfo.pathname)); + info.site_name = urlInfo.host; + + if(contentType[0].startsWith('image/')) { + // + } else if(contentType[0].startsWith('video/')) { + // + } else if(contentType[0].startsWith('audio/')) { + // + } + } + + return info; +}; + +const requestHandler = async (req: Request): Response => { + const url = new URL(req.url); + const headers = { 'X-Powered-By': 'Uiharu' }; + + if(req.headers.has('origin')) { + const originRaw = req.headers.get('origin'); + const origin = new URL(originRaw); + + if(!allowedOrigins.includes(origin.host)) + return new Response('403', { status: 403, headers }); + + headers['Access-Control-Allow-Origin'] = originRaw; + headers['Vary'] = 'Origin'; + } + + if(req.method === 'OPTIONS') { + headers['Allow'] = 'OPTIONS, GET, HEAD, POST'; + headers['Access-Control-Allow-Methods'] = 'OPTIONS, GET, HEAD, POST'; + + // idk if this is the appropriate status code but: balls + return new Response('', { status: 204, headers }); + } + + if(url.pathname === '/metadata') { + if(!['GET', 'HEAD', 'POST'].includes(req.method)) + return new Response('', { status: 405, headers }); + + const started = performance.now(); + + headers['Content-Type'] = 'application/json;charset=utf-8'; + + let urlParamRaw: String = ''; + if(req.method === 'POST') + urlParamRaw = (await readableStreamToString(req.body)).trim(); + else + urlParamRaw = (new URLSearchParams(url.search)).get('url')?.trim() ?? ''; + + if(urlParamRaw === '') + return new Response('{"error":"metadata:uri"}', { status: 400, headers }); + if(urlParamRaw.startsWith('//')) + urlParamRaw = 'https:' + urlParamRaw; + + let urlParam: URL; + try { + urlParam = new URL(urlParamRaw); + } catch(ex) { + return new Response('{"error":"metadata:uri"}', { status: 400, headers }); + } + + urlParamRaw = urlParam.toString(); + + const urlHash = encodeBase64Url( + await crypto.subtle.digest('SHA-256', new TextEncoder().encode(urlParamRaw)) + ); + const cacheKey = `uiharu:metadata:${urlHash}`; + // const cacheInfo = await cache.get(cacheKey); + // if(cacheInfo !== undefined) + // return new Response( + // brotliDecompressSync(cacheInfo.value), + // { + // status: 200, + // headers: { + // ...headers, + // ...{ + // 'Server-Timing': `metadata;dur=${(performance.now() - started).toFixed(6)}`, + // 'X-Uiharu-State': 'cache', + // }, + // }, + // } + // ); + + try { + const json = JSON.stringify( + await extractMetadata(urlParamRaw, urlParam) + ); + + cache.set(cacheKey, brotliCompressSync(json), { + compress: false, + lifetime: 600 + }); + + return new Response(json, { + status: 200, + headers: { + ...headers, + ...{ + 'Server-Timing': `metadata;dur=${(performance.now() - started).toFixed(6)}`, + 'X-Uiharu-State': 'fresh', + }, + }, + }); + } catch(ex) { + console.error(ex); + return new Response('{"error":"metadata:lookup"}', { status: 500, headers }); + } + } + + if(url.pathname === '/metadata/batch') { + if(!['GET', 'HEAD', 'POST'].includes(req.method)) + return new Response('', { status: 405, headers }); + + return new Response('{"took":0,"results":[]}', { + headers: { + ...headers, + ...{ 'Content-Type': 'application/json' }, + }, + }); + } + + const isAudio = url.pathname === '/metadata/thumb/audio'; + const isVideo = url.pathname === '/metadata/thumb/video'; + if(isAudio || isVideo) { + if(!['HEAD', 'GET'].includes(req.method)) + return new Response('', { status: 405, headers }); + + let urlParamRaw: String = (new URLSearchParams(url.search)).get('url')?.trim() ?? ''; + if(urlParamRaw === '') + return new Response('missing url parameter', { status: 400, headers }); + + let scheme: String = ''; + try { + const urlParam = new URL(urlParamRaw); + if(typeof urlParam.protocol === 'string') + scheme = urlParam.protocol; + + urlParamRaw = urlParam.toString(); + } catch(ex) { + return new Response('invalid url parameter', { status: 400, headers }); + } + + if(!['http:', 'https:'].includes(scheme)) + return new Response('unsupported url scheme', { status: 400, headers }); + + // this seems like a terrible idea lol + const args = ['-i', urlParamRaw]; + if(isAudio) args.push('-an'); + args.push('-f'); + args.push('image2pipe'); + args.push('-c:v'); + args.push(isVideo ? 'png' : 'copy'); + args.push('-frames:v'); + args.push('1'); + args.push('-'); + + const { code, stdout, stderr } = await (new Deno.Command('ffmpeg', { + stdin: 'null', + stdout: 'piped', + stderr: 'piped', + args, + })).output(); + + if(code !== 0) { + console.error(new TextDecoder().decode(stderr)); + return new Response('decode failed', { status: 500, headers }); + } + + // TODO: bother with cache someday maybe + const thumb = stdout; + + return new Response(thumb, { + headers: { + ...headers, + ...{ + 'Content-Type': 'image/png', + 'Cache-Control': 'public, max-age=31536000, immutable', + }, + }, + }); + } + + // serving files from /public dir + if(['HEAD', 'GET'].includes(req.method)) { + const localPathPrefix = import.meta.dirname + '/public/'; + const localPathSuffix = pathNormalize(url.pathname === '/' ? '/index.html' : url.pathname); + const localPath = pathNormalize(localPathPrefix + localPathSuffix); + if(localPath.startsWith(localPathPrefix) && existsSync(localPath)) { + const mediaTypes = { + 'html': 'text/html;charset=utf-8', + 'css': 'text/css;charset=utf-8', + 'txt': 'text/plain;charset=utf-8', + 'png': 'image/png', + }; + + let mediaType: String = 'application/octet-stream'; + const dotIndex = localPathSuffix.lastIndexOf('.'); + if(dotIndex >= 0) { + const ext = localPathSuffix.substring(dotIndex + 1); + if(ext in mediaTypes) + mediaType = mediaTypes[ext]; + } + + return new Response('', { + status: 200, + headers: { + ...headers, + ...{ + 'Content-Type': mediaType, + 'X-Accel-Redirect': `/_public${localPathSuffix}`, + } + }, + }); + } + + // 404 page + return new Response('404 Not Found

404 Not Found

', { + status: 404, + headers: { + ...headers, + ...{ 'Content-Type': 'text/html;charset=utf-8' }, + }, + }); + } + + // 404 fallback + return new Response('', { + status: ['OPTIONS', 'HEAD', 'GET', 'POST'].includes(req.method) ? 404 : 405, + headers, + }); +}; + +Deno.serve({ port }, requestHandler);