From dcfcb99e116aed1881035386d6aca28d5b0bce92 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sat, 27 Jul 2024 12:39:51 +0600 Subject: [PATCH 01/13] add --- package-lock.json | 31 ++++++++++++++++++++++++++++++- package.json | 5 ++++- src/routes/proxy/+server.ts | 24 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/routes/proxy/+server.ts diff --git a/package-lock.json b/package-lock.json index f5b95e6d..42beffb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,9 +11,12 @@ "./scripts" ], "dependencies": { + "@types/node": "^20.14.12", "@vercel/analytics": "^1.3.1", "@vercel/speed-insights": "^1.0.12", - "svelte-portal": "^2.2.1" + "color-thief-wasm": "^1.0.11", + "svelte-portal": "^2.2.1", + "undici": "^6.19.4" }, "devDependencies": { "@playwright/test": "^1.45.3", @@ -1234,6 +1237,14 @@ "integrity": "sha512-HMwFiRujE5PjrgwHQ25+bsLJgowjGjm5Z8FVSf0N6PwgJrwxH0QxzHYDcKsTfV3wva0vzrpqMTJS2jXPr5BMEQ==", "dev": true }, + "node_modules/@types/node": { + "version": "20.14.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.12.tgz", + "integrity": "sha512-r7wNXakLeSsGT0H1AU863vS2wa5wBOK4bWMjZz2wj+8nBx+m5PeIn0k8AloSLpRuiwdRQZwarZqHE4FNArPuJQ==", + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/@types/pug": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.10.tgz", @@ -2170,6 +2181,11 @@ "simple-swizzle": "^0.2.2" } }, + "node_modules/color-thief-wasm": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/color-thief-wasm/-/color-thief-wasm-1.0.11.tgz", + "integrity": "sha512-xXq3BGTXqlcUfAKu3DIlhu4+7VvRgBI+n2/v97yKcuH6uAA2R1C7ZuL5Rzz9kDQfHgOh4Ok8DmUhfjmHHiGDzg==" + }, "node_modules/color-thief-wasm-web": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/color-thief-wasm-web/-/color-thief-wasm-web-1.0.11.tgz", @@ -6150,6 +6166,19 @@ "node": ">=14.17" } }, + "node_modules/undici": { + "version": "6.19.4", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.4.tgz", + "integrity": "sha512-i3uaEUwNdkRq2qtTRRJb13moW5HWqviu7Vl7oYRYz++uPtGHJj+x7TGjcEuwS5Mt2P4nA0U9dhIX3DdB6JGY0g==", + "engines": { + "node": ">=18.17" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "node_modules/universalify": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", diff --git a/package.json b/package.json index 71e56b2f..5733f72a 100644 --- a/package.json +++ b/package.json @@ -106,8 +106,11 @@ "@rollup/rollup-win32-arm64-msvc": "4.19.0" }, "dependencies": { + "@types/node": "^20.14.12", "@vercel/analytics": "^1.3.1", "@vercel/speed-insights": "^1.0.12", - "svelte-portal": "^2.2.1" + "color-thief-wasm": "^1.0.11", + "svelte-portal": "^2.2.1", + "undici": "^6.19.4" } } diff --git a/src/routes/proxy/+server.ts b/src/routes/proxy/+server.ts new file mode 100644 index 00000000..75f4818a --- /dev/null +++ b/src/routes/proxy/+server.ts @@ -0,0 +1,24 @@ +import { error } from "@sveltejs/kit"; +import type { RequestHandler } from "./$types"; +import { get_color_thief } from "color-thief-wasm"; +import undici from "undici"; + +export const GET: RequestHandler = async ({ url, setHeaders }) => { + try { + const image_url = url.searchParams.get("url"); + if (!image_url) throw new Error(`There must be an "url" param`); + + const { statusCode, body } = await undici.request(image_url); + if (statusCode != 200) throw new Error(`The image returned ${statusCode}`); + + const image_buffer = new Uint8Array(await body.arrayBuffer()); + const colors = get_color_thief(image_buffer, 64 * 64, 10, 5) as Array; + + setHeaders({ + "Content-Type": "application/json" + }); + return new Response(JSON.stringify({ colors: colors, image: image_buffer })); + } catch (e) { + error(400, String(e)); + } +}; From da2e2c479c7964ca24cdf23ec64ba0a3e602d7a4 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sat, 27 Jul 2024 12:41:36 +0600 Subject: [PATCH 02/13] d --- src/routes/{proxy => api/colorthief}/+server.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/routes/{proxy => api/colorthief}/+server.ts (100%) diff --git a/src/routes/proxy/+server.ts b/src/routes/api/colorthief/+server.ts similarity index 100% rename from src/routes/proxy/+server.ts rename to src/routes/api/colorthief/+server.ts From 5d72e5aee3ed1e008223adde8440e1846f5c109a Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 28 Jul 2024 10:05:05 +0600 Subject: [PATCH 03/13] Create image.svelte --- src/lib/components/image.svelte | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/lib/components/image.svelte diff --git a/src/lib/components/image.svelte b/src/lib/components/image.svelte new file mode 100644 index 00000000..5fec8636 --- /dev/null +++ b/src/lib/components/image.svelte @@ -0,0 +1,28 @@ + + +{#await fetch_image()} + +{:then res} + +{:catch error} + +{/await} From 0ca3b351a6fc2778e49ab96237c411afbab4b4b5 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 28 Jul 2024 10:15:06 +0600 Subject: [PATCH 04/13] Update image.svelte --- src/lib/components/image.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/components/image.svelte b/src/lib/components/image.svelte index 5fec8636..8bb957d4 100644 --- a/src/lib/components/image.svelte +++ b/src/lib/components/image.svelte @@ -3,7 +3,7 @@ const API_URL = new URL($page.url.hostname + "/api/colorthief"); - let { url }: { url: string } = $props(); + let { url, dominant_color = $bindable() }: { url: string; dominant_color: number[] } = $props(); API_URL.searchParams.append("url", url); @@ -12,6 +12,8 @@ if (res.status != 200) throw new Error("Image is not loadable from server"); const data = (await res.json()) as { colors: number[]; image: Uint8Array }; + dominant_color = data.colors; + const arrayBufferView = new Uint8Array(data.image); const blob = new Blob([arrayBufferView], { type: "image/jpeg" }); const image = URL.createObjectURL(blob); From 589d0eff686cefca025de90a23c4728c5e880282 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 28 Jul 2024 12:47:05 +0600 Subject: [PATCH 05/13] add --- package-lock.json | 377 +++++++++++++++++++++++++-- package.json | 7 +- src/lib/components/image.svelte | 2 +- src/routes/api/colorthief/+server.ts | 5 +- 4 files changed, 367 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 42beffb9..eb26221f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,11 +11,10 @@ "./scripts" ], "dependencies": { - "@types/node": "^20.14.12", "@vercel/analytics": "^1.3.1", "@vercel/speed-insights": "^1.0.12", "color-thief-wasm": "^1.0.11", - "svelte-portal": "^2.2.1", + "sharp": "^0.33.4", "undici": "^6.19.4" }, "devDependencies": { @@ -31,6 +30,7 @@ "@tailwindcss/typography": "^0.5.13", "@types/chroma-js": "^2.4.4", "@types/eslint": "^9.6.0", + "@types/node": "^20.14.12", "@typescript-eslint/eslint-plugin": "^7.17.0", "@typescript-eslint/parser": "^7.17.0", "@vitejs/plugin-vue": "^5.1.0", @@ -84,6 +84,7 @@ "svelte-check": "^3.8.4", "svelte-gestures": "^5.0.4", "svelte-intersection-observer": "^1.0.0", + "svelte-portal": "^2.2.1", "sveltekit-i18n": "^2.4.2", "tailwind-merge": "^2.4.0", "tailwind-scrollbar": "^3.1.0", @@ -150,6 +151,15 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@emnapi/runtime": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz", + "integrity": "sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@esbuild/linux-x64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz", @@ -372,6 +382,161 @@ "url": "https://github.com/sponsors/nzakas" } }, + "node_modules/@img/sharp-darwin-arm64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.4.tgz", + "integrity": "sha512-p0suNqXufJs9t3RqLBO6vvrgr5OhgbWp76s5gTRvdmxmuv9E1rcaqGUsl3l4mKVmXPkTkTErXediAui4x+8PSA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "glibc": ">=2.26", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-arm64": "1.0.2" + } + }, + "node_modules/@img/sharp-darwin-x64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.33.4.tgz", + "integrity": "sha512-0l7yRObwtTi82Z6ebVI2PnHT8EB2NxBgpK2MiKJZJ7cz32R4lxd001ecMhzzsZig3Yv9oclvqqdV93jo9hy+Dw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "glibc": ">=2.26", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-x64": "1.0.2" + } + }, + "node_modules/@img/sharp-libvips-darwin-arm64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.0.2.tgz", + "integrity": "sha512-tcK/41Rq8IKlSaKRCCAuuY3lDJjQnYIW1UXU1kxcEKrfL8WR7N6+rzNoOxoQRJWTAECuKwgAHnPvqXGN8XfkHA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "macos": ">=11", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-x64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.0.2.tgz", + "integrity": "sha512-Ofw+7oaWa0HiiMiKWqqaZbaYV3/UGL2wAPeLuJTx+9cXpCRdvQhCLG0IH8YGwM0yGWGLpsF4Su9vM1o6aer+Fw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "macos": ">=10.13", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.0.2.tgz", + "integrity": "sha512-iLWCvrKgeFoglQxdEwzu1eQV04o8YeYGFXtfWU26Zr2wWT3q3MTzC+QTCO3ZQfWd3doKHT4Pm2kRmLbupT+sZw==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.28", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.0.2.tgz", + "integrity": "sha512-x7kCt3N00ofFmmkkdshwj3vGPCnmiDh7Gwnd4nUwZln2YjqPxV1NlTyZOvoDWdKQVDL911487HOueBvrpflagw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.26", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-s390x": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.0.2.tgz", + "integrity": "sha512-cmhQ1J4qVhfmS6szYW7RT+gLJq9dH2i4maq+qyXayUSn9/3iY2ZeWpbAgSpSVbV2E1JUL2Gg7pwnYQ1h8rQIog==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.28", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, "node_modules/@img/sharp-libvips-linux-x64": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.2.tgz", @@ -379,7 +544,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -394,6 +558,27 @@ "url": "https://opencollective.com/libvips" } }, + "node_modules/@img/sharp-libvips-linuxmusl-arm64": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.0.2.tgz", + "integrity": "sha512-3CAkndNpYUrlDqkCM5qhksfE+qSIREVpyoeHIU6jd48SJZViAmznoQQLAv4hVXF7xyUB9zf+G++e2v1ABjCbEQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "musl": ">=1.2.2", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, "node_modules/@img/sharp-libvips-linuxmusl-x64": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.2.tgz", @@ -401,7 +586,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -416,6 +600,81 @@ "url": "https://opencollective.com/libvips" } }, + "node_modules/@img/sharp-linux-arm": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.33.4.tgz", + "integrity": "sha512-RUgBD1c0+gCYZGCCe6mMdTiOFS0Zc/XrN0fYd6hISIKcDUbAW5NtSQW9g/powkrXYm6Vzwd6y+fqmExDuCdHNQ==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.28", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm": "1.0.2" + } + }, + "node_modules/@img/sharp-linux-arm64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.33.4.tgz", + "integrity": "sha512-2800clwVg1ZQtxwSoTlHvtm9ObgAax7V6MTAB/hDT945Tfyy3hVkmiHpeLPCKYqYR1Gcmv1uDZ3a4OFwkdBL7Q==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.26", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm64": "1.0.2" + } + }, + "node_modules/@img/sharp-linux-s390x": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.33.4.tgz", + "integrity": "sha512-h3RAL3siQoyzSoH36tUeS0PDmb5wINKGYzcLB5C6DIiAn2F3udeFAum+gj8IbA/82+8RGCTn7XW8WTFnqag4tQ==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "glibc": ">=2.31", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-s390x": "1.0.2" + } + }, "node_modules/@img/sharp-linux-x64": { "version": "0.33.4", "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.4.tgz", @@ -423,7 +682,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -442,6 +700,31 @@ "@img/sharp-libvips-linux-x64": "1.0.2" } }, + "node_modules/@img/sharp-linuxmusl-arm64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.33.4.tgz", + "integrity": "sha512-nhr1yC3BlVrKDTl6cO12gTpXMl4ITBUZieehFvMntlCXFzH2bvKG76tBL2Y/OqhupZt81pR7R+Q5YhJxW0rGgQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "musl": ">=1.2.2", + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-arm64": "1.0.2" + } + }, "node_modules/@img/sharp-linuxmusl-x64": { "version": "0.33.4", "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.4.tgz", @@ -449,7 +732,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -468,6 +750,69 @@ "@img/sharp-libvips-linuxmusl-x64": "1.0.2" } }, + "node_modules/@img/sharp-wasm32": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.33.4.tgz", + "integrity": "sha512-Bmmauh4sXUsUqkleQahpdNXKvo+wa1V9KhT2pDA4VJGKwnKMJXiSTGphn0gnJrlooda0QxCtXc6RX1XAU6hMnQ==", + "cpu": [ + "wasm32" + ], + "optional": true, + "dependencies": { + "@emnapi/runtime": "^1.1.1" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-ia32": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.33.4.tgz", + "integrity": "sha512-99SJ91XzUhYHbx7uhK3+9Lf7+LjwMGQZMDlO/E/YVJ7Nc3lyDFZPGhjwiYdctoH2BOzW9+TnfqcaMKt0jHLdqw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-x64": { + "version": "0.33.4", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.33.4.tgz", + "integrity": "sha512-3QLocdTRVIrFNye5YocZl+KKpYKP+fksi1QhmOArgx7GyhIbQp/WrJRu176jm8IxromS7RIkzMiMINVdBtC8Aw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "npm": ">=9.6.5", + "pnpm": ">=7.1.0", + "yarn": ">=3.2.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -1241,6 +1586,7 @@ "version": "20.14.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.12.tgz", "integrity": "sha512-r7wNXakLeSsGT0H1AU863vS2wa5wBOK4bWMjZz2wj+8nBx+m5PeIn0k8AloSLpRuiwdRQZwarZqHE4FNArPuJQ==", + "dev": true, "dependencies": { "undici-types": "~5.26.4" } @@ -2144,7 +2490,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz", "integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==", - "dev": true, "dependencies": { "color-convert": "^2.0.1", "color-string": "^1.9.0" @@ -2157,7 +2502,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "dependencies": { "color-name": "~1.1.4" }, @@ -2168,14 +2512,12 @@ "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, "node_modules/color-string": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz", "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", - "dev": true, "dependencies": { "color-name": "^1.0.0", "simple-swizzle": "^0.2.2" @@ -2461,7 +2803,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", "integrity": "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==", - "dev": true, "engines": { "node": ">=8" } @@ -3508,8 +3849,7 @@ "node_modules/is-arrayish": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", - "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==", - "dev": true + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" }, "node_modules/is-binary-path": { "version": "2.1.0", @@ -5262,7 +5602,6 @@ "version": "7.6.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", - "dev": true, "bin": { "semver": "bin/semver.js" }, @@ -5285,7 +5624,6 @@ "version": "0.33.4", "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.33.4.tgz", "integrity": "sha512-7i/dt5kGl7qR4gwPRD2biwD2/SvBn3O04J77XKFgL2OnZtQw+AG9wnuS/csmu80nPRHLYE9E41fyEiG8nhH6/Q==", - "dev": true, "hasInstallScript": true, "dependencies": { "color": "^4.2.3", @@ -5364,7 +5702,6 @@ "version": "0.2.2", "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", "integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==", - "dev": true, "dependencies": { "is-arrayish": "^0.3.1" } @@ -5680,6 +6017,7 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/svelte-portal/-/svelte-portal-2.2.1.tgz", "integrity": "sha512-uF7is5sM4aq5iN7QF/67XLnTUvQCf2iiG/B1BHTqLwYVY1dsVmTeXZ/LeEyU6dLjApOQdbEG9lkqHzxiQtOLEQ==", + "dev": true, "license": "MIT" }, "node_modules/svelte-preprocess": { @@ -6139,7 +6477,7 @@ "version": "2.6.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz", "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==", - "dev": true + "devOptional": true }, "node_modules/type-check": { "version": "0.4.0", @@ -6177,7 +6515,8 @@ "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true }, "node_modules/universalify": { "version": "0.2.0", diff --git a/package.json b/package.json index 5733f72a..60288a5e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "./scripts" ], "scripts": { - "prepare": "svelte-kit sync", + "build": "vite build", "build:node": "cross-env BUILD_NODE_ENV=node vite build", "build:static": "cross-env BUILD_STATIC_ENV=static vite build", @@ -34,6 +34,7 @@ "@tailwindcss/typography": "^0.5.13", "@types/chroma-js": "^2.4.4", "@types/eslint": "^9.6.0", + "@types/node": "^20.14.12", "@typescript-eslint/eslint-plugin": "^7.17.0", "@typescript-eslint/parser": "^7.17.0", "@vitejs/plugin-vue": "^5.1.0", @@ -87,6 +88,7 @@ "svelte-check": "^3.8.4", "svelte-gestures": "^5.0.4", "svelte-intersection-observer": "^1.0.0", + "svelte-portal": "^2.2.1", "sveltekit-i18n": "^2.4.2", "tailwind-merge": "^2.4.0", "tailwind-scrollbar": "^3.1.0", @@ -106,11 +108,10 @@ "@rollup/rollup-win32-arm64-msvc": "4.19.0" }, "dependencies": { - "@types/node": "^20.14.12", "@vercel/analytics": "^1.3.1", "@vercel/speed-insights": "^1.0.12", "color-thief-wasm": "^1.0.11", - "svelte-portal": "^2.2.1", + "sharp": "^0.33.4", "undici": "^6.19.4" } } diff --git a/src/lib/components/image.svelte b/src/lib/components/image.svelte index 8bb957d4..91538bd3 100644 --- a/src/lib/components/image.svelte +++ b/src/lib/components/image.svelte @@ -15,7 +15,7 @@ dominant_color = data.colors; const arrayBufferView = new Uint8Array(data.image); - const blob = new Blob([arrayBufferView], { type: "image/jpeg" }); + const blob = new Blob([arrayBufferView], { type: "image/avif" }); const image = URL.createObjectURL(blob); return image; }; diff --git a/src/routes/api/colorthief/+server.ts b/src/routes/api/colorthief/+server.ts index 75f4818a..8367206a 100644 --- a/src/routes/api/colorthief/+server.ts +++ b/src/routes/api/colorthief/+server.ts @@ -2,6 +2,7 @@ import { error } from "@sveltejs/kit"; import type { RequestHandler } from "./$types"; import { get_color_thief } from "color-thief-wasm"; import undici from "undici"; +import sharp from "sharp"; export const GET: RequestHandler = async ({ url, setHeaders }) => { try { @@ -14,10 +15,12 @@ export const GET: RequestHandler = async ({ url, setHeaders }) => { const image_buffer = new Uint8Array(await body.arrayBuffer()); const colors = get_color_thief(image_buffer, 64 * 64, 10, 5) as Array; + const avif_image_buffer = await sharp(image_buffer).avif({ effort: 9 }).toBuffer(); + setHeaders({ "Content-Type": "application/json" }); - return new Response(JSON.stringify({ colors: colors, image: image_buffer })); + return new Response(JSON.stringify({ colors: colors, image: avif_image_buffer })); } catch (e) { error(400, String(e)); } From 53dcb346714d11832e2f09db669185deb7288962 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:22:17 +0600 Subject: [PATCH 06/13] maybe add redis --- package-lock.json | 91 ++++++++++++++++++++++++++++ package.json | 2 +- src/lib/server/redis.ts | 15 +++++ src/routes/api/colorthief/+server.ts | 18 +++++- 4 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 src/lib/server/redis.ts diff --git a/package-lock.json b/package-lock.json index eb26221f..c4ba1e33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@vercel/analytics": "^1.3.1", "@vercel/speed-insights": "^1.0.12", "color-thief-wasm": "^1.0.11", + "redis": "^4.6.15", "sharp": "^0.33.4", "undici": "^6.19.4" }, @@ -1033,6 +1034,59 @@ "integrity": "sha512-j7P6Rgr3mmtdkeDGTe0E/aYyWEWVtc5yFXtHCRHs28/jptDEWfaVOc5T7cblqy1XKPPfCxJc/8DwQ5YgLOZOVQ==", "dev": true }, + "node_modules/@redis/bloom": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-1.2.0.tgz", + "integrity": "sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/client": { + "version": "1.5.17", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.17.tgz", + "integrity": "sha512-IPvU9A31qRCZ7lds/x+ksuK/UMndd0EASveAvCvEtFFKIZjZ+m/a4a0L7S28KEWoR5ka8526hlSghDo4Hrc2Hg==", + "dependencies": { + "cluster-key-slot": "1.1.2", + "generic-pool": "3.9.0", + "yallist": "4.0.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/@redis/graph": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.1.1.tgz", + "integrity": "sha512-FEMTcTHZozZciLRl6GiiIB4zGm5z5F3F6a6FZCyrfxdKOhFlGkiAqlexWMBzCi4DcRoyiOsuLfW+cjlGWyExOw==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/json": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.6.tgz", + "integrity": "sha512-rcZO3bfQbm2zPRpqo82XbW8zg4G/w4W3tI7X8Mqleq9goQjAGLL7q/1n1ZX4dXEAmORVZ4s1+uKLaUOg7LrUhw==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/search": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.1.6.tgz", + "integrity": "sha512-mZXCxbTYKBQ3M2lZnEddwEAks0Kc7nauire8q20oA0oA/LoA+E/b5Y5KZn232ztPb1FkIGqo12vh3Lf+Vw5iTw==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/time-series": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.5.tgz", + "integrity": "sha512-IFjIgTusQym2B5IZJG3XKr5llka7ey84fw/NOYqESP5WUfQs9zz1ww/9+qoz4ka/S6KcGBodzlCeZ5UImKbscg==", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, "node_modules/@rollup/plugin-commonjs": { "version": "26.0.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-26.0.1.tgz", @@ -2486,6 +2540,14 @@ "node": ">=12" } }, + "node_modules/cluster-key-slot": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz", + "integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/color": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz", @@ -3555,6 +3617,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/generic-pool": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz", + "integrity": "sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==", + "engines": { + "node": ">= 4" + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -5294,6 +5364,22 @@ "node": ">=8.10.0" } }, + "node_modules/redis": { + "version": "4.6.15", + "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.15.tgz", + "integrity": "sha512-2NtuOpMW3tnYzBw6S8mbXSX7RPzvVFCA2wFJq9oErushO2UeBkxObk+uvo7gv7n0rhWeOj/IzrHO8TjcFlRSOg==", + "workspaces": [ + "./packages/*" + ], + "dependencies": { + "@redis/bloom": "1.2.0", + "@redis/client": "1.5.17", + "@redis/graph": "1.1.1", + "@redis/json": "1.0.6", + "@redis/search": "1.1.6", + "@redis/time-series": "1.0.5" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -6946,6 +7032,11 @@ "node": ">=10" } }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/yaml": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", diff --git a/package.json b/package.json index 60288a5e..9924303a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "./scripts" ], "scripts": { - "build": "vite build", "build:node": "cross-env BUILD_NODE_ENV=node vite build", "build:static": "cross-env BUILD_STATIC_ENV=static vite build", @@ -111,6 +110,7 @@ "@vercel/analytics": "^1.3.1", "@vercel/speed-insights": "^1.0.12", "color-thief-wasm": "^1.0.11", + "redis": "^4.6.15", "sharp": "^0.33.4", "undici": "^6.19.4" } diff --git a/src/lib/server/redis.ts b/src/lib/server/redis.ts new file mode 100644 index 00000000..ca9c90bc --- /dev/null +++ b/src/lib/server/redis.ts @@ -0,0 +1,15 @@ +import { createClient } from 'redis' +import { env } from '$env/dynamic/private'; + +export const redis_client = createClient({ + url: env.REDIS_URL, + socket: { + tls: true, + }, +}) + +redis_client.on("error", function (err) { + return new Response(JSON.stringify({ err })) +}) + +await redis_client.connect() \ No newline at end of file diff --git a/src/routes/api/colorthief/+server.ts b/src/routes/api/colorthief/+server.ts index 8367206a..e1f06a98 100644 --- a/src/routes/api/colorthief/+server.ts +++ b/src/routes/api/colorthief/+server.ts @@ -3,8 +3,18 @@ import type { RequestHandler } from "./$types"; import { get_color_thief } from "color-thief-wasm"; import undici from "undici"; import sharp from "sharp"; +import { redis_client } from "$lib/server/redis"; export const GET: RequestHandler = async ({ url, setHeaders }) => { + if(redis_client){ + const value = await redis_client.get(url.pathname); + + if(value) { + const data = JSON.parse(value) as {colors:number[],avif_image_buffer:Uint8Array}; + return new Response(JSON.stringify({ colors: data.colors, image: data.avif_image_buffer })) + } + } + try { const image_url = url.searchParams.get("url"); if (!image_url) throw new Error(`There must be an "url" param`); @@ -17,10 +27,16 @@ export const GET: RequestHandler = async ({ url, setHeaders }) => { const avif_image_buffer = await sharp(image_buffer).avif({ effort: 9 }).toBuffer(); + const data = { colors: colors, image: avif_image_buffer}; + + if(redis_client){ + await redis_client.set(url.pathname,JSON.stringify(data)); + } + setHeaders({ "Content-Type": "application/json" }); - return new Response(JSON.stringify({ colors: colors, image: avif_image_buffer })); + return new Response(JSON.stringify(data)); } catch (e) { error(400, String(e)); } From aa02f6c3b57e2237db47dd76668063411d7d202d Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:26:03 +0600 Subject: [PATCH 07/13] Update +server.ts --- src/routes/api/colorthief/+server.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/api/colorthief/+server.ts b/src/routes/api/colorthief/+server.ts index e1f06a98..2a67f0e5 100644 --- a/src/routes/api/colorthief/+server.ts +++ b/src/routes/api/colorthief/+server.ts @@ -25,9 +25,9 @@ export const GET: RequestHandler = async ({ url, setHeaders }) => { const image_buffer = new Uint8Array(await body.arrayBuffer()); const colors = get_color_thief(image_buffer, 64 * 64, 10, 5) as Array; - const avif_image_buffer = await sharp(image_buffer).avif({ effort: 9 }).toBuffer(); + //const avif_image_buffer = await sharp(image_buffer).avif({ effort: 9 }).toBuffer(); - const data = { colors: colors, image: avif_image_buffer}; + const data = { colors: colors, image: image_buffer}; if(redis_client){ await redis_client.set(url.pathname,JSON.stringify(data)); From 1be9cf4e7f639639d55138b9a8f3f1ee9a5df56f Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:44:02 +0600 Subject: [PATCH 08/13] Update +server.ts --- src/routes/api/colorthief/+server.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/routes/api/colorthief/+server.ts b/src/routes/api/colorthief/+server.ts index 2a67f0e5..06321f42 100644 --- a/src/routes/api/colorthief/+server.ts +++ b/src/routes/api/colorthief/+server.ts @@ -6,12 +6,17 @@ import sharp from "sharp"; import { redis_client } from "$lib/server/redis"; export const GET: RequestHandler = async ({ url, setHeaders }) => { - if(redis_client){ + setHeaders({ + "Content-Type": "application/json" + }); + + + if (redis_client) { const value = await redis_client.get(url.pathname); - - if(value) { - const data = JSON.parse(value) as {colors:number[],avif_image_buffer:Uint8Array}; - return new Response(JSON.stringify({ colors: data.colors, image: data.avif_image_buffer })) + + if (value) { + const data = JSON.parse(value) as { colors: number[]; avif_image_buffer: Uint8Array }; + return new Response(JSON.stringify({ colors: data.colors, image: data.avif_image_buffer })); } } @@ -27,15 +32,12 @@ export const GET: RequestHandler = async ({ url, setHeaders }) => { //const avif_image_buffer = await sharp(image_buffer).avif({ effort: 9 }).toBuffer(); - const data = { colors: colors, image: image_buffer}; + const data = { colors: colors, image: image_buffer }; - if(redis_client){ - await redis_client.set(url.pathname,JSON.stringify(data)); + if (redis_client) { + await redis_client.set(url.pathname, JSON.stringify(data)); } - setHeaders({ - "Content-Type": "application/json" - }); return new Response(JSON.stringify(data)); } catch (e) { error(400, String(e)); From 5e6110218f948f2a3220fc0f97974b113f20b2d6 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:44:09 +0600 Subject: [PATCH 09/13] Update +server.ts --- src/routes/api/colorthief/+server.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/routes/api/colorthief/+server.ts b/src/routes/api/colorthief/+server.ts index 06321f42..f7b7065b 100644 --- a/src/routes/api/colorthief/+server.ts +++ b/src/routes/api/colorthief/+server.ts @@ -10,7 +10,7 @@ export const GET: RequestHandler = async ({ url, setHeaders }) => { "Content-Type": "application/json" }); - + if (redis_client) { const value = await redis_client.get(url.pathname); @@ -37,7 +37,6 @@ export const GET: RequestHandler = async ({ url, setHeaders }) => { if (redis_client) { await redis_client.set(url.pathname, JSON.stringify(data)); } - return new Response(JSON.stringify(data)); } catch (e) { error(400, String(e)); From 5f7a9703601b0c5f6e7bc16aa7290da0606f4dd2 Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:48:06 +0600 Subject: [PATCH 10/13] Fix shits --- src/lib/server/redis.ts | 17 +++++++---------- src/routes/api/colorthief/+server.ts | 13 +++++++------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/lib/server/redis.ts b/src/lib/server/redis.ts index ca9c90bc..82ff7671 100644 --- a/src/lib/server/redis.ts +++ b/src/lib/server/redis.ts @@ -1,15 +1,12 @@ -import { createClient } from 'redis' -import { env } from '$env/dynamic/private'; +import { createClient } from "redis"; +import { env } from "$env/dynamic/private"; export const redis_client = createClient({ - url: env.REDIS_URL, - socket: { - tls: true, - }, -}) + url: env.REDIS_URL +}); redis_client.on("error", function (err) { - return new Response(JSON.stringify({ err })) -}) + throw new Error(err); +}); -await redis_client.connect() \ No newline at end of file +await redis_client.connect(); diff --git a/src/routes/api/colorthief/+server.ts b/src/routes/api/colorthief/+server.ts index f7b7065b..97708fa3 100644 --- a/src/routes/api/colorthief/+server.ts +++ b/src/routes/api/colorthief/+server.ts @@ -6,17 +6,15 @@ import sharp from "sharp"; import { redis_client } from "$lib/server/redis"; export const GET: RequestHandler = async ({ url, setHeaders }) => { - setHeaders({ - "Content-Type": "application/json" - }); - - if (redis_client) { const value = await redis_client.get(url.pathname); if (value) { const data = JSON.parse(value) as { colors: number[]; avif_image_buffer: Uint8Array }; - return new Response(JSON.stringify({ colors: data.colors, image: data.avif_image_buffer })); + setHeaders({ + "Content-Type": "application/json" + }); + return new Response(JSON.stringify(data)); } } @@ -37,6 +35,9 @@ export const GET: RequestHandler = async ({ url, setHeaders }) => { if (redis_client) { await redis_client.set(url.pathname, JSON.stringify(data)); } + setHeaders({ + "Content-Type": "application/json" + }); return new Response(JSON.stringify(data)); } catch (e) { error(400, String(e)); From 1b44b86aaa35c7dd4d338799e5df1e5b6c3a84af Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:49:31 +0600 Subject: [PATCH 11/13] FINALLY FIX REDIS Update redis.ts Update node.js.yml Update redis.ts Update node.js.yml Update node.js.yml Update node.js.yml Update node.js.yml Update node.js.yml Update node.js.yml Update node.js.yml Update node.js.yml Update node.js.yml Update node.js.yml Update redis.ts Update node.js.yml Update node.js.yml Update redis.ts Update redis.ts Update node.js.yml Update node.js.yml Update redis.ts --- .github/workflows/node.js.yml | 23 +++++++++++++++++++---- src/lib/server/redis.ts | 17 ++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 9d2daf2d..73550483 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -7,14 +7,27 @@ on: push: branches: - "*" - pull_request: - branches: - - "*" jobs: build: runs-on: ubuntu-latest + # Service containers to run with `runner-job` + services: + # Label used to access the service container + redis: + # Docker Hub image + image: redis + # Set health checks to wait until redis has started + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps port 6379 on service container to the host + - 6379:6379 + strategy: matrix: node-version: [22.x] @@ -36,4 +49,6 @@ jobs: run: | npm run build npm run build:node - npm run build:static + + # env: + # REDIS_URL: "redis://localhost:6379" diff --git a/src/lib/server/redis.ts b/src/lib/server/redis.ts index 82ff7671..dda43080 100644 --- a/src/lib/server/redis.ts +++ b/src/lib/server/redis.ts @@ -1,12 +1,11 @@ import { createClient } from "redis"; import { env } from "$env/dynamic/private"; -export const redis_client = createClient({ - url: env.REDIS_URL -}); - -redis_client.on("error", function (err) { - throw new Error(err); -}); - -await redis_client.connect(); +export const redis_client = await createClient({ + url: env.REDIS_URL ?? undefined, + socket: { + tls: env.REDIS_TLS === "true" + } +}) + .on("error", (err) => console.log(err)) + .connect(); From c6572389eeb45f55e89cb7e5c49ae24dcd699745 Mon Sep 17 00:00:00 2001 From: tokitouq Date: Wed, 31 Jul 2024 09:02:54 +0530 Subject: [PATCH 12/13] uhm --- src/routes/api/colorthief/+server.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/routes/api/colorthief/+server.ts b/src/routes/api/colorthief/+server.ts index 97708fa3..66a918d4 100644 --- a/src/routes/api/colorthief/+server.ts +++ b/src/routes/api/colorthief/+server.ts @@ -2,7 +2,6 @@ import { error } from "@sveltejs/kit"; import type { RequestHandler } from "./$types"; import { get_color_thief } from "color-thief-wasm"; import undici from "undici"; -import sharp from "sharp"; import { redis_client } from "$lib/server/redis"; export const GET: RequestHandler = async ({ url, setHeaders }) => { From 27a962fcddda97a2b10e6e35d7adfc3921238541 Mon Sep 17 00:00:00 2001 From: tokitouq Date: Thu, 15 Aug 2024 20:16:31 +0530 Subject: [PATCH 13/13] deps: upgrdade to latest --- package-lock.json | 98 ++++++++++++++++++++++++++--------------------- package.json | 14 +++---- 2 files changed, 61 insertions(+), 51 deletions(-) diff --git a/package-lock.json b/package-lock.json index 04122e93..6f7108d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,9 +15,9 @@ "@vercel/analytics": "^1.3.1", "@vercel/speed-insights": "^1.0.12", "color-thief-wasm": "^1.0.11", - "redis": "^4.6.15", + "redis": "^4.7.0", "sharp": "^0.33.4", - "undici": "^6.19.4" + "undici": "^6.19.7" }, "devDependencies": { "@playwright/test": "^1.46.0", @@ -32,10 +32,10 @@ "@tailwindcss/typography": "^0.5.14", "@types/chroma-js": "^2.4.4", "@types/eslint": "^9.6.0", - "@types/node": "^20.14.12", - "@typescript-eslint/eslint-plugin": "^7.17.0", - "@typescript-eslint/parser": "^7.17.0", - "@vitejs/plugin-vue": "^5.1.0", + "@types/node": "^22.3.0", + "@typescript-eslint/eslint-plugin": "^8.1.0", + "@typescript-eslint/parser": "^8.1.0", + "@vitejs/plugin-vue": "^5.1.2", "@zxcvbn-ts/core": "^3.0.4", "@zxcvbn-ts/language-ar": "^3.1.0", "@zxcvbn-ts/language-common": "^3.0.4", @@ -82,7 +82,6 @@ "quick-lru": "^7.0.0", "rollup-plugin-visualizer": "^5.12.0", "sass": "^1.77.8", - "svelte": "^5.0.0-next.222", "svelte-check": "^3.8.5", "svelte-gestures": "^5.0.4", @@ -96,7 +95,7 @@ "ts-node": "^10.9.2", "tslib": "^2.6.3", "typescript": "^5.5.4", - "vite": "^5.4.0", + "vite": "^5.4.1", "vitest": "^2.0.5", "xss": "^1.0.15", "zod": "^3.23.8" @@ -1050,9 +1049,10 @@ } }, "node_modules/@redis/client": { - "version": "1.5.17", - "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.5.17.tgz", - "integrity": "sha512-IPvU9A31qRCZ7lds/x+ksuK/UMndd0EASveAvCvEtFFKIZjZ+m/a4a0L7S28KEWoR5ka8526hlSghDo4Hrc2Hg==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.6.0.tgz", + "integrity": "sha512-aR0uffYI700OEEH4gYnitAnv3vzVGXCFvYfdpu/CJKvk4pHfLPEy/JSZyrpQ+15WhXe1yJRXLtfQ84s4mEXnPg==", + "license": "MIT", "dependencies": { "cluster-key-slot": "1.1.2", "generic-pool": "3.9.0", @@ -1071,25 +1071,28 @@ } }, "node_modules/@redis/json": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.6.tgz", - "integrity": "sha512-rcZO3bfQbm2zPRpqo82XbW8zg4G/w4W3tI7X8Mqleq9goQjAGLL7q/1n1ZX4dXEAmORVZ4s1+uKLaUOg7LrUhw==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.7.tgz", + "integrity": "sha512-6UyXfjVaTBTJtKNG4/9Z8PSpKE6XgSyEb8iwaqDcy+uKrd/DGYHTWkUdnQDyzm727V7p21WUMhsqz5oy65kPcQ==", + "license": "MIT", "peerDependencies": { "@redis/client": "^1.0.0" } }, "node_modules/@redis/search": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.1.6.tgz", - "integrity": "sha512-mZXCxbTYKBQ3M2lZnEddwEAks0Kc7nauire8q20oA0oA/LoA+E/b5Y5KZn232ztPb1FkIGqo12vh3Lf+Vw5iTw==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.2.0.tgz", + "integrity": "sha512-tYoDBbtqOVigEDMAcTGsRlMycIIjwMCgD8eR2t0NANeQmgK/lvxNAvYyb6bZDD4frHRhIHkJu2TBRvB0ERkOmw==", + "license": "MIT", "peerDependencies": { "@redis/client": "^1.0.0" } }, "node_modules/@redis/time-series": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.0.5.tgz", - "integrity": "sha512-IFjIgTusQym2B5IZJG3XKr5llka7ey84fw/NOYqESP5WUfQs9zz1ww/9+qoz4ka/S6KcGBodzlCeZ5UImKbscg==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.1.0.tgz", + "integrity": "sha512-c1Q99M5ljsIuc4YdaCwfUEXsofakb9c8+Zse2qxTadu8TalLXuAESzLvFAvNVbkmSlvlzIQOLpBCmWI9wTOt+g==", + "license": "MIT", "peerDependencies": { "@redis/client": "^1.0.0" } @@ -1644,12 +1647,13 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.14.12", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.12.tgz", - "integrity": "sha512-r7wNXakLeSsGT0H1AU863vS2wa5wBOK4bWMjZz2wj+8nBx+m5PeIn0k8AloSLpRuiwdRQZwarZqHE4FNArPuJQ==", + "version": "22.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.3.0.tgz", + "integrity": "sha512-nrWpWVaDZuaVc5X84xJ0vNrLvomM205oQyLsRt7OHNZbSHslcWsvgFR7O7hire2ZonjLrWBbedmotmIlJDVd6g==", "dev": true, + "license": "MIT", "dependencies": { - "undici-types": "~5.26.4" + "undici-types": "~6.18.2" } }, "node_modules/@types/pug": { @@ -2547,6 +2551,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz", "integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==", + "license": "Apache-2.0", "engines": { "node": ">=0.10.0" } @@ -3632,6 +3637,7 @@ "version": "3.9.0", "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz", "integrity": "sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==", + "license": "MIT", "engines": { "node": ">= 4" } @@ -5380,19 +5386,20 @@ } }, "node_modules/redis": { - "version": "4.6.15", - "resolved": "https://registry.npmjs.org/redis/-/redis-4.6.15.tgz", - "integrity": "sha512-2NtuOpMW3tnYzBw6S8mbXSX7RPzvVFCA2wFJq9oErushO2UeBkxObk+uvo7gv7n0rhWeOj/IzrHO8TjcFlRSOg==", + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/redis/-/redis-4.7.0.tgz", + "integrity": "sha512-zvmkHEAdGMn+hMRXuMBtu4Vo5P6rHQjLoHftu+lBqq8ZTA3RCVC/WzD790bkKKiNFp7d5/9PcSD19fJyyRvOdQ==", + "license": "MIT", "workspaces": [ "./packages/*" ], "dependencies": { "@redis/bloom": "1.2.0", - "@redis/client": "1.5.17", + "@redis/client": "1.6.0", "@redis/graph": "1.1.1", - "@redis/json": "1.0.6", - "@redis/search": "1.1.6", - "@redis/time-series": "1.0.5" + "@redis/json": "1.0.7", + "@redis/search": "1.2.0", + "@redis/time-series": "1.1.0" } }, "node_modules/require-directory": { @@ -6032,7 +6039,6 @@ } }, "node_modules/svelte": { - "version": "5.0.0-next.222", "resolved": "https://registry.npmjs.org/svelte/-/svelte-5.0.0-next.222.tgz", "integrity": "sha512-+dPkIIyoqDYVwBBJL/nu3at8oCfg5jsUx+/qLl6/l2QpLrXVN4zfe9VS4rc//qNJmA59i/TBzWGRl/KTplQVTw==", @@ -6607,18 +6613,20 @@ } }, "node_modules/undici": { - "version": "6.19.4", - "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.4.tgz", - "integrity": "sha512-i3uaEUwNdkRq2qtTRRJb13moW5HWqviu7Vl7oYRYz++uPtGHJj+x7TGjcEuwS5Mt2P4nA0U9dhIX3DdB6JGY0g==", + "version": "6.19.7", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.7.tgz", + "integrity": "sha512-HR3W/bMGPSr90i8AAp2C4DM3wChFdJPLrWYpIS++LxS8K+W535qftjt+4MyjNYHeWabMj1nvtmLIi7l++iq91A==", + "license": "MIT", "engines": { "node": ">=18.17" } }, "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true + "version": "6.18.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.18.2.tgz", + "integrity": "sha512-5ruQbENj95yDYJNS3TvcaxPMshV7aizdv/hWYjGIKoANWKjhWNBsr2YEuYZKodQulB1b8l7ILOuDQep3afowQQ==", + "dev": true, + "license": "MIT" }, "node_modules/universalify": { "version": "0.2.0", @@ -6691,13 +6699,14 @@ "dev": true }, "node_modules/vite": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.0.tgz", - "integrity": "sha512-5xokfMX0PIiwCMCMb9ZJcMyh5wbBun0zUzKib+L65vAZ8GY9ePZMXxFrHbr/Kyll2+LSCY7xtERPpxkBDKngwg==", + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.1.tgz", + "integrity": "sha512-1oE6yuNXssjrZdblI9AfBbHCC41nnyoVoEZxQnID6yvQZAFBzxxkqoFLtHUMkYunL8hwOLEjgTuxpkRxvba3kA==", "dev": true, + "license": "MIT", "dependencies": { "esbuild": "^0.21.3", - "postcss": "^8.4.40", + "postcss": "^8.4.41", "rollup": "^4.13.0" }, "bin": { @@ -7055,7 +7064,8 @@ "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "license": "ISC" }, "node_modules/yaml": { "version": "1.10.2", diff --git a/package.json b/package.json index 0b8eec21..320e9ec4 100644 --- a/package.json +++ b/package.json @@ -33,10 +33,10 @@ "@tailwindcss/typography": "^0.5.14", "@types/chroma-js": "^2.4.4", "@types/eslint": "^9.6.0", - "@types/node": "^20.14.12", - "@typescript-eslint/eslint-plugin": "^7.17.0", - "@typescript-eslint/parser": "^7.17.0", - "@vitejs/plugin-vue": "^5.1.0", + "@types/node": "^22.3.0", + "@typescript-eslint/eslint-plugin": "^8.1.0", + "@typescript-eslint/parser": "^8.1.0", + "@vitejs/plugin-vue": "^5.1.2", "@zxcvbn-ts/core": "^3.0.4", "@zxcvbn-ts/language-ar": "^3.1.0", "@zxcvbn-ts/language-common": "^3.0.4", @@ -97,7 +97,7 @@ "ts-node": "^10.9.2", "tslib": "^2.6.3", "typescript": "^5.5.4", - "vite": "^5.4.0", + "vite": "^5.4.1", "vitest": "^2.0.5", "xss": "^1.0.15", "zod": "^3.23.8" @@ -112,8 +112,8 @@ "@vercel/analytics": "^1.3.1", "@vercel/speed-insights": "^1.0.12", "color-thief-wasm": "^1.0.11", - "redis": "^4.6.15", + "redis": "^4.7.0", "sharp": "^0.33.4", - "undici": "^6.19.4" + "undici": "^6.19.7" } }