release 0.3.4
This commit is contained in:
38
apps/web/app/api/collaboration/count/route.ts
Normal file
38
apps/web/app/api/collaboration/count/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { findCollaborationInviteCount } from "@/lib/db/collaboration";
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Record<string, string | string | undefined[]> },
|
||||
) {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
if (!id || id === "undefined") {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Empty roomId",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const res = await findCollaborationInviteCount(id);
|
||||
if (res) {
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
msg: "Successed!",
|
||||
data: res,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
code: 404,
|
||||
msg: "Not joined the collaboration space",
|
||||
data: null,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(error);
|
||||
}
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic";
|
45
apps/web/app/api/collaboration/id/route.ts
Normal file
45
apps/web/app/api/collaboration/id/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { authOptions } from "../../auth/[...nextauth]/route";
|
||||
import { getUserByEmail } from "@/lib/db/user";
|
||||
import {
|
||||
findCollaborationByDBId,
|
||||
findCollaborationInviteCount,
|
||||
} from "@/lib/db/collaboration";
|
||||
|
||||
// /invite/:id 邀请页调用,查询此邀请详细信息,不需要登录,点击“加入协作”后才需要鉴权
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Record<string, string | string | undefined[]> },
|
||||
) {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
if (!id) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Empty roomId",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const res = await findCollaborationByDBId(id);
|
||||
if (res) {
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
msg: "Successed!",
|
||||
data: res,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
code: 404,
|
||||
msg: "Not joined the collaboration space",
|
||||
data: null,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(error);
|
||||
}
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic";
|
65
apps/web/app/api/collaboration/local-id/route.ts
Normal file
65
apps/web/app/api/collaboration/local-id/route.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { authOptions } from "../../auth/[...nextauth]/route";
|
||||
import { getUserByEmail } from "@/lib/db/user";
|
||||
import {
|
||||
findCollaborationByDBId,
|
||||
findCollaborationBylocalId,
|
||||
} from "@/lib/db/collaboration";
|
||||
|
||||
// /invite/:id 邀请页调用,查询此邀请详细信息,不需要登录,点击“加入协作”后才需要鉴权
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Record<string, string | string | undefined[]> },
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({
|
||||
code: 401,
|
||||
msg: "Unauthorized! Please login",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const user = await getUserByEmail(session.user.email);
|
||||
|
||||
if (!user) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Something wrong",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("localId");
|
||||
if (!id) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Empty id",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const res = await findCollaborationBylocalId(id, user.id);
|
||||
|
||||
if (res) {
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
msg: "Successed!",
|
||||
data: res,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
code: 404,
|
||||
msg: "Not joined collaboration",
|
||||
data: null,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(error);
|
||||
}
|
||||
}
|
||||
|
||||
export const dynamic = "force-dynamic";
|
107
apps/web/app/api/collaboration/room/route.ts
Normal file
107
apps/web/app/api/collaboration/room/route.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { authOptions } from "../../auth/[...nextauth]/route";
|
||||
import { getUserByEmail } from "@/lib/db/user";
|
||||
import { findCollaborationByRoomId } from "@/lib/db/collaboration";
|
||||
|
||||
// post页面获取详情时调用,需要用户id查询是否已经加入,加入才开启协作模式
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Record<string, string | string | undefined[]> },
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({
|
||||
code: 401,
|
||||
msg: "Unauthorized! Please login first",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const user = await getUserByEmail(session.user.email);
|
||||
|
||||
if (!user) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Not found user",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("roomId");
|
||||
if (!id) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Empty roomId",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
// 查询用户是否已经加入了这个协作(已经创建了这个room记录)
|
||||
const res = await findCollaborationByRoomId(id, user.id);
|
||||
|
||||
if (res) {
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
msg: "Successed!",
|
||||
data: res,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
code: 404,
|
||||
msg: "You haven't joined this collaboration yet",
|
||||
data: null,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
code: 500,
|
||||
msg: error,
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Record<string, string | string | undefined[]> },
|
||||
) {
|
||||
try {
|
||||
const { roomId } = await req.json();
|
||||
|
||||
if (!roomId) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Empty roomId",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const res = await findCollaborationByRoomId(roomId);
|
||||
|
||||
if (res) {
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
msg: "Successed!",
|
||||
data: res,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
code: 404,
|
||||
msg: "Not found",
|
||||
data: null,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
code: 500,
|
||||
msg: error,
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// fix error: "DYNAMIC_SERVER_USAGE"
|
||||
export const dynamic = "force-dynamic";
|
180
apps/web/app/api/collaboration/route.ts
Normal file
180
apps/web/app/api/collaboration/route.ts
Normal file
@@ -0,0 +1,180 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { authOptions } from "../auth/[...nextauth]/route";
|
||||
import { getUserByEmail } from "@/lib/db/user";
|
||||
import {
|
||||
createCollaboration,
|
||||
deleteCollaborationNote,
|
||||
findCollaborationByRoomId,
|
||||
findUserCollaborations,
|
||||
} from "@/lib/db/collaboration";
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Record<string, string | string | undefined[]> },
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({
|
||||
code: 401,
|
||||
msg: "Unauthorized! Please login",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const user = await getUserByEmail(session.user.email);
|
||||
|
||||
if (!user) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Something wrong",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const res = await findUserCollaborations(user.id);
|
||||
|
||||
if (res) {
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
msg: "Successed!",
|
||||
data: res,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
code: 404,
|
||||
msg: "Not joined collaboration",
|
||||
data: null,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Record<string, string | string | undefined[]> },
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({
|
||||
code: 401,
|
||||
msg: "Unauthorized! Please login",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const user = await getUserByEmail(session.user.email);
|
||||
|
||||
if (!user) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Something wrong",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const { localId, roomId, title } = await req.json();
|
||||
if (!localId || !roomId) {
|
||||
return NextResponse.json({
|
||||
code: 405,
|
||||
msg: "Empty params",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
// 判断用户是否已经加入此协作
|
||||
const find_res = await findCollaborationByRoomId(roomId, user.id);
|
||||
|
||||
if (find_res) {
|
||||
return NextResponse.json({
|
||||
code: 301,
|
||||
msg: "Joined! Redirecting...",
|
||||
data: find_res,
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: 限制新建个数
|
||||
// 新建
|
||||
const res = await createCollaboration(user.id, localId, roomId, title);
|
||||
|
||||
if (res) {
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
msg: "Successfully!Redirecting...",
|
||||
data: res,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
code: 404,
|
||||
msg: "Something wrong",
|
||||
data: null,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
code: 500,
|
||||
msg: error,
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Record<string, string | string | undefined[]> },
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({
|
||||
code: 401,
|
||||
msg: "Unauthorized! Please login",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const user = await getUserByEmail(session.user.email);
|
||||
|
||||
if (!user) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Something wrong",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(req.url);
|
||||
const id = searchParams.get("id");
|
||||
if (!id) {
|
||||
return NextResponse.json({
|
||||
code: 403,
|
||||
msg: "Empty id",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const res = await deleteCollaborationNote(id);
|
||||
if (res) {
|
||||
return NextResponse.json({
|
||||
code: 200,
|
||||
msg: "Successed!",
|
||||
data: res,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
code: 404,
|
||||
msg: "Something wrong",
|
||||
data: null,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(error);
|
||||
}
|
||||
}
|
||||
|
||||
// fix error: "DYNAMIC_SERVER_USAGE"
|
||||
export const dynamic = "force-dynamic";
|
Reference in New Issue
Block a user