Skip to content

Commit

Permalink
nsfs: handle content type
Browse files Browse the repository at this point in the history
Signed-off-by: Guy Margalit <guymguym@gmail.com>
(cherry picked from commit ba3ecda)
  • Loading branch information
guymguym authored and nimrod-becker committed Aug 3, 2023
1 parent 09c9170 commit 37390bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/native/fs/fs_napi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const static std::map<std::string, int> flags_to_case = {
};

const static std::vector<std::string> GPFS_XATTRS{ GPFS_ENCRYPTION_XATTR_NAME };
const static std::vector<std::string> USER_XATTRS{ "user.content_md5", "user.version_id", "user.prev_version_id", "user.delete_marker"};
const static std::vector<std::string> USER_XATTRS{ "user.content_type", "user.content_md5", "user.version_id", "user.prev_version_id", "user.delete_marker"};

struct Entry
{
Expand Down
8 changes: 7 additions & 1 deletion src/sdk/namespace_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const buffers_pool = new buffer_utils.BuffersPool({

const XATTR_USER_PREFIX = 'user.';
// TODO: In order to verify validity add content_md5_mtime as well
const XATTR_CONTENT_TYPE = XATTR_USER_PREFIX + 'content_type';
const XATTR_MD5_KEY = XATTR_USER_PREFIX + 'content_md5';
const XATTR_VERSION_ID = XATTR_USER_PREFIX + 'version_id';
const XATTR_PREV_VERSION_ID = XATTR_USER_PREFIX + 'prev_version_id';
Expand Down Expand Up @@ -825,6 +826,10 @@ class NamespaceFS {
// handle xattr
if (!params.copy_source || !params.xattr_copy) {
fs_xattr = to_fs_xattr(params.xattr);
if (params.content_type) {
fs_xattr = fs_xattr || {};
fs_xattr[XATTR_CONTENT_TYPE] = params.content_type;
}
if (digest) {
const { md5_b64, key, bucket, upload_id } = params;
if (md5_b64) {
Expand Down Expand Up @@ -1473,14 +1478,15 @@ class NamespaceFS {
const etag = this._get_etag(stat);
const encryption = this._get_encryption_info(stat);
const version_id = return_version_id && this._is_versioning_enabled() && this._get_version_id_by_xattr(stat);
const content_type = stat.xattr[XATTR_CONTENT_TYPE] || mime.getType(key) || 'application/octet-stream';
return {
obj_id: etag,
bucket,
key,
etag,
size: stat.size,
create_time: stat.mtime.getTime(),
content_type: mime.getType(key) || 'application/octet-stream',
content_type,
// temp:
version_id: version_id,
is_latest: true,
Expand Down

0 comments on commit 37390bf

Please sign in to comment.