@autonomys/file-server 1.5.14 → 1.5.16

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.
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Autonomys Network (autonomys.xyz)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ 1. **Attribution**: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+
14
+ 2. **No Warranty**: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15
+
16
+ 3. **Limitation of Liability**: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+
18
+ ---
@@ -23,7 +23,7 @@ const setFileResponseHeaders = (res, metadata, isEncrypted, isExpectedDocument,
23
23
  res.set('Content-Type', contentType);
24
24
  res.set('Content-Disposition', `${isExpectedDocument ? 'inline' : 'attachment'}; filename="${safeName}"`);
25
25
  const compressedButNoEncrypted = metadata.isCompressed && !isEncrypted;
26
- if (compressedButNoEncrypted && shouldHandleEncoding && !rawMode) {
26
+ if (compressedButNoEncrypted && shouldHandleEncoding && !rawMode && !byteRange) {
27
27
  res.set('Content-Encoding', 'deflate');
28
28
  }
29
29
  if (byteRange) {
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.5.14",
4
+ "version": "1.5.16",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "repository": {
@@ -47,9 +47,9 @@
47
47
  "typescript": "^5.8.3"
48
48
  },
49
49
  "dependencies": {
50
- "@autonomys/asynchronous": "^1.5.14",
51
- "@autonomys/auto-dag-data": "^1.5.14",
52
- "@autonomys/auto-utils": "^1.5.14",
50
+ "@autonomys/asynchronous": "^1.5.16",
51
+ "@autonomys/auto-dag-data": "^1.5.16",
52
+ "@autonomys/auto-utils": "^1.5.16",
53
53
  "@keyvhq/sqlite": "^2.1.7",
54
54
  "cache-manager": "^6.4.2",
55
55
  "express": "^4.19.2",
@@ -61,5 +61,5 @@
61
61
  "uuid": "^11.1.0",
62
62
  "zod": "^3.24.2"
63
63
  },
64
- "gitHead": "ef4c21d683cad697f7015e52becd399a8ca2ed84"
64
+ "gitHead": "7242b27a7d9e095399c3d87209767f012355340b"
65
65
  }
@@ -1,19 +0,0 @@
1
- import Keyv from 'keyv';
2
- export declare const defaultMemoryAndSqliteConfig: ({ dirname, cacheMaxSize, cacheTtl, }: {
3
- dirname: string;
4
- cacheMaxSize: number;
5
- cacheTtl: number;
6
- }) => {
7
- cacheDir: string;
8
- pathPartitions: number;
9
- stores: Keyv<any>[];
10
- };
11
- export declare const defaultInitMemoryConfig: ({ dirname, cacheMaxSize, }: {
12
- dirname: string;
13
- cacheMaxSize: number;
14
- }) => {
15
- cacheDir: string;
16
- pathPartitions: number;
17
- stores: Keyv<any>[];
18
- };
19
- //# sourceMappingURL=defaultConfigs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaultConfigs.d.ts","sourceRoot":"","sources":["../src/defaultConfigs.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,MAAM,CAAA;AAKvB,eAAO,MAAM,4BAA4B,GAAI,sCAI1C;IACD,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;CACjB;;;;CA2BA,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAI,4BAGrC;IACD,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;CACrB;;;;CAoBA,CAAA"}
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.defaultInitMemoryConfig = exports.defaultMemoryAndSqliteConfig = void 0;
7
- const auto_utils_1 = require("@autonomys/auto-utils");
8
- const sqlite_1 = __importDefault(require("@keyvhq/sqlite"));
9
- const keyv_1 = __importDefault(require("keyv"));
10
- const lru_cache_1 = require("lru-cache");
11
- const path_1 = __importDefault(require("path"));
12
- const utils_1 = require("./utils");
13
- const defaultMemoryAndSqliteConfig = ({ dirname, cacheMaxSize, cacheTtl, }) => {
14
- const cacheDir = (0, utils_1.ensureDirectoryExists)(path_1.default.join(dirname, 'files'));
15
- return {
16
- cacheDir,
17
- pathPartitions: 3,
18
- stores: [
19
- new keyv_1.default({
20
- serialize: auto_utils_1.stringify,
21
- store: new lru_cache_1.LRUCache({
22
- maxSize: cacheMaxSize,
23
- maxEntrySize: Number.MAX_SAFE_INTEGER,
24
- sizeCalculation: (value) => {
25
- var _a;
26
- const { value: parsedValue } = JSON.parse(value);
27
- return Number((_a = parsedValue === null || parsedValue === void 0 ? void 0 : parsedValue.size) !== null && _a !== void 0 ? _a : 0);
28
- },
29
- }),
30
- }),
31
- new keyv_1.default({
32
- store: new sqlite_1.default({
33
- uri: path_1.default.join(cacheDir, 'files.sqlite'),
34
- }),
35
- ttl: cacheTtl,
36
- serialize: auto_utils_1.stringify,
37
- }),
38
- ],
39
- };
40
- };
41
- exports.defaultMemoryAndSqliteConfig = defaultMemoryAndSqliteConfig;
42
- const defaultInitMemoryConfig = ({ dirname, cacheMaxSize, }) => {
43
- const cacheDir = (0, utils_1.ensureDirectoryExists)(path_1.default.join(dirname, 'files'));
44
- return {
45
- cacheDir,
46
- pathPartitions: 3,
47
- stores: [
48
- new keyv_1.default({
49
- serialize: auto_utils_1.stringify,
50
- store: new lru_cache_1.LRUCache({
51
- maxSize: cacheMaxSize,
52
- maxEntrySize: Number.MAX_SAFE_INTEGER,
53
- sizeCalculation: (value) => {
54
- var _a;
55
- const { value: parsedValue } = JSON.parse(value);
56
- return Number((_a = parsedValue === null || parsedValue === void 0 ? void 0 : parsedValue.size) !== null && _a !== void 0 ? _a : 0);
57
- },
58
- }),
59
- }),
60
- ],
61
- };
62
- };
63
- exports.defaultInitMemoryConfig = defaultInitMemoryConfig;
@@ -1,8 +0,0 @@
1
- import { BaseCacheConfig, FileCacheOptions, FileResponse } from './models';
2
- export declare const createFileCache: (config: BaseCacheConfig) => {
3
- get: (cid: string, options?: FileCacheOptions) => Promise<FileResponse | null>;
4
- set: (cid: string, fileResponse: FileResponse) => Promise<void>;
5
- has: (cid: string) => Promise<boolean>;
6
- remove: (cid: string) => Promise<void>;
7
- };
8
- //# sourceMappingURL=fileCache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fileCache.d.ts","sourceRoot":"","sources":["../src/fileCache.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAS1E,eAAO,MAAM,eAAe,GAAI,QAAQ,eAAe;eA8B7B,MAAM,YAAY,gBAAgB,KAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;eAyBjE,MAAM,gBAAgB,YAAY;eARlC,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;kBAoBtB,MAAM;CA0BlC,CAAA"}
package/dist/fileCache.js DELETED
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.createFileCache = void 0;
27
- const cache_manager_1 = require("cache-manager");
28
- const fs_1 = __importDefault(require("fs"));
29
- const promises_1 = __importDefault(require("fs/promises"));
30
- const path_1 = __importDefault(require("path"));
31
- const utils_1 = require("./utils");
32
- const CHARS_PER_PARTITION = 2;
33
- const createFileCache = (config) => {
34
- const cidToFilePath = (cid) => {
35
- const partitions = config.pathPartitions;
36
- let filePath = '';
37
- let head = cid;
38
- for (let i = 0; i < partitions; i++) {
39
- filePath = path_1.default.join(filePath, `${head.slice(-CHARS_PER_PARTITION)}/`);
40
- head = head.slice(0, -CHARS_PER_PARTITION);
41
- }
42
- filePath = path_1.default.join(filePath, head, cid);
43
- return path_1.default.join(config.cacheDir, filePath);
44
- };
45
- const filepathCache = (0, cache_manager_1.createCache)({
46
- stores: config.stores,
47
- nonBlocking: false,
48
- });
49
- const deserialize = (data) => {
50
- var _a;
51
- if (!data) {
52
- return null;
53
- }
54
- return Object.assign(Object.assign({}, data), { size: BigInt((_a = data.size) !== null && _a !== void 0 ? _a : 0) });
55
- };
56
- const get = (cid, options) => __awaiter(void 0, void 0, void 0, function* () {
57
- var _a, _b;
58
- const data = deserialize(yield filepathCache.get(cid));
59
- if (!data) {
60
- return null;
61
- }
62
- const path = cidToFilePath(cid);
63
- return Object.assign(Object.assign({}, data), { data: fs_1.default.createReadStream(path, {
64
- start: (_a = options === null || options === void 0 ? void 0 : options.byteRange) === null || _a === void 0 ? void 0 : _a[0],
65
- end: (_b = options === null || options === void 0 ? void 0 : options.byteRange) === null || _b === void 0 ? void 0 : _b[1],
66
- }) });
67
- });
68
- const has = (cid) => __awaiter(void 0, void 0, void 0, function* () {
69
- const path = cidToFilePath(cid);
70
- return promises_1.default
71
- .access(path, fs_1.default.constants.F_OK)
72
- .then(() => true)
73
- .catch(() => false);
74
- });
75
- const set = (cid, fileResponse) => __awaiter(void 0, void 0, void 0, function* () {
76
- const filePath = cidToFilePath(cid);
77
- const { data } = fileResponse, rest = __rest(fileResponse, ["data"]);
78
- yield (0, utils_1.writeFile)(filePath, data);
79
- yield filepathCache.set(cid, Object.assign({}, rest));
80
- });
81
- const remove = (cid) => __awaiter(void 0, void 0, void 0, function* () {
82
- const data = deserialize(yield filepathCache.get(cid));
83
- if (!data) {
84
- return;
85
- }
86
- const path = cidToFilePath(cid);
87
- yield Promise.all([filepathCache.del(cid), promises_1.default.rm(path)]);
88
- });
89
- filepathCache.on('del', (_a) => __awaiter(void 0, [_a], void 0, function* ({ key, error }) {
90
- if (error) {
91
- console.error(`Error deleting file cache entry for ${key}: ${error}`);
92
- }
93
- else {
94
- yield promises_1.default.rm(cidToFilePath(key));
95
- }
96
- }));
97
- const cache = {
98
- get,
99
- set,
100
- has,
101
- remove,
102
- };
103
- return cache;
104
- };
105
- exports.createFileCache = createFileCache;