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/src/config.js CHANGED
@@ -1,20 +1,37 @@
1
1
  /**
2
- * Application Configuration
2
+ * 应用配置
3
3
  */
4
4
 
5
- // File size limits
5
+ // 文件大小限制
6
6
  export const MAX_FILE_SIZE = 100 * 1024 * 1024 * 1024 // 100 GB
7
7
 
8
- // Network timeouts (ms)
8
+ // 网络超时(毫秒)
9
9
  export const CONNECTION_TIMEOUT = 120000
10
10
  export const DOWNLOAD_TIMEOUT = 900000
11
11
 
12
- // P2P settings
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
- // DHT Bootstrap nodes for Hyperswarm/HyperDHT
16
- // Using the same bootstrap nodes as Keet.io/HyperDHT for compatibility
17
- // Format: [suggested-IP@]<host>:<port> to avoid DNS calls
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 (Content Identifier) Calculation Module
3
- * Handles IPFS UnixFS CID computation for files
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
- * Dummy Blockstore for CID calculation
12
- * Does not store any data, only used for streaming CID computation
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
- * Calculate IPFS UnixFS CID v1 for content
24
- * Uses streaming approach to handle large files efficiently
23
+ * 计算内容的 IPFS UnixFS CID v1
24
+ * 使用流式方法高效处理大文件
25
25
  *
26
- * @param {string|Buffer|AsyncIterable} content - File path (string), Buffer, or async iterable
27
- * @param {object} options - Calculation options
28
- * @param {boolean} [options.rawLeaves=true] - Use raw leaves for modern CID
29
- * @param {number} [options.cidVersion=1] - CID version (0 or 1)
30
- * @param {number} [options.size] - Total size in bytes (optional, auto-detected for files)
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
- // Ignore stat errors, size will be 0
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
- * Validate a CID string
96
- * @param {string} cidString - CID string to validate
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
- * Parse a most:// link and extract the CID
113
- * @param {string} link - most://<cid> format link
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
- // Remove any trailing slashes or whitespace
127
+ // 移除尾部斜杠和空白
128
128
  cidString = cidString.trim().replace(/\/+$/, '')
129
129
 
130
- // Handle URL-like parsing for potential extra paths
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
  }