refactor(api): move app-image endpoint to app directory
This commit is contained in:
parent
3d5a041a9d
commit
fb9cde68c1
2 changed files with 21 additions and 27 deletions
21
src/app/api/app-image/route.ts
Normal file
21
src/app/api/app-image/route.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { getConfig } from '@/server/core/TipiConfig/TipiConfig';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get('id');
|
||||
|
||||
if (typeof id !== 'string') {
|
||||
return new Response('Not found', { status: 404 });
|
||||
}
|
||||
|
||||
const filePath = path.join(getConfig().rootFolder, 'repos', getConfig().appsRepoId, 'apps', id, 'metadata', 'logo.jpg');
|
||||
const file = fs.readFileSync(filePath);
|
||||
|
||||
return new Response(file, { headers: { 'content-type': 'image/jpeg' } });
|
||||
} catch (error) {
|
||||
return new Response('Error', { status: 500 });
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
import fs from 'fs';
|
||||
import { getConfig } from '@/server/core/TipiConfig/TipiConfig';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* API endpoint to get the image of an app
|
||||
*
|
||||
* @param {NextApiRequest} req - The request
|
||||
* @param {NextApiResponse} res - The response
|
||||
*/
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (typeof req.query.id !== 'string') {
|
||||
res.status(404).send('Not found');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const filePath = path.join(getConfig().rootFolder, 'repos', getConfig().appsRepoId, 'apps', req.query.id, 'metadata', 'logo.jpg');
|
||||
const file = fs.readFileSync(filePath);
|
||||
|
||||
res.setHeader('Content-Type', 'image/jpeg');
|
||||
res.send(file);
|
||||
} catch (e) {
|
||||
res.status(404).send('Not found');
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue