ocremote 2.0.1 → 2.1.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/lib/rpc.mjs +22 -13
- package/oc-remote.mjs +1 -1
- package/package.json +1 -1
package/lib/rpc.mjs
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { b64 } from './crypto.mjs'
|
|
2
2
|
|
|
3
|
+
function sendChunks(session, id, buffer, size) {
|
|
4
|
+
for (let offset = 0; offset < buffer.length; offset += size) {
|
|
5
|
+
session.sendSealed({ t: 'chunk', id, data: b64(buffer.subarray(offset, offset + size)) })
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
const MAX_CONCURRENT = 8
|
|
4
10
|
const MAX_UPLOAD = 24 << 20
|
|
5
|
-
const MAX_RESPONSE =
|
|
11
|
+
const MAX_RESPONSE = 64 << 20
|
|
12
|
+
const SMALL_RESPONSE = 256 << 10
|
|
13
|
+
const RESPONSE_CHUNK = 256 << 10
|
|
14
|
+
const STREAM_CHUNK = 64 << 10
|
|
6
15
|
|
|
7
16
|
export class RpcAdapter {
|
|
8
17
|
constructor({ baseUrl, authHeader, logger }) {
|
|
@@ -92,6 +101,7 @@ export class RpcAdapter {
|
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
const res = await fetch(url, init)
|
|
104
|
+
const contentType = res.headers.get('content-type') || ''
|
|
95
105
|
if (!stream) {
|
|
96
106
|
const chunks = []
|
|
97
107
|
let size = 0
|
|
@@ -99,33 +109,32 @@ export class RpcAdapter {
|
|
|
99
109
|
size += chunk.length
|
|
100
110
|
if (size > MAX_RESPONSE) {
|
|
101
111
|
controller.abort()
|
|
102
|
-
session.sendSealed({ t: 'res', id, error: '
|
|
112
|
+
session.sendSealed({ t: 'res', id, error: 'response_too_large' })
|
|
103
113
|
return
|
|
104
114
|
}
|
|
105
115
|
chunks.push(Buffer.from(chunk))
|
|
106
116
|
}
|
|
107
117
|
const buffer = Buffer.concat(chunks)
|
|
108
|
-
|
|
109
|
-
t: 'res',
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
if (buffer.length <= SMALL_RESPONSE) {
|
|
119
|
+
session.sendSealed({ t: 'res', id, status: res.status, contentType, body: b64(buffer) })
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
opened = true
|
|
123
|
+
session.sendSealed({ t: 'open', id, status: res.status, contentType })
|
|
124
|
+
sendChunks(session, id, buffer, RESPONSE_CHUNK)
|
|
125
|
+
session.sendSealed({ t: 'end', id })
|
|
115
126
|
return
|
|
116
127
|
}
|
|
117
128
|
|
|
118
129
|
opened = true
|
|
119
|
-
session.sendSealed({ t: 'open', id, status: res.status, contentType
|
|
130
|
+
session.sendSealed({ t: 'open', id, status: res.status, contentType })
|
|
120
131
|
if (!res.body) {
|
|
121
132
|
session.sendSealed({ t: 'end', id })
|
|
122
133
|
return
|
|
123
134
|
}
|
|
124
135
|
for await (const chunk of res.body) {
|
|
125
136
|
if (controller.signal.aborted) break
|
|
126
|
-
|
|
127
|
-
session.sendSealed({ t: 'chunk', id, data: b64(chunk.subarray(offset, offset + 64 * 1024)) })
|
|
128
|
-
}
|
|
137
|
+
sendChunks(session, id, chunk, STREAM_CHUNK)
|
|
129
138
|
}
|
|
130
139
|
session.sendSealed({ t: 'end', id })
|
|
131
140
|
} catch (err) {
|
package/oc-remote.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import { b64 } from './lib/crypto.mjs'
|
|
|
17
17
|
|
|
18
18
|
const require = createRequire(import.meta.url)
|
|
19
19
|
const NAME = 'oc-remote'
|
|
20
|
-
const VERSION = '2.0
|
|
20
|
+
const VERSION = '2.1.0'
|
|
21
21
|
const LAUNCH_LABEL = 'com.raul.ocremote'
|
|
22
22
|
const LOG_PATH =
|
|
23
23
|
process.platform === 'darwin'
|