@ceki/sdk 1.9.2 → 1.10.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/dist/cli.js +28 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +24 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +24 -5
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.d.cts
CHANGED
|
@@ -254,7 +254,8 @@ declare class Browser {
|
|
|
254
254
|
data: string;
|
|
255
255
|
} | Buffer>;
|
|
256
256
|
snapshot(): Promise<Snapshot>;
|
|
257
|
-
|
|
257
|
+
private static _detectMime;
|
|
258
|
+
upload(selector: string, source: string | Buffer, filename?: string, mime?: string): Promise<{
|
|
258
259
|
ok: boolean;
|
|
259
260
|
filename: string;
|
|
260
261
|
size: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -254,7 +254,8 @@ declare class Browser {
|
|
|
254
254
|
data: string;
|
|
255
255
|
} | Buffer>;
|
|
256
256
|
snapshot(): Promise<Snapshot>;
|
|
257
|
-
|
|
257
|
+
private static _detectMime;
|
|
258
|
+
upload(selector: string, source: string | Buffer, filename?: string, mime?: string): Promise<{
|
|
258
259
|
ok: boolean;
|
|
259
260
|
filename: string;
|
|
260
261
|
size: number;
|
package/dist/index.js
CHANGED
|
@@ -133,6 +133,9 @@ var ChatSendFailed = class extends CekiBrowserError {
|
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
+
// src/browser.ts
|
|
137
|
+
import mime from "mime-types";
|
|
138
|
+
|
|
136
139
|
// src/chat.ts
|
|
137
140
|
import * as crypto from "crypto";
|
|
138
141
|
import * as fs from "fs";
|
|
@@ -198,7 +201,7 @@ var BrowserChat = class {
|
|
|
198
201
|
if (buf.length > MAX_IMAGE_SIZE) {
|
|
199
202
|
throw new Error(`Image too large: ${buf.length} bytes (max ${MAX_IMAGE_SIZE})`);
|
|
200
203
|
}
|
|
201
|
-
const { mime, ext } = detectMime(buf);
|
|
204
|
+
const { mime: mime2, ext } = detectMime(buf);
|
|
202
205
|
if (!filename.includes(".")) {
|
|
203
206
|
filename = `${filename}.${ext}`;
|
|
204
207
|
}
|
|
@@ -209,7 +212,7 @@ var BrowserChat = class {
|
|
|
209
212
|
session_id: this._browser.sessionId,
|
|
210
213
|
client_msg_id: clientMsgId,
|
|
211
214
|
filename,
|
|
212
|
-
mime,
|
|
215
|
+
mime: mime2,
|
|
213
216
|
data_b64
|
|
214
217
|
};
|
|
215
218
|
if (text) msg.text = text;
|
|
@@ -558,7 +561,7 @@ function keymapForChar(char) {
|
|
|
558
561
|
}
|
|
559
562
|
|
|
560
563
|
// src/browser.ts
|
|
561
|
-
var Browser = class {
|
|
564
|
+
var Browser = class _Browser {
|
|
562
565
|
sessionId;
|
|
563
566
|
browserId;
|
|
564
567
|
scheduleId;
|
|
@@ -798,7 +801,10 @@ var Browser = class {
|
|
|
798
801
|
ts: /* @__PURE__ */ new Date()
|
|
799
802
|
};
|
|
800
803
|
}
|
|
801
|
-
|
|
804
|
+
static _detectMime(filename) {
|
|
805
|
+
return mime.lookup(filename) || "application/octet-stream";
|
|
806
|
+
}
|
|
807
|
+
async upload(selector, source, filename, mime2) {
|
|
802
808
|
let buf;
|
|
803
809
|
let resolvedFilename;
|
|
804
810
|
if (typeof source === "string") {
|
|
@@ -810,6 +816,8 @@ var Browser = class {
|
|
|
810
816
|
buf = Buffer.isBuffer(source) ? source : Buffer.from(source);
|
|
811
817
|
resolvedFilename = filename ?? "file";
|
|
812
818
|
}
|
|
819
|
+
const mimeType = mime2 ?? _Browser._detectMime(resolvedFilename);
|
|
820
|
+
console.info(`upload: file=${resolvedFilename} mime=${mimeType} size=${buf.length}`);
|
|
813
821
|
const b64 = buf.toString("base64");
|
|
814
822
|
const size = buf.length;
|
|
815
823
|
const expression = `
|
|
@@ -820,7 +828,7 @@ var Browser = class {
|
|
|
820
828
|
var binary = atob(b64);
|
|
821
829
|
var bytes = new Uint8Array(binary.length);
|
|
822
830
|
for (var i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
823
|
-
var file = new File([bytes], ${JSON.stringify(resolvedFilename)}, {type:
|
|
831
|
+
var file = new File([bytes], ${JSON.stringify(resolvedFilename)}, {type: ${JSON.stringify(mimeType)}});
|
|
824
832
|
var dt = new DataTransfer();
|
|
825
833
|
dt.items.add(file);
|
|
826
834
|
input.files = dt.files;
|
|
@@ -833,6 +841,17 @@ var Browser = class {
|
|
|
833
841
|
params: { expression, returnByValue: true }
|
|
834
842
|
});
|
|
835
843
|
const resultObj = result?.result;
|
|
844
|
+
try {
|
|
845
|
+
await this.send({
|
|
846
|
+
method: "Input.dispatchKeyEvent",
|
|
847
|
+
params: { type: "keyDown", key: "Escape", code: "Escape", windowsVirtualKeyCode: 27, nativeVirtualKeyCode: 27 }
|
|
848
|
+
});
|
|
849
|
+
await this.send({
|
|
850
|
+
method: "Input.dispatchKeyEvent",
|
|
851
|
+
params: { type: "keyUp", key: "Escape", code: "Escape", windowsVirtualKeyCode: 27, nativeVirtualKeyCode: 27 }
|
|
852
|
+
});
|
|
853
|
+
} catch {
|
|
854
|
+
}
|
|
836
855
|
if (resultObj?.value) {
|
|
837
856
|
return JSON.parse(String(resultObj.value));
|
|
838
857
|
}
|