remove sharp

This commit is contained in:
hamid zarghami
2026-06-16 09:33:57 +03:30
parent 7a00b884ad
commit 78d45e7280
6 changed files with 6 additions and 127 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ const nextConfig: NextConfig = {
],
},
{
source: "/((?!sw\\.js|api/pwa-icon).*)",
source: "/((?!sw\\.js).*)",
headers: [
{
key: "Cache-Control",
+4 -1
View File
@@ -44,7 +44,6 @@
"react-leaflet": "^5.0.0",
"react-otp-input": "^3.1.1",
"react-virtualized": "^9.22.6",
"sharp": "^0.34.5",
"tailwind-merge": "^3.3.1",
"use-long-press": "^3.3.0",
"yup": "^1.7.1",
@@ -1860,6 +1859,7 @@
"resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.0.0.tgz",
"integrity": "sha512-A5P/LfWGFSl6nsckYtjw9da+19jB8hkJ6ACTGcDfEJ0aE+l2n2El7dsVM7UVHZQ9s2lmYMWlrS21YLy2IR1LUw==",
"license": "MIT",
"optional": true,
"engines": {
"node": ">=18"
}
@@ -5643,6 +5643,7 @@
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
"devOptional": true,
"license": "Apache-2.0",
"engines": {
"node": ">=8"
@@ -9623,6 +9624,7 @@
"version": "7.7.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz",
"integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==",
"devOptional": true,
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
@@ -9692,6 +9694,7 @@
"integrity": "sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg==",
"hasInstallScript": true,
"license": "Apache-2.0",
"optional": true,
"dependencies": {
"@img/colour": "^1.0.0",
"detect-libc": "^2.1.2",
-1
View File
@@ -45,7 +45,6 @@
"react-leaflet": "^5.0.0",
"react-otp-input": "^3.1.1",
"react-virtualized": "^9.22.6",
"sharp": "^0.34.5",
"tailwind-merge": "^3.3.1",
"use-long-press": "^3.3.0",
"yup": "^1.7.1",
-3
View File
@@ -1,3 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 200 200"><rect width="200" height="200" fill="url('#gradient')"></rect><defs><linearGradient id="SvgjsLinearGradient1001" gradientTransform="rotate(101 0.5 0.5)"><stop offset="0%" stop-color="#b7b8ba"></stop><stop offset="100%" stop-color="#ebf1f1"></stop></linearGradient></defs><g><g fill="#242f35" transform="matrix(7.071823204419889,0,0,7.071823204419889,-7.597636903188501,150.28003879410127)" stroke="#323847" stroke-width="0.2"><path d="M5.75 0L1.07 0L1.07-14.22L5.65-14.22Q7.54-14.22 9.04-13.36Q10.55-12.51 11.39-10.95Q12.24-9.39 12.25-7.46L12.25-7.46L12.25-6.81Q12.25-4.85 11.42-3.31Q10.60-1.76 9.10-0.88Q7.60-0.01 5.75 0L5.75 0ZM5.65-11.57L4.50-11.57L4.50-2.64L5.69-2.64Q7.17-2.64 7.96-3.69Q8.75-4.74 8.75-6.81L8.75-6.81L8.75-7.42Q8.75-9.48 7.96-10.53Q7.17-11.57 5.65-11.57L5.65-11.57ZM14.00-14.22L18.51-14.22L21.68-4.33L24.84-14.22L29.36-14.22L29.36 0L25.92 0L25.92-3.32L26.25-10.12L22.81 0L20.55 0L17.10-10.13L17.43-3.32L17.43 0L14.00 0L14.00-14.22Z"></path></g></g></svg><style>@media (prefers-color-scheme: light) { :root { filter: none; } }
@media (prefers-color-scheme: dark) { :root { filter: none; } }
</style></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

+1 -87
View File
@@ -1,99 +1,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { fetchWithTimeout } from "@/lib/helpers/fetchWithTimeout";
import { PWA_ICON_192 } from "@/lib/helpers/pwaIcons";
import { NextRequest, NextResponse } from "next/server";
import sharp from "sharp";
export const dynamic = "force-dynamic";
export const revalidate = 0;
const FETCH_TIMEOUT_MS = 5000;
const DEFAULT_ICON = PWA_ICON_192;
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ name: string }> },
) {
// Restaurant logo processing disabled redirect to static PWA icon
return NextResponse.redirect(new URL(PWA_ICON_192, request.url), 302);
/* Restaurant logo processing uncomment to re-enable dynamic PWA icons
try {
await params;
const searchParams = request.nextUrl.searchParams;
const logoUrl = searchParams.get("url");
const size = parseInt(searchParams.get("size") || "192");
if (!logoUrl) {
return new NextResponse("Logo URL is required", { status: 400 });
}
const imageResponse = await fetchWithTimeout(logoUrl, {
timeoutMs: FETCH_TIMEOUT_MS,
});
if (!imageResponse.ok) {
return NextResponse.redirect(new URL(DEFAULT_ICON, request.url), 302);
}
const imageBuffer = Buffer.from(await imageResponse.arrayBuffer());
const metadata = await sharp(imageBuffer).metadata();
const { width, height } = metadata;
if (!width || !height) {
return NextResponse.redirect(new URL(DEFAULT_ICON, request.url), 302);
}
if (width === height) {
const processedImage = sharp(imageBuffer).resize(size, size, {
fit: "contain",
background: { r: 0, g: 0, b: 0, alpha: 0 },
});
const outputBuffer: any = await processedImage.png().toBuffer();
return new NextResponse(outputBuffer, {
headers: {
"Content-Type": "image/png",
"Cache-Control": "public, max-age=31536000, immutable",
},
});
}
const maxDimension = Math.max(width, height);
const scale = size / maxDimension;
const newWidth = Math.round(width * scale);
const newHeight = Math.round(height * scale);
const paddingTop = Math.floor((size - newHeight) / 2);
const paddingBottom = size - newHeight - paddingTop;
const paddingLeft = Math.floor((size - newWidth) / 2);
const paddingRight = size - newWidth - paddingLeft;
const processedImage = sharp(imageBuffer)
.resize(newWidth, newHeight, {
fit: "contain",
background: { r: 0, g: 0, b: 0, alpha: 0 },
})
.extend({
top: paddingTop,
bottom: paddingBottom,
left: paddingLeft,
right: paddingRight,
background: { r: 0, g: 0, b: 0, alpha: 0 },
});
const outputBuffer: any = await processedImage.png().toBuffer();
return new NextResponse(outputBuffer, {
headers: {
"Content-Type": "image/png",
"Cache-Control": "public, max-age=31536000, immutable",
},
});
} catch (error) {
console.error("Error processing logo:", error);
return NextResponse.redirect(new URL(DEFAULT_ICON, request.url), 302);
}
*/
return NextResponse.redirect(new URL(PWA_ICON_192, request.url), 302);
}
-34
View File
@@ -1,34 +0,0 @@
import { readFile } from 'fs/promises';
import path from 'path';
import sharp from 'sharp';
import { NextRequest, NextResponse } from 'next/server';
const VALID_SIZES = [192, 512] as const;
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ size: string }> },
) {
const { size: sizeParam } = await params;
const size = parseInt(sizeParam, 10);
if (!VALID_SIZES.includes(size as (typeof VALID_SIZES)[number])) {
return new NextResponse('Invalid size', { status: 400 });
}
try {
const svgPath = path.join(process.cwd(), 'public', 'icon0.svg');
const svgBuffer = await readFile(svgPath);
const pngBuffer = await sharp(svgBuffer).resize(size, size).png().toBuffer();
return new NextResponse(new Uint8Array(pngBuffer), {
headers: {
'Content-Type': 'image/png',
'Cache-Control': 'public, max-age=31536000, immutable',
},
});
} catch (error) {
console.error('Error generating PWA icon:', error);
return new NextResponse('Failed to generate icon', { status: 500 });
}
}