Skip to content

Commit

Permalink
Server: Fixed error message when item is over the limit
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Jun 16, 2021
1 parent 1711f7e commit ea65313
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions packages/server/src/models/ItemModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,15 @@ export default class ItemModel extends BaseModel<Item> {
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;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/models/UserModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ export default class UserModel extends BaseModel<User> {
}

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)
));
}
Expand Down

0 comments on commit ea65313

Please sign in to comment.