Skip to content

Commit 9982975

Browse files
committed
Replace mime with mime-type
- Replace mime with mime-type Signed-off-by: liranmauda <liran.mauda@gmail.com>
1 parent 9bf2199 commit 9982975

File tree

12 files changed

+101
-39
lines changed

12 files changed

+101
-39
lines changed

package-lock.json

Lines changed: 58 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"jsonwebtoken": "9.0.2",
9898
"linux-blockutils": "0.2.0",
9999
"lodash": "4.17.21",
100-
"mime": "3.0.0",
100+
"mime-type": "5.0.2",
101101
"minimist": "1.2.8",
102102
"moment": "2.30.1",
103103
"moment-timezone": "0.5.47",

src/endpoint/blob/ops/blob_put_blob.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const blob_utils = require('../blob_utils');
55
const http_utils = require('../../../util/http_utils');
66
const time_utils = require('../../../util/time_utils');
7-
const mime = require('mime');
7+
const mime = require('mime-types');
88

99

1010
/**
@@ -16,7 +16,7 @@ async function put_blob(req, res) {
1616
const { etag } = await req.object_sdk.upload_object({
1717
bucket: req.params.bucket,
1818
key: req.params.key,
19-
content_type: req.headers['x-ms-blob-content-type'] || (copy_source ? undefined : (mime.getType(req.params.key) || 'application/octet-stream')),
19+
content_type: req.headers['x-ms-blob-content-type'] || (copy_source ? undefined : (mime.lookup(req.params.key) || 'application/octet-stream')),
2020
size: req.content_length >= 0 ? req.content_length : undefined,
2121
md5_b64: req.content_md5 ? req.content_md5.toString('base64') : undefined,
2222
sha256_b64: req.content_sha256_buf ? req.content_sha256_buf.toString('base64') : undefined,

src/endpoint/blob/ops/blob_put_blob_blocklist.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const _ = require('lodash');
55

66
const blob_utils = require('../blob_utils');
77
const http_utils = require('../../../util/http_utils');
8-
const mime = require('mime');
8+
const mime = require('mime-types');
99

1010
/**
1111
* https://docs.microsoft.com/en-us/rest/api/storageservices/put-block-list
@@ -19,7 +19,7 @@ async function put_blob_blocklist(req, res) {
1919
const reply = await req.object_sdk.commit_blob_block_list({
2020
bucket: req.params.bucket,
2121
key: req.params.key,
22-
content_type: req.headers['x-ms-blob-content-type'] || mime.getType(req.params.key) || 'application/octet-stream',
22+
content_type: req.headers['x-ms-blob-content-type'] || mime.lookup(req.params.key) || 'application/octet-stream',
2323
md_conditions: http_utils.get_md_conditions(req),
2424
xattr: blob_utils.get_request_xattr(req),
2525
block_list

src/endpoint/s3/ops/s3_post_object_uploads.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33

44
const s3_utils = require('../s3_utils');
5-
const mime = require('mime');
5+
const mime = require('mime-types');
66
const config = require('../../../../config');
77
const S3Error = require('../s3_errors').S3Error;
88

@@ -21,7 +21,7 @@ async function post_object_uploads(req, res) {
2121
const reply = await req.object_sdk.create_object_upload({
2222
bucket: req.params.bucket,
2323
key: req.params.key,
24-
content_type: req.headers['content-type'] || mime.getType(req.params.key) || 'application/octet-stream',
24+
content_type: req.headers['content-type'] || mime.lookup(req.params.key) || 'application/octet-stream',
2525
content_encoding: req.headers['content-encoding'],
2626
xattr: s3_utils.get_request_xattr(req),
2727
storage_class,

src/endpoint/s3/ops/s3_put_object.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const dbg = require('../../../util/debug_module')(__filename);
55
const s3_utils = require('../s3_utils');
66
const S3Error = require('../s3_errors').S3Error;
77
const http_utils = require('../../../util/http_utils');
8-
const mime = require('mime');
8+
const mime = require('mime-types');
99
const config = require('../../../../config');
1010

1111
const s3_error_options = {
@@ -41,7 +41,7 @@ async function put_object(req, res) {
4141
const reply = await req.object_sdk.upload_object({
4242
bucket: req.params.bucket,
4343
key: req.params.key,
44-
content_type: req.headers['content-type'] || (copy_source ? undefined : (mime.getType(req.params.key) || 'application/octet-stream')),
44+
content_type: req.headers['content-type'] || (copy_source ? undefined : (mime.lookup(req.params.key) || 'application/octet-stream')),
4545
content_encoding: req.headers['content-encoding'],
4646
copy_source,
4747
source_stream,

src/sdk/endpoint_stats_collector.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
'use strict';
33

44
const _ = require('lodash');
5-
const mime = require('mime');
5+
const mime = require('mime-types');
66

77
const dbg = require('../util/debug_module')(__filename);
88
const prom_report = require('../server/analytic_services/prometheus_reporting');
99
const stats_aggregator = require('../server/system_services/stats_aggregator');
1010
const DelayedCollector = require('../util/delayed_collector');
1111
const config = require('../../config');
1212
const cluster = /** @type {import('node:cluster').Cluster} */ (
13-
/** @type {unknown} */ (require('node:cluster'))
13+
/** @type {unknown} */
14+
(require('node:cluster'))
1415
);
1516

1617
/**
@@ -239,16 +240,20 @@ class EndpointStatsCollector {
239240
}
240241

241242
update_bucket_read_counters({ bucket_name, key, content_type, }) {
242-
content_type = content_type || mime.getType(key) || 'application/octet-stream';
243+
content_type = content_type || mime.lookup(key) || 'application/octet-stream';
243244
this.endpoint_stats_collector.update({
244-
bucket_counters: { [bucket_name]: { [content_type]: { read_count: 1 } } }
245+
bucket_counters: {
246+
[bucket_name]: {
247+
[content_type]: { read_count: 1 } } }
245248
});
246249
}
247250

248251
update_bucket_write_counters({ bucket_name, key, content_type, }) {
249-
content_type = content_type || mime.getType(key) || 'application/octet-stream';
252+
content_type = content_type || mime.lookup(key) || 'application/octet-stream';
250253
this.endpoint_stats_collector.update({
251-
bucket_counters: { [bucket_name]: { [content_type]: { write_count: 1 } } }
254+
bucket_counters: {
255+
[bucket_name]: {
256+
[content_type]: { write_count: 1 } } }
252257
});
253258
}
254259

@@ -361,7 +366,7 @@ class EndpointStatsCollector {
361366
update_fork_counter() {
362367
// add fork related metrics to prometheus
363368
const code = `worker_${cluster.worker.id}`;
364-
this.prom_metrics_report.inc('fork_counter', {code});
369+
this.prom_metrics_report.inc('fork_counter', { code });
365370
}
366371
}
367372
if (cluster.isWorker) {

src/sdk/namespace_fs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const _ = require('lodash');
77
const fs = require('fs');
88
const path = require('path');
99
const util = require('util');
10-
const mime = require('mime');
10+
const mime = require('mime-types');
1111
const P = require('../util/promise');
1212
const dbg = require('../util/debug_module')(__filename);
1313
const config = require('../../config');
@@ -2546,7 +2546,7 @@ class NamespaceFS {
25462546
const dir_content_type = stat.xattr?.[XATTR_DIR_CONTENT] && ((Number(stat.xattr?.[XATTR_DIR_CONTENT]) > 0 && 'application/octet-stream') || 'application/x-directory');
25472547
const content_type = stat.xattr?.[XATTR_CONTENT_TYPE] ||
25482548
(isDir && dir_content_type) ||
2549-
mime.getType(key) || 'application/octet-stream';
2549+
mime.lookup(key) || 'application/octet-stream';
25502550

25512551
const storage_class = Glacier.storage_class_from_xattr(stat.xattr);
25522552
const size = Number(stat.xattr?.[XATTR_DIR_CONTENT] || stat.size);

src/sdk/namespace_net_storage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const _ = require('lodash');
55
const util = require('util');
66

77
const P = require('../util/promise');
8-
const mime = require('mime');
8+
const mime = require('mime-types');
99
const dbg = require('../util/debug_module')(__filename);
1010
const NetStorage = require('../util/NetStorageKit-Node-master/lib/netstorage');
1111

@@ -158,7 +158,7 @@ class NamespaceNetStorage {
158158
size: res.size,
159159
etag,
160160
create_time: new Date(Number(res.mtime || 0) * 1000),
161-
content_type: mime.getType(res.name) || 'application/octet-stream',
161+
content_type: mime.lookup(res.name) || 'application/octet-stream',
162162
xattr,
163163
};
164164
}

src/server/object_services/md_store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const _ = require('lodash');
77
const assert = require('assert');
88
const moment = require('moment');
99
const mongodb = require('mongodb');
10-
const mime = require('mime');
10+
const mime = require('mime-types');
1111

1212
const P = require('../../util/promise');
1313
const dbg = require('../../util/debug_module')(__filename);
@@ -292,7 +292,7 @@ class MDStore {
292292
system: obj.system,
293293
bucket: obj.bucket,
294294
key: obj.key,
295-
content_type: obj.content_type || mime.getType(obj.key) || 'application/octet-stream',
295+
content_type: obj.content_type || mime.lookup(obj.key) || 'application/octet-stream',
296296
delete_marker: true,
297297
create_time: new Date(),
298298
version_seq,

0 commit comments

Comments
 (0)