Compare commits
No commits in common. "ac5e68536fe1e4d7fafb3e29640828e8a58895e7" and "9ebea74b45941e5d9460d7878eeeab3c5d6e6f7a" have entirely different histories.
ac5e68536f
...
9ebea74b45
6 changed files with 4 additions and 62 deletions
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 --port=3000",
|
"db:studio": "drizzle-kit studio",
|
||||||
"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,18 +3,14 @@ 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("/", () => {
|
api.get("/", () => {
|
||||||
return "Hello from PlanPostAI Canvas API";
|
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);
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
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 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
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(),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
@ -11,6 +11,4 @@ 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