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
修正 mobile view 下 chat-input 位置問題
  • Loading branch information
mm-sam committed Apr 15, 2024
commit 2fc55ad5f4b4794f25297dbc24cb2922a1ee5e0b
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ yarn.lock
# pmpm
pnpm-lock.yaml
/.idea
/*.exe
2 changes: 1 addition & 1 deletion app/api/auth/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function POST(request: NextRequest) {
const channel = await authSpeedyAgencyMember(mobile);

if (channel) {
console.log(`auth req: ${sessionId}`);
// console.log(`auth req: ${sessionId}`);

return await ResponseWithSession(NextResponse.json({
status: true,
Expand Down
11 changes: 7 additions & 4 deletions app/api/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ChatClient } from 'dify-client'
import { v4 } from 'uuid'
import { API_KEY, API_URL, APP_ID } from '@/config'
import { encrypt, decrypt } from '@/utils/tools'
import crypto from "crypto";

const userPrefix = `user_${APP_ID}:`

Expand All @@ -28,14 +27,18 @@ export const ResponseWithSession = async (resp:NextResponse, sessionId: string,
return resp;
}

export const getSession = (request: NextRequest, sessionID: string) => {
export async function getSession(request: NextRequest, sessionID: string): Promise<Record<string, string>|any> {
const cookies = request.cookies;
const k = cookies.get(sessionID)
const raw = k?.value || '';
if (raw) {
return decrypt(raw);
try {
return await decrypt(raw);
} catch (error: any) {
console.error(error);
}
}
return {};
return null;
}

export const client = new ChatClient(API_KEY, API_URL || undefined)
2 changes: 1 addition & 1 deletion app/components/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const Chat: FC<IChatProps> = ({
</div>
{
!isHideSendInput && (
<div className={cn(!feedbackDisabled && '!left-3.5 !right-3.5', 'absolute z-10 bottom-0 left-0 right-0')}>
<div className={cn(!feedbackDisabled && '!left-3.5 !right-3.5', 'absolute z-10 bottom-0 left-0 right-0 chat-input')}>
<div className='p-[5.5px] max-h-[150px] bg-white border-[1.5px] border-gray-200 rounded-xl overflow-y-auto'>
{
visionConfig?.enabled && (
Expand Down
6 changes: 3 additions & 3 deletions app/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ const Main: FC = ({params}: any) => {
return <Loading type='app' />

return (
<div className='bg-gray-100'>
<div className='bg-gray-100 main-wrapper'>
<Header
title={APP_INFO.title}
isMobile={isMobile}
Expand All @@ -597,7 +597,7 @@ const Main: FC = ({params}: any) => {
</div>
)}
{/* main */}
<div className='flex-grow flex-col flex h-[calc(100vh_-_3rem)] overflow-y-auto'>
<div className='flex-grow flex-col flex h-[calc(100vh_-_3rem)] overflow-y-auto chat-wrapper'>
<ConfigSence
conversationName={conversationName}
hasSetInputs={hasSetInputs}
Expand All @@ -612,7 +612,7 @@ const Main: FC = ({params}: any) => {

{
hasSetInputs && (
<div className='relative grow h-[200px] pc:w-[794px] max-w-full mobile:w-full pb-[66px] mx-auto mb-3.5 overflow-hidden'>
<div className='relative grow pc:w-[794px] max-w-full mobile:w-full pb-[66px] mx-auto mb-3.5 overflow-hidden'>
<div className='h-full overflow-y-auto' ref={chatListDomRef}>
<Chat
chatList={chatList}
Expand Down
24 changes: 24 additions & 0 deletions app/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,27 @@ html,
.font-sans {
font-family: Helvetica, Arial, Helvetica Neue, MHeiHK-Medium, PingFang HK, SourceHanSansTWHK-Light, Microsoft JhengHei, sans-serif;
}

@media (max-width: 768px) {
.main-wrapper {
display: flex;
flex-direction: column;
justify-content: flex-start;
height: 100%;
}
.main-wrapper > .overflow-hidden {
flex: 1;
}
.chat-wrapper {
flex-direction: column;
justify-content: space-between;
height: 100% !important;
}
.chat-wrapper > .relative {
flex: 1;
}
.chat-wrapper .chat-input {
position: fixed;
bottom: 1em;
}
}
5 changes: 2 additions & 3 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { createSessionStore, userSession } from '@/utils/tools'
import { getInfo, setSession, getSession } from '@/app/api/utils/common'
import { ENABLE_AUTH } from '@/config'

Expand All @@ -25,11 +24,11 @@ export async function middleware(request: NextRequest) {
});
}

console.log(`middleware: ${sessionId}`);
// console.log(`middleware: ${sessionId}`);

if (ENABLE_AUTH) {
const session = await getSession(request, sessionId);
console.log(`middleware: ${JSON.stringify(session)}`);
// console.log(`middleware: ${JSON.stringify(session)}`);

if (session?.channel) {
return NextResponse.next({
Expand Down
3 changes: 1 addition & 2 deletions utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ export const encrypt = async (value: Record<string, string>) => {
const pwHash = await subtle.digest('SHA-256', pwUtf8);

const iv = getRandomValues(new Uint8Array(12));
console.log(iv.toString());
const alg = { name: 'AES-GCM', iv: iv };
const key = await subtle.importKey('raw', pwHash, alg, false, ['encrypt']);

const encData = await subtle.encrypt(alg, key, ptUtf8);

const encryptedDataArray = new Uint8Array(encData);
const encryptedData = [...iv].map(b => ('00' + b.toString(16)).slice(-2)).join('') + Array.from(encryptedDataArray, byte => String.fromCharCode(byte)).join('');
console.log([...iv].map(b => ('00' + b.toString(16)).slice(-2)).join(''));
return btoa(encryptedData);
}

Expand All @@ -32,6 +30,7 @@ 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