Compare commits
4 commits
0ec6755c97
...
75ad9eeceb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75ad9eeceb | ||
| b071602b7b | |||
|
|
363edc548a | ||
|
|
c76b18346a |
8 changed files with 126 additions and 18 deletions
21
env.example
Normal file
21
env.example
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
SERVER_URL=
|
||||||
|
SERVER_PORT=
|
||||||
|
|
||||||
|
DATABASE_URL=
|
||||||
|
|
||||||
|
MINIO_ACCESS_KEY=
|
||||||
|
MINIO_SECRET_KEY=
|
||||||
|
MINIO_ENDPOINT=
|
||||||
|
MINIO_PORT=
|
||||||
|
|
||||||
|
CLERK_SECRET_KEY=
|
||||||
|
|
||||||
|
JWT_ACCESS_TOKEN_SECRET=
|
||||||
|
|
||||||
|
JWT_REFRESH_TOKEN_SECRET=
|
||||||
|
|
||||||
|
# developer canvas server url
|
||||||
|
CANVAS_SERVER_URL_DEV=
|
||||||
|
|
||||||
|
PEXELS_URL=
|
||||||
|
PEXELS_ACCESS_KEY=
|
||||||
18
src/api/design/design.controller.ts
Normal file
18
src/api/design/design.controller.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { ENV } from "../../config/env";
|
||||||
|
|
||||||
|
export const getAllDesign = async (token: string) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${ENV.CANVAS_SERVER_URL_DEV}/design`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error: any) {
|
||||||
|
console.log(error);
|
||||||
|
return { status: 500, message: error.message, token };
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/api/design/design.route.ts
Normal file
24
src/api/design/design.route.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import Elysia from "elysia";
|
||||||
|
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
||||||
|
import { getAllDesign } from "./design.controller";
|
||||||
|
|
||||||
|
export const designRoute = new Elysia({
|
||||||
|
prefix: "/design",
|
||||||
|
tags: ["Design"],
|
||||||
|
detail: {
|
||||||
|
description: "Routes for managing designs",
|
||||||
|
}
|
||||||
|
}).derive(async ({ cookie }) => {
|
||||||
|
const authData = await verifyAuth(cookie);
|
||||||
|
return { authData }; // Inject into context
|
||||||
|
})
|
||||||
|
|
||||||
|
designRoute.get("/", async ({ authData }) => {
|
||||||
|
if (authData.status !== 200)
|
||||||
|
return authData;
|
||||||
|
else {
|
||||||
|
const token = authData.token;
|
||||||
|
const response = await getAllDesign(token);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
@ -3,6 +3,8 @@ 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";
|
||||||
|
import { designRoute } from "./design/design.route";
|
||||||
|
|
||||||
export const api = new Elysia({ prefix: "" })
|
export const api = new Elysia({ prefix: "" })
|
||||||
.get("/", () => {
|
.get("/", () => {
|
||||||
|
|
@ -13,6 +15,8 @@ export const api = new Elysia({ prefix: "" })
|
||||||
.use(projectRoutes)
|
.use(projectRoutes)
|
||||||
.use(uploadRoutes)
|
.use(uploadRoutes)
|
||||||
.use(downloadRoute)
|
.use(downloadRoute)
|
||||||
|
// .use(photoLibraryRoutes)
|
||||||
|
.use(designRoute)
|
||||||
.onError(({ code, error, set }) => {
|
.onError(({ code, error, set }) => {
|
||||||
console.error(`API Error: ${code}`, error);
|
console.error(`API Error: ${code}`, error);
|
||||||
if (code === "NOT_FOUND") {
|
if (code === "NOT_FOUND") {
|
||||||
|
|
|
||||||
|
|
@ -86,10 +86,10 @@ export const createProject = async (userId: string, token: string) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateProject = async (id: string, body: any, token: string) => {
|
export const updateProject = async (id: string, body: any, token: string, user_id: string) => {
|
||||||
try {
|
try {
|
||||||
// 1. Validate if project exists
|
// 1. Validate if project exists
|
||||||
const existingProject = await db.select().from(projects).where(eq(projects.id, id)).limit(1);
|
const existingProject = await db.select().from(projects).where(eq(projects.id, id));
|
||||||
if (existingProject.length === 0) {
|
if (existingProject.length === 0) {
|
||||||
return { status: 404, message: "Project not found", token };
|
return { status: 404, message: "Project not found", token };
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +101,8 @@ export const updateProject = async (id: string, body: any, token: string) => {
|
||||||
object,
|
object,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
preview_url
|
preview_url,
|
||||||
|
userId: user_id,
|
||||||
}).where(eq(projects.id, id)).returning({
|
}).where(eq(projects.id, id)).returning({
|
||||||
id: projects.id,
|
id: projects.id,
|
||||||
object: projects.object,
|
object: projects.object,
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,9 @@ projectRoutes.put("/update/:project_id", async ({ body, params: { project_id },
|
||||||
return authData;
|
return authData;
|
||||||
else {
|
else {
|
||||||
const token = authData.token;
|
const token = authData.token;
|
||||||
const response = await updateProject(project_id, body, token);
|
const user_id = authData?.userId;
|
||||||
|
// sending user_id to the controller to update the project with the user_id, when user tried to design a existing project from the design project panel
|
||||||
|
const response = await updateProject(project_id, body, token, user_id as string);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|
|
||||||
45
src/app.ts
45
src/app.ts
|
|
@ -4,15 +4,21 @@ import cors from "@elysiajs/cors";
|
||||||
import { ENV } from "./config/env";
|
import { ENV } from "./config/env";
|
||||||
import { api } from "./api";
|
import { api } from "./api";
|
||||||
|
|
||||||
const app = new Elysia()
|
const allowedOrigins = [
|
||||||
.use(
|
|
||||||
cors({
|
|
||||||
origin: [
|
|
||||||
"http://localhost:5175",
|
"http://localhost:5175",
|
||||||
|
"http://localhost:5174",
|
||||||
"http://localhost:5173",
|
"http://localhost:5173",
|
||||||
"https://dashboard.planpostai.com",
|
"https://dashboard.planpostai.com",
|
||||||
"https://canvas.planpostai.com",
|
"https://canvas.planpostai.com",
|
||||||
],
|
];
|
||||||
|
|
||||||
|
const app = new Elysia({
|
||||||
|
prefix: "",
|
||||||
|
tags: ["Default"],
|
||||||
|
})
|
||||||
|
.use(
|
||||||
|
cors({
|
||||||
|
origin: allowedOrigins,
|
||||||
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
|
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
|
||||||
allowedHeaders: [
|
allowedHeaders: [
|
||||||
"Content-Type",
|
"Content-Type",
|
||||||
|
|
@ -25,22 +31,37 @@ const app = new Elysia()
|
||||||
credentials: true,
|
credentials: true,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.get("/test", () => "Hello World", {})
|
|
||||||
.use(api)
|
|
||||||
.use(
|
.use(
|
||||||
swagger({
|
swagger({
|
||||||
path: "/swagger",
|
path: "/api/docs",
|
||||||
documentation: {
|
documentation: {
|
||||||
openapi: "3.1.0",
|
|
||||||
info: {
|
info: {
|
||||||
title: "Canvas API",
|
title: "Canvas API",
|
||||||
version: "1.0.0",
|
version: "1.0.0",
|
||||||
description: "Canvas API Documentation",
|
description: "Canvas API Documentation",
|
||||||
},
|
},
|
||||||
|
tags: [
|
||||||
|
{
|
||||||
|
name: "Projects",
|
||||||
|
description: "All APIs related to Projects",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Uploads",
|
||||||
|
description: "All APIs related to Uploads",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.listen(ENV.SERVER_PORT);
|
.onError(({ code, error }) => {
|
||||||
|
if (code === "NOT_FOUND") return "Not Found :(";
|
||||||
|
console.log("hello from app.ts under error");
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
|
||||||
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}`);
|
// all routes here
|
||||||
console.log(`Swagger docs available at ${ENV.SERVER_URL}/swagger`);
|
app.use(api);
|
||||||
|
|
||||||
|
app.listen(ENV.SERVER_PORT, () => {
|
||||||
|
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}`);
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import "dotenv/config";
|
import "dotenv/config";
|
||||||
|
|
||||||
export const ENV = {
|
export const ENV = {
|
||||||
|
<<<<<<< HEAD
|
||||||
SERVER_URL: process.env.SERVER_URL,
|
SERVER_URL: process.env.SERVER_URL,
|
||||||
SERVER_PORT: process.env.SERVER_PORT || 5000,
|
SERVER_PORT: process.env.SERVER_PORT || 5000,
|
||||||
DATABASE_URL: process.env.DATABASE_URL,
|
DATABASE_URL: process.env.DATABASE_URL,
|
||||||
|
|
@ -12,3 +13,19 @@ export const ENV = {
|
||||||
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,
|
||||||
};
|
};
|
||||||
|
=======
|
||||||
|
SERVER_URL: process.env.SERVER_URL,
|
||||||
|
SERVER_PORT: process.env.SERVER_PORT || 5000,
|
||||||
|
CANVAS_SERVER_URL_DEV: process.env.CANVAS_SERVER_URL_DEV,
|
||||||
|
DATABASE_URL: process.env.DATABASE_URL,
|
||||||
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
||||||
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
||||||
|
MINIO_ENDPOINT: process.env.MINIO_ENDPOINT,
|
||||||
|
MINIO_PORT: process.env.MINIO_PORT,
|
||||||
|
CLERK_SECRET_KEY: process.env.CLERK_SECRET_KEY,
|
||||||
|
JWT_ACCESS_TOKEN_SECRET: process.env.JWT_ACCESS_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,
|
||||||
|
}
|
||||||
|
>>>>>>> canvas_updated_be
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue