support user
This commit is contained in:
13
friends.sql
Normal file
13
friends.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
PRAGMA defer_foreign_keys=TRUE;
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
phone VARCHAR(11) NOT NULL UNIQUE,
|
||||
nickname VARCHAR(50),
|
||||
avatar_url TEXT,
|
||||
status INTEGER DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_login_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
INSERT INTO users VALUES(1,'13800138000','测试用户',NULL,1,'2025-03-26 08:39:15','2025-03-26 08:39:15','2025-03-26 08:39:15');
|
||||
INSERT INTO users VALUES(2,'13391881866','Hobby',NULL,1,'2025-03-26 09:42:30','2025-03-27 05:50:04','2025-03-27 03:21:40');
|
||||
24
functions/api/user/upload.ts
Normal file
24
functions/api/user/upload.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export const onRequestPost: PagesFunction<Env> = async (context) =>{
|
||||
const { env, data } = context;
|
||||
|
||||
// 创建 FormData 对象
|
||||
const formData = new FormData();
|
||||
formData.append('requireSignedURLs', 'false');
|
||||
formData.append('metadata', JSON.stringify({
|
||||
user: data.user.userId
|
||||
}));
|
||||
|
||||
// 调用 Cloudflare Images API 获取直接上传 URL
|
||||
const response = await fetch(`https://api.cloudflare.com/client/v4/accounts/${env.CF_ACCOUNT_ID}/images/v2/direct_upload`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${env.CF_API_TOKEN}`,
|
||||
},
|
||||
body: formData
|
||||
});
|
||||
|
||||
const data1 = await response.json();
|
||||
console.log('上传头像', data1);
|
||||
//下发image前缀
|
||||
return Response.json(data1.result);
|
||||
}
|
||||
25
src/store/userStore.ts
Normal file
25
src/store/userStore.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { create } from 'zustand'
|
||||
|
||||
interface UserInfo {
|
||||
id: number;
|
||||
phone: string;
|
||||
nickname: string;
|
||||
avatar_url: string | null;
|
||||
status: number;
|
||||
}
|
||||
|
||||
interface UserStore {
|
||||
userInfo: UserInfo;
|
||||
setUserInfo: (userInfo: UserInfo) => void;
|
||||
}
|
||||
|
||||
export const useUserStore = create<UserStore>((set) => ({
|
||||
userInfo: {
|
||||
id: 0,
|
||||
phone: '',
|
||||
nickname: '',
|
||||
avatar_url: null,
|
||||
status: 0
|
||||
},
|
||||
setUserInfo: (userInfo: UserInfo) => set({ userInfo })
|
||||
}));
|
||||
Reference in New Issue
Block a user