From 898e2836c4bf579da043cf7d8a9409567b2e52bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Mar 2026 21:30:43 +0000 Subject: [PATCH 1/3] chore(deps): bump picomatch from 2.3.1 to 2.3.2 Bumps [picomatch](https://github.com/micromatch/picomatch) from 2.3.1 to 2.3.2. - [Release notes](https://github.com/micromatch/picomatch/releases) - [Changelog](https://github.com/micromatch/picomatch/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/picomatch/compare/2.3.1...2.3.2) --- updated-dependencies: - dependency-name: picomatch dependency-version: 2.3.2 dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 315 +++++----------------------------------------- 1 file changed, 30 insertions(+), 285 deletions(-) diff --git a/package-lock.json b/package-lock.json index 73404bf..9d6cfe4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,8 +27,8 @@ "butterchurn-presets": "^2.4.7", "client-zip": "^2.5.0", "cookie-session": "^2.1.1", - "dashjs": "https://github.com/Dash-Industry-Forum/dash.js/archive/refs/tags/v5.1.1.tar.gz", "eventemitter3": "^5.0.4", + "events": "^3.3.0", "fuse.js": "^7.1.0", "hls.js": "^1.6.15", "jose": "^6.2.0", @@ -36,6 +36,7 @@ "mime": "^4.1.0", "npm": "^11.11.1", "pocketbase": "^0.26.8", + "shaka-player": "^5.0.7", "simple-icons": "^16.12.0", "svgo": "^4.0.1", "url-toolkit": "^2.2.5", @@ -103,7 +104,6 @@ "version": "7.29.0", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -2024,7 +2024,6 @@ "resolved": "https://registry.npmjs.org/@capacitor/core/-/core-8.2.0.tgz", "integrity": "sha512-oKaoNeNtH2iIZMDFVrb1atoyRECDGHcfLMunJ5KWN8DtvpVBeeA4c41e20NTuhMxw1cSYbpq2PV2hb+/9CJxlQ==", "license": "MIT", - "peer": true, "dependencies": { "tslib": "^2.1.0" } @@ -2155,7 +2154,6 @@ } ], "license": "MIT", - "peer": true, "engines": { "node": ">=18" }, @@ -2200,7 +2198,6 @@ } ], "license": "MIT", - "peer": true, "engines": { "node": ">=18" } @@ -4031,7 +4028,9 @@ "license": "MIT" }, "node_modules/@rollup/pluginutils/node_modules/picomatch": { - "version": "2.3.1", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", "dev": true, "license": "MIT", "engines": { @@ -4412,110 +4411,6 @@ "string.prototype.matchall": "^4.0.6" } }, - "node_modules/@svta/cml-608": { - "version": "1.0.1", - "license": "Apache-2.0", - "engines": { - "node": ">=20" - } - }, - "node_modules/@svta/cml-cmcd": { - "version": "1.0.1", - "license": "Apache-2.0", - "engines": { - "node": ">=20" - }, - "peerDependencies": { - "@svta/cml-cta": "1.0.1", - "@svta/cml-structured-field-values": "1.0.1", - "@svta/cml-utils": "1.0.1" - } - }, - "node_modules/@svta/cml-cmsd": { - "version": "1.0.1", - "license": "Apache-2.0", - "engines": { - "node": ">=20" - }, - "peerDependencies": { - "@svta/cml-cta": "1.0.1", - "@svta/cml-structured-field-values": "1.0.1", - "@svta/cml-utils": "1.0.1" - } - }, - "node_modules/@svta/cml-cta": { - "version": "1.0.1", - "license": "Apache-2.0", - "peer": true, - "engines": { - "node": ">=20" - }, - "peerDependencies": { - "@svta/cml-structured-field-values": "1.0.1", - "@svta/cml-utils": "1.0.1" - } - }, - "node_modules/@svta/cml-dash": { - "version": "1.0.1", - "license": "Apache-2.0", - "engines": { - "node": ">=20" - }, - "peerDependencies": { - "@svta/cml-utils": "1.0.1" - } - }, - "node_modules/@svta/cml-id3": { - "version": "1.0.1", - "license": "Apache-2.0", - "engines": { - "node": ">=20" - }, - "peerDependencies": { - "@svta/cml-utils": "1.0.1" - } - }, - "node_modules/@svta/cml-request": { - "version": "1.0.1", - "license": "Apache-2.0", - "engines": { - "node": ">=20" - }, - "peerDependencies": { - "@svta/cml-utils": "1.0.1", - "@svta/cml-xml": "1.0.1" - } - }, - "node_modules/@svta/cml-structured-field-values": { - "version": "1.0.1", - "license": "Apache-2.0", - "peer": true, - "engines": { - "node": ">=20" - }, - "peerDependencies": { - "@svta/cml-utils": "1.0.1" - } - }, - "node_modules/@svta/cml-utils": { - "version": "1.0.1", - "license": "Apache-2.0", - "peer": true, - "engines": { - "node": ">=20" - } - }, - "node_modules/@svta/cml-xml": { - "version": "1.0.1", - "license": "Apache-2.0", - "peer": true, - "engines": { - "node": ">=20" - }, - "peerDependencies": { - "@svta/cml-utils": "1.0.1" - } - }, "node_modules/@svta/common-media-library": { "version": "0.18.1", "license": "Apache-2.0", @@ -4773,7 +4668,6 @@ "version": "25.5.0", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "undici-types": "~7.18.0" } @@ -4850,7 +4744,6 @@ "version": "8.16.0", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -4906,7 +4799,6 @@ "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -5264,39 +5156,6 @@ "node": ">=6.0.0" } }, - "node_modules/bcp-47": { - "version": "2.1.0", - "license": "MIT", - "dependencies": { - "is-alphabetical": "^2.0.0", - "is-alphanumerical": "^2.0.0", - "is-decimal": "^2.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/bcp-47-match": { - "version": "2.0.3", - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/bcp-47-normalize": { - "version": "2.3.0", - "license": "MIT", - "dependencies": { - "bcp-47": "^2.0.0", - "bcp-47-match": "^2.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/big-integer": { "version": "1.6.52", "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.52.tgz", @@ -5396,7 +5255,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -5667,10 +5525,6 @@ "node": ">=12" } }, - "node_modules/codem-isoboxer": { - "version": "0.3.10", - "license": "MIT" - }, "node_modules/color": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz", @@ -6646,30 +6500,6 @@ "node": ">=8" } }, - "node_modules/dashjs": { - "version": "5.1.1", - "resolved": "https://github.com/Dash-Industry-Forum/dash.js/archive/refs/tags/v5.1.1.tar.gz", - "integrity": "sha512-lhD1tvEe4PO6t086flm6WfO2Jt1EOIolDQ17F3vLomMthaL1RH96h8peIQTvrDvfSJTRXeisL+CwPj4oud5e9g==", - "license": "BSD-3-Clause", - "dependencies": { - "@svta/cml-608": "1.0.1", - "@svta/cml-cmcd": "1.0.1", - "@svta/cml-cmsd": "1.0.1", - "@svta/cml-dash": "1.0.1", - "@svta/cml-id3": "1.0.1", - "@svta/cml-request": "1.0.1", - "@svta/cml-xml": "1.0.1", - "bcp-47-match": "^2.0.3", - "bcp-47-normalize": "^2.3.0", - "codem-isoboxer": "0.3.10", - "fast-deep-equal": "3.1.3", - "html-entities": "^2.5.2", - "imsc": "^1.1.5", - "localforage": "^1.10.0", - "path-browserify": "^1.0.1", - "ua-parser-js": "^1.0.37" - } - }, "node_modules/data-view-buffer": { "version": "1.0.2", "dev": true, @@ -7368,7 +7198,6 @@ "version": "9.39.4", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -7569,6 +7398,15 @@ "version": "5.0.4", "license": "MIT" }, + "node_modules/events": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", + "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", + "license": "MIT", + "engines": { + "node": ">=0.8.x" + } + }, "node_modules/events-universal": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/events-universal/-/events-universal-1.0.1.tgz", @@ -7599,6 +7437,7 @@ }, "node_modules/fast-deep-equal": { "version": "3.1.3", + "dev": true, "license": "MIT" }, "node_modules/fast-fifo": { @@ -8992,20 +8831,6 @@ "dev": true, "license": "ISC" }, - "node_modules/html-entities": { - "version": "2.6.0", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/mdevils" - }, - { - "type": "patreon", - "url": "https://patreon.com/mdevils" - } - ], - "license": "MIT" - }, "node_modules/html-tags": { "version": "3.3.1", "dev": true, @@ -9084,10 +8909,6 @@ "node": ">= 4" } }, - "node_modules/immediate": { - "version": "3.0.6", - "license": "MIT" - }, "node_modules/import-fresh": { "version": "3.3.1", "dev": true, @@ -9111,17 +8932,6 @@ "node": ">=4" } }, - "node_modules/imsc": { - "version": "1.1.5", - "license": "BSD-2-Clause", - "dependencies": { - "sax": "1.2.1" - } - }, - "node_modules/imsc/node_modules/sax": { - "version": "1.2.1", - "license": "ISC" - }, "node_modules/imurmurhash": { "version": "0.1.4", "dev": true, @@ -9180,26 +8990,6 @@ "node": ">=8" } }, - "node_modules/is-alphabetical": { - "version": "2.0.1", - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/is-alphanumerical": { - "version": "2.0.1", - "license": "MIT", - "dependencies": { - "is-alphabetical": "^2.0.0", - "is-decimal": "^2.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/is-array-buffer": { "version": "3.0.5", "dev": true, @@ -9324,14 +9114,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-decimal": { - "version": "2.0.1", - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/is-docker": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", @@ -9914,7 +9696,6 @@ "integrity": "sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@keyv/serialize": "^1.1.1" } @@ -9960,13 +9741,6 @@ "node": ">= 0.8.0" } }, - "node_modules/lie": { - "version": "3.1.1", - "license": "MIT", - "dependencies": { - "immediate": "~3.0.5" - } - }, "node_modules/lines-and-columns": { "version": "1.2.4", "dev": true, @@ -10037,13 +9811,6 @@ "node": ">=4" } }, - "node_modules/localforage": { - "version": "1.10.0", - "license": "Apache-2.0", - "dependencies": { - "lie": "3.1.1" - } - }, "node_modules/locate-path": { "version": "6.0.0", "dev": true, @@ -10232,7 +9999,9 @@ } }, "node_modules/micromatch/node_modules/picomatch": { - "version": "2.3.1", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", "dev": true, "license": "MIT", "engines": { @@ -12352,7 +12121,6 @@ "version": "4.0.3", "inBundle": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -12635,10 +12403,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/path-browserify": { - "version": "1.0.1", - "license": "MIT" - }, "node_modules/path-exists": { "version": "4.0.0", "dev": true, @@ -12714,7 +12478,9 @@ "license": "ISC" }, "node_modules/picomatch": { - "version": "4.0.3", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", + "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", "dev": true, "license": "MIT", "engines": { @@ -12787,7 +12553,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -12861,7 +12626,6 @@ "version": "7.1.1", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -13823,7 +13587,6 @@ "integrity": "sha512-cIFJOD1DESzpjOBl763Kp1AH7UE/0fcdHe6rZXUdQ9c50uvgigvW97u3IcSeBwOkgqL/PXPBktBCh0KEu5L8XQ==", "dev": true, "license": "MIT", - "peer": true, "bin": { "rollup": "dist/bin/rollup" }, @@ -14027,6 +13790,15 @@ "node": ">=0.10.0" } }, + "node_modules/shaka-player": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/shaka-player/-/shaka-player-5.0.8.tgz", + "integrity": "sha512-f886rKRvQ0IKhWGk+rINS++YTjTJyc4DT5YypTsHW6wiNV9fiHi2n35+lg5R+hj9RfhqkmJHMjJb3gprUTNa8w==", + "license": "Apache-2.0", + "engines": { + "node": ">=18" + } + }, "node_modules/sharp": { "version": "0.34.5", "dev": true, @@ -14631,7 +14403,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "@csstools/css-parser-algorithms": "^3.0.5", "@csstools/css-syntax-patches-for-csstree": "^1.0.19", @@ -15025,7 +14796,6 @@ "version": "5.46.1", "dev": true, "license": "BSD-2-Clause", - "peer": true, "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.15.0", @@ -15333,7 +15103,6 @@ "version": "5.9.3", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -15342,30 +15111,6 @@ "node": ">=14.17" } }, - "node_modules/ua-parser-js": { - "version": "1.0.41", - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/ua-parser-js" - }, - { - "type": "paypal", - "url": "https://paypal.me/faisalman" - }, - { - "type": "github", - "url": "https://github.com/sponsors/faisalman" - } - ], - "license": "MIT", - "bin": { - "ua-parser-js": "script/cli.js" - }, - "engines": { - "node": "*" - } - }, "node_modules/uglify-js": { "version": "3.19.3", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.3.tgz", From 535153d778fcf7ebbb2a4ac40dfce35ee8f93c42 Mon Sep 17 00:00:00 2001 From: edideaur Date: Thu, 26 Mar 2026 02:04:39 +0200 Subject: [PATCH 2/3] slop 2 --- public/editors-picks.json | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/public/editors-picks.json b/public/editors-picks.json index ab4fbe4..225f77b 100644 --- a/public/editors-picks.json +++ b/public/editors-picks.json @@ -1,4 +1,70 @@ [ + { + "type": "album", + "id": 18083938, + "title": "The Glow, Pt. 2", + "artist": { "id": 3941394, "name": "The Microphones" }, + "releaseDate": "2001-09-25", + "cover": "ec648c22-9140-41d3-a7ae-0ba69ef0420e", + "explicit": false, + "audioQuality": "LOSSLESS", + "mediaMetadata": { "tags": ["LOSSLESS"] } + }, + { + "type": "album", + "id": 382839956, + "title": "my anti-aircraft friend", + "artist": { "id": 19359095, "name": "julie" }, + "releaseDate": "2024-09-13", + "cover": "ac790b52-61cc-460c-9277-bdac88722cc3", + "explicit": false, + "audioQuality": "LOSSLESS", + "mediaMetadata": { "tags": ["LOSSLESS", "HIRES_LOSSLESS"] } + }, + { + "type": "album", + "id": 456475370, + "title": "It Aint Nun", + "artist": { "id": 9981740, "name": "CHRIST DILLINGER" }, + "releaseDate": "2024-09-12", + "cover": "3ffc27f6-a77c-4e68-ba44-e04f034783be", + "explicit": true, + "audioQuality": "LOSSLESS", + "mediaMetadata": { "tags": ["LOSSLESS", "HIRES_LOSSLESS"] } + }, + { + "type": "album", + "id": 112547160, + "title": "R F Y", + "artist": { "id": 36042731, "name": "RFY" }, + "releaseDate": "2019-06-27", + "cover": "ffe3f6f9-5bc8-4b53-99c3-9b83676c099a", + "explicit": true, + "audioQuality": "LOSSLESS", + "mediaMetadata": { "tags": ["LOSSLESS"] } + }, + { + "type": "album", + "id": 18658568, + "title": "100% Ghetto 4", + "artist": { "id": 4191963, "name": "DJ Clent" }, + "releaseDate": "2010-10-02", + "cover": "82b839bd-7cf6-4650-bade-192f47301ffd", + "explicit": true, + "audioQuality": "LOSSLESS", + "mediaMetadata": { "tags": ["LOSSLESS"] } + }, + { + "type": "album", + "id": 504004321, + "title": "Half Blood (BloodLuxe)", + "artist": { "id": 50799233, "name": "slayr" }, + "releaseDate": "2025-11-05", + "cover": "2767cc63-7e92-4a48-aa4b-806a3ea7ec1c", + "explicit": true, + "audioQuality": "LOSSLESS", + "mediaMetadata": { "tags": ["LOSSLESS", "HIRES_LOSSLESS"] } + }, { "type": "album", "id": 89313048, @@ -164,6 +230,17 @@ "audioQuality": "LOSSLESS", "mediaMetadata": { "tags": ["LOSSLESS", "HIRES_LOSSLESS"] } }, + { + "type": "album", + "id": 365819314, + "title": "One Life", + "artist": { "id": "17300439", "name": "1oneam" }, + "releaseDate": "2024-05-30", + "cover": "eb5d74f6-7403-4404-8452-9b68713445fe", + "explicit": true, + "audioQuality": "LOSSLESS", + "mediaMetadata": { "tags": ["LOSSLESS"] } + }, { "type": "album", "id": 379517195, From a5a893c1ef8d521ba7db2c4cbfa36f4941eae462 Mon Sep 17 00:00:00 2001 From: edidealt Date: Thu, 26 Mar 2026 11:36:25 +0200 Subject: [PATCH 3/3] Delete functions/upload.js --- functions/upload.js | 195 -------------------------------------------- 1 file changed, 195 deletions(-) delete mode 100644 functions/upload.js diff --git a/functions/upload.js b/functions/upload.js deleted file mode 100644 index 31a1183..0000000 --- a/functions/upload.js +++ /dev/null @@ -1,195 +0,0 @@ -const API_URL = 'https://catbox.moe/user/api.php'; -const R2_PUBLIC_URL = 'https://cucks.qzz.io'; - -const R2_ENDPOINT = 'https://faae2f5c0a232c7f3733ef597c55bd69.r2.cloudflarestorage.com'; -const R2_BUCKET = 'monochrome-image-uploads'; - -async function hmac(key, data) { - const cryptoKey = await crypto.subtle.importKey('raw', key, { name: 'HMAC', hash: 'SHA-1' }, false, ['sign']); - return new Uint8Array(await crypto.subtle.sign('HMAC', cryptoKey, data)); -} - -async function sha256(data) { - return new Uint8Array(await crypto.subtle.digest('SHA-256', data)); -} - -function buf2hex(buffer) { - return Array.from(buffer) - .map((b) => b.toString(16).padStart(2, '0')) - .join(''); -} - -async function signature(secretKey, dateStamp, region, service, stringToSign) { - const kDate = await hmac(new TextEncoder().encode('AWS4' + secretKey), new TextEncoder().encode(dateStamp)); - const kRegion = await hmac(kDate, new TextEncoder().encode(region)); - const kService = await hmac(kRegion, new TextEncoder().encode(service)); - const kSigning = await hmac(kService, new TextEncoder().encode('aws4_request')); - const sig = await hmac(kSigning, new TextEncoder().encode(stringToSign)); - return buf2hex(sig); -} - -async function createSignature(method, path, headers, payloadHash, accessKeyId, secretAccessKey, amzDate, dateStamp) { - const region = 'auto'; - const service = 's3'; - - const signedHeaders = Object.keys(headers).sort().join(';'); - const canonicalHeaders = - Object.entries(headers) - .sort((a, b) => a[0].localeCompare(b[0])) - .map(([k, v]) => `${k.toLowerCase()}:${v}`) - .join('\n') + '\n'; - - const canonicalRequest = `${method}\n${path}\n\n${canonicalHeaders}\n${signedHeaders}\n${payloadHash}`; - const credentialScope = `${dateStamp}/${region}/${service}/aws4_request`; - const stringToSign = `AWS4-HMAC-SHA256\n${amzDate}\n${credentialScope}\n${buf2hex(await sha256(new TextEncoder().encode(canonicalRequest)))}`; - - const sig = await signature(secretAccessKey, dateStamp, region, service, stringToSign); - return `AWS4-HMAC-SHA256 Credential=${accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${sig}`; -} - -export async function onRequest(context) { - const { request, env } = context; - - if (request.method === 'OPTIONS') { - return new Response(null, { status: 204, headers: corsHeaders() }); - } - - if (request.method !== 'POST') { - return jsonError('Method not allowed', 405); - } - - const useR2 = env.R2_ENABLED === 'true'; - - try { - const contentType = request.headers.get('content-type') || ''; - let file; - let fileName; - let fileType; - - if (contentType.includes('application/json')) { - const body = await request.json(); - if (!body.fileUrl) return jsonError('No fileUrl provided', 400); - - const res = await fetch(body.fileUrl); - if (!res.ok) throw new Error('Failed to fetch remote file'); - - file = await res.arrayBuffer(); - fileName = body.fileName || body.fileUrl.split('/').pop(); - fileType = res.headers.get('content-type') || 'application/octet-stream'; - } else { - const form = await request.formData(); - const uploaded = form.get('file'); - if (!uploaded) return jsonError('No file provided', 400); - - if (uploaded.size > 10 * 1024 * 1024) { - return jsonError('File exceeds 10MB', 400); - } - - file = await uploaded.arrayBuffer(); - fileName = uploaded.name; - fileType = uploaded.type || 'application/octet-stream'; - } - - let url; - - if (useR2) { - try { - const key = `${Date.now()}-${fileName}`; - const now = new Date(); - const amzDate = - now - .toISOString() - .replace(/[:-]|\.\d{3}/g, '') - .slice(0, 15) + 'Z'; - const dateStamp = now - .toISOString() - .replace(/[:-]|\.\d{3}/g, '') - .slice(0, 8); - const payloadHash = buf2hex(await sha256(file)); - - const host = new URL(R2_ENDPOINT).host; - const headers = { - 'Content-Type': fileType, - 'Content-Length': file.byteLength, - 'x-amz-date': amzDate, - 'x-amz-content-sha256': payloadHash, - Host: host, - }; - - const auth = await createSignature( - 'PUT', - `/${R2_BUCKET}/${key}`, - headers, - payloadHash, - env.R2_ACCESS_KEY_ID, - env.R2_SECRET_ACCESS_KEY, - amzDate, - dateStamp - ); - headers['Authorization'] = auth; - - const res = await fetch(`${R2_ENDPOINT}/${R2_BUCKET}/${key}`, { - method: 'PUT', - headers, - body: new Uint8Array(file), - }); - - if (!res.ok) { - const err = await res.text(); - throw new Error(`R2 error: ${res.status} - ${err}`); - } - - url = `${R2_PUBLIC_URL}/${key}`; - } catch (r2Err) { - console.error('R2 upload error:', r2Err); - return jsonError(`R2 upload failed: ${r2Err.message}`, 500); - } - } else { - const formData = new FormData(); - formData.append('reqtype', 'fileupload'); - formData.append('fileToUpload', new Blob([file], { type: fileType }), fileName); - - const response = await fetch(API_URL, { - method: 'POST', - body: formData, - }); - - const responseText = await response.text(); - - if (!response.ok) { - throw new Error(`Upload failed: ${responseText}`); - } - - url = responseText.trim(); - } - - return jsonResponse({ - success: true, - url: url, - }); - } catch (err) { - return jsonError(err.message, 500); - } -} - -function jsonResponse(obj, status = 200) { - return new Response(JSON.stringify(obj), { - status, - headers: { - 'Content-Type': 'application/json', - ...corsHeaders(), - }, - }); -} - -function jsonError(message, status) { - return jsonResponse({ success: false, error: message }, status); -} - -function corsHeaders() { - return { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'POST, OPTIONS', - 'Access-Control-Allow-Headers': '*', - }; -}