浏览代码

refac: do NOT change default behaviour in a PR

Timothy J. Baek 8 月之前
父节点
当前提交
ef28330c1a
共有 2 个文件被更改,包括 22 次插入14 次删除
  1. 2 2
      src/lib/components/admin/Settings/Documents.svelte
  2. 20 12
      src/lib/components/chat/MessageInput.svelte

+ 2 - 2
src/lib/components/admin/Settings/Documents.svelte

@@ -233,8 +233,8 @@
 			tikaServerUrl = res.content_extraction.tika_server_url;
 			showTikaServerUrl = contentExtractionEngine === 'tika';
 
-			fileMaxSize = res.file.file_max_size;
-			fileMaxCount = res.file.file_max_count;
+			fileMaxSize = res.file.max_size;
+			fileMaxCount = res.file.max_count;
 		}
 	});
 </script>

+ 20 - 12
src/lib/components/chat/MessageInput.svelte

@@ -364,7 +364,8 @@
 					multiple
 					on:change={async () => {
 						if (inputFiles && inputFiles.length > 0) {
-							inputFilesHandler(inputFiles);
+							const _inputFiles = Array.from(inputFiles);
+							inputFilesHandler(_inputFiles);
 						} else {
 							toast.error($i18n.t(`File not found.`));
 						}
@@ -667,19 +668,26 @@
 									}}
 									on:paste={async (e) => {
 										const clipboardData = e.clipboardData || window.clipboardData;
-										try {
-											if (clipboardData && clipboardData.items) {
-												const inputFiles = Array.from(clipboardData.items)
-													.map((item) => item.getAsFile())
-													.filter((file) => file);
 
-												inputFilesHandler(inputFiles);
-											} else {
-												toast.error($i18n.t(`File not found.`));
+										if (clipboardData && clipboardData.items) {
+											for (const item of clipboardData.items) {
+												if (item.type.indexOf('image') !== -1) {
+													const blob = item.getAsFile();
+													const reader = new FileReader();
+
+													reader.onload = function (e) {
+														files = [
+															...files,
+															{
+																type: 'image',
+																url: `${e.target.result}`
+															}
+														];
+													};
+
+													reader.readAsDataURL(blob);
+												}
 											}
-										} catch (error) {
-											console.error('Error processing files:', error);
-											toast.error($i18n.t(`An error occurred while processing files.`));
 										}
 									}}
 								/>