@autonomys/file-server 1.6.2-beta.0 → 1.6.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/http/headers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAiG3E,eAAO,MAAM,6BAA6B,GACxC,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,UAAU,gBAAgB,EAC1B,wBAA4C,eAAe,SAyC5D,CAAA;AAED,eAAO,MAAM,+BAA+B,GAC1C,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,UAAU,gBAAgB,SAS3B,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,KAAK,OAAO,KAAG,SAAS,GAAG,SAgBvD,CAAA"}
1
+ {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/http/headers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAqF3E,eAAO,MAAM,6BAA6B,GACxC,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,UAAU,gBAAgB,EAC1B,wBAA4C,eAAe,SA+C5D,CAAA;AAED,eAAO,MAAM,+BAA+B,GAC1C,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,UAAU,gBAAgB,SAS3B,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,KAAK,OAAO,KAAG,SAAS,GAAG,SAgBvD,CAAA"}
@@ -1,4 +1,19 @@
1
1
  import { CompressionAlgorithm, EncryptionAlgorithm } from '@autonomys/auto-dag-data';
2
+ import { inferMimeType } from '../utils.js';
3
+ // Generic mimetypes that should trigger extension-based fallback
4
+ const GENERIC_MIME_TYPES = new Set(['application/octet-stream', 'binary/octet-stream']);
5
+ // Get the best mimetype for a file, falling back to extension-based inference
6
+ // when the stored mimetype is missing or generic
7
+ const getMimeType = (metadata) => {
8
+ var _a;
9
+ const storedMime = (_a = metadata.mimeType) === null || _a === void 0 ? void 0 : _a.toLowerCase();
10
+ // If we have a meaningful mimetype, use it
11
+ if (storedMime && !GENERIC_MIME_TYPES.has(storedMime)) {
12
+ return metadata.mimeType;
13
+ }
14
+ // Otherwise, infer from filename extension
15
+ return inferMimeType(metadata.name);
16
+ };
2
17
  // Check if this is actually a document navigation (based on headers only)
3
18
  // Used to determine if browser will auto-decompress Content-Encoding
4
19
  const isDocumentNavigation = (req) => {
@@ -15,43 +30,12 @@ const isDocumentNavigation = (req) => {
15
30
  // Decide if this file type is something browsers can usually render inline via URL
16
31
  // (mirrors the logic in canDisplayDirectly but on DownloadMetadata)
17
32
  const isPreviewableInline = (metadata) => {
18
- var _a, _b, _c, _d, _e;
19
33
  if (metadata.isEncrypted)
20
34
  return false;
21
- const mimeType = (_b = (_a = metadata.mimeType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
22
- const extension = (_e = (_d = (_c = metadata.name) === null || _c === void 0 ? void 0 : _c.split('.').pop()) === null || _d === void 0 ? void 0 : _d.toLowerCase()) !== null && _e !== void 0 ? _e : '';
35
+ // Use getMimeType to get the best available mimetype (with extension fallback)
36
+ const mimeType = getMimeType(metadata).toLowerCase();
23
37
  const directDisplayTypes = ['image/', 'video/', 'audio/'];
24
- const directDisplayExtensions = [
25
- // Images
26
- 'jpg',
27
- 'jpeg',
28
- 'png',
29
- 'gif',
30
- 'svg',
31
- 'webp',
32
- 'bmp',
33
- 'ico',
34
- // Videos
35
- 'mp4',
36
- 'webm',
37
- 'avi',
38
- 'mov',
39
- 'mkv',
40
- 'flv',
41
- 'wmv',
42
- // Audio
43
- 'mp3',
44
- 'wav',
45
- 'ogg',
46
- 'flac',
47
- 'm4a',
48
- 'aac',
49
- // PDFs
50
- 'pdf',
51
- ];
52
- return (directDisplayTypes.some((type) => mimeType.startsWith(type)) ||
53
- mimeType === 'application/pdf' ||
54
- directDisplayExtensions.includes(extension));
38
+ return (directDisplayTypes.some((type) => mimeType.startsWith(type)) || mimeType === 'application/pdf');
55
39
  };
56
40
  const isInlineDisposition = (req, metadata) => {
57
41
  // Explicit query overrides - treat presence as boolean flag
@@ -89,7 +73,7 @@ export const handleDownloadResponseHeaders = (req, res, metadata, { byteRange =
89
73
  const baseName = metadata.name || 'download';
90
74
  const fileName = metadata.type === 'file' ? baseName : `${baseName}.zip`;
91
75
  if (metadata.type === 'file') {
92
- const contentType = (!metadata.isEncrypted && !rawMode && metadata.mimeType) || 'application/octet-stream';
76
+ const contentType = !metadata.isEncrypted && !rawMode ? getMimeType(metadata) : 'application/octet-stream';
93
77
  res.set('Content-Type', contentType);
94
78
  // Advertise range support for files so browsers like Chrome can seek in media
95
79
  if (metadata.size != null) {
@@ -102,7 +86,12 @@ export const handleDownloadResponseHeaders = (req, res, metadata, { byteRange =
102
86
  ? req.query.ignoreEncoding !== 'true'
103
87
  : isDocumentNavigation(req);
104
88
  if (compressedButNotEncrypted && shouldHandleEncoding && !rawMode && !byteRange) {
105
- res.set('Content-Encoding', 'deflate');
89
+ // Never set Content-Encoding for media types that need range support for seeking
90
+ const mimeType = contentType.toLowerCase();
91
+ const isMediaType = mimeType.startsWith('video/') || mimeType.startsWith('audio/');
92
+ if (!isMediaType) {
93
+ res.set('Content-Encoding', 'deflate');
94
+ }
106
95
  }
107
96
  if (byteRange) {
108
97
  res.status(206);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@autonomys/file-server",
3
3
  "packageManager": "yarn@4.7.0",
4
- "version": "1.6.2-beta.0",
4
+ "version": "1.6.2-beta.2",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "repository": {
@@ -48,9 +48,9 @@
48
48
  "typescript": "^5.8.3"
49
49
  },
50
50
  "dependencies": {
51
- "@autonomys/asynchronous": "^1.6.2-beta.0",
52
- "@autonomys/auto-dag-data": "^1.6.2-beta.0",
53
- "@autonomys/auto-utils": "^1.6.2-beta.0",
51
+ "@autonomys/asynchronous": "^1.6.2-beta.2",
52
+ "@autonomys/auto-dag-data": "^1.6.2-beta.2",
53
+ "@autonomys/auto-utils": "^1.6.2-beta.2",
54
54
  "@keyvhq/sqlite": "^2.1.7",
55
55
  "cache-manager": "^6.4.2",
56
56
  "express": "^4.19.2",
@@ -62,5 +62,5 @@
62
62
  "uuid": "^11.1.0",
63
63
  "zod": "^3.24.2"
64
64
  },
65
- "gitHead": "ee6436b04e85cb1a3da9c58250c3505f6c18d22b"
65
+ "gitHead": "7539f6cb4886fbd98cbb4cf9b991c879afe6b8cf"
66
66
  }