Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): Added cid property to storage files #502

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api-tests-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
| `/filters` | `GET` | 4 | ✅ (4) | ❌ (0) |
| `/users` | `POST` | 4 | ✅ (3) | ✅ (1) |
| `/users/:user/filters/:filter` | `PUT` | 4 | ✅ (4) | ❌ (0) |
| `/users/:user/mailboxes` | `POST` | 4 | ✅ (3) | ✅ (1) |
| `/users/:user/storage` | `GET` | 4 | ✅ (2) | ✅ (2) |
| `/users/:user` | `PUT` | 3 | ✅ (3) | ❌ (0) |
| `/users/:user/addresses/:address` | `DELETE` | 3 | ✅ (2) | ✅ (1) |
Expand Down Expand Up @@ -96,6 +95,7 @@
| `/users/:user/autoreply` | `GET` | 0 | ❌ (0) | ❌ (0) |
| `/users/:user/autoreply` | `DELETE` | 0 | ❌ (0) | ❌ (0) |
| `/users/:user/filters/:filter` | `GET` | 0 | ❌ (0) | ❌ (0) |
| `/users/:user/mailboxes` | `POST` | 0 | ❌ (0) | ❌ (0) |
| `/users/:user/mailboxes/:mailbox` | `GET` | 0 | ❌ (0) | ❌ (0) |
| `/users/:user/mailboxes/:mailbox` | `PUT` | 0 | ❌ (0) | ❌ (0) |
| `/users/:user/mailboxes/:mailbox` | `DELETE` | 0 | ❌ (0) | ❌ (0) |
Expand Down
1 change: 1 addition & 0 deletions imap-core/lib/indexer/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ class Indexer {
contentType,
disposition,
transferEncoding,
cid: contentId ? `<${contentId}>` : null,
related,
// approximite size in kilobytes
sizeKb: Math.ceil((transferEncoding === 'base64' ? this.expectedB64Size(node.size) : node.size) / 1024)
Expand Down
3 changes: 2 additions & 1 deletion lib/api/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,8 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
id: fileData.id,
filename: fileData.filename,
contentType: fileData.contentType,
size: fileData.size
size: fileData.size,
cid: fileData.cid
});
}
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions lib/api/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = (db, server, storageHandler) => {
encoding: Joi.string().empty('').valid('base64'),

content: Joi.binary().max(consts.MAX_ALLOWED_MESSAGE_SIZE).empty('').required(),
cid: Joi.string().empty('').max(255),

sess: sessSchema,
ip: sessIPSchema
Expand Down Expand Up @@ -214,6 +215,7 @@ module.exports = (db, server, storageHandler) => {
id: fileData._id.toString(),
filename: fileData.filename || false,
contentType: fileData.contentType || false,
cid: fileData.metadata?.cid,
size: fileData.length,
created: fileData.uploadDate.toISOString(),
md5: fileData.md5
Expand Down
18 changes: 12 additions & 6 deletions lib/storage-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class StorageHandler {
}

async add(user, options) {
let filename = options.filename;
let contentType = options.contentType;
let { filename, contentType, cid } = options;

let filebase = 'upload-' + new Date().toISOString().substr(0, 10);
if (!contentType && !filename) {
Expand All @@ -31,12 +30,18 @@ class StorageHandler {
filename = filebase + '.' + libmime.detectExtension(contentType);
}

let metadata = {
user
};

if (cid) {
metadata.cid = cid;
}

return new Promise((resolve, reject) => {
let store = this.gridstore.openUploadStream(filename, {
contentType,
metadata: {
user
}
metadata
});

store.on('error', err => {
Expand Down Expand Up @@ -109,7 +114,8 @@ class StorageHandler {
filename: fileData.filename,
contentType: fileData.contentType,
size: fileData.length,
content: Buffer.concat(chunks, chunklen)
content: Buffer.concat(chunks, chunklen),
cid: fileData.metadata?.cid
});
});
});
Expand Down
Loading
Loading