try to solve swagger issue
This commit is contained in:
parent
75ad9eeceb
commit
38fe798582
3 changed files with 54 additions and 2 deletions
|
|
@ -3,7 +3,7 @@ import { projectRoutes } from "./project/project.route";
|
|||
import { uploadRoutes } from "./upload/upload.route";
|
||||
import { authRoute } from "./auth/auth.route";
|
||||
import { downloadRoute } from "./downloadCount/download.count.route";
|
||||
// import { photoLibraryRoutes } from "./photoLibrary/photo.library.route";
|
||||
import { photoLibraryRoutes } from "./photoLibrary/photo.library.route";
|
||||
import { designRoute } from "./design/design.route";
|
||||
|
||||
export const api = new Elysia({ prefix: "" })
|
||||
|
|
@ -15,7 +15,7 @@ export const api = new Elysia({ prefix: "" })
|
|||
.use(projectRoutes)
|
||||
.use(uploadRoutes)
|
||||
.use(downloadRoute)
|
||||
// .use(photoLibraryRoutes)
|
||||
.use(photoLibraryRoutes)
|
||||
.use(designRoute)
|
||||
.onError(({ code, error, set }) => {
|
||||
console.error(`API Error: ${code}`, error);
|
||||
|
|
|
|||
21
src/api/photoLibrary/photo.library.controller.ts
Normal file
21
src/api/photoLibrary/photo.library.controller.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { ENV } from "../../config/env";
|
||||
|
||||
export const getPhotos = async (keyword: string, pre_page: number, token: string) => {
|
||||
try {
|
||||
const url = `${ENV.PEXELS_URL}/search?query=${keyword}&per_page=${pre_page}`;
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
Authorization: process.env.PEXELS_ACCESS_KEY as string,
|
||||
},
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
return { status: 500, message: "An error occurred while getting the photos", token }
|
||||
}
|
||||
const data = await response.json();
|
||||
return { data, token }
|
||||
} catch (error: any) {
|
||||
console.log("Error in getting photos:", error.message || error.toString());
|
||||
return { status: 500, message: "An error occurred while getting the photos", token };
|
||||
}
|
||||
}
|
||||
31
src/api/photoLibrary/photo.library.route.ts
Normal file
31
src/api/photoLibrary/photo.library.route.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import Elysia, { t } from "elysia";
|
||||
import { getPhotos } from "./photo.library.controller";
|
||||
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
||||
|
||||
export const photoLibraryRoutes = new Elysia({
|
||||
prefix: "/photos",
|
||||
tags: ["Photos"],
|
||||
detail: {
|
||||
description: "Routes for managing photo library",
|
||||
}
|
||||
}).derive(async ({ cookie }) => {
|
||||
const authData = await verifyAuth(cookie);
|
||||
return { authData }; // Inject into context
|
||||
});
|
||||
|
||||
photoLibraryRoutes.get("/", async ({ query, authData
|
||||
}) => {
|
||||
if (authData.status !== 200)
|
||||
return authData;
|
||||
else {
|
||||
const { keyword, per_page } = query;
|
||||
const token = authData.token;
|
||||
const data = await getPhotos(keyword, per_page, token);
|
||||
return { data };
|
||||
}
|
||||
}, {
|
||||
query: t.Object({
|
||||
keyword: t.String(),
|
||||
per_page: t.Number(),
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Reference in a new issue