mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 19:47:43 +01:00
refactor: updated the upload endpoint for attachments (#759)
This commit is contained in:
@@ -24,7 +24,6 @@ pub struct DeleteAttachmentResponse {
|
|||||||
#[command]
|
#[command]
|
||||||
pub async fn upload_attachment(
|
pub async fn upload_attachment(
|
||||||
server_id: String,
|
server_id: String,
|
||||||
session_id: String,
|
|
||||||
file_paths: Vec<PathBuf>,
|
file_paths: Vec<PathBuf>,
|
||||||
) -> Result<UploadAttachmentResponse, String> {
|
) -> Result<UploadAttachmentResponse, String> {
|
||||||
let mut form = Form::new();
|
let mut form = Form::new();
|
||||||
@@ -47,7 +46,7 @@ pub async fn upload_attachment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let server = get_server_by_id(&server_id).ok_or("Server not found")?;
|
let server = get_server_by_id(&server_id).ok_or("Server not found")?;
|
||||||
let url = HttpClient::join_url(&server.endpoint, &format!("chat/{}/_upload", session_id));
|
let url = HttpClient::join_url(&server.endpoint, &format!("attachment/_upload"));
|
||||||
|
|
||||||
let token = get_server_token(&server_id).await?;
|
let token = get_server_token(&server_id).await?;
|
||||||
let mut headers = HashMap::new();
|
let mut headers = HashMap::new();
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ export const ChatContent = ({
|
|||||||
timedoutShow,
|
timedoutShow,
|
||||||
Question,
|
Question,
|
||||||
handleSendMessage,
|
handleSendMessage,
|
||||||
getFileUrl,
|
|
||||||
}: ChatContentProps) => {
|
}: ChatContentProps) => {
|
||||||
const sessionId = useConnectStore((state) => state.currentSessionId);
|
const sessionId = useConnectStore((state) => state.currentSessionId);
|
||||||
const setCurrentSessionId = useConnectStore((state) => {
|
const setCurrentSessionId = useConnectStore((state) => {
|
||||||
@@ -165,9 +164,9 @@ export const ChatContent = ({
|
|||||||
<div ref={messagesEndRef} />
|
<div ref={messagesEndRef} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{sessionId && uploadFiles.length > 0 && (
|
{uploadFiles.length > 0 && (
|
||||||
<div key={sessionId} className="max-h-[120px] overflow-auto p-2">
|
<div key={sessionId} className="max-h-[120px] overflow-auto p-2">
|
||||||
<FileList sessionId={sessionId} getFileUrl={getFileUrl} />
|
<FileList />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,7 @@ import platformAdapter from "@/utils/platformAdapter";
|
|||||||
import Tooltip2 from "../Common/Tooltip2";
|
import Tooltip2 from "../Common/Tooltip2";
|
||||||
import FileIcon from "../Common/Icons/FileIcon";
|
import FileIcon from "../Common/Icons/FileIcon";
|
||||||
|
|
||||||
interface FileListProps {
|
const FileList = () => {
|
||||||
sessionId: string;
|
|
||||||
getFileUrl: (path: string) => string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const FileList = (props: FileListProps) => {
|
|
||||||
const { sessionId } = props;
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { uploadFiles, setUploadFiles } = useChatStore();
|
const { uploadFiles, setUploadFiles } = useChatStore();
|
||||||
const { currentService } = useConnectStore();
|
const { currentService } = useConnectStore();
|
||||||
@@ -44,7 +38,6 @@ const FileList = (props: FileListProps) => {
|
|||||||
"upload_attachment",
|
"upload_attachment",
|
||||||
{
|
{
|
||||||
serverId,
|
serverId,
|
||||||
sessionId,
|
|
||||||
filePaths: [path],
|
filePaths: [path],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ export default function ChatInput({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const currentAssistant = useConnectStore((state) => state.currentAssistant);
|
const currentAssistant = useConnectStore((state) => state.currentAssistant);
|
||||||
// const sessionId = useConnectStore((state) => state.currentSessionId);
|
|
||||||
|
|
||||||
const setBlurred = useAppStore((state) => state.setBlurred);
|
const setBlurred = useAppStore((state) => state.setBlurred);
|
||||||
const isTauri = useAppStore((state) => state.isTauri);
|
const isTauri = useAppStore((state) => state.isTauri);
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ const InputControls = ({
|
|||||||
|
|
||||||
const isTauri = useAppStore((state) => state.isTauri);
|
const isTauri = useAppStore((state) => state.isTauri);
|
||||||
|
|
||||||
const { currentAssistant, currentSessionId } = useConnectStore();
|
const { currentAssistant } = useConnectStore();
|
||||||
const { modeSwitch, deepThinking } = useShortcutsStore();
|
const { modeSwitch, deepThinking } = useShortcutsStore();
|
||||||
|
|
||||||
const source = currentAssistant?._source;
|
const source = currentAssistant?._source;
|
||||||
@@ -171,19 +171,17 @@ const InputControls = ({
|
|||||||
>
|
>
|
||||||
{isChatMode ? (
|
{isChatMode ? (
|
||||||
<div className="flex gap-2 text-[12px] leading-3 text-[#333] dark:text-[#d8d8d8]">
|
<div className="flex gap-2 text-[12px] leading-3 text-[#333] dark:text-[#d8d8d8]">
|
||||||
{currentSessionId && (
|
<InputUpload
|
||||||
<InputUpload
|
checkScreenPermission={checkScreenPermission}
|
||||||
checkScreenPermission={checkScreenPermission}
|
requestScreenPermission={requestScreenPermission}
|
||||||
requestScreenPermission={requestScreenPermission}
|
getScreenMonitors={getScreenMonitors}
|
||||||
getScreenMonitors={getScreenMonitors}
|
getScreenWindows={getScreenWindows}
|
||||||
getScreenWindows={getScreenWindows}
|
captureMonitorScreenshot={captureMonitorScreenshot}
|
||||||
captureMonitorScreenshot={captureMonitorScreenshot}
|
captureWindowScreenshot={captureWindowScreenshot}
|
||||||
captureWindowScreenshot={captureWindowScreenshot}
|
openFileDialog={openFileDialog}
|
||||||
openFileDialog={openFileDialog}
|
getFileMetadata={getFileMetadata}
|
||||||
getFileMetadata={getFileMetadata}
|
getFileIcon={getFileIcon}
|
||||||
getFileIcon={getFileIcon}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{source?.type === "deep_think" && source?.config?.visible && (
|
{source?.type === "deep_think" && source?.config?.visible && (
|
||||||
<button
|
<button
|
||||||
@@ -233,8 +231,7 @@ const InputControls = ({
|
|||||||
getMCPByServer={getMCPByServer}
|
getMCPByServer={getMCPByServer}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!currentSessionId &&
|
{!(source?.datasource?.enabled && source?.datasource?.visible) &&
|
||||||
!(source?.datasource?.enabled && source?.datasource?.visible) &&
|
|
||||||
(source?.type !== "deep_think" || !source?.config?.visible) &&
|
(source?.type !== "deep_think" || !source?.config?.visible) &&
|
||||||
!(source?.mcp_servers?.enabled && source?.mcp_servers?.visible) && (
|
!(source?.mcp_servers?.enabled && source?.mcp_servers?.visible) && (
|
||||||
<div className="px-[9px]">
|
<div className="px-[9px]">
|
||||||
|
|||||||
Reference in New Issue
Block a user