most-box 0.0.1 → 0.0.4

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.
Files changed (71) hide show
  1. package/README.md +182 -73
  2. package/out/404/index.html +15 -0
  3. package/out/404.html +15 -0
  4. package/out/__next.__PAGE__.txt +9 -0
  5. package/out/__next._full.txt +18 -0
  6. package/out/__next._head.txt +5 -0
  7. package/out/__next._index.txt +6 -0
  8. package/out/__next._tree.txt +2 -0
  9. package/out/_next/static/0h4f4QFk_KC9FlSRfQACk/_buildManifest.js +11 -0
  10. package/out/_next/static/0h4f4QFk_KC9FlSRfQACk/_clientMiddlewareManifest.js +1 -0
  11. package/out/_next/static/0h4f4QFk_KC9FlSRfQACk/_ssgManifest.js +1 -0
  12. package/out/_next/static/chunks/00l-yd3t8dvwz.js +5 -0
  13. package/out/_next/static/chunks/03k8t3tgym~8~.js +1 -0
  14. package/out/_next/static/chunks/03~yq9q893hmn.js +1 -0
  15. package/out/_next/static/chunks/09vfh8lfuacc0.css +1 -0
  16. package/out/_next/static/chunks/0bogtdbh.dcu1.js +1 -0
  17. package/out/_next/static/chunks/0dbhjjzl8qfwv.js +1 -0
  18. package/out/_next/static/chunks/0f73psqhr8dre.css +1 -0
  19. package/out/_next/static/chunks/0fbi7z4_.4j1j.js +1 -0
  20. package/out/_next/static/chunks/0ht900cau6_ur.js +31 -0
  21. package/out/_next/static/chunks/0ohm.ia-4ec60.js +1 -0
  22. package/out/_next/static/chunks/0u5ydb-f0.vxl.js +1 -0
  23. package/out/_next/static/chunks/14t2m1on-s5v~.js +1 -0
  24. package/out/_next/static/chunks/turbopack-076ce9exut_h3.js +1 -0
  25. package/out/_not-found/__next._full.txt +16 -0
  26. package/out/_not-found/__next._head.txt +5 -0
  27. package/out/_not-found/__next._index.txt +6 -0
  28. package/out/_not-found/__next._not-found/__PAGE__.txt +5 -0
  29. package/out/_not-found/__next._not-found.txt +5 -0
  30. package/out/_not-found/__next._tree.txt +2 -0
  31. package/out/_not-found/index.html +15 -0
  32. package/out/_not-found/index.txt +16 -0
  33. package/out/app.css +1535 -0
  34. package/out/bundle.js +107 -0
  35. package/out/bundle.js.map +7 -0
  36. package/out/chat/__next._full.txt +19 -0
  37. package/out/chat/__next._head.txt +5 -0
  38. package/out/chat/__next._index.txt +6 -0
  39. package/out/chat/__next._tree.txt +3 -0
  40. package/out/chat/__next.chat/__PAGE__.txt +9 -0
  41. package/out/chat/__next.chat.txt +5 -0
  42. package/out/chat/index.html +15 -0
  43. package/out/chat/index.txt +19 -0
  44. package/out/chat-page.js +112 -0
  45. package/out/chat.css +378 -0
  46. package/out/favicon.ico +0 -0
  47. package/out/index.html +15 -0
  48. package/out/index.js +148 -0
  49. package/out/index.txt +18 -0
  50. package/package.json +16 -7
  51. package/public/app.css +1535 -0
  52. package/public/bundle.js +10 -14
  53. package/public/bundle.js.map +4 -4
  54. package/public/chat-page.js +112 -0
  55. package/public/chat.css +378 -0
  56. package/public/index.js +148 -0
  57. package/server.js +464 -199
  58. package/src/config.js +36 -8
  59. package/src/core/cid.js +28 -19
  60. package/src/index.js +872 -276
  61. package/src/utils/api.js +6 -0
  62. package/src/utils/security.js +27 -24
  63. package/build.mjs +0 -40
  64. package/public/app.jsx +0 -1335
  65. package/public/icons/apple-touch-icon.png +0 -0
  66. package/public/icons/mask-icon.svg +0 -3
  67. package/public/icons/most.png +0 -0
  68. package/public/icons/pwa-192x192.png +0 -0
  69. package/public/icons/pwa-512x512.png +0 -0
  70. package/public/index.html +0 -15
  71. package/public/index.jsx +0 -5
package/src/config.js CHANGED
@@ -1,22 +1,50 @@
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',
21
38
  '138.68.147.8@node3.hyperdht.org:49737'
22
- ]
39
+ ]
40
+
41
+ export const FRIEND_CODE_LENGTH = 16
42
+ export const FRIEND_CODE_PREFIX = 'MOST'
43
+
44
+ export const CHANNEL_NAME_MIN_LENGTH = 3
45
+ export const CHANNEL_NAME_MAX_LENGTH = 20
46
+ export const CHANNEL_NAME_REGEX = /^[a-zA-Z0-9_-]+$/
47
+ export const CHANNEL_NAME_PREFIX = 'most-box-room-'
48
+ export const CHANNEL_TOPIC_STRING = 'most-box-channels-v1'
49
+ export const CHANNEL_MESSAGE_LIMIT = 100
50
+ export const MAX_MESSAGE_LENGTH = 10000
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,19 @@ 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,提取 filename
131
+ let fileName = null
132
+ if (cidString.includes('?')) {
133
+ const [cidPart, queryPart] = cidString.split('?')
134
+ cidString = cidPart
135
+ const params = new URLSearchParams(queryPart)
136
+ fileName = params.get('filename')
137
+ }
138
+
139
+ // 处理可能的额外路径的 URL 解析
131
140
  if (cidString.includes('/')) {
132
141
  cidString = cidString.split('/')[0]
133
142
  }
@@ -137,5 +146,5 @@ export function parseMostLink(link) {
137
146
  return { cid: '', error: validation.error }
138
147
  }
139
148
 
140
- return { cid: cidString }
149
+ return { cid: cidString, fileName }
141
150
  }