feat: 0.1.2
1. login page && auth required 2. file dir cleanup
This commit is contained in:
32
frontend/src/api/auth.ts
Normal file
32
frontend/src/api/auth.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import {useState} from "react";
|
||||
import {message} from "../component/message/u-message.tsx";
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
username: string;
|
||||
login_at: number;
|
||||
token: string;
|
||||
}
|
||||
|
||||
export const useAuth = () => {
|
||||
const [user, setUser] = useState<User | null>(null)
|
||||
|
||||
const login = async (username: string, password: string) => {
|
||||
let res = await fetch("/api/uauth/login", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({username: username, password: password}),
|
||||
})
|
||||
|
||||
if(res.status !== 200) {
|
||||
message.error("账号或密码错误")
|
||||
throw new Error(await res.text())
|
||||
}
|
||||
|
||||
let jes = await res.json() as User;
|
||||
|
||||
setUser(jes)
|
||||
}
|
||||
|
||||
return {user, login}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export const useFileUpload = () => {
|
||||
|
||||
try {
|
||||
console.log(`[D] api.Upload: upload file = ${file.name}, size = ${file.size}`, file);
|
||||
const url = `/api/share/${file.name}`;
|
||||
const url = `/api/ushare/${file.name}`;
|
||||
|
||||
// 1. 初始化上传
|
||||
const res1 = await fetch(url, {
|
||||
@@ -51,7 +51,7 @@ export const useFileUpload = () => {
|
||||
const end = Math.min(start + CHUNK_SIZE, file.size);
|
||||
const chunk = file.slice(start, end);
|
||||
|
||||
const res = await fetch(`/api/share/${code}`, {
|
||||
const res = await fetch(`/api/ushare/${code}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Range": `bytes=${start}-${end - 1}`,
|
||||
|
||||
Reference in New Issue
Block a user