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 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 = 700 * 1024
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: 'Response exceeds the relay limit. Narrow the request and try again.' })
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
- session.sendSealed({
109
- t: 'res',
110
- id,
111
- status: res.status,
112
- contentType: res.headers.get('content-type') || '',
113
- body: b64(buffer),
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: res.headers.get('content-type') || '' })
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
- for (let offset = 0; offset < chunk.length; offset += 64 * 1024) {
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.1'
20
+ const VERSION = '2.1.0'
21
21
  const LAUNCH_LABEL = 'com.raul.ocremote'
22
22
  const LOG_PATH =
23
23
  process.platform === 'darwin'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ocremote",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Control opencode on your computer from the OpenCode Remote iOS app: supervisor, pairing QR, relay and tunnel transports",
5
5
  "type": "module",
6
6
  "bin": {