From 67d72149304ba4fc9302cf1b95f46a64a28a0591 Mon Sep 17 00:00:00 2001 From: Christ Date: Sat, 8 Aug 2026 22:16:35 +0800 Subject: [PATCH] feat: add account automation and isolated chat - add account-level auto rating and daily polish tasks\n- add cached historical chat, media, emoji, and per-account realtime sync\n- add SQLite, MySQL, and PostgreSQL migrations and regression coverage\n- align account, sidebar, and chat interfaces with the new workflows --- cmd/server/main.go | 4 + frontend/App.tsx | 15 +- frontend/chatEmojis.test.tsx | 22 + frontend/chatEmojis.tsx | 516 +++++++++++++++++ frontend/chatFeature.test.ts | 46 ++ .../components/AccountAutomationModal.tsx | 156 ++++++ frontend/components/AccountList.tsx | 67 ++- frontend/components/Chat.tsx | 523 ++++++++++++++++++ frontend/components/Sidebar.tsx | 104 ++-- frontend/components/sidebarState.test.ts | 28 + frontend/components/sidebarState.ts | 18 + frontend/services/api.test.ts | 36 ++ frontend/services/api.ts | 62 +++ frontend/types.ts | 55 ++ frontend/vite.config.ts | 1 + internal/adapter/adapter.go | 34 +- internal/automation/account_tasks.go | 229 ++++++++ internal/automation/account_tasks_test.go | 156 ++++++ internal/automation/center.go | 25 +- internal/automation/scheduler.go | 1 + internal/chat/service.go | 498 +++++++++++++++++ internal/chat/service_test.go | 241 ++++++++ internal/db/account_tasks.go | 189 +++++++ internal/db/chat.go | 272 +++++++++ internal/db/migrate_test.go | 13 +- .../mysql/00024_chat_account_tasks.sql | 75 +++ .../mysql/00025_chat_direction_repair.sql | 12 + .../postgres/00024_chat_account_tasks.sql | 72 +++ .../postgres/00025_chat_direction_repair.sql | 12 + .../sqlite/00024_chat_account_tasks.sql | 75 +++ .../sqlite/00025_chat_direction_repair.sql | 12 + internal/db/multidb_test.go | 102 +++- internal/db/store.go | 4 + internal/engine/account.go | 69 ++- internal/engine/dispatch.go | 6 + internal/engine/engine_test.go | 11 + internal/engine/outgoing_chat_test.go | 43 ++ internal/engine/reply_extra_test.go | 3 + internal/server/account_task_handlers.go | 107 ++++ internal/server/chat_account_tasks_test.go | 123 ++++ internal/server/chat_handlers.go | 435 +++++++++++++++ internal/server/cookie_handlers.go | 78 +-- internal/server/server.go | 8 + ...-B_BfwiL0.js => charts-vendor-BxxJOyEX.js} | 2 +- ...r-RenKjhri.js => icons-vendor-DjsKcZkz.js} | 191 ++++--- .../webui/static/assets/index-2_f0Vmhn.js | 19 - .../webui/static/assets/index-BIyp4is6.js | 19 + .../webui/static/assets/index-DMeflf1O.css | 1 - .../webui/static/assets/index-DtBcYu3b.css | 1 + ...r-DZnRGM0-.js => react-vendor-C_od1ZSF.js} | 2 +- ...{vendor-w5t2K9ux.js => vendor-D-Edl3pr.js} | 2 +- internal/webui/static/index.html | 12 +- internal/xianyu/mtop/account_tasks.go | 269 +++++++++ .../account_tasks_live_integration_test.go | 54 ++ internal/xianyu/mtop/account_tasks_test.go | 103 ++++ internal/xianyu/mtop/chat_media.go | 54 ++ internal/xianyu/mtop/chat_media_test.go | 48 ++ internal/xianyu/mtop/client.go | 19 +- internal/xianyu/ws/client.go | 59 ++ 59 files changed, 5202 insertions(+), 211 deletions(-) create mode 100644 frontend/chatEmojis.test.tsx create mode 100644 frontend/chatEmojis.tsx create mode 100644 frontend/chatFeature.test.ts create mode 100644 frontend/components/AccountAutomationModal.tsx create mode 100644 frontend/components/Chat.tsx create mode 100644 frontend/components/sidebarState.test.ts create mode 100644 frontend/components/sidebarState.ts create mode 100644 internal/automation/account_tasks.go create mode 100644 internal/automation/account_tasks_test.go create mode 100644 internal/chat/service.go create mode 100644 internal/chat/service_test.go create mode 100644 internal/db/account_tasks.go create mode 100644 internal/db/chat.go create mode 100644 internal/db/migrations/mysql/00024_chat_account_tasks.sql create mode 100644 internal/db/migrations/mysql/00025_chat_direction_repair.sql create mode 100644 internal/db/migrations/postgres/00024_chat_account_tasks.sql create mode 100644 internal/db/migrations/postgres/00025_chat_direction_repair.sql create mode 100644 internal/db/migrations/sqlite/00024_chat_account_tasks.sql create mode 100644 internal/db/migrations/sqlite/00025_chat_direction_repair.sql create mode 100644 internal/engine/outgoing_chat_test.go create mode 100644 internal/server/account_task_handlers.go create mode 100644 internal/server/chat_account_tasks_test.go create mode 100644 internal/server/chat_handlers.go rename internal/webui/static/assets/{charts-vendor-B_BfwiL0.js => charts-vendor-BxxJOyEX.js} (99%) rename internal/webui/static/assets/{icons-vendor-RenKjhri.js => icons-vendor-DjsKcZkz.js} (59%) delete mode 100644 internal/webui/static/assets/index-2_f0Vmhn.js create mode 100644 internal/webui/static/assets/index-BIyp4is6.js delete mode 100644 internal/webui/static/assets/index-DMeflf1O.css create mode 100644 internal/webui/static/assets/index-DtBcYu3b.css rename internal/webui/static/assets/{react-vendor-DZnRGM0-.js => react-vendor-C_od1ZSF.js} (99%) rename internal/webui/static/assets/{vendor-w5t2K9ux.js => vendor-D-Edl3pr.js} (99%) create mode 100644 internal/xianyu/mtop/account_tasks.go create mode 100644 internal/xianyu/mtop/account_tasks_live_integration_test.go create mode 100644 internal/xianyu/mtop/account_tasks_test.go create mode 100644 internal/xianyu/mtop/chat_media.go create mode 100644 internal/xianyu/mtop/chat_media_test.go diff --git a/cmd/server/main.go b/cmd/server/main.go index b8fd85f..291ad1f 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -28,6 +28,7 @@ import ( "xianyu-go/internal/auth" "xianyu-go/internal/automation" "xianyu-go/internal/browser" + "xianyu-go/internal/chat" "xianyu-go/internal/db" "xianyu-go/internal/logging" "xianyu-go/internal/notify" @@ -149,6 +150,8 @@ func main() { } var mgr *account.Manager ap := adapter.New(store, bm, logger) + chatService := chat.New(store) + ap.SetChatService(chatService) mgr = account.NewManager(store, ap, logger) autoCenter := automation.New(store, mgr, logger) autoCenter.SetOrderDetailFetcher(ap) @@ -167,6 +170,7 @@ func main() { // 3) HTTP 服务。 srv := server.New(store, mgr, *secure, *webDir, *addr, logger, autoCenter, notifier) + srv.SetChatService(chatService) srv.StartPublishBatchRecovery(ctx) if err := srv.Run(ctx); err != nil { logger.Error("HTTP 服务退出", "err", err) diff --git a/frontend/App.tsx b/frontend/App.tsx index ba7cd10..e8313f6 100644 --- a/frontend/App.tsx +++ b/frontend/App.tsx @@ -8,6 +8,8 @@ import ItemList from './components/ItemList'; import Settings from './components/Settings'; import Rules from './components/Rules'; import Notifications from './components/Notifications'; +import Chat from './components/Chat'; +import { readSidebarCollapsed, writeSidebarCollapsed } from './components/sidebarState'; import { YdisksBrandIcon } from './components/YdisksLogo'; import { login, logout, verifySession } from './services/api'; import { ShieldCheck, ArrowRight, Loader2, User, Lock } from 'lucide-react'; @@ -24,6 +26,7 @@ interface DeliveryRuleTarget { const ROUTES: Record = { '/app/dashboard': 'dashboard', '/app/accounts': 'accounts', + '/app/chat': 'chat', '/app/orders': 'orders', '/app/cards': 'cards', '/app/items': 'items', @@ -50,6 +53,7 @@ const App: React.FC = () => { const [loginLoading, setLoginLoading] = useState(false); const [loginError, setLoginError] = useState(''); const [deliveryRuleTarget, setDeliveryRuleTarget] = useState(); + const [sidebarCollapsed, setSidebarCollapsed] = useState(readSidebarCollapsed); // 切换 tab 并同步 URL。若 tab 没有对应 path(不应发生)则只切 tab。 const navigate = (tab: string) => { @@ -266,6 +270,7 @@ const App: React.FC = () => { switch (activeTab) { case 'dashboard': return ; case 'accounts': return ; + case 'chat': return ; case 'orders': return ; case 'cards': return ; case 'items': return { @@ -287,15 +292,21 @@ const App: React.FC = () => { setSidebarCollapsed(current => { + const next = !current; + writeSidebarCollapsed(next); + return next; + })} onNavigate={navigate} onLogout={handleLogout} /> -
+
{/* Subtle background decoration */}
-
+
{renderContent()}
diff --git a/frontend/chatEmojis.test.tsx b/frontend/chatEmojis.test.tsx new file mode 100644 index 0000000..fd8631e --- /dev/null +++ b/frontend/chatEmojis.test.tsx @@ -0,0 +1,22 @@ +import { renderToStaticMarkup } from 'react-dom/server'; +import { describe, expect, test } from 'vitest'; +import { renderXianyuText, xianyuEmojis } from './chatEmojis'; + +describe('official Xianyu emoji mapping', () => { + test('contains the complete official panel in official order', () => { + expect(xianyuEmojis).toHaveLength(126); + expect(xianyuEmojis[0][0]).toBe('尊嘟假嘟'); + expect(xianyuEmojis.at(-1)?.[0]).toBe('爱心'); + expect(new Set(xianyuEmojis.map(([name]) => name)).size).toBe(126); + }); + + test('uses official CDN assets and renders bracket codes inline', () => { + for (const [, url] of xianyuEmojis) { + expect(url).toMatch(/^https:\/\/img\.alicdn\.com\//); + } + const html = renderToStaticMarkup(<>{renderXianyuText('你好[捂脸哭][送花]')}); + expect(html).toContain('你好'); + expect(html).toContain('alt="[捂脸哭]"'); + expect(html).toContain('alt="[送花]"'); + }); +}); diff --git a/frontend/chatEmojis.tsx b/frontend/chatEmojis.tsx new file mode 100644 index 0000000..df310ee --- /dev/null +++ b/frontend/chatEmojis.tsx @@ -0,0 +1,516 @@ +import React from 'react'; + +export const xianyuEmojis = [ + [ + "尊嘟假嘟", + "https://img.alicdn.com/imgextra/i2/O1CN01hWzOgD1KcmFEIaGwE_!!6000000001185-2-tps-64-64.png_110x10000.jpg_.webp" + ], + [ + "鸡哔你", + "https://img.alicdn.com/imgextra/i1/O1CN01P9TVJl1JCqCZcQIdW_!!6000000000993-2-tps-64-64.png_110x10000.jpg_.webp" + ], + [ + "谁懂啊", + "https://img.alicdn.com/imgextra/i1/O1CN01r9qUnx1g3tcrtSmcs_!!6000000004087-2-tps-64-64.png_110x10000.jpg_.webp" + ], + [ + "吗喽", + "https://img.alicdn.com/imgextra/i4/O1CN01dTynZh1LnbIYTHI1D_!!6000000001344-2-tps-64-64.png_110x10000.jpg_.webp" + ], + [ + "功德+1", + "https://img.alicdn.com/imgextra/i1/O1CN01l1G5pS1IVn37pfQJi_!!6000000000899-2-tps-64-64.png_110x10000.jpg_.webp" + ], + [ + "city不city啊", + "https://img.alicdn.com/imgextra/i2/O1CN01zRjPTR29lWHqabmDA_!!6000000008108-2-tps-64-64.png_110x10000.jpg_.webp" + ], + [ + "激推", + "https://img.alicdn.com/imgextra/i3/O1CN01ADTJ6u1khypfxbfnQ_!!6000000004716-2-tps-64-64.png_110x10000.jpg_.webp" + ], + [ + "微笑", + "https://img.alicdn.com/imgextra/i1/O1CN017b61R51wRk2lVV7vx_!!6000000006305-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "龇牙", + "https://img.alicdn.com/imgextra/i2/O1CN01nmOh4S22Yxz8IdEVf_!!6000000007133-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "流泪", + "https://img.alicdn.com/imgextra/i2/O1CN01Ec1EaL1zqQETcM2dX_!!6000000006765-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "尴尬", + "https://img.alicdn.com/imgextra/i2/O1CN01UrWH7a1ZVBrgRYXlc_!!6000000003199-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "撇嘴", + "https://img.alicdn.com/imgextra/i2/O1CN01Sr7o2b1lUWg5KfOD8_!!6000000004822-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "破涕为笑", + "https://img.alicdn.com/imgextra/i4/O1CN01pPetah1gkwndfn7Fs_!!6000000004181-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "捂脸哭", + "https://img.alicdn.com/imgextra/i2/O1CN0170KgpE1dE1TuQgd66_!!6000000003703-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "害羞", + "https://img.alicdn.com/imgextra/i3/O1CN01ZoB0Lb1ps7XpqP8PQ_!!6000000005415-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "感动", + "https://img.alicdn.com/imgextra/i2/O1CN01wqD4ly29yndR3Qp3A_!!6000000008137-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "滴泪", + "https://img.alicdn.com/imgextra/i1/O1CN01MpkJ3L1oUTTqfryOn_!!6000000005228-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "暗中观察", + "https://img.alicdn.com/imgextra/i1/O1CN010LO9yj272W07GlLls_!!6000000007739-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "偷笑", + "https://img.alicdn.com/imgextra/i4/O1CN01vJtO031g818IuYO7x_!!6000000004096-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "ok", + "https://img.alicdn.com/imgextra/i3/O1CN01QRkqDF25tz0WcANje_!!6000000007585-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "送花", + "https://img.alicdn.com/imgextra/i2/O1CN01PpzBNX1JNpeJBWnvr_!!6000000001017-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "大哭", + "https://img.alicdn.com/imgextra/i4/O1CN014TiaNb1ViEgNvRrTB_!!6000000002686-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "色", + "https://img.alicdn.com/imgextra/i2/O1CN01840t1B1JaCLGvHnBK_!!6000000001044-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "惊慌", + "https://img.alicdn.com/imgextra/i1/O1CN01mnqO7G1LAfUnfAN2U_!!6000000001259-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "惊讶", + "https://img.alicdn.com/imgextra/i3/O1CN0127IeyS1Kw0p0P4jzI_!!6000000001227-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "得意", + "https://img.alicdn.com/imgextra/i4/O1CN018QUnFv1WpOUES9POZ_!!6000000002837-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "睡", + "https://img.alicdn.com/imgextra/i2/O1CN01RprGZl1lqVgnEJLCx_!!6000000004870-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "不好意思", + "https://img.alicdn.com/imgextra/i3/O1CN01rMJJgn1SUXzuVpUhO_!!6000000002250-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "托腮", + "https://img.alicdn.com/imgextra/i1/O1CN01w3reBU1d3wlgOBtyZ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "发怒", + "https://img.alicdn.com/imgextra/i2/O1CN013Wzy8d2A8PxGJZPpT_!!6000000008158-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "难过", + "https://img.alicdn.com/imgextra/i2/O1CN01zcwaSh1G9gZCFuFal_!!6000000000580-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "调皮", + "https://img.alicdn.com/imgextra/i3/O1CN01Zd1YHi1TI0lwpBe8c_!!6000000002358-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "愉快", + "https://img.alicdn.com/imgextra/i2/O1CN0145wDk21SWpyjTvsvA_!!6000000002255-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "白眼", + "https://img.alicdn.com/imgextra/i4/O1CN01nexGth1hwEAT1SHO2_!!6000000004341-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "拒绝", + "https://img.alicdn.com/imgextra/i2/O1CN01nqusqS1uHXzoUcpXr_!!6000000006012-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "期待", + "https://img.alicdn.com/imgextra/i3/O1CN01M44QY11Oh8Q5PdMIx_!!6000000001736-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "困", + "https://img.alicdn.com/imgextra/i4/O1CN01J4hFFz1Y9pmNdBq76_!!6000000003017-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "流汗", + "https://img.alicdn.com/imgextra/i4/O1CN01BU3NZ21gdcSjkqnST_!!6000000004165-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "憨笑", + "https://img.alicdn.com/imgextra/i2/O1CN01Pee9Ql1SJ661eH9By_!!6000000002225-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "耶", + "https://img.alicdn.com/imgextra/i2/O1CN01pFicsL1ipBhIqzcgs_!!6000000004461-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "奋斗", + "https://img.alicdn.com/imgextra/i3/O1CN01ZhQ4AV25xBmTK3CnF_!!6000000007592-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "咒骂", + "https://img.alicdn.com/imgextra/i3/O1CN01r1Zh9927QKb4pnf7k_!!6000000007791-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "疑问", + "https://img.alicdn.com/imgextra/i4/O1CN01UZqbzt29MmlNctCQS_!!6000000008054-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "嘘", + "https://img.alicdn.com/imgextra/i1/O1CN01qBlYkM1ojaYF75On5_!!6000000005261-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "晕", + "https://img.alicdn.com/imgextra/i2/O1CN014zhM2h1wPuSUFoMwV_!!6000000006301-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "开心到模糊", + "https://img.alicdn.com/imgextra/i1/O1CN01T1Dy271j6akZWo7Vr_!!6000000004499-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "衰", + "https://img.alicdn.com/imgextra/i1/O1CN01aOXsNr1LmgMvtyzOO_!!6000000001342-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "委屈", + "https://img.alicdn.com/imgextra/i2/O1CN013J0bMk1QNYih3UFTk_!!6000000001964-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "再见", + "https://img.alicdn.com/imgextra/i2/O1CN01IHKsQx1UdpFgeTHcA_!!6000000002541-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "鼓掌", + "https://img.alicdn.com/imgextra/i4/O1CN01DHxB5s1G1RRBxekIu_!!6000000000562-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "吐", + "https://img.alicdn.com/imgextra/i1/O1CN01xyVxH21LNUaMgW4hh_!!6000000001287-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "坏笑", + "https://img.alicdn.com/imgextra/i1/O1CN01zV7opv1bIU6iI8OhM_!!6000000003442-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "抠鼻", + "https://img.alicdn.com/imgextra/i1/O1CN01QOanju1sNqCrtYstu_!!6000000005755-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "叹气", + "https://img.alicdn.com/imgextra/i3/O1CN01RElx7R1QD1c8ZN07f_!!6000000001941-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "无聊", + "https://img.alicdn.com/imgextra/i2/O1CN01d91LnZ1UJDQjKCouC_!!6000000002496-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "思考", + "https://img.alicdn.com/imgextra/i2/O1CN01wQjg2f1tO84ZWitn9_!!6000000005891-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "呆", + "https://img.alicdn.com/imgextra/i1/O1CN01GLqBWC1DGbhqmpD2L_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "哇哦", + "https://img.alicdn.com/imgextra/i2/O1CN01MtLpS21qRO2bnAA5k_!!6000000005492-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "飞吻", + "https://img.alicdn.com/imgextra/i4/O1CN01q1WpFE25ljsNKjvHX_!!6000000007567-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "好喜欢", + "https://img.alicdn.com/imgextra/i2/O1CN01mD4iQM1O57XyQ5SHD_!!6000000001653-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "拜托", + "https://img.alicdn.com/imgextra/i4/O1CN01SQgrTH1dzCH3pIyRN_!!6000000003806-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "真棒", + "https://img.alicdn.com/imgextra/i2/O1CN017fcAmd1SCgYCj9Upk_!!6000000002211-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "流鼻血", + "https://img.alicdn.com/imgextra/i3/O1CN0139JscY1rC6RS9GR4j_!!6000000005594-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "费解", + "https://img.alicdn.com/imgextra/i1/O1CN01FqAVvR1tyJMPj13ie_!!6000000005970-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "秃头", + "https://img.alicdn.com/imgextra/i4/O1CN01ZF4bV11thMhqm2Z1h_!!6000000005933-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "嘿哈", + "https://img.alicdn.com/imgextra/i4/O1CN01ObcOw61FOVlvQg7Mw_!!6000000000477-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "吃土", + "https://img.alicdn.com/imgextra/i3/O1CN01Z6nJ1b1ZYr22YseHN_!!6000000003207-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "机智", + "https://img.alicdn.com/imgextra/i1/O1CN01rfKY351zDUZJlBiir_!!6000000006680-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "举杯", + "https://img.alicdn.com/imgextra/i4/O1CN01R2tn4F1mn8NuEIE8J_!!6000000004998-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "握手", + "https://img.alicdn.com/imgextra/i4/O1CN01NDcA251JDkvuFhSDb_!!6000000000995-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "挥手", + "https://img.alicdn.com/imgextra/i4/O1CN01iVN0ht1TmEuSwauGt_!!6000000002424-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "yeah", + "https://img.alicdn.com/imgextra/i3/O1CN01opt7hh27Wk8omjR4t_!!6000000007805-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "666", + "https://img.alicdn.com/imgextra/i3/O1CN01YRWDPF1OjQOpXeuTC_!!6000000001741-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "棒", + "https://img.alicdn.com/imgextra/i3/O1CN01agprvs1HU7rPRxOnB_!!6000000000760-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "爱你", + "https://img.alicdn.com/imgextra/i1/O1CN01SzxgcH1GSSo6Lwmwk_!!6000000000621-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "比心", + "https://img.alicdn.com/imgextra/i1/O1CN01YHZ39t1DeQIeb0TWQ_!!6000000000241-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "感谢", + "https://img.alicdn.com/imgextra/i3/O1CN01ywacF81baLYNeyK1n_!!6000000003481-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "拍手", + "https://img.alicdn.com/imgextra/i4/O1CN01wbj4wv1K7ArD9AU44_!!6000000001116-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "拉钩", + "https://img.alicdn.com/imgextra/i1/O1CN01dePkKH1HOd6ivAcu8_!!6000000000748-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "没钱", + "https://img.alicdn.com/imgextra/i3/O1CN01qhxGjp1zD2AfqmWx5_!!6000000006679-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "小刀", + "https://img.alicdn.com/imgextra/i3/O1CN01tFVx5Y1T2thPjhR6b_!!6000000002325-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "不刀", + "https://img.alicdn.com/imgextra/i4/O1CN01zTxff61clcvOcTS3n_!!6000000003641-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "同出", + "https://img.alicdn.com/imgextra/i3/O1CN01URKas6249R8ozS98O_!!6000000007348-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "递钱", + "https://img.alicdn.com/imgextra/i4/O1CN01PzhgV51FLlOaZHZ6n_!!6000000000471-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "数钱", + "https://img.alicdn.com/imgextra/i3/O1CN01CzXXvp23khkljToQH_!!6000000007294-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "打call", + "https://img.alicdn.com/imgextra/i1/O1CN01X7VUVm1il48IYv8Qw_!!6000000004452-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "号外", + "https://img.alicdn.com/imgextra/i2/O1CN01vg6xSM1Vxo9EKyfjR_!!6000000002720-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "包邮", + "https://img.alicdn.com/imgextra/i3/O1CN01yVS7ys24jA22oVZ2T_!!6000000007426-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "求赞", + "https://img.alicdn.com/imgextra/i1/O1CN01Xwqi5A1giCQMRcX6N_!!6000000004175-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "非主流", + "https://img.alicdn.com/imgextra/i1/O1CN013wyI1j1hlEfDUoATI_!!6000000004317-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "吃瓜", + "https://img.alicdn.com/imgextra/i1/O1CN01LLOFsh1UUCw0deZba_!!6000000002520-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "种草", + "https://img.alicdn.com/imgextra/i2/O1CN01ooeRC81hA8a4x9S3q_!!6000000004236-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "佛系", + "https://img.alicdn.com/imgextra/i4/O1CN01BYXEe321GMHMZ9w66_!!6000000006957-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "超便宜", + "https://img.alicdn.com/imgextra/i4/O1CN01mqgSZi1Er4rOIDiP7_!!6000000000404-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "拥抱", + "https://img.alicdn.com/imgextra/i1/O1CN01yuGD9c1hJkttfKHAm_!!6000000004257-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "摊手", + "https://img.alicdn.com/imgextra/i2/O1CN014AiIqE1o9repE6STR_!!6000000005183-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "举手", + "https://img.alicdn.com/imgextra/i1/O1CN01xizuHZ1WPkJCogbuj_!!6000000002781-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "蹲", + "https://img.alicdn.com/imgextra/i3/O1CN01Midjjn1FrMj2CWer6_!!6000000000540-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "跪了", + "https://img.alicdn.com/imgextra/i3/O1CN01F2y52j24E16L6RIjF_!!6000000007358-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "拜", + "https://img.alicdn.com/imgextra/i4/O1CN01Jldd1G1oXDrEHH2qr_!!6000000005234-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "排", + "https://img.alicdn.com/imgextra/i3/O1CN01uSUmYD1jD0IJf0UVU_!!6000000004513-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "旺财", + "https://img.alicdn.com/imgextra/i3/O1CN01A25Mv01DKjGseAmuP_!!6000000000198-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "招财猫", + "https://img.alicdn.com/imgextra/i3/O1CN01WmJ7Sr20EhDyp86Bd_!!6000000006818-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "酸了", + "https://img.alicdn.com/imgextra/i3/O1CN01UFgjn61JJi5Iqxdk7_!!6000000001008-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "鸭鸭", + "https://img.alicdn.com/imgextra/i3/O1CN01pHSCSQ1deaS8WDiqG_!!6000000003761-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "方了", + "https://img.alicdn.com/imgextra/i3/O1CN01br7g711whlu8xOPUt_!!6000000006340-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "白菜", + "https://img.alicdn.com/imgextra/i1/O1CN01KABFLt24WKwXjVp08_!!6000000007398-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "桃子", + "https://img.alicdn.com/imgextra/i1/O1CN01CQhhPH1vJfRjDGBv5_!!6000000006152-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "打包", + "https://img.alicdn.com/imgextra/i3/O1CN01oYOkUI1VT7c0ivZHV_!!6000000002653-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "沙发", + "https://img.alicdn.com/imgextra/i4/O1CN018qUFaE1DGbhqpMIit_!!6000000000189-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "南", + "https://img.alicdn.com/imgextra/i1/O1CN01ZSA6wg1PEZKf4h99R_!!6000000001809-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "盯", + "https://img.alicdn.com/imgextra/i4/O1CN01OWB1Gx1s01bzBhHN6_!!6000000005703-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "hot", + "https://img.alicdn.com/imgextra/i4/O1CN01DDD9uA22cAl7VDH7d_!!6000000007140-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "new", + "https://img.alicdn.com/imgextra/i3/O1CN01rRJXJo1qwzN4YnOHX_!!6000000005561-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "cool", + "https://img.alicdn.com/imgextra/i4/O1CN013bUubF2855qb2Qt5l_!!6000000007880-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "1", + "https://img.alicdn.com/imgextra/i1/O1CN01U8XG5y1Ie22frQHCQ_!!6000000000917-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "可", + "https://img.alicdn.com/imgextra/i2/O1CN01SMjtPG1iJaN17p94N_!!6000000004392-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "搬砖", + "https://img.alicdn.com/imgextra/i1/O1CN01GbqW6G1LOrm0Gllcb_!!6000000001290-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "菜狗", + "https://img.alicdn.com/imgextra/i2/O1CN01VtN0t91USNLmvfmol_!!6000000002516-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "开心面具", + "https://img.alicdn.com/imgextra/i3/O1CN017elkpk22EoYlBPKd3_!!6000000007089-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "快递", + "https://img.alicdn.com/imgextra/i2/O1CN01AmUZXk1d3wle5O8IJ_!!6000000003681-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "裂开", + "https://img.alicdn.com/imgextra/i1/O1CN01BihwvO1a5N9bFt0LU_!!6000000003278-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "啤酒", + "https://img.alicdn.com/imgextra/i4/O1CN01jDkgEj1WvLdXUVBDx_!!6000000002850-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "瑞思拜", + "https://img.alicdn.com/imgextra/i4/O1CN011gR0Um1K3VgpYjPOi_!!6000000001108-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "小丑", + "https://img.alicdn.com/imgextra/i3/O1CN01jMikhO1NJUM15XKTf_!!6000000001549-2-tps-980-980.png_110x10000.jpg_.webp" + ], + [ + "爱心", + "https://img.alicdn.com/imgextra/i1/O1CN015RVSWf23s25eETJqO_!!6000000007310-2-tps-980-980.png_110x10000.jpg_.webp" + ] +] as const; + +export const emojiURL = (url: string) => url; +const emojiLookup = new Map(xianyuEmojis.map(([name, url]) => [name, url])); + +export const renderXianyuText = (text: string) => text.split(/(\[[^\]]+\])/g).map((part, index) => { + const url = part.startsWith('[') ? emojiLookup.get(part.slice(1, -1)) : undefined; + return url ? {part} : {part}; +}); diff --git a/frontend/chatFeature.test.ts b/frontend/chatFeature.test.ts new file mode 100644 index 0000000..af255f1 --- /dev/null +++ b/frontend/chatFeature.test.ts @@ -0,0 +1,46 @@ +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; +import { describe, expect, test } from 'vitest'; + +const source = (path: string) => readFileSync(resolve(__dirname, path), 'utf8'); + +describe('online chat UI contract', () => { + test('uses account tabs above a two-column buyer/chat layout', () => { + const chat = source('components/Chat.tsx'); + expect(chat).toContain('role="tablist"'); + expect(chat).toContain('grid-cols-[320px_minmax(0,1fr)]'); + expect(chat).toContain('min-h-0 min-w-0 flex-col overflow-hidden'); + expect(chat).not.toContain('grid-cols-[320px_minmax(0,1fr)_'); + expect(chat).toContain('activeAccountID'); + expect(chat).toContain('activeChatID'); + }); + + test('uses neutral user labels instead of assuming buyer role', () => { + const chat = source('components/Chat.tsx'); + expect(chat).toContain('用户 ID:'); + expect(chat).not.toContain('买家 ID:'); + expect(chat).not.toContain('选择一个买家'); + }); + + test('frontend connects only to the application chat websocket', () => { + const chat = source('components/Chat.tsx'); + expect(chat).toContain('/api/chat/ws'); + expect(chat).not.toContain('wss-goofish.dingtalk.com'); + }); + + test('renders peer/self identity and verified media capabilities', () => { + const chat = source('components/Chat.tsx'); + expect(chat).toContain('selectedSession.buyer_avatar_url'); + expect(chat).toContain('activeAccount?.avatar_url'); + expect(chat).toContain("message.message_type === 'image'"); + expect(chat).toContain("message.message_type === 'video'"); + expect(chat).toContain('sendChatImage'); + }); + + test('sidebar exposes collapse control and chat primary navigation', () => { + const sidebar = source('components/Sidebar.tsx'); + expect(sidebar).toContain("id: 'chat'"); + expect(sidebar).toContain('onToggleCollapsed'); + expect(sidebar).toContain('collapsed ? \'w-16\' : \'w-64\''); + }); +}); diff --git a/frontend/components/AccountAutomationModal.tsx b/frontend/components/AccountAutomationModal.tsx new file mode 100644 index 0000000..6b3177b --- /dev/null +++ b/frontend/components/AccountAutomationModal.tsx @@ -0,0 +1,156 @@ +import React, { useState } from 'react'; +import { CalendarClock, Loader2, MessageSquareQuote, Play, Save, Sparkles, X } from 'lucide-react'; +import { AccountDetail, AccountTaskSettings, AccountTaskSummary } from '../types'; +import { getAccountTaskSettings, runAccountTask, updateAccountTaskSettings } from '../services/api'; + +interface Props { + account: AccountDetail; + onClose: () => void; + onSaved: (settings: AccountTaskSettings) => void; +} + +const Toggle: React.FC<{checked: boolean; onChange: () => void; label: string}> = ({ checked, onChange, label }) => ( + +); + +const AccountAutomationModal: React.FC = ({ account, onClose, onSaved }) => { + const [form, setForm] = useState({ + account_id: account.id, + auto_rate_enabled: account.auto_rate_enabled === true, + rate_content: account.rate_content || '不错的买家,交易愉快', + auto_polish_enabled: account.auto_polish_enabled === true, + polish_time: account.polish_time || '03:00', + last_rate_scan_at: account.last_rate_scan_at, + last_polish_date: account.last_polish_date, + last_polish_at: account.last_polish_at, + }); + const [saving, setSaving] = useState(false); + const [running, setRunning] = useState<'' | 'auto_rate' | 'auto_polish'>(''); + const [error, setError] = useState(''); + const [summary, setSummary] = useState(null); + + const save = async () => { + setSaving(true); + setError(''); + try { + const stored = await updateAccountTaskSettings(account.id, form); + setForm(stored); + onSaved(stored); + } catch (saveError) { + setError(saveError instanceof Error ? saveError.message : '保存失败'); + } finally { + setSaving(false); + } + }; + + const run = async (taskType: 'auto_rate' | 'auto_polish') => { + setRunning(taskType); + setError(''); + setSummary(null); + try { + await updateAccountTaskSettings(account.id, form); + const result = await runAccountTask(account.id, taskType); + const stored = await getAccountTaskSettings(account.id); + setSummary(result.summary); + setForm(stored); + onSaved(stored); + } catch (runError) { + setError(runError instanceof Error ? runError.message : '任务执行失败'); + } finally { + setRunning(''); + } + }; + + return ( +
+
+
+
+

账号自动任务

+

{account.nickname || account.remark || account.id}

+
+ +
+ +
+
+
+
+
+
+
+

自动评价

+

持续扫描待评价订单,按订单执行;不是每日任务。

+
+ setForm(current => ({ ...current, auto_rate_enabled: !current.auto_rate_enabled }))} label="自动评价" /> +
+ +