most-box 0.0.1 → 0.0.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.
- package/README.md +156 -73
- package/cli.js +2 -2
- package/package.json +9 -5
- package/public/app.css +1519 -0
- package/public/app.jsx +607 -399
- package/public/bundle.css +1 -0
- package/public/bundle.js +10 -14
- package/public/error-boundary.jsx +50 -0
- package/public/index.html +2 -1
- package/public/index.jsx +16 -1
- package/server.js +280 -197
- package/src/config.js +24 -7
- package/src/core/cid.js +23 -18
- package/src/index.js +400 -272
- package/src/utils/security.js +27 -24
- package/public/bundle.js.map +0 -7
- package/public/icons/apple-touch-icon.png +0 -0
- package/public/icons/mask-icon.svg +0 -3
- package/public/icons/most.png +0 -0
- package/public/icons/pwa-192x192.png +0 -0
- package/public/icons/pwa-512x512.png +0 -0
package/src/config.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 应用配置
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
//
|
|
5
|
+
// 文件大小限制
|
|
6
6
|
export const MAX_FILE_SIZE = 100 * 1024 * 1024 * 1024 // 100 GB
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// 网络超时(毫秒)
|
|
9
9
|
export const CONNECTION_TIMEOUT = 120000
|
|
10
10
|
export const DOWNLOAD_TIMEOUT = 900000
|
|
11
11
|
|
|
12
|
-
// P2P
|
|
12
|
+
// P2P 设置
|
|
13
13
|
export const GLOBAL_SHARED_SEED_STRING = 'most-box-global-shared-seed-v1'
|
|
14
|
+
export const MAX_PEERS = 64
|
|
15
|
+
export const SWARM_KEEP_ALIVE_INTERVAL = 5000
|
|
16
|
+
export const SWARM_RANDOM_PUNCH_INTERVAL = 20000
|
|
14
17
|
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
// 驱动器超时(毫秒)
|
|
19
|
+
export const DRIVE_ENTRY_TIMEOUT = 10000
|
|
20
|
+
export const DRIVE_SYNC_TIMEOUT = 10000
|
|
21
|
+
export const STREAM_READ_TIMEOUT = 10000
|
|
22
|
+
|
|
23
|
+
// 下载轮询间隔(毫秒)
|
|
24
|
+
export const DOWNLOAD_POLL_INTERVAL = 1000
|
|
25
|
+
|
|
26
|
+
// 进度更新节流间隔(毫秒)
|
|
27
|
+
export const PROGRESS_THROTTLE = 500
|
|
28
|
+
|
|
29
|
+
// 默认读取限制
|
|
30
|
+
export const DEFAULT_READ_LIMIT = 10000
|
|
31
|
+
|
|
32
|
+
// DHT 引导节点,用于 Hyperswarm/HyperDHT
|
|
33
|
+
// 使用与 Keet.io/HyperDHT 相同的引导节点以保证兼容性
|
|
34
|
+
// 格式:[suggested-IP@]<host>:<port> 以避免 DNS 调用
|
|
18
35
|
export const SWARM_BOOTSTRAP = [
|
|
19
36
|
'88.99.3.86@node1.hyperdht.org:49737',
|
|
20
37
|
'142.93.90.113@node2.hyperdht.org:49737',
|
package/src/core/cid.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CID
|
|
3
|
-
*
|
|
2
|
+
* CID(内容标识符)计算模块
|
|
3
|
+
* 处理文件的 IPFS UnixFS CID 计算
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import fs from 'node:fs'
|
|
@@ -8,8 +8,8 @@ import { Readable } from 'node:stream'
|
|
|
8
8
|
import { importer } from 'ipfs-unixfs-importer'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* 用于 CID 计算的虚拟 Blockstore
|
|
12
|
+
* 不存储任何数据,仅用于流式 CID 计算
|
|
13
13
|
*/
|
|
14
14
|
function createDummyBlockstore() {
|
|
15
15
|
return {
|
|
@@ -20,14 +20,14 @@ function createDummyBlockstore() {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* 计算内容的 IPFS UnixFS CID v1
|
|
24
|
+
* 使用流式方法高效处理大文件
|
|
25
25
|
*
|
|
26
|
-
* @param {string|Buffer|AsyncIterable} content -
|
|
27
|
-
* @param {object} options -
|
|
28
|
-
* @param {boolean} [options.rawLeaves=true] -
|
|
29
|
-
* @param {number} [options.cidVersion=1] - CID
|
|
30
|
-
* @param {number} [options.size] -
|
|
26
|
+
* @param {string|Buffer|AsyncIterable} content - 文件路径(字符串)、Buffer 或异步迭代器
|
|
27
|
+
* @param {object} options - 计算选项
|
|
28
|
+
* @param {boolean} [options.rawLeaves=true] - 使用原始叶子节点以支持现代 CID
|
|
29
|
+
* @param {number} [options.cidVersion=1] - CID 版本(0 或 1)
|
|
30
|
+
* @param {number} [options.size] - 总字节数(可选,自动检测)
|
|
31
31
|
* @returns {Promise<{cid: import('multiformats/cid').CID, size: number}>}
|
|
32
32
|
*/
|
|
33
33
|
export async function calculateCid(content, options = {}) {
|
|
@@ -50,7 +50,7 @@ export async function calculateCid(content, options = {}) {
|
|
|
50
50
|
const stat = await fs.promises.stat(filePath)
|
|
51
51
|
totalSize = stat.size
|
|
52
52
|
} catch {
|
|
53
|
-
//
|
|
53
|
+
// 忽略 stat 错误,大小将为 0
|
|
54
54
|
}
|
|
55
55
|
source = [{
|
|
56
56
|
path: 'file',
|
|
@@ -92,8 +92,8 @@ export async function calculateCid(content, options = {}) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param {string} cidString - CID
|
|
95
|
+
* 验证 CID 字符串
|
|
96
|
+
* @param {string} cidString - 要验证的 CID 字符串
|
|
97
97
|
* @returns {{ valid: boolean, error?: string }}
|
|
98
98
|
*/
|
|
99
99
|
export function validateCidString(cidString) {
|
|
@@ -109,8 +109,8 @@ export function validateCidString(cidString) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @param {string} link - most://<cid>
|
|
112
|
+
* 解析 most:// 链接并提取 CID
|
|
113
|
+
* @param {string} link - most://<cid> 格式的链接
|
|
114
114
|
* @returns {{ cid: string, error?: string }}
|
|
115
115
|
*/
|
|
116
116
|
export function parseMostLink(link) {
|
|
@@ -124,10 +124,15 @@ export function parseMostLink(link) {
|
|
|
124
124
|
cidString = link.replace('most://', '')
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
//
|
|
127
|
+
// 移除尾部斜杠和空白
|
|
128
128
|
cidString = cidString.trim().replace(/\/+$/, '')
|
|
129
129
|
|
|
130
|
-
//
|
|
130
|
+
// 移除 query string
|
|
131
|
+
if (cidString.includes('?')) {
|
|
132
|
+
cidString = cidString.split('?')[0]
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// 处理可能的额外路径的 URL 解析
|
|
131
136
|
if (cidString.includes('/')) {
|
|
132
137
|
cidString = cidString.split('/')[0]
|
|
133
138
|
}
|