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.
- package/README.md +88 -17
- package/client/browser.js +7 -7
- package/client/connectSocket.js +257 -22
- package/client/index.js +3 -3
- package/dist/ape.js +1 -1
- package/dist/ape.js.map +3 -3
- package/dist/api-ape.min.js +1 -1
- package/dist/api-ape.min.js.map +3 -3
- package/index.d.ts +183 -19
- package/package.json +2 -2
- package/server/README.md +311 -5
- package/server/adapters/README.md +275 -0
- package/server/adapters/firebase.js +172 -0
- package/server/adapters/index.js +144 -0
- package/server/adapters/mongo.js +161 -0
- package/server/adapters/postgres.js +177 -0
- package/server/adapters/redis.js +154 -0
- package/server/adapters/supabase.js +199 -0
- package/server/index.js +3 -3
- package/server/lib/broadcast.js +115 -49
- package/server/lib/bun.js +4 -4
- package/server/lib/fileTransfer.js +129 -0
- package/server/lib/longPolling.js +22 -13
- package/server/lib/main.js +40 -8
- package/server/lib/wiring.js +23 -19
- package/server/socket/receive.js +46 -0
- package/server/socket/send.js +7 -0
package/server/socket/receive.js
CHANGED
|
@@ -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) => {
|
package/server/socket/send.js
CHANGED
|
@@ -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
|