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

fix(upload): fix upload failed #9

Merged
merged 1 commit into from
Dec 23, 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
5 changes: 1 addition & 4 deletions src/components/UploadImage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ export default function UploadImage({
});
}

// let formData = new FormData();
const imagePath = `${pathPrefix}${imageName}.${imageMIME}`;
// formData.append('imageKey', `${pathPrefix}${imageName}.${imageMIME}`);
// formData.append('image', images[0], images[0].name);
// const uploadRes = await uploadStatic(formData);

const uploadRes = await uploadToCOS({
pathKey: imagePath,
file: images[0],
Expand Down
37 changes: 18 additions & 19 deletions src/pages/auth/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import useAuthStore from "@/stores/auth";
import { useMutation } from "@tanstack/react-query";
import { useForm } from "@mantine/form";
import useAuthStore from '@/stores/auth';
import { useMutation } from '@tanstack/react-query';
import { useForm } from '@mantine/form';

import { login as loginFn } from "@/api/auth";
import { notifications } from "@mantine/notifications";
import { useNavigate } from "react-router-dom";
import { Button, TextInput } from "@mantine/core";
import { login as loginFn } from '@/api/auth';
import { notifications } from '@mantine/notifications';
import { useNavigate } from 'react-router-dom';
import { Button, TextInput } from '@mantine/core';

export default function Auth() {
const { login, refreshToken } = useAuthStore();
const navigate = useNavigate();

const form = useForm({
mode: "uncontrolled",
mode: 'uncontrolled',
initialValues: {
email: "",
password: "",
email: '',
password: '',
},

validate: {
email: (value) => (/^\S+@\S+$/.test(value) ? null : "Invalid email"),
password: (value) => (value.length < 6 ? "密码长度至少为6位" : null),
email: (value) => (/^\S+@\S+$/.test(value) ? null : 'Invalid email'),
password: (value) => (value.length < 6 ? '密码长度至少为6位' : null),
},
});

Expand All @@ -29,9 +29,9 @@ export default function Auth() {
onSuccess: (data) => {
login(data.user);
refreshToken(data.token);
navigate("/dashboard");
navigate('/dashboard');
notifications.show({
message: "登录成功",
message: '登录成功',
});
},
});
Expand All @@ -54,7 +54,6 @@ export default function Auth() {
<div className="bg-white px-6 py-12 shadow sm:rounded-lg sm:px-12">
<form
onSubmit={form.onSubmit((values) => {
console.log(values);
mutate(values);
})}
className="space-y-6"
Expand All @@ -73,8 +72,8 @@ export default function Auth() {
type="email"
required
autoComplete="email"
key={form.key("email")}
{...form.getInputProps("email")}
key={form.key('email')}
{...form.getInputProps('email')}
/>
</div>
</div>
Expand All @@ -93,8 +92,8 @@ export default function Auth() {
type="password"
required
autoComplete="current-password"
key={form.key("password")}
{...form.getInputProps("password")}
key={form.key('password')}
{...form.getInputProps('password')}
/>
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions src/pages/dashboard/event/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ function EventEditorContent({ event }: { event?: EventType }) {
}
};

console.log(form.values);

return (
<Box mx="auto">
<form onSubmit={form.onSubmit(handleSubmit)}>
Expand Down
1 change: 1 addition & 0 deletions src/utils/cos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export async function uploadToCOS({
Region: region,
Key: key,
Body: file, // 要上传的文件对象。
SliceSize: 1024 * 1024 * 50, // 分片大小,单位 B,默认 1MB。
onProgress: (progressData) => {
console.log("上传进度:", progressData);
},
Expand Down
Loading