Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 improve code #196

Merged
merged 12 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/server/src/factories/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async function createConnection() {
uri: GlobalConfig.database_url,
multipleStatements: true,
waitForConnections: true,
connectTimeout: 10000, // 增加连接超时时间(毫秒)
connectionLimit: 10,
maxIdle: 10,
idleTimeout: 60000,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/channel/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { DB, DbType } from '../global/providers/db.provider';
import { CreateChannelDto, UpdateChannelDto } from './dto/channel.dto';
import { work } from '@poster-craft/schema';
import { eq, sql } from 'drizzle-orm';
import { eq } from 'drizzle-orm';
import { v6 as uuidV6 } from 'uuid';

type ChannelProps = {
Expand Down
2 changes: 0 additions & 2 deletions apps/server/src/modules/page/page.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Inject, Injectable } from '@nestjs/common';
import { DB, DbType } from '../global/providers/db.provider';
import { work } from '@poster-craft/schema';
import { eq } from 'drizzle-orm';
import ReactDOMServer from 'react-dom/server';
import React from 'react';

@Injectable()
export class PageService {
Expand Down
7 changes: 2 additions & 5 deletions apps/server/src/modules/template/template.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ApiBearerAuth, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiParam, ApiTags } from '@nestjs/swagger';
import { TemplateService } from './template.service';
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
import { Controller, Get, Param, Query } from '@nestjs/common';
import { string } from 'zod';
import { JwtAuthGuard } from 'src/guards/jwt.guard';
import { GetTemplateListDto } from './dto/template.dto';

@ApiBearerAuth()
Expand All @@ -12,7 +11,6 @@ export class TemplateController {
constructor(private readonly templateService: TemplateService) {}

@Get()
@UseGuards(JwtAuthGuard)
async getTemplates(@Query() query: GetTemplateListDto) {
try {
const data = await this.templateService.getTemplatesList(query);
Expand All @@ -29,7 +27,6 @@ export class TemplateController {
}

@Get(':workId')
@UseGuards(JwtAuthGuard)
@ApiParam({
name: 'workId',
required: true,
Expand Down
3 changes: 0 additions & 3 deletions apps/server/src/modules/work/work.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Post,
Put,
Query,
Redirect,
UseGuards,
} from '@nestjs/common';
import {
Expand Down Expand Up @@ -84,7 +83,6 @@ export class WorkController {
}

@Get('list')
@UseGuards(JwtAuthGuard)
@ApiOperation({
summary: '获取工作区列表',
description: '获取工作区列表',
Expand Down Expand Up @@ -114,7 +112,6 @@ export class WorkController {
}

@Get(':workId')
@UseGuards(JwtAuthGuard)
@ApiParam({
name: 'workId',
description: '工作区Id',
Expand Down
12 changes: 8 additions & 4 deletions apps/server/vercel.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"version": 2,
"framework": null,
"buildCommand": "cd ../.. && pnpm build -F server",
"installCommand": "cd ../.. && pnpm install",
"builds": [
{
"src": "src/main.ts",
"src": "dist/main.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "src/main.ts",
"methods": ["GET", "POST", "PUT", "DELETE", "PATCH"]
"dest": "dist/main.js"
}
]
],
"regions": ["hkg1"],
"public": false
}
18 changes: 0 additions & 18 deletions apps/web/api/template.ts

This file was deleted.

15 changes: 0 additions & 15 deletions apps/web/api/types/email.ts

This file was deleted.

10 changes: 0 additions & 10 deletions apps/web/api/types/sms.ts

This file was deleted.

7 changes: 0 additions & 7 deletions apps/web/api/types/upload.ts

This file was deleted.

49 changes: 0 additions & 49 deletions apps/web/api/work.ts

This file was deleted.

11 changes: 0 additions & 11 deletions apps/web/app/[locale]/about/page.tsx

This file was deleted.

46 changes: 38 additions & 8 deletions apps/web/app/[locale]/auth/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import { defaultSignIn, loginBySMS } from "@/api/auth";
import AuthLayout from "@/components/layouts/AuthLayout";
import Dialog from "@/components/pages/auth/Dialog";
import Oauth2 from "@/components/pages/auth/Oauth2";
Expand All @@ -10,19 +9,51 @@ import { Form } from "@/components/ui/form";
import { ToastAction } from "@/components/ui/toast";
import { useToast } from "@/components/ui/use-toast";
import { useToken } from "@/hooks/useToken";
import { defaultSignIn, loginBySMS } from "@/http/auth";
import { useUserStore } from "@/stores/user";
import { loginFormSchema, loginFormSchemaType } from "@/utils/formSchema";
import { Link } from "@/utils/i18n/routing";
import { zodResolver } from "@hookform/resolvers/zod";
import { useTranslations } from "next-intl";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";

export default function Login() {
const router = useRouter();
const [_, setTokenHandler] = useToken();
const { setUserId } = useUserStore();
const { toast } = useToast();
const t = useTranslations();
const loginFormSchema = z.object({
email: z.string().email({
message: t("form.email.invalid"),
}),
phone: z
.string()
.length(11, {
message: t("form.phone.invalid"),
})
.regex(/^\d+$/, {
message: t("form.phone.invalid"),
}),
password: z.string().min(1, {
message: t("form.password.required"),
}),
code: z
.string()
.length(6, {
message: t("form.code.length"),
})
.regex(/^\d+$/, {
message: t("form.code.length"),
}),
username: z.string().min(2, {
message: t("form.username.minLength"),
}),
});

type loginFormSchemaType = z.infer<typeof loginFormSchema>;
const form = useForm<loginFormSchemaType>({
resolver: zodResolver(loginFormSchema),
defaultValues: {
Expand All @@ -37,7 +68,7 @@ export default function Login() {
console.log(values);
}

//登录模式(是否为手机短信登录)
/** 登录模式(是否为手机短信登录) */
const [isPhoneMode, setIsPhoneMode] = useState(false);

const handleSign = async () => {
Expand All @@ -52,12 +83,12 @@ export default function Login() {
toast({
variant: "success",
title: "Success",
description: "登录成功,即将跳转至主页...",
description: t("loginSuccess"),
});
if (res.data.token) {
setTokenHandler(res.data.token);
}
setUserId(res.data.data.userId);
setUserId(res.data.data?.userId);
router.push("/");
} else {
toast({
Expand Down Expand Up @@ -96,7 +127,7 @@ export default function Login() {
onClick={() => handleSign()}
type="submit"
>
登 录
{t("login")}
</Button>
</div>
<div className="flex justify-between items-center">
Expand All @@ -105,15 +136,14 @@ export default function Login() {
href="/auth/register"
className="label-text-alt link link-hover hover:text-gray-500 dark:hover:text-white/80 text-[#EF4444] dark:text-white"
>
点此注册
{t("registerLink")}
</Link>
</label>
<Oauth2 />
</div>
</form>
</Form>
</div>

<Dialog />
</AuthLayout>
);
Expand Down
Loading