👀 Fix Common users cannot upload files

💄Fix format

💄Fix format i18

 Feat paste upload files and make restrictions

 Feat paste upload files and make restrictions
This commit is contained in:
Clivia 2024-08-26 23:32:37 +08:00
parent b01d72ade3
commit 775478534a
45 changed files with 119 additions and 42 deletions

View File

@ -577,6 +577,14 @@ async def get_query_settings(user=Depends(get_admin_user)):
}
@app.get("/file/limit/settings")
async def get_query_settings(user=Depends(get_verified_user)):
return {
"max_file_size": app.state.config.MAX_FILE_SIZE,
"max_file_count": app.state.config.MAX_FILE_COUNT,
}
class QuerySettingsForm(BaseModel):
k: Optional[int] = None
r: Optional[float] = None

View File

@ -134,6 +134,33 @@ export const getQuerySettings = async (token: string) => {
return res;
};
export const getFileLimitSettings = async (token: string) => {
let error = null;
const res = await fetch(`${RAG_API_BASE_URL}/file/limit/settings`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
console.log(err);
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
type QuerySettings = {
k: number | null;
r: number | null;

View File

@ -18,11 +18,8 @@
import { transcribeAudio } from '$lib/apis/audio';
import {
getQuerySettings,
getFileLimitSettings,
processDocToVectorDB,
uploadDocToVectorDB,
uploadWebToVectorDB,
uploadYoutubeTranscriptionToVectorDB
} from '$lib/apis/rag';
import { uploadFile } from '$lib/apis/files';
@ -62,7 +59,7 @@
let commandsElement;
let inputFiles;
let querySettings;
let fileLimitSettings;
let dragged = false;
let user = null;
@ -196,8 +193,8 @@
return [true, inputFiles];
};
const processFileSizeLimit = async (querySettings, file) => {
if (file.size <= querySettings.max_file_size * 1024 * 1024) {
const processFileSizeLimit = async (fileLimitSettings, file) => {
if (file.size <= fileLimitSettings.max_file_size * 1024 * 1024) {
if (['image/gif', 'image/webp', 'image/jpeg', 'image/png'].includes(file['type'])) {
if (visionCapableModels.length === 0) {
toast.error($i18n.t('Selected model(s) do not support image inputs'));
@ -220,21 +217,22 @@
} else {
toast.error(
$i18n.t('File size exceeds the limit of {{size}}MB', {
size: querySettings.max_file_size
size: fileLimitSettings.max_file_size
})
);
}
};
onMount(() => {
const initializeSettings = async () => {
const initFileLimitSettings = async () => {
try {
querySettings = await getQuerySettings(localStorage.token);
fileLimitSettings = await getFileLimitSettings(localStorage.token);
} catch (error) {
console.error('Error fetching query settings:', error);
}
};
initializeSettings();
initFileLimitSettings();
window.setTimeout(() => chatTextAreaElement?.focus(), 0);
const dropZone = document.querySelector('body');
@ -265,7 +263,7 @@
if (inputFiles && inputFiles.length > 0) {
console.log(inputFiles);
const [canProcess, filesToProcess] = await processFileCountLimit(
querySettings,
fileLimitSettings,
inputFiles
);
if (!canProcess) {
@ -275,7 +273,7 @@
console.log(filesToProcess);
filesToProcess.forEach((file) => {
console.log(file, file.name.split('.').at(-1));
processFileSizeLimit(querySettings, file);
processFileSizeLimit(fileLimitSettings, file);
});
} else {
toast.error($i18n.t(`File not found.`));
@ -400,7 +398,7 @@
const _inputFiles = Array.from(inputFiles);
console.log(_inputFiles);
const [canProcess, filesToProcess] = await processFileCountLimit(
querySettings,
fileLimitSettings,
_inputFiles
);
if (!canProcess) {
@ -410,7 +408,7 @@
console.log(filesToProcess);
filesToProcess.forEach((file) => {
console.log(file, file.name.split('.').at(-1));
processFileSizeLimit(querySettings, file);
processFileSizeLimit(fileLimitSettings, file);
});
} else {
toast.error($i18n.t(`File not found.`));
@ -703,37 +701,40 @@
}
}}
rows="1"
on:input={(e) => {
on:input={async (e) => {
e.target.style.height = '';
e.target.style.height = Math.min(e.target.scrollHeight, 200) + 'px';
user = null;
}}
on:focus={(e) => {
on:focus={async (e) => {
e.target.style.height = '';
e.target.style.height = Math.min(e.target.scrollHeight, 200) + 'px';
}}
on:paste={(e) => {
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);
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);
const [canProcess, filesToProcess] = await processFileCountLimit(
fileLimitSettings,
inputFiles
);
if (!canProcess) {
return;
}
filesToProcess.forEach((file) => {
console.log(file, file.name.split('.').at(-1));
processFileSizeLimit(fileLimitSettings, file);
});
} else {
toast.error($i18n.t(`File not found.`));
}
} catch (error) {
console.error('Error processing files:', error);
toast.error($i18n.t(`An error occurred while processing files.`));
}
}}
/>

View File

@ -8,7 +8,7 @@
import { createNewDoc, deleteDocByName, getDocs } from '$lib/apis/documents';
import { SUPPORTED_FILE_TYPE, SUPPORTED_FILE_EXTENSIONS } from '$lib/constants';
import { getQuerySettings, processDocToVectorDB, uploadDocToVectorDB } from '$lib/apis/rag';
import { getFileLimitSettings, processDocToVectorDB, uploadDocToVectorDB } from '$lib/apis/rag';
import { blobToFile, transformFileName } from '$lib/utils';
import Checkbox from '$lib/components/common/Checkbox.svelte';
@ -24,7 +24,7 @@
let importFiles = '';
let inputFiles = '';
let querySettings;
let fileLimitSettings;
let query = '';
let documentsImportInputElement: HTMLInputElement;
let tags = [];
@ -99,16 +99,16 @@
}
};
const initializeSettings = async () => {
const initFileLimitSettings = async () => {
try {
querySettings = await getQuerySettings(localStorage.token);
fileLimitSettings = await getFileLimitSettings(localStorage.token);
} catch (error) {
console.error('Error fetching query settings:', error);
}
};
onMount(() => {
initializeSettings();
initFileLimitSettings();
documents.subscribe((docs) => {
tags = docs.reduce((a, e, i, arr) => {
@ -147,7 +147,7 @@
if (inputFiles && inputFiles.length > 0) {
for (const file of inputFiles) {
console.log(file, file.name.split('.').at(-1));
if (file.size <= querySettings.max_file_size * 1024 * 1024) {
if (file.size <= fileLimitSettings.max_file_size * 1024 * 1024) {
if (
SUPPORTED_FILE_TYPE.includes(file['type']) ||
SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
@ -162,7 +162,7 @@
} else {
toast.error(
$i18n.t('File size exceeds the limit of {{size}}MB', {
size: querySettings.max_file_size
size: fileLimitSettings.max_file_size
})
);
}

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "الأحرف الأبجدية الرقمية والواصلات",
"Already have an account?": "هل تملك حساب ؟",
"an assistant": "مساعد",
"An error occurred while processing files.": "",
"and": "و",
"and create a new shared link.": "و أنشئ رابط مشترك جديد.",
"API Base URL": "API الرابط الرئيسي",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "алфанумерични знаци и тире",
"Already have an account?": "Вече имате акаунт? ",
"an assistant": "асистент",
"An error occurred while processing files.": "",
"and": "и",
"and create a new shared link.": "и създай нов общ линк.",
"API Base URL": "API Базов URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "ইংরেজি অক্ষর, সংখ্যা এবং হাইফেন",
"Already have an account?": "আগে থেকেই একাউন্ট আছে?",
"an assistant": "একটা এসিস্ট্যান্ট",
"An error occurred while processing files.": "",
"and": "এবং",
"and create a new shared link.": "এবং একটি নতুন শেয়ারে লিংক তৈরি করুন.",
"API Base URL": "এপিআই বেজ ইউআরএল",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "caràcters alfanumèrics i guions",
"Already have an account?": "Ja tens un compte?",
"an assistant": "un assistent",
"An error occurred while processing files.": "",
"and": "i",
"and create a new shared link.": "i crear un nou enllaç compartit.",
"API Base URL": "URL Base de l'API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "alphanumeric nga mga karakter ug hyphen",
"Already have an account?": "Naa na kay account ?",
"an assistant": "usa ka katabang",
"An error occurred while processing files.": "",
"and": "Ug",
"and create a new shared link.": "",
"API Base URL": "API Base URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "alphanumerische Zeichen und Bindestriche",
"Already have an account?": "Haben Sie bereits einen Account?",
"an assistant": "ein Assistent",
"An error occurred while processing files.": "",
"and": "und",
"and create a new shared link.": "und erstellen Sie einen neuen freigegebenen Link.",
"API Base URL": "API-Basis-URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "so alpha, many hyphen",
"Already have an account?": "Such account exists?",
"an assistant": "such assistant",
"An error occurred while processing files.": "",
"and": "and",
"and create a new shared link.": "",
"API Base URL": "API Base URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "",
"Already have an account?": "",
"an assistant": "",
"An error occurred while processing files.": "",
"and": "",
"and create a new shared link.": "",
"API Base URL": "",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "",
"Already have an account?": "",
"an assistant": "",
"An error occurred while processing files.": "",
"and": "",
"and create a new shared link.": "",
"API Base URL": "",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "caracteres alfanuméricos y guiones",
"Already have an account?": "¿Ya tienes una cuenta?",
"an assistant": "un asistente",
"An error occurred while processing files.": "",
"and": "y",
"and create a new shared link.": "y crear un nuevo enlace compartido.",
"API Base URL": "Dirección URL de la API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "حروف الفبایی و خط فاصله",
"Already have an account?": "از قبل حساب کاربری دارید؟",
"an assistant": "یک دستیار",
"An error occurred while processing files.": "",
"and": "و",
"and create a new shared link.": "و یک لینک به اشتراک گذاری جدید ایجاد کنید.",
"API Base URL": "API Base URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "kirjaimia, numeroita ja väliviivoja",
"Already have an account?": "Onko sinulla jo tili?",
"an assistant": "avustaja",
"An error occurred while processing files.": "",
"and": "ja",
"and create a new shared link.": "ja luo uusi jaettu linkki.",
"API Base URL": "APIn perus-URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "caractères alphanumériques et tirets",
"Already have an account?": "Avez-vous déjà un compte ?",
"an assistant": "un assistant",
"An error occurred while processing files.": "",
"and": "et",
"and create a new shared link.": "et créer un nouveau lien partagé.",
"API Base URL": "URL de base de l'API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "caractères alphanumériques et tirets",
"Already have an account?": "Avez-vous déjà un compte ?",
"an assistant": "un assistant",
"An error occurred while processing files.": "",
"and": "et",
"and create a new shared link.": "et créer un nouveau lien partagé.",
"API Base URL": "URL de base de l'API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "תווים אלפאנומריים ומקפים",
"Already have an account?": "כבר יש לך חשבון?",
"an assistant": "עוזר",
"An error occurred while processing files.": "",
"and": "וגם",
"and create a new shared link.": "וצור קישור משותף חדש.",
"API Base URL": "כתובת URL בסיסית ל-API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "अल्फ़ान्यूमेरिक वर्ण और हाइफ़न",
"Already have an account?": "क्या आपके पास पहले से एक खाता मौजूद है?",
"an assistant": "एक सहायक",
"An error occurred while processing files.": "",
"and": "और",
"and create a new shared link.": "और एक नई साझा लिंक बनाएं.",
"API Base URL": "एपीआई बेस यूआरएल",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "alfanumerički znakovi i crtice",
"Already have an account?": "Već imate račun?",
"an assistant": "asistent",
"An error occurred while processing files.": "",
"and": "i",
"and create a new shared link.": "i stvorite novu dijeljenu vezu.",
"API Base URL": "Osnovni URL API-ja",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "karakter alfanumerik dan tanda hubung",
"Already have an account?": "Sudah memiliki akun?",
"an assistant": "asisten",
"An error occurred while processing files.": "",
"and": "dan",
"and create a new shared link.": "dan membuat tautan bersama baru.",
"API Base URL": "URL Dasar API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "caratteri alfanumerici e trattini",
"Already have an account?": "Hai già un account?",
"an assistant": "un assistente",
"An error occurred while processing files.": "",
"and": "e",
"and create a new shared link.": "e crea un nuovo link condiviso.",
"API Base URL": "URL base API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "英数字とハイフン",
"Already have an account?": "すでにアカウントをお持ちですか?",
"an assistant": "アシスタント",
"An error occurred while processing files.": "",
"and": "および",
"and create a new shared link.": "し、新しい共有リンクを作成します。",
"API Base URL": "API ベース URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "ალფანუმერული სიმბოლოები და დეფისები",
"Already have an account?": "უკვე გაქვს ანგარიში?",
"an assistant": "ასისტენტი",
"An error occurred while processing files.": "",
"and": "და",
"and create a new shared link.": "და შექმენით ახალი გაზიარებული ბმული.",
"API Base URL": "API საბაზისო URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "영문자, 숫자, 하이픈",
"Already have an account?": "이미 계정이 있으신가요?",
"an assistant": "어시스턴트",
"An error occurred while processing files.": "",
"and": "그리고",
"and create a new shared link.": "새로운 공유 링크를 생성합니다.",
"API Base URL": "API 기본 URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "skaičiai, raidės ir brūkšneliai",
"Already have an account?": "Ar jau turite paskyrą?",
"an assistant": "assistentas",
"An error occurred while processing files.": "",
"and": "ir",
"and create a new shared link.": "sukurti naują dalinimosi nuorodą",
"API Base URL": "API basės nuoroda",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "alfanumeriske tegn og bindestreker",
"Already have an account?": "Har du allerede en konto?",
"an assistant": "en assistent",
"An error occurred while processing files.": "",
"and": "og",
"and create a new shared link.": "og opprett en ny delt lenke.",
"API Base URL": "API Grunn-URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "alfanumerieke karakters en streepjes",
"Already have an account?": "Heb je al een account?",
"an assistant": "een assistent",
"An error occurred while processing files.": "",
"and": "en",
"and create a new shared link.": "en maak een nieuwe gedeelde link.",
"API Base URL": "API Base URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "ਅਲਫ਼ਾਨਯੂਮੈਰਿਕ ਅੱਖਰ ਅਤੇ ਹਾਈਫਨ",
"Already have an account?": "ਪਹਿਲਾਂ ਹੀ ਖਾਤਾ ਹੈ?",
"an assistant": "ਇੱਕ ਸਹਾਇਕ",
"An error occurred while processing files.": "",
"and": "ਅਤੇ",
"and create a new shared link.": "ਅਤੇ ਇੱਕ ਨਵਾਂ ਸਾਂਝਾ ਲਿੰਕ ਬਣਾਓ।",
"API Base URL": "API ਬੇਸ URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "znaki alfanumeryczne i myślniki",
"Already have an account?": "Masz już konto?",
"an assistant": "asystent",
"An error occurred while processing files.": "",
"and": "i",
"and create a new shared link.": "i utwórz nowy udostępniony link",
"API Base URL": "Podstawowy adres URL interfejsu API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "caracteres alfanuméricos e hífens",
"Already have an account?": "Já tem uma conta?",
"an assistant": "um assistente",
"An error occurred while processing files.": "",
"and": "e",
"and create a new shared link.": "e criar um novo link compartilhado.",
"API Base URL": "URL Base da API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "caracteres alfanuméricos e hífens",
"Already have an account?": "Já tem uma conta?",
"an assistant": "um assistente",
"An error occurred while processing files.": "",
"and": "e",
"and create a new shared link.": "e criar um novo link partilhado.",
"API Base URL": "URL Base da API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "caractere alfanumerice și cratime",
"Already have an account?": "Deja ai un cont?",
"an assistant": "un asistent",
"An error occurred while processing files.": "",
"and": "și",
"and create a new shared link.": "și creează un nou link partajat.",
"API Base URL": "URL Bază API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "буквенно цифровые символы и дефисы",
"Already have an account?": "У вас уже есть учетная запись?",
"an assistant": "ассистент",
"An error occurred while processing files.": "",
"and": "и",
"and create a new shared link.": "и создайте новую общую ссылку.",
"API Base URL": "Базовый адрес API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "алфанумерички знакови и цртице",
"Already have an account?": "Већ имате налог?",
"an assistant": "помоћник",
"An error occurred while processing files.": "",
"and": "и",
"and create a new shared link.": "и направи нову дељену везу.",
"API Base URL": "Основна адреса API-ја",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "alfanumeriska tecken och bindestreck",
"Already have an account?": "Har du redan ett konto?",
"an assistant": "en assistent",
"An error occurred while processing files.": "",
"and": "och",
"and create a new shared link.": "och skapa en ny delad länk.",
"API Base URL": "API-bas-URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "อักขระตัวเลขและขีดกลาง",
"Already have an account?": "มีบัญชีอยู่แล้ว?",
"an assistant": "ผู้ช่วย",
"An error occurred while processing files.": "",
"and": "และ",
"and create a new shared link.": "และสร้างลิงก์ที่แชร์ใหม่",
"API Base URL": "URL ฐานของ API",

View File

@ -40,6 +40,7 @@
"alphanumeric characters and hyphens": "harply-sanjy belgiler we defisler",
"Already have an account?": "Hasabyňyz barmy?",
"an assistant": "kömekçi",
"An error occurred while processing files.": "",
"and": "we",
"and create a new shared link.": "we täze paýlaşylan baglanyşyk dörediň.",
"API Base URL": "API Esasy URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "",
"Already have an account?": "",
"an assistant": "",
"An error occurred while processing files.": "",
"and": "",
"and create a new shared link.": "",
"API Base URL": "",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "alfanumerik karakterler ve tireler",
"Already have an account?": "Zaten bir hesabınız mı var?",
"an assistant": "bir asistan",
"An error occurred while processing files.": "",
"and": "ve",
"and create a new shared link.": "ve yeni bir paylaşılan bağlantı oluşturun.",
"API Base URL": "API Temel URL",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "алфавітно-цифрові символи та дефіси",
"Already have an account?": "Вже є обліковий запис?",
"an assistant": "асистента",
"An error occurred while processing files.": "",
"and": "та",
"and create a new shared link.": "і створіть нове спільне посилання.",
"API Base URL": "URL-адреса API",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "ký tự số và gạch nối",
"Already have an account?": "Bạn đã có tài khoản?",
"an assistant": "trợ lý",
"An error occurred while processing files.": "",
"and": "và",
"and create a new shared link.": "và tạo một link chia sẻ mới",
"API Base URL": "Đường dẫn tới API (API Base URL)",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "字母数字字符和连字符",
"Already have an account?": "已经拥有账号了?",
"an assistant": "助手",
"An error occurred while processing files.": "",
"and": "和",
"and create a new shared link.": "并创建一个新的分享链接。",
"API Base URL": "API 基础地址",

View File

@ -52,6 +52,7 @@
"alphanumeric characters and hyphens": "英文字母、數字和連字號",
"Already have an account?": "已經有帳號了嗎?",
"an assistant": "一位助手",
"An error occurred while processing files.": "",
"and": "和",
"and create a new shared link.": "並建立新的共用連結。",
"API Base URL": "API 基礎 URL",