api-ape 2.2.2 → 2.3.0

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.
@@ -47,6 +47,42 @@ function findUploadTags(obj, path = '') {
47
47
  return uploads
48
48
  }
49
49
 
50
+ /**
51
+ * Find F-tagged properties in data (indicating client-to-client file sharing)
52
+ * Returns array of { path, hash }
53
+ */
54
+ function findFileTags(obj, path = '') {
55
+ const files = []
56
+
57
+ if (obj === null || obj === undefined || typeof obj !== 'object') {
58
+ return files
59
+ }
60
+
61
+ if (Array.isArray(obj)) {
62
+ for (let i = 0; i < obj.length; i++) {
63
+ files.push(...findFileTags(obj[i], path ? `${path}.${i}` : String(i)))
64
+ }
65
+ return files
66
+ }
67
+
68
+ for (const key of Object.keys(obj)) {
69
+ // Check for F tag (client-to-client file sharing marker)
70
+ const fMatch = key.match(/^(.+)<!F>$/)
71
+
72
+ if (fMatch) {
73
+ files.push({
74
+ path: path ? `${path}.${fMatch[1]}` : fMatch[1],
75
+ hash: obj[key],
76
+ originalKey: key
77
+ })
78
+ } else {
79
+ files.push(...findFileTags(obj[key], path ? `${path}.${key}` : key))
80
+ }
81
+ }
82
+
83
+ return files
84
+ }
85
+
50
86
  /**
51
87
  * Clean upload tags from data (rename key<!B> to key)
52
88
  */
@@ -157,6 +193,16 @@ module.exports = function receiveHandler(ape) {
157
193
  return
158
194
  }
159
195
  }
196
+
197
+ // Check for F-tagged files (client-to-client sharing)
198
+ // Register them but DON'T wait - controller invoked immediately
199
+ const fileTags = findFileTags(data)
200
+ if (fileTags.length > 0) {
201
+ console.log(`📁 Registering ${fileTags.length} streaming file(s) for ${type}`)
202
+ fileTags.forEach(({ hash }) => {
203
+ fileTransfer.registerStreamingFile(hash, hostId)
204
+ })
205
+ }
160
206
  }
161
207
 
162
208
  const result = new Promise((resolve, reject) => {
@@ -78,6 +78,13 @@ function processBinaryData(data, queryId, fileTransfer, clientId, path = '') {
78
78
  const allBinaryEntries = []
79
79
 
80
80
  for (const key of Object.keys(data)) {
81
+ // F-tagged values pass through unchanged (client-to-client sharing)
82
+ // Client will fetch from /api/ape/data/:hash
83
+ if (key.endsWith('<!F>')) {
84
+ processedObj[key] = data[key]
85
+ continue
86
+ }
87
+
81
88
  const itemPath = path ? `${path}.${key}` : key
82
89
  const { processedData, binaryEntries } = processBinaryData(
83
90
  data[key], queryId, fileTransfer, clientId, itemPath