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

点击suggestion提问时,inputs值缺失 #69

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 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
933a48d
完善 rate limit 处理
mm-sam Apr 26, 2024
ba5f12c
修正 conversation delete api的問題
mm-sam Apr 26, 2024
86e51dc
点击suggestion提问时,inputs值缺失
Apr 29, 2024
77a9ea3
同上
Apr 29, 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
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.env
.vscode
.next
.git
.idea
.yarn
.husky
.swc
.pnp*
node_modules
12 changes: 9 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# APP ID
NEXT_PUBLIC_APP_ID=
APP_ID=
# APP API key
NEXT_PUBLIC_APP_KEY=
APP_KEY=
# API url prefix
NEXT_PUBLIC_API_URL=
API_URL=
# SA API endpoint
SA_API_URL=https://speedyagency.demo2.mixmedia.com/api
SA_API_TOKEN=
ENABLE_AUTH=false
SECRET_KEY=IEboqt3vmYau9ic6zye78sX2l4JfVHFw
SHOW_MOBILE=false
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
# local .env files
.env*.local
.env

Expand All @@ -49,3 +49,5 @@ yarn.lock

# pmpm
pnpm-lock.yaml
/.idea
/*.exe
28 changes: 0 additions & 28 deletions .vscode/launch.json

This file was deleted.

32 changes: 0 additions & 32 deletions .vscode/settings.json

This file was deleted.

45 changes: 40 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
FROM --platform=linux/amd64 node:19-bullseye-slim
FROM node:18-alpine AS base

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app

#COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN yarn install
RUN yarn build
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN yarn install \
&& yarn run output

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

CMD ["yarn","start"]
ENV PORT 3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD HOSTNAME="0.0.0.0" node server.js
23 changes: 23 additions & 0 deletions __tests__/route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { type NextRequest, NextResponse } from 'next/server'
import { NextRequest as Request } from 'next/server'
import GetConversationsHandler from '@/app/api/conversations/route'
import { v4 } from 'uuid'

function generateRequestWithCookies(request: NextRequest) {
const sessionID = v4();
request.cookies.set('session_id', sessionID);
request.headers.set('user_hash', '11111111');
return request;
}


describe("Test API Route", () => {
it('GET /api/conversations', async function () {
const req = generateRequestWithCookies(new Request(new URL('')));
const resp = await GetConversationsHandler.GET(req);

console.log(resp);

expect(resp.statusCode).toEqual(200);
});
});
41 changes: 41 additions & 0 deletions __tests__/server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { authSpeedyAgencyMember } from '@/app/api/utils/speedyagency';
import { encrypt, decrypt, generateHash } from '@/utils/tools'

describe("Test Server", () => {
it('authSpeedyAgencyMember', async function () {
const channel = await authSpeedyAgencyMember('11111111');

console.log(channel);

expect(channel).toEqual("aia")
});

it('encrypt', async function () {
const encryptedData = await encrypt({
first: "First",
Three: "3",
})

console.log(encryptedData);

expect(encryptedData).not.toBeNull()
});

it('decrypt', async function () {
const encryptedData = 'NzQxNWYzOTYyNjZkODA3YjM4N2MyNDMxp3iSeaCBi1g0A5O9bHYo31XR2oy1tVVu3mp+3Jo8bWLkRx9yi5Q/gFh+u77EaK2+HJ5OF5ZZEJc=';
const decryptedData = await decrypt(encryptedData)

console.dir(decryptedData);

expect(decryptedData).not.toBeNull()
});

it ("generateHash", async function() {
const hash = await generateHash('1234567890');

console.log(hash);

expect(hash).not.toBeNull()
});
})

65 changes: 65 additions & 0 deletions app/api/auth/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { getInfo, ResponseWithSession, getSessionFromRequest } from '@/app/api/utils/common'
import { authSpeedyAgencyMember } from '@/app/api/utils/speedyagency'

export const dynamic = 'force-dynamic'

export async function POST(request: NextRequest) {
const { sessionId } = getInfo(request)

try {
const postData = await request.json();
const mobile = postData?.mobile;
if (mobile) {
const channel = await authSpeedyAgencyMember(mobile);

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

return await ResponseWithSession(NextResponse.json({
status: true,
}), sessionId, {
mobile,
channel: `${channel}`,
})
}
}
}
catch (error: any) {
if (error instanceof Error) {
return NextResponse.json({
status: false,
error: error.message,
})
}
}

return NextResponse.json({
status: false,
error: 'auth error',
})
}

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

const hosts = request.headers.get('x-forwarded-host')?.split(',') || [];
const ports = request.headers.get('x-forwarded-port')?.split(',') || [];
const protos = request.headers.get('x-forwarded-proto')?.split(',') || [];

const url = request.nextUrl.clone()
url.host = hosts[0] || request.nextUrl.host
url.port = ports[0] || request.nextUrl.port
url.protocol = protos[0] || request.nextUrl.protocol
url.pathname = '/';
url.search = '';

if (data) {
// console.log(data);
return ResponseWithSession(NextResponse.redirect(url), sessionId, data);
}

return NextResponse.redirect(url);
}
15 changes: 15 additions & 0 deletions app/api/conversations/[conversationId]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { client, getInfo } from '@/app/api/utils/common'

export const dynamic = 'force-dynamic'

export async function DELETE(request: NextRequest, { params }: {
params: { conversationId: string }
}) {
const { user } = getInfo(request);

const { conversationId } = params
const { data } = await client.deleteConversation(conversationId, user)
return NextResponse.json(data)
}
12 changes: 12 additions & 0 deletions app/api/messages/[messageId]/suggested/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { client, getInfo } from '@/app/api/utils/common'

export async function GET(request: NextRequest, { params }: {
params: { messageId: string }
}) {
const { messageId } = params
const { user } = getInfo(request)
const { data } = await client.sendRequest("GET", `/messages/${messageId}/suggested`, null, {user})
return NextResponse.json(data)
}
3 changes: 3 additions & 0 deletions app/api/parameters/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { draftMode } from 'next/headers'
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { client, getInfo, setSession } from '@/app/api/utils/common'

export async function GET(request: NextRequest) {
draftMode().enable();
const { sessionId, user } = getInfo(request)
// console.log(`paramters: ${user}`);
try {
const { data } = await client.getApplicationParameters(user)
return NextResponse.json(data as object, {
Expand Down
Loading