-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Release v1.1.0
- Loading branch information
Showing
95 changed files
with
1,733 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
self.addEventListener('install', () => { | ||
console.log('Service worker installed'); | ||
// 서비스 워커 설치 됐을 때 동작 | ||
}); | ||
|
||
self.addEventListener('activate', () => { | ||
console.log('Service worker activated'); | ||
// 서비스 워커 작동할 때 동작 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import sharp from 'sharp'; | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export async function GET(request: NextRequest) { | ||
const { searchParams } = new URL(request.url); | ||
|
||
const src = searchParams.get('src'); | ||
// const width = searchParams.get('width'); | ||
// const height = searchParams.get('height'); | ||
|
||
if (!src || typeof src !== 'string') { | ||
return new NextResponse('Missing or invalid "src" query parameter', { | ||
status: 400, | ||
}); | ||
} | ||
|
||
// const widthInt = width ? parseInt(width as string, 10) : null; | ||
// const heightInt = height ? parseInt(height as string, 10) : null; | ||
const isGif = src.endsWith('.gif'); | ||
|
||
const getImageBuffer = async () => { | ||
if (src.startsWith('http://') || src.startsWith('https://')) { | ||
// 외부 이미지 URL 처리 | ||
const response = await fetch(src, { | ||
next: { revalidate: 60 * 60 * 24 }, | ||
headers: { | ||
responseType: 'arraybuffer', | ||
}, | ||
}); | ||
const imageBuffer = await response.arrayBuffer(); | ||
|
||
return imageBuffer; | ||
} else { | ||
// 로컬 이미지 경로 처리 | ||
const imagePath = path.join('./public', src); | ||
const imageBuffer = fs.readFileSync(imagePath); | ||
|
||
return imageBuffer; | ||
} | ||
}; | ||
|
||
try { | ||
const imageBuffer = await getImageBuffer(); | ||
|
||
// 이미지 최적화 작업 | ||
const image = isGif | ||
? sharp(imageBuffer, { animated: true }).gif() | ||
: sharp(imageBuffer).webp(); | ||
|
||
// // 이미지 리사이징 | ||
// if (widthInt || heightInt) { | ||
// image.resize(widthInt, heightInt); | ||
// } | ||
|
||
const optimizedImageBuffer = await image.toBuffer(); | ||
|
||
// 응답 헤더 설정 | ||
const contentTypeHeader = isGif | ||
? { | ||
'Content-Type': 'image/gif', | ||
} | ||
: { | ||
'Content-Type': 'image/webp', | ||
}; | ||
|
||
// 최적화된 이미지 전송 | ||
return new NextResponse(optimizedImageBuffer, { | ||
status: 200, | ||
headers: contentTypeHeader, | ||
}); | ||
} catch (error) { | ||
console.error('Error optimizing image:', error); | ||
return new NextResponse('Error optimizing image', { | ||
status: 500, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.