minor changes added
This commit is contained in:
parent
1ef2b41a75
commit
f91ff472d0
8 changed files with 69 additions and 10 deletions
3
.env
3
.env
|
|
@ -14,3 +14,6 @@ JWT_ACCESS_TOKEN_SECRET=planpostai%^$_%43%65576canvas%%$$
|
||||||
|
|
||||||
JWT_REFRESH_TOKEN_SECRET=planpostai!@43223_canvas$%^$349332$$
|
JWT_REFRESH_TOKEN_SECRET=planpostai!@43223_canvas$%^$349332$$
|
||||||
|
|
||||||
|
PEXELS_URL=https://api.pexels.com/v1
|
||||||
|
PEXELS_ACCESS_KEY=6PK7hLvOuG6nFsmC8c9EV0P8hGkyHeIhYpiRxhkEfh2ePK0GhiQypBhI
|
||||||
|
|
||||||
|
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -25,7 +25,7 @@ yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"version": "1.0.50",
|
"version": "1.0.50",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"db:studio": "drizzle-kit studio",
|
"db:studio": "drizzle-kit studio --port=3000",
|
||||||
"db:generate": "drizzle-kit generate",
|
"db:generate": "drizzle-kit generate",
|
||||||
"db:migrate": "drizzle-kit migrate",
|
"db:migrate": "drizzle-kit migrate",
|
||||||
"db:push": "drizzle-kit push:pg",
|
"db:push": "drizzle-kit push:pg",
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,18 @@ import { projectRoutes } from "./project/project.route";
|
||||||
import { uploadRoutes } from "./upload/upload.route";
|
import { uploadRoutes } from "./upload/upload.route";
|
||||||
import { authRoute } from "./auth/auth.route";
|
import { authRoute } from "./auth/auth.route";
|
||||||
import { downloadRoute } from "./downloadCount/download.count.route";
|
import { downloadRoute } from "./downloadCount/download.count.route";
|
||||||
|
import { photoLibraryRoutes } from "./photoLibrary/photo.library.route";
|
||||||
|
|
||||||
export const api = new Elysia({
|
export const api = new Elysia({
|
||||||
prefix: "/api",
|
prefix: "/api",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
api.get("/", () => {
|
||||||
|
return "Hello from PlanPostAI Canvas API";
|
||||||
|
});
|
||||||
|
|
||||||
api.use(authRoute);
|
api.use(authRoute);
|
||||||
api.use(projectRoutes);
|
api.use(projectRoutes);
|
||||||
api.use(uploadRoutes);
|
api.use(uploadRoutes);
|
||||||
api.use(downloadRoute);
|
api.use(downloadRoute);
|
||||||
|
api.use(photoLibraryRoutes);
|
||||||
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(),
|
||||||
|
})
|
||||||
|
})
|
||||||
10
src/app.ts
10
src/app.ts
|
|
@ -8,7 +8,8 @@ import { api } from "./api";
|
||||||
const allowedOrigins = [
|
const allowedOrigins = [
|
||||||
"http://localhost:5175",
|
"http://localhost:5175",
|
||||||
"http://localhost:5173",
|
"http://localhost:5173",
|
||||||
"https://your-production-site.com",
|
"https://dashboard.planpostai.com",
|
||||||
|
"https://canvas.planpostai.com",
|
||||||
];
|
];
|
||||||
|
|
||||||
const app = new Elysia({
|
const app = new Elysia({
|
||||||
|
|
@ -22,7 +23,7 @@ const app = new Elysia({
|
||||||
credentials: true,
|
credentials: true,
|
||||||
}))
|
}))
|
||||||
.use(swagger({
|
.use(swagger({
|
||||||
path: "/docs",
|
path: "/api/docs",
|
||||||
documentation: {
|
documentation: {
|
||||||
info: {
|
info: {
|
||||||
title: "Canvas API",
|
title: "Canvas API",
|
||||||
|
|
@ -48,11 +49,6 @@ const app = new Elysia({
|
||||||
console.error(error)
|
console.error(error)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.get("/", () => {
|
|
||||||
return "Hello from PlanPostAI Canvas API";
|
|
||||||
});
|
|
||||||
|
|
||||||
// all routes here
|
// all routes here
|
||||||
app.use(api);
|
app.use(api);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,6 @@ export const ENV = {
|
||||||
CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY,
|
CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY,
|
||||||
JWT_ACCESS_TOKEN_SECRET: process.env.JWT_ACCESS_TOKEN_SECRET,
|
JWT_ACCESS_TOKEN_SECRET: process.env.JWT_ACCESS_TOKEN_SECRET,
|
||||||
JWT_REFRESH_TOKEN_SECRET: process.env.JWT_REFRESH_TOKEN_SECRET,
|
JWT_REFRESH_TOKEN_SECRET: process.env.JWT_REFRESH_TOKEN_SECRET,
|
||||||
|
PEXELS_URL: process.env.PEXELS_URL,
|
||||||
|
PEXELS_ACCESS_KEY: process.env.PEXELS_ACCESS_KEY,
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue