fix: dates not preserved after importing chat

This commit is contained in:
conql 2025-06-23 01:52:50 +08:00
parent b5f4c85bb1
commit 04775fa34e
4 changed files with 22 additions and 8 deletions

View File

@ -72,6 +72,8 @@ class ChatImportForm(ChatForm):
meta: Optional[dict] = {}
pinned: Optional[bool] = False
folder_id: Optional[str] = None
created_at: Optional[int] = None
updated_at: Optional[int] = None
class ChatTitleMessagesForm(BaseModel):
@ -147,8 +149,16 @@ class ChatTable:
"meta": form_data.meta,
"pinned": form_data.pinned,
"folder_id": form_data.folder_id,
"created_at": int(time.time()),
"updated_at": int(time.time()),
"created_at": (
form_data.created_at
if hasattr(form_data, "created_at") and form_data.created_at
else int(time.time())
),
"updated_at": (
form_data.updated_at
if hasattr(form_data, "updated_at") and form_data.updated_at
else int(time.time())
),
}
)

View File

@ -37,7 +37,9 @@ export const importChat = async (
chat: object,
meta: object | null,
pinned?: boolean,
folderId?: string | null
folderId?: string | null,
createdAt?: number,
updatedAt?: number
) => {
let error = null;
@ -52,7 +54,9 @@ export const importChat = async (
chat: chat,
meta: meta ?? {},
pinned: pinned,
folder_id: folderId
folder_id: folderId,
created_at: createdAt,
updated_at: updatedAt
})
})
.then(async (res) => {

View File

@ -6,7 +6,7 @@
import {
archiveAllChats,
createNewChat,
importChat,
deleteAllChats,
getAllChats,
getAllUserChats,
@ -58,9 +58,9 @@
console.log(chat);
if (chat.chat) {
await createNewChat(localStorage.token, chat.chat);
await importChat(localStorage.token, chat.chat, chat.meta ?? {}, false, null, chat.created_at, chat.updated_at);
} else {
await createNewChat(localStorage.token, chat);
await importChat(localStorage.token, chat, chat.meta ?? {}, false, null, chat.created_at, chat.updated_at);
}
}

View File

@ -202,7 +202,7 @@
for (const item of items) {
console.log(item);
if (item.chat) {
await importChat(localStorage.token, item.chat, item?.meta ?? {}, pinned, folderId);
await importChat(localStorage.token, item.chat, item?.meta ?? {}, pinned, folderId, item.created_at, item.updated_at);
}
}