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

Msg error #66

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5834426
完善 UI
mm-sam Apr 11, 2024
c3d379f
完善 docker 配置
mm-sam Apr 11, 2024
eeb2f75
完善 對話 超 max token 處理
mm-sam Apr 12, 2024
4c54c97
完善 build 流程,完善 docker build 流程
mm-sam Apr 13, 2024
bf7f32a
完善身份验证
mm-sam Apr 14, 2024
74c91d0
完善 auth 驗證
mm-sam Apr 15, 2024
2fc55ad
修正 mobile view 下 chat-input 位置問題
mm-sam Apr 15, 2024
768fca1
完善 Auth 驗證
mm-sam Apr 15, 2024
bb871dd
增加 hash 快捷登入 API
mm-sam Apr 15, 2024
f226de9
完善頁面跳轉
mm-sam Apr 15, 2024
ceb9713
尝试修正苹果手机输入框获得焦点时放大页面的bug
Apr 16, 2024
75492cc
完善 auth 的user 标识
mm-sam Apr 16, 2024
2779fc6
Merge remote-tracking branch 'remotes/origin/echo'
mm-sam Apr 16, 2024
f03997c
同上
Apr 16, 2024
a7332fe
Merge remote-tracking branch 'remotes/origin/echo'
mm-sam Apr 16, 2024
99122d6
完善 主题颜色
mm-sam Apr 16, 2024
732c860
完善 Tools UI 及提示
mm-sam Apr 16, 2024
8df3b2e
修正错别字,完善 emoji 渲染
mm-sam Apr 17, 2024
eee0b4a
完善代理兼容
mm-sam Apr 17, 2024
92c3fdf
完善 proxy 支持
mm-sam Apr 17, 2024
55120d4
完善 hash code 登入API
mm-sam Apr 18, 2024
e4f1396
取消 会话列表小于20条才显示【新对话】按钮的限制
Apr 18, 2024
e5442f1
Merge remote-tracking branch 'remotes/origin/new-chat-btn'
mm-sam Apr 18, 2024
1f4c157
修正 user 身份丟失的問題
mm-sam Apr 18, 2024
b15c1d2
補完 Server API
mm-sam Apr 19, 2024
cfaaa6e
删除及建议功能UI
Apr 19, 2024
8e56366
Merge branch 'main' into delete-suggest-btn
Apr 19, 2024
c3c8119
尝试添加删除会话功能
Apr 19, 2024
c70a6db
fixed: 删除时item.id 错误
Apr 22, 2024
4245bb6
完善删除功能
Apr 23, 2024
2ea6f6d
建议UI
Apr 23, 2024
244bf3f
完善UI
Apr 23, 2024
6aedbb0
1. 把建议的UI抽成组件 2. 补充点击建议项按钮的逻辑
Apr 24, 2024
43c9902
获取底部高度,动态设置页面的padding bottom值
Apr 24, 2024
40541ef
Merge remote-tracking branch 'remotes/origin/suggestion'
mm-sam Apr 25, 2024
12f2724
1. fixed: 请求error 或者 suggested请求没有内容返回 2. 删除多余代码
Apr 25, 2024
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
Prev Previous commit
Next Next commit
增加 hash 快捷登入 API
  • Loading branch information
mm-sam committed Apr 15, 2024
commit bb871dd9d693a9426bf3c1ccbe227da96a66213d
21 changes: 20 additions & 1 deletion app/api/auth/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { getInfo, ResponseWithSession } from '@/app/api/utils/common'
import { getInfo, ResponseWithSession, getSessionFromRequest } from '@/app/api/utils/common'
import { authSpeedyAgencyMember } from '@/app/api/utils/speedyagency'
import {setSession} from "../utils/common";

export async function POST(request: NextRequest) {
const { sessionId } = getInfo(request)
Expand Down Expand Up @@ -38,3 +39,21 @@ export async function POST(request: NextRequest) {
error: 'auth error',
})
}

export async function GET(request: NextRequest) {
const data = await getSessionFromRequest(request);
const {sessionId} = getInfo(request);

if (data) {
console.log(data);
const url = request.nextUrl.clone()
url.pathname = '/';
url.search = '';
return ResponseWithSession(NextResponse.redirect(url), sessionId, data);
}

return NextResponse.json({
status: false,
error: 'auth error',
})
}
17 changes: 17 additions & 0 deletions app/api/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ export const getInfo = (request: NextRequest) => {
}
}

export const getSessionFromRequest = async (req: NextRequest): Promise<null|Record<string, string>> => {
const hash = req.nextUrl.searchParams.get('hash');

try {
if (hash) {
const data = await decrypt(hash);
if (data?.channel) {
return data;
}
}
} catch (error) {
console.error(error);
}

return null;
}

export const setSession = (sessionId: string) => {
return { 'Set-Cookie': `session_id=${sessionId}` }
}
Expand Down
2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function middleware(request: NextRequest) {
const url = request.nextUrl.clone()
url.pathname = '/auth';

return NextResponse.rewrite(url, {
return NextResponse.redirect(url, {
headers: setSession(sessionId),
});
}
Expand Down
14 changes: 13 additions & 1 deletion utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ export type userSession = {
channel: string,
}

function arrayBufferToHex(buffer: ArrayBuffer) {
let byteArray = new Uint8Array(buffer);
let hexParts = [];

for(let i = 0; i < byteArray.length; i++) {
let hex = byteArray[i].toString(16);
let paddedHex = ('00' + hex).slice(-2);
hexParts.push(paddedHex);
}

return hexParts.join('');
}

export const encrypt = async (value: Record<string, string>) => {
const plainText = JSON.stringify(value);
const ptUtf8 = new TextEncoder().encode(plainText);
Expand All @@ -30,7 +43,6 @@ export const decrypt = async (encryptedData: string): Promise<Record<string, str
const ctBytes = new Uint8Array(ctStr.split('').map(c => c.charCodeAt(0)));

// Parse hexadecimal (base 16) iv and ciphertext from ctBytes array

const iv = ctBytes.slice(0, 24).reduce<number[]>((result, v, i) => {
if (i % 2 === 0) {
result.push(parseInt(ctStr.substr(i, 2), 16));
Expand Down