Skip to content

Commit bc05038

Browse files
committed
✨ Add caching for icons with an image proxy
Fixes #307
1 parent b4bdf37 commit bc05038

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

next.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({
55
});
66

77
module.exports = withBundleAnalyzer({
8+
images: {
9+
domains: ['cdn.jsdelivr.net'],
10+
},
811
reactStrictMode: false,
912
experimental: {
1013
outputStandalone: true,

src/components/AppShelf/AppShelfItem.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Card,
44
Anchor,
55
AspectRatio,
6-
Image,
76
Center,
87
createStyles,
98
useMantineColorScheme,
@@ -12,6 +11,7 @@ import { motion } from 'framer-motion';
1211
import { useState } from 'react';
1312
import { useSortable } from '@dnd-kit/sortable';
1413
import { CSS } from '@dnd-kit/utilities';
14+
import Image from 'next/image';
1515
import { serviceItem } from '../../tools/types';
1616
import PingComponent from '../../modules/ping/PingModule';
1717
import AppShelfMenu from './AppShelfMenu';
@@ -121,11 +121,13 @@ export function AppShelfItem(props: any) {
121121
}}
122122
>
123123
<Image
124-
styles={{ root: { cursor: 'pointer' } }}
124+
style={{
125+
cursor: 'pointer',
126+
}}
125127
width={80}
126128
height={80}
127-
src={service.icon}
128-
fit="contain"
129+
src={`/api/imageproxy?url=${service.icon}`}
130+
objectFit="contain"
129131
onClick={() => {
130132
if (service.openedUrl) {
131133
window.open(service.openedUrl, service.newTab === false ? '_top' : '_blank');

src/pages/api/imageproxy.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NextApiRequest, NextApiResponse } from 'next';
2+
3+
export default async (req: NextApiRequest, res: NextApiResponse) => {
4+
const url = decodeURIComponent(req.query.url as string);
5+
const result = await fetch(url);
6+
const body = await result.body;
7+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
8+
// @ts-ignore
9+
body.pipe(res);
10+
};

0 commit comments

Comments
 (0)