diff --git a/packages/server/src/models/ItemModel.ts b/packages/server/src/models/ItemModel.ts index 3a01cf49d57..33fcce37a45 100644 --- a/packages/server/src/models/ItemModel.ts +++ b/packages/server/src/models/ItemModel.ts @@ -309,13 +309,15 @@ export default class ItemModel extends BaseModel { item.jop_encryption_applied = joplinItem.encryption_applied || 0; item.jop_share_id = joplinItem.share_id || ''; - delete joplinItem.id; - delete joplinItem.parent_id; - delete joplinItem.share_id; - delete joplinItem.type_; - delete joplinItem.encryption_applied; + const joplinItemToSave = { ...joplinItem }; - item.content = Buffer.from(JSON.stringify(joplinItem)); + delete joplinItemToSave.id; + delete joplinItemToSave.parent_id; + delete joplinItemToSave.share_id; + delete joplinItemToSave.type_; + delete joplinItemToSave.encryption_applied; + + item.content = Buffer.from(JSON.stringify(joplinItemToSave)); } else { item.content = buffer; } diff --git a/packages/server/src/models/UserModel.ts b/packages/server/src/models/UserModel.ts index cb7dd3c6cdc..4ce7f74ead1 100644 --- a/packages/server/src/models/UserModel.ts +++ b/packages/server/src/models/UserModel.ts @@ -108,17 +108,17 @@ export default class UserModel extends BaseModel { } public async checkMaxItemSizeLimit(user: User, buffer: Buffer, item: Item, joplinItem: any) { - const itemTitle = joplinItem ? joplinItem.title || '' : ''; - const isNote = joplinItem && joplinItem.type_ === ModelType.Note; - // If the item is encrypted, we apply a multipler because encrypted // items can be much larger (seems to be up to twice the size but for // safety let's go with 2.2). const maxSize = user.max_item_size * (item.jop_encryption_applied ? 2.2 : 1); if (maxSize && buffer.byteLength > maxSize) { + const itemTitle = joplinItem ? joplinItem.title || '' : ''; + const isNote = joplinItem && joplinItem.type_ === ModelType.Note; + throw new ErrorPayloadTooLarge(_('Cannot save %s "%s" because it is larger than than the allowed limit (%s)', isNote ? _('note') : _('attachment'), - itemTitle ? itemTitle : name, + itemTitle ? itemTitle : item.name, formatBytes(user.max_item_size) )); }