make some overall QoL improvements
This commit is contained in:
@@ -162,7 +162,7 @@ export function createAttachmentService(db, config, modelService, visionDebugSer
|
||||
db.prepare("DELETE FROM attachments WHERE id=?").run(id);
|
||||
return cleanup();
|
||||
},
|
||||
async upload(file, user) {
|
||||
async upload(file, user, {forImport = false} = {}) {
|
||||
await cleanup();
|
||||
if (!file?.buffer?.length) throw new AttachmentError("Choose a non-empty PNG, JPEG or WebP image");
|
||||
if (file.size > config.uploadMaxSizeMb * 1024 * 1024) throw new AttachmentError("Image is too large", 413);
|
||||
@@ -178,9 +178,9 @@ export function createAttachmentService(db, config, modelService, visionDebugSer
|
||||
try {
|
||||
// Bound abandoned uploads per account as well as per submitted message.
|
||||
db.transaction(() => {
|
||||
if (db.prepare("SELECT COUNT(*) AS n FROM attachments WHERE username=? AND status='temporary'").get(user).n >= config.uploadMaxFiles * 4) throw new AttachmentError("Too many pending images. Remove unused uploads first.");
|
||||
if (!forImport && db.prepare("SELECT COUNT(*) AS n FROM attachments WHERE username=? AND status='temporary'").get(user).n >= config.uploadMaxFiles * 4) throw new AttachmentError("Too many pending images. Remove unused uploads first.");
|
||||
db.prepare("INSERT INTO attachments(id,username,original_name,storage_key,mime_type,size_bytes,width,height) VALUES(?,?,?,?,?,?,?,?)").run(id, user,
|
||||
String(file.originalname || "image").replace(/[\\/\x00-\x1f]/g, "_").slice(0, 255), storageKey, `image/${info.format}`, file.size, info.width, info.height);
|
||||
[...String(file.originalname || "image").replace(/[\\/]/g, "_")].map(character => character.charCodeAt(0) < 32 ? "_" : character).join("").slice(0, 255), storageKey, `image/${info.format}`, file.size, info.width, info.height);
|
||||
})();
|
||||
} catch (error) { await storage.delete(storageKey); throw error; }
|
||||
log("attachmentUploadSuccess", {id, size: file.size, mime: `image/${info.format}`});
|
||||
|
||||
@@ -584,7 +584,7 @@ export function createChatService(repositories, modelService, config, webSearchP
|
||||
|
||||
const cloneChatThroughMessage = ({ user, sourceChat, messageId = null }) => {
|
||||
if (repositories.countChats(user) >= config.chatLimit) {
|
||||
return { error: `Maximum of ${config.chatLimit} chats reached. Please delete an old chat to create a new one.`, status: 400 };
|
||||
return { error: `Maximum of ${config.chatLimit} active chats reached. Archive or delete an active chat to create a new one.`, status: 400 };
|
||||
}
|
||||
|
||||
const sourceMessages = messageId == null
|
||||
|
||||
Reference in New Issue
Block a user