muxi feng commited on
Commit
689a1dd
·
1 Parent(s): ebde50b

添加会员拦截和模型分类

Browse files
app/api/user/vip/route.ts ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { auth } from "../../auth";
3
+
4
+ export async function POST(req: NextRequest) {
5
+ try {
6
+ const authResult = auth(req);
7
+ if (authResult.error) {
8
+ return NextResponse.json(authResult, {
9
+ status: 401,
10
+ });
11
+ }
12
+ const token=req.headers.get("auth") ?? ""
13
+ const admin=process.env.ADMIN
14
+ const key=process.env.KEY
15
+ const user=req.nextUrl.searchParams.get("user")
16
+ const password=req.nextUrl.searchParams.get("password")
17
+ let res=await fetch("https://dujiaoka.dwzynj.top/main/api/user/user_vip.php?admin="+admin+"&key="+key+"&user="+user+"&password="+password, {
18
+ method: "GET",
19
+ headers:{
20
+ "token":token
21
+ }
22
+ })
23
+ let msg=await res.json()
24
+ console.log(msg)
25
+ return new Response(JSON.stringify(msg))
26
+ } catch (e) {
27
+ console.error("[shuixian] ", e);
28
+ return new Response(JSON.stringify(e));
29
+ }
30
+ }
app/components/user.tsx CHANGED
@@ -49,6 +49,7 @@ export function User() {
49
  }
50
 
51
  useEffect(()=>{
 
52
  setUserName(useStor.name)
53
  },[useStor.name])
54
 
@@ -128,7 +129,9 @@ export function User() {
128
  <div className={styles.vipTime}>{getVipTime()}</div>
129
  </div>
130
  </ListItem>
 
131
 
 
132
  <ListItem title={Locale.User.kami}>
133
  <div>
134
  <input
@@ -149,6 +152,16 @@ export function User() {
149
  </div>
150
  </ListItem>
151
 
 
 
 
 
 
 
 
 
 
 
152
  <ListItem title={Locale.User.SigState}>
153
  <IconButton
154
  icon={<EditIcon />}
@@ -159,8 +172,10 @@ export function User() {
159
  }}
160
  />
161
  </ListItem>
 
162
 
163
- <ListItem title={Locale.User.Ststus}>
 
164
  <IconButton
165
  className={styles.logoutButton}
166
  disabled={!accessStore.auth}
@@ -173,7 +188,7 @@ export function User() {
173
  }}
174
  />
175
  </ListItem>
176
- </List>
177
  </div>
178
  </ErrorBoundary>
179
  );
 
49
  }
50
 
51
  useEffect(()=>{
52
+ useStor.getUserInfo()
53
  setUserName(useStor.name)
54
  },[useStor.name])
55
 
 
129
  <div className={styles.vipTime}>{getVipTime()}</div>
130
  </div>
131
  </ListItem>
132
+ </List>
133
 
134
+ <List>
135
  <ListItem title={Locale.User.kami}>
136
  <div>
137
  <input
 
152
  </div>
153
  </ListItem>
154
 
155
+ <ListItem title={Locale.User.SigState}>
156
+ <IconButton
157
+ icon={<EditIcon />}
158
+ text="购买卡密"
159
+ onClick={()=>{
160
+ window.location.href="https://qtka.scgzfw.cn/details/B74975C8"
161
+ }}
162
+ />
163
+ </ListItem>
164
+
165
  <ListItem title={Locale.User.SigState}>
166
  <IconButton
167
  icon={<EditIcon />}
 
172
  }}
173
  />
174
  </ListItem>
175
+ </List>
176
 
177
+ <List>
178
+ <ListItem title={Locale.User.Ststus}>
179
  <IconButton
180
  className={styles.logoutButton}
181
  disabled={!accessStore.auth}
 
188
  }}
189
  />
190
  </ListItem>
191
+ </List>
192
  </div>
193
  </ErrorBoundary>
194
  );
app/requests.ts CHANGED
@@ -3,6 +3,7 @@ import {
3
  Message,
4
  ModelConfig,
5
  ModelType,
 
6
  useAccessStore,
7
  useAppConfig,
8
  useChatStore,
@@ -188,6 +189,23 @@ function updateWallet() {
188
  }
189
  }
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  export async function requestChatStream(
192
  messages: Message[],
193
  options?: {
@@ -198,13 +216,78 @@ export async function requestChatStream(
198
  onController?: (controller: AbortController) => void;
199
  },
200
  ) {
201
- if(useUserStore.getState().vip_state=="未开通"){
 
 
202
  if(!updateWallet()){
203
- options?.onMessage("积分不足请充值或开通会员!", true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  return
205
  }
206
  }
207
- const Bot = useAppConfig.getState().bot;
208
  if (Bot == "OpenAI") {
209
  const req = makeRequestParam(messages, {
210
  stream: true,
@@ -396,7 +479,7 @@ export async function requestChatStream(
396
  console.error("NetWork Error", err);
397
  options?.onMessage("请换一个问题试试吧", true);
398
  }
399
- } else {
400
  const req = makeRevChatRequestParam(messages);
401
 
402
  console.log("[Request] ", req);
 
3
  Message,
4
  ModelConfig,
5
  ModelType,
6
+ shuixianRes,
7
  useAccessStore,
8
  useAppConfig,
9
  useChatStore,
 
189
  }
190
  }
191
 
192
+ async function isVip() {
193
+ let res=await fetch("/api/user/vip?user="+useUserStore.getState().user+"&password="+useUserStore.getState().password,{
194
+ method:"POST",
195
+ headers:{
196
+ ...getHeaders()
197
+ }
198
+ })
199
+ let response=await res.json() as shuixianRes
200
+ if(response.code==1){
201
+ if(response.msg=="1"){
202
+ return true
203
+ }
204
+ }
205
+ return false
206
+ }
207
+
208
+
209
  export async function requestChatStream(
210
  messages: Message[],
211
  options?: {
 
216
  onController?: (controller: AbortController) => void;
217
  },
218
  ) {
219
+ let vip=await isVip()
220
+ const Bot = useAppConfig.getState().bot;
221
+ if(!vip){
222
  if(!updateWallet()){
223
+ options?.onMessage("积分不足请购买积分或会员卡密!", true);
224
+ return
225
+ }
226
+ if (Bot == "Lemur"){
227
+ const req = makeRevChatRequestParam(messages);
228
+
229
+ console.log("[Request] ", req);
230
+
231
+ const controller = new AbortController();
232
+ const reqTimeoutId = setTimeout(() => controller.abort(), TIME_OUT_MS);
233
+
234
+ try {
235
+ const res = await fetch("/api/lemur", {
236
+ method: "POST",
237
+ headers: {
238
+ "Content-Type": "application/json",
239
+ ...getHeaders(),
240
+ },
241
+ body: JSON.stringify(req),
242
+ signal: controller.signal,
243
+ });
244
+ clearTimeout(reqTimeoutId);
245
+
246
+ let responseText = "";
247
+
248
+ const finish = () => {
249
+ options?.onMessage(responseText, true);
250
+ controller.abort();
251
+ };
252
+
253
+ if (res.ok) {
254
+ const reader = res.body?.getReader();
255
+ const decoder = new TextDecoder();
256
+
257
+ options?.onController?.(controller);
258
+
259
+ while (true) {
260
+ // handle time out, will stop if no response in 10 secs
261
+ const resTimeoutId = setTimeout(() => finish(), TIME_OUT_MS);
262
+ const content = await reader?.read();
263
+ clearTimeout(resTimeoutId);
264
+ const text = decoder.decode(content?.value);
265
+ responseText += text;
266
+
267
+ const done = !content || content.done;
268
+ options?.onMessage(responseText, false);
269
+
270
+ if (done) {
271
+ break;
272
+ }
273
+ }
274
+ finish();
275
+ } else if (res.status === 401) {
276
+ console.error("Unauthorized");
277
+ options?.onError(new Error("Unauthorized"), res.status);
278
+ } else {
279
+ console.error("Stream Error", res.body);
280
+ options?.onError(new Error("Stream Error"), res.status);
281
+ }
282
+ } catch (err) {
283
+ console.error("NetWork Error", err);
284
+ options?.onError(err as Error);
285
+ }
286
+ }else{
287
+ options?.onMessage("该模型需要开通会员才能使用!", true);
288
  return
289
  }
290
  }
 
291
  if (Bot == "OpenAI") {
292
  const req = makeRequestParam(messages, {
293
  stream: true,
 
479
  console.error("NetWork Error", err);
480
  options?.onMessage("请换一个问题试试吧", true);
481
  }
482
+ }else{
483
  const req = makeRevChatRequestParam(messages);
484
 
485
  console.log("[Request] ", req);
app/store/user.ts CHANGED
@@ -184,8 +184,12 @@ export const useUserStore = create<UserStore>()(
184
  }
185
  });
186
  let responsedata=await resdata.json() as shuixianRes
187
- let data=responsedata.data
 
188
  this.updateInfo(data.name,data.wallet,data.vip_state,data.vip_time_stmp,data.mail,data.sig_state,data.head)
 
 
 
189
  },
190
  async findPwd(user) {
191
  let res=await fetch("/api/user/findpwd?user="+user,{
 
184
  }
185
  });
186
  let responsedata=await resdata.json() as shuixianRes
187
+ if(responsedata.code==1){
188
+ let data=responsedata.data
189
  this.updateInfo(data.name,data.wallet,data.vip_state,data.vip_time_stmp,data.mail,data.sig_state,data.head)
190
+ }else{
191
+ showToast(responsedata.msg)
192
+ }
193
  },
194
  async findPwd(user) {
195
  let res=await fetch("/api/user/findpwd?user="+user,{