enh: apply file size limit to knowledge

This commit is contained in:
Timothy Jaeryang Baek 2025-03-19 08:36:41 -07:00
parent f806ab0bd2
commit c69d1c86fe

View File

@ -9,7 +9,7 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { mobile, showSidebar, knowledge as _knowledge } from '$lib/stores';
import { mobile, showSidebar, knowledge as _knowledge, config } from '$lib/stores';
import { updateFileDataContentById, uploadFile, deleteFileById } from '$lib/apis/files';
import {
@ -131,6 +131,22 @@
return null;
}
if (
($config?.file?.max_size ?? null) !== null &&
file.size > ($config?.file?.max_size ?? 0) * 1024 * 1024
) {
console.log('File exceeds max size limit:', {
fileSize: file.size,
maxSize: ($config?.file?.max_size ?? 0) * 1024 * 1024
});
toast.error(
$i18n.t(`File size should not exceed {{maxSize}} MB.`, {
maxSize: $config?.file?.max_size
})
);
return;
}
knowledge.files = [...(knowledge.files ?? []), fileItem];
try {