tevrocsdk 0.1.81 → 0.1.82
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 +12 -0
- package/package.json +1 -1
- package/tevroc-sdk.cjs.js +1110 -324
- package/tevroc-sdk.cjs.js.map +4 -4
- package/tevroc-sdk.esm.js +225 -105
- package/tevroc-sdk.esm.js.map +4 -4
package/tevroc-sdk.esm.js
CHANGED
|
@@ -8711,13 +8711,13 @@ var require_html2canvas = __commonJS({
|
|
|
8711
8711
|
var textList = toCodePoints$1(node2.data).map(function(i5) {
|
|
8712
8712
|
return fromCodePoint$1(i5);
|
|
8713
8713
|
});
|
|
8714
|
-
var
|
|
8714
|
+
var offset2 = 0;
|
|
8715
8715
|
var prev = {};
|
|
8716
8716
|
var supports = textList.every(function(text2, i5) {
|
|
8717
|
-
range.setStart(node2,
|
|
8718
|
-
range.setEnd(node2,
|
|
8717
|
+
range.setStart(node2, offset2);
|
|
8718
|
+
range.setEnd(node2, offset2 + text2.length);
|
|
8719
8719
|
var rect = range.getBoundingClientRect();
|
|
8720
|
-
|
|
8720
|
+
offset2 += text2.length;
|
|
8721
8721
|
var boundAhead = rect.x > prev.x || rect.y > prev.y;
|
|
8722
8722
|
prev = rect;
|
|
8723
8723
|
if (i5 === 0) {
|
|
@@ -8866,16 +8866,16 @@ var require_html2canvas = __commonJS({
|
|
|
8866
8866
|
var parseTextBounds = function(context, value, styles, node2) {
|
|
8867
8867
|
var textList = breakText(value, styles);
|
|
8868
8868
|
var textBounds = [];
|
|
8869
|
-
var
|
|
8869
|
+
var offset2 = 0;
|
|
8870
8870
|
textList.forEach(function(text2) {
|
|
8871
8871
|
if (styles.textDecorationLine.length || text2.trim().length > 0) {
|
|
8872
8872
|
if (FEATURES.SUPPORT_RANGE_BOUNDS) {
|
|
8873
|
-
var clientRects = createRange(node2,
|
|
8873
|
+
var clientRects = createRange(node2, offset2, text2.length).getClientRects();
|
|
8874
8874
|
if (clientRects.length > 1) {
|
|
8875
8875
|
var subSegments = segmentGraphemes(text2);
|
|
8876
8876
|
var subOffset_1 = 0;
|
|
8877
8877
|
subSegments.forEach(function(subSegment) {
|
|
8878
|
-
textBounds.push(new TextBounds(subSegment, Bounds.fromDOMRectList(context, createRange(node2, subOffset_1 +
|
|
8878
|
+
textBounds.push(new TextBounds(subSegment, Bounds.fromDOMRectList(context, createRange(node2, subOffset_1 + offset2, subSegment.length).getClientRects())));
|
|
8879
8879
|
subOffset_1 += subSegment.length;
|
|
8880
8880
|
});
|
|
8881
8881
|
} else {
|
|
@@ -8889,7 +8889,7 @@ var require_html2canvas = __commonJS({
|
|
|
8889
8889
|
} else if (!FEATURES.SUPPORT_RANGE_BOUNDS) {
|
|
8890
8890
|
node2 = node2.splitText(text2.length);
|
|
8891
8891
|
}
|
|
8892
|
-
|
|
8892
|
+
offset2 += text2.length;
|
|
8893
8893
|
});
|
|
8894
8894
|
return textBounds;
|
|
8895
8895
|
};
|
|
@@ -8910,14 +8910,14 @@ var require_html2canvas = __commonJS({
|
|
|
8910
8910
|
}
|
|
8911
8911
|
return Bounds.EMPTY;
|
|
8912
8912
|
};
|
|
8913
|
-
var createRange = function(node2,
|
|
8913
|
+
var createRange = function(node2, offset2, length) {
|
|
8914
8914
|
var ownerDocument = node2.ownerDocument;
|
|
8915
8915
|
if (!ownerDocument) {
|
|
8916
8916
|
throw new Error("Node has no owner document");
|
|
8917
8917
|
}
|
|
8918
8918
|
var range = ownerDocument.createRange();
|
|
8919
|
-
range.setStart(node2,
|
|
8920
|
-
range.setEnd(node2,
|
|
8919
|
+
range.setStart(node2, offset2);
|
|
8920
|
+
range.setEnd(node2, offset2 + length);
|
|
8921
8921
|
return range;
|
|
8922
8922
|
};
|
|
8923
8923
|
var segmentGraphemes = function(value) {
|
|
@@ -21228,13 +21228,13 @@ var init_index_es = __esm({
|
|
|
21228
21228
|
} else if (typeof ctx.mozDash !== "undefined" && !(gaps.length === 1 && gaps[0] === 0)) {
|
|
21229
21229
|
ctx.mozDash = gaps;
|
|
21230
21230
|
}
|
|
21231
|
-
var
|
|
21231
|
+
var offset2 = strokeDashoffsetProp.getPixels();
|
|
21232
21232
|
if (typeof ctx.lineDashOffset !== "undefined") {
|
|
21233
|
-
ctx.lineDashOffset =
|
|
21233
|
+
ctx.lineDashOffset = offset2;
|
|
21234
21234
|
} else if (typeof ctx.webkitLineDashOffset !== "undefined") {
|
|
21235
|
-
ctx.webkitLineDashOffset =
|
|
21235
|
+
ctx.webkitLineDashOffset = offset2;
|
|
21236
21236
|
} else if (typeof ctx.mozDashOffset !== "undefined") {
|
|
21237
|
-
ctx.mozDashOffset =
|
|
21237
|
+
ctx.mozDashOffset = offset2;
|
|
21238
21238
|
}
|
|
21239
21239
|
}
|
|
21240
21240
|
}
|
|
@@ -22671,7 +22671,7 @@ var init_index_es = __esm({
|
|
|
22671
22671
|
constructor(document2, node2, captureTextNodes) {
|
|
22672
22672
|
super(document2, node2, captureTextNodes);
|
|
22673
22673
|
this.type = "stop";
|
|
22674
|
-
var
|
|
22674
|
+
var offset2 = Math.max(0, Math.min(1, this.getAttribute("offset").getNumber()));
|
|
22675
22675
|
var stopOpacity = this.getStyle("stop-opacity");
|
|
22676
22676
|
var stopColor = this.getStyle("stop-color", true);
|
|
22677
22677
|
if (stopColor.getString() === "") {
|
|
@@ -22680,7 +22680,7 @@ var init_index_es = __esm({
|
|
|
22680
22680
|
if (stopOpacity.hasValue()) {
|
|
22681
22681
|
stopColor = stopColor.addOpacity(stopOpacity);
|
|
22682
22682
|
}
|
|
22683
|
-
this.offset =
|
|
22683
|
+
this.offset = offset2;
|
|
22684
22684
|
this.color = stopColor.getColor();
|
|
22685
22685
|
}
|
|
22686
22686
|
};
|
|
@@ -23079,17 +23079,17 @@ var init_index_es = __esm({
|
|
|
23079
23079
|
return this.letterSpacingCache[idx] || 0;
|
|
23080
23080
|
}
|
|
23081
23081
|
findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber, inputOffset, dy, c4, charI) {
|
|
23082
|
-
var
|
|
23082
|
+
var offset2 = inputOffset;
|
|
23083
23083
|
var glyphWidth = this.measureText(ctx, c4);
|
|
23084
23084
|
if (c4 === " " && anchor === "justify" && textFullWidth < fullPathWidth) {
|
|
23085
23085
|
glyphWidth += (fullPathWidth - textFullWidth) / spacesNumber;
|
|
23086
23086
|
}
|
|
23087
23087
|
if (charI > -1) {
|
|
23088
|
-
|
|
23088
|
+
offset2 += this.getLetterSpacingAt(charI);
|
|
23089
23089
|
}
|
|
23090
23090
|
var splineStep = this.textHeight / 20;
|
|
23091
|
-
var p0 = this.getEquidistantPointOnPath(
|
|
23092
|
-
var p1 = this.getEquidistantPointOnPath(
|
|
23091
|
+
var p0 = this.getEquidistantPointOnPath(offset2, splineStep, 0);
|
|
23092
|
+
var p1 = this.getEquidistantPointOnPath(offset2 + glyphWidth, splineStep, 0);
|
|
23093
23093
|
var segment = {
|
|
23094
23094
|
p0,
|
|
23095
23095
|
p1
|
|
@@ -23107,9 +23107,9 @@ var init_index_es = __esm({
|
|
|
23107
23107
|
y: p1.y + dyY
|
|
23108
23108
|
});
|
|
23109
23109
|
}
|
|
23110
|
-
|
|
23110
|
+
offset2 += glyphWidth;
|
|
23111
23111
|
return {
|
|
23112
|
-
offset,
|
|
23112
|
+
offset: offset2,
|
|
23113
23113
|
segment,
|
|
23114
23114
|
rotation
|
|
23115
23115
|
};
|
|
@@ -23163,21 +23163,21 @@ var init_index_es = __esm({
|
|
|
23163
23163
|
this.glyphInfo = [];
|
|
23164
23164
|
var fullPathWidth = this.getPathLength();
|
|
23165
23165
|
var startOffset = this.getStyle("startOffset").getNumber(0) * fullPathWidth;
|
|
23166
|
-
var
|
|
23166
|
+
var offset2 = 0;
|
|
23167
23167
|
if (anchor === "middle" || anchor === "center") {
|
|
23168
|
-
|
|
23168
|
+
offset2 = -textFullWidth / 2;
|
|
23169
23169
|
}
|
|
23170
23170
|
if (anchor === "end" || anchor === "right") {
|
|
23171
|
-
|
|
23171
|
+
offset2 = -textFullWidth;
|
|
23172
23172
|
}
|
|
23173
|
-
|
|
23173
|
+
offset2 += startOffset;
|
|
23174
23174
|
chars.forEach((char, i5) => {
|
|
23175
23175
|
var {
|
|
23176
23176
|
offset: nextOffset,
|
|
23177
23177
|
segment,
|
|
23178
23178
|
rotation
|
|
23179
|
-
} = this.findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber,
|
|
23180
|
-
|
|
23179
|
+
} = this.findSegmentToFitChar(ctx, anchor, textFullWidth, fullPathWidth, spacesNumber, offset2, dy, char, i5);
|
|
23180
|
+
offset2 = nextOffset;
|
|
23181
23181
|
if (!segment.p0 || !segment.p1) {
|
|
23182
23182
|
return;
|
|
23183
23183
|
}
|
|
@@ -25805,10 +25805,10 @@ var init_dist_js2 = __esm({
|
|
|
25805
25805
|
*
|
|
25806
25806
|
* @since 2.0.0
|
|
25807
25807
|
*/
|
|
25808
|
-
async seek(
|
|
25808
|
+
async seek(offset2, whence) {
|
|
25809
25809
|
return await invoke("plugin:fs|seek", {
|
|
25810
25810
|
rid: this.rid,
|
|
25811
|
-
offset,
|
|
25811
|
+
offset: offset2,
|
|
25812
25812
|
whence
|
|
25813
25813
|
});
|
|
25814
25814
|
}
|
|
@@ -28149,12 +28149,12 @@ var IOBuffer = class _IOBuffer {
|
|
|
28149
28149
|
dataIsGiven = true;
|
|
28150
28150
|
this.lastWrittenByte = data.byteLength;
|
|
28151
28151
|
}
|
|
28152
|
-
const
|
|
28153
|
-
const byteLength = data.byteLength -
|
|
28154
|
-
let dvOffset =
|
|
28152
|
+
const offset2 = options.offset ? options.offset >>> 0 : 0;
|
|
28153
|
+
const byteLength = data.byteLength - offset2;
|
|
28154
|
+
let dvOffset = offset2;
|
|
28155
28155
|
if (ArrayBuffer.isView(data) || data instanceof _IOBuffer) {
|
|
28156
28156
|
if (data.byteLength !== data.buffer.byteLength) {
|
|
28157
|
-
dvOffset = data.byteOffset +
|
|
28157
|
+
dvOffset = data.byteOffset + offset2;
|
|
28158
28158
|
}
|
|
28159
28159
|
data = data.buffer;
|
|
28160
28160
|
}
|
|
@@ -28236,8 +28236,8 @@ var IOBuffer = class _IOBuffer {
|
|
|
28236
28236
|
* @param offset - The offset to move to.
|
|
28237
28237
|
* @returns This.
|
|
28238
28238
|
*/
|
|
28239
|
-
seek(
|
|
28240
|
-
this.offset =
|
|
28239
|
+
seek(offset2) {
|
|
28240
|
+
this.offset = offset2;
|
|
28241
28241
|
return this;
|
|
28242
28242
|
}
|
|
28243
28243
|
/**
|
|
@@ -28274,11 +28274,11 @@ var IOBuffer = class _IOBuffer {
|
|
|
28274
28274
|
* @returns This.
|
|
28275
28275
|
*/
|
|
28276
28276
|
popMark() {
|
|
28277
|
-
const
|
|
28278
|
-
if (
|
|
28277
|
+
const offset2 = this._marks.pop();
|
|
28278
|
+
if (offset2 === void 0) {
|
|
28279
28279
|
throw new Error("Mark stack empty");
|
|
28280
28280
|
}
|
|
28281
|
-
this.seek(
|
|
28281
|
+
this.seek(offset2);
|
|
28282
28282
|
return this;
|
|
28283
28283
|
}
|
|
28284
28284
|
/**
|
|
@@ -28356,10 +28356,10 @@ var IOBuffer = class _IOBuffer {
|
|
|
28356
28356
|
*/
|
|
28357
28357
|
readArray(size2, type) {
|
|
28358
28358
|
const bytes = typedArrays[type].BYTES_PER_ELEMENT * size2;
|
|
28359
|
-
const
|
|
28360
|
-
const slice = this.buffer.slice(
|
|
28359
|
+
const offset2 = this.byteOffset + this.offset;
|
|
28360
|
+
const slice = this.buffer.slice(offset2, offset2 + bytes);
|
|
28361
28361
|
if (this.littleEndian === hostBigEndian && type !== "uint8" && type !== "int8") {
|
|
28362
|
-
const slice2 = new Uint8Array(this.buffer.slice(
|
|
28362
|
+
const slice2 = new Uint8Array(this.buffer.slice(offset2, offset2 + bytes));
|
|
28363
28363
|
slice2.reverse();
|
|
28364
28364
|
const returnArray2 = new typedArrays[type](slice2.buffer);
|
|
28365
28365
|
this.offset += bytes;
|
|
@@ -33063,7 +33063,7 @@ function decodeInterlaceAdam7(params) {
|
|
|
33063
33063
|
];
|
|
33064
33064
|
const bytesPerPixel = Math.ceil(depth / 8) * channels;
|
|
33065
33065
|
const resultData = new Uint8Array(height * width * bytesPerPixel);
|
|
33066
|
-
let
|
|
33066
|
+
let offset2 = 0;
|
|
33067
33067
|
for (let passIndex = 0; passIndex < 7; passIndex++) {
|
|
33068
33068
|
const pass = passes[passIndex];
|
|
33069
33069
|
const passWidth = Math.ceil((width - pass.x) / pass.xStep);
|
|
@@ -33073,9 +33073,9 @@ function decodeInterlaceAdam7(params) {
|
|
|
33073
33073
|
const passLineBytes = passWidth * bytesPerPixel;
|
|
33074
33074
|
const prevLine = new Uint8Array(passLineBytes);
|
|
33075
33075
|
for (let y3 = 0; y3 < passHeight; y3++) {
|
|
33076
|
-
const filterType = data[
|
|
33077
|
-
const currentLine = data.subarray(
|
|
33078
|
-
|
|
33076
|
+
const filterType = data[offset2++];
|
|
33077
|
+
const currentLine = data.subarray(offset2, offset2 + passLineBytes);
|
|
33078
|
+
offset2 += passLineBytes;
|
|
33079
33079
|
const newLine = new Uint8Array(passLineBytes);
|
|
33080
33080
|
applyUnfilter(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
|
|
33081
33081
|
prevLine.set(newLine);
|
|
@@ -33117,13 +33117,13 @@ function decodeInterlaceNull(params) {
|
|
|
33117
33117
|
const bytesPerLine = Math.ceil(depth / 8 * channels * width);
|
|
33118
33118
|
const newData = new Uint8Array(height * bytesPerLine);
|
|
33119
33119
|
let prevLine = empty;
|
|
33120
|
-
let
|
|
33120
|
+
let offset2 = 0;
|
|
33121
33121
|
let currentLine;
|
|
33122
33122
|
let newLine;
|
|
33123
33123
|
for (let i4 = 0; i4 < height; i4++) {
|
|
33124
|
-
currentLine = data.subarray(
|
|
33124
|
+
currentLine = data.subarray(offset2 + 1, offset2 + 1 + bytesPerLine);
|
|
33125
33125
|
newLine = newData.subarray(i4 * bytesPerLine, (i4 + 1) * bytesPerLine);
|
|
33126
|
-
switch (data[
|
|
33126
|
+
switch (data[offset2]) {
|
|
33127
33127
|
case 0:
|
|
33128
33128
|
unfilterNone(currentLine, newLine, bytesPerLine);
|
|
33129
33129
|
break;
|
|
@@ -33140,10 +33140,10 @@ function decodeInterlaceNull(params) {
|
|
|
33140
33140
|
unfilterPaeth(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);
|
|
33141
33141
|
break;
|
|
33142
33142
|
default:
|
|
33143
|
-
throw new Error(`Unsupported filter: ${data[
|
|
33143
|
+
throw new Error(`Unsupported filter: ${data[offset2]}`);
|
|
33144
33144
|
}
|
|
33145
33145
|
prevLine = newLine;
|
|
33146
|
-
|
|
33146
|
+
offset2 += bytesPerLine + 1;
|
|
33147
33147
|
}
|
|
33148
33148
|
if (depth === 16) {
|
|
33149
33149
|
const uint16Data = new Uint16Array(newData.buffer);
|
|
@@ -33328,7 +33328,7 @@ var PngDecoder = class extends IOBuffer {
|
|
|
33328
33328
|
}
|
|
33329
33329
|
// https://www.w3.org/TR/PNG/#5Chunk-layout
|
|
33330
33330
|
decodeChunk(length, type) {
|
|
33331
|
-
const
|
|
33331
|
+
const offset2 = this.offset;
|
|
33332
33332
|
switch (type) {
|
|
33333
33333
|
// 11.2 Critical chunks
|
|
33334
33334
|
case "IHDR":
|
|
@@ -33360,7 +33360,7 @@ var PngDecoder = class extends IOBuffer {
|
|
|
33360
33360
|
this.skip(length);
|
|
33361
33361
|
break;
|
|
33362
33362
|
}
|
|
33363
|
-
if (this.offset -
|
|
33363
|
+
if (this.offset - offset2 !== length) {
|
|
33364
33364
|
throw new Error(`Length mismatch while decoding chunk ${type}`);
|
|
33365
33365
|
}
|
|
33366
33366
|
if (this._checkCrc) {
|
|
@@ -33370,7 +33370,7 @@ var PngDecoder = class extends IOBuffer {
|
|
|
33370
33370
|
}
|
|
33371
33371
|
}
|
|
33372
33372
|
decodeApngChunk(length, type) {
|
|
33373
|
-
const
|
|
33373
|
+
const offset2 = this.offset;
|
|
33374
33374
|
if (type !== "fdAT" && type !== "IDAT" && this._writingDataChunks) {
|
|
33375
33375
|
this.pushDataToFrame();
|
|
33376
33376
|
}
|
|
@@ -33386,10 +33386,10 @@ var PngDecoder = class extends IOBuffer {
|
|
|
33386
33386
|
break;
|
|
33387
33387
|
default:
|
|
33388
33388
|
this.decodeChunk(length, type);
|
|
33389
|
-
this.offset =
|
|
33389
|
+
this.offset = offset2 + length;
|
|
33390
33390
|
break;
|
|
33391
33391
|
}
|
|
33392
|
-
if (this.offset -
|
|
33392
|
+
if (this.offset - offset2 !== length) {
|
|
33393
33393
|
throw new Error(`Length mismatch while decoding chunk ${type}`);
|
|
33394
33394
|
}
|
|
33395
33395
|
if (this._checkCrc) {
|
|
@@ -42723,10 +42723,12 @@ function createChatbotClient(options = {}) {
|
|
|
42723
42723
|
var TevrocClient = class {
|
|
42724
42724
|
constructor(options = {}) {
|
|
42725
42725
|
const baseUrl = options.baseUrl ?? options.url;
|
|
42726
|
-
const serviceUrl = options.serviceUrl ?? options.url;
|
|
42726
|
+
const serviceUrl = options.serviceUrl ?? options.url ?? baseUrl;
|
|
42727
|
+
const vpsUrl = options.vpsUrl ?? serviceUrl;
|
|
42727
42728
|
if (!baseUrl) throw new TypeError("createClient requires a baseUrl");
|
|
42728
42729
|
this.baseUrl = normalizeBaseUrl(baseUrl);
|
|
42729
42730
|
this.serviceUrl = normalizeBaseUrl(serviceUrl);
|
|
42731
|
+
this.vpsUrl = normalizeBaseUrl(vpsUrl);
|
|
42730
42732
|
this.appId = options.appId;
|
|
42731
42733
|
this.appName = options.appName;
|
|
42732
42734
|
this.payAccount = options.payAccount ?? "default";
|
|
@@ -43822,29 +43824,6 @@ function base64ToBlob(base64, contentType = "application/octet-stream") {
|
|
|
43822
43824
|
}
|
|
43823
43825
|
return new Blob([bytes], { type: contentType });
|
|
43824
43826
|
}
|
|
43825
|
-
function arrayBufferToBase64(buffer) {
|
|
43826
|
-
let binary = "";
|
|
43827
|
-
const bytes = new Uint8Array(buffer);
|
|
43828
|
-
const chunkSize = 32768;
|
|
43829
|
-
for (let i4 = 0; i4 < bytes.length; i4 += chunkSize) {
|
|
43830
|
-
const chunk = bytes.subarray(i4, i4 + chunkSize);
|
|
43831
|
-
binary += String.fromCharCode.apply(null, chunk);
|
|
43832
|
-
}
|
|
43833
|
-
return btoa(binary);
|
|
43834
|
-
}
|
|
43835
|
-
async function normalizeUploadBody(file) {
|
|
43836
|
-
if (typeof Blob !== "undefined" && file instanceof Blob) {
|
|
43837
|
-
return { data: await blobToBase643(file), contentType: file.type || "application/octet-stream", bodyIsBase64: true };
|
|
43838
|
-
}
|
|
43839
|
-
if (file && typeof file.arrayBuffer === "function") {
|
|
43840
|
-
const buffer = await file.arrayBuffer();
|
|
43841
|
-
return { data: arrayBufferToBase64(buffer), contentType: "application/octet-stream", bodyIsBase64: true };
|
|
43842
|
-
}
|
|
43843
|
-
if (typeof file === "string") {
|
|
43844
|
-
return { data: file, contentType: "text/plain", bodyIsBase64: false };
|
|
43845
|
-
}
|
|
43846
|
-
return { data: JSON.stringify(file), contentType: "application/json", bodyIsBase64: false };
|
|
43847
|
-
}
|
|
43848
43827
|
function createFileApi(client) {
|
|
43849
43828
|
return {
|
|
43850
43829
|
url: async (key) => {
|
|
@@ -43980,34 +43959,174 @@ function createFileApi(client) {
|
|
|
43980
43959
|
};
|
|
43981
43960
|
}
|
|
43982
43961
|
async function upload(client, path, file, options = {}) {
|
|
43983
|
-
const
|
|
43984
|
-
if (
|
|
43985
|
-
|
|
43986
|
-
|
|
43987
|
-
|
|
43988
|
-
|
|
43989
|
-
|
|
43990
|
-
|
|
43991
|
-
|
|
43992
|
-
|
|
43962
|
+
const isElectron = await detectElectronEnvironment(client);
|
|
43963
|
+
if (isElectron) {
|
|
43964
|
+
return uploadViaElectronBridge(client, file, options);
|
|
43965
|
+
}
|
|
43966
|
+
return uploadViaGoogleStorage(client, file, { ...options, path });
|
|
43967
|
+
}
|
|
43968
|
+
async function detectElectronEnvironment(client) {
|
|
43969
|
+
try {
|
|
43970
|
+
const serviceUrl = String(client?.serviceUrl || "").replace(/\/$/, "");
|
|
43971
|
+
const response = await client.fetch(`${serviceUrl}/api/environment`, {
|
|
43972
|
+
method: "GET",
|
|
43973
|
+
headers: { Accept: "application/json" },
|
|
43974
|
+
cache: "no-store"
|
|
43975
|
+
});
|
|
43976
|
+
if (response && response.ok) {
|
|
43977
|
+
const data = await response.json();
|
|
43978
|
+
if (data && typeof data === "object" && "isElectron" in data) {
|
|
43979
|
+
return Boolean(data.isElectron);
|
|
43980
|
+
}
|
|
43981
|
+
}
|
|
43982
|
+
} catch (error) {
|
|
43983
|
+
console.debug("[tevrocsdk][env] /api/environment fallback", error);
|
|
43984
|
+
}
|
|
43985
|
+
if (typeof navigator !== "undefined") {
|
|
43986
|
+
const userAgent = navigator.userAgent || "";
|
|
43987
|
+
if (/electron/i.test(userAgent)) return true;
|
|
43988
|
+
}
|
|
43989
|
+
if (typeof window !== "undefined") {
|
|
43990
|
+
const bridge = window?.bridge || window?.electronBridge || window?.nativeBridge;
|
|
43991
|
+
if (bridge) return true;
|
|
43992
|
+
if (window.process && window.process.versions && window.process.versions.electron) return true;
|
|
43993
|
+
}
|
|
43994
|
+
return false;
|
|
43995
|
+
}
|
|
43996
|
+
async function uploadViaElectronBridge(client, file, options = {}) {
|
|
43997
|
+
const fileName = options.filename || "upload";
|
|
43998
|
+
const contentType = options.contentType || "application/octet-stream";
|
|
43999
|
+
const resolvedFile = file instanceof Blob ? file : new Blob([String(file ?? "")], { type: contentType });
|
|
44000
|
+
const dataUrl = resolvedFile instanceof Blob ? `data:${contentType};base64,${await blobToBase643(resolvedFile)}` : String(file);
|
|
44001
|
+
const packetSize = options.packetSize || 1024 * 1024;
|
|
44002
|
+
const packets = [];
|
|
44003
|
+
for (let offset2 = 0; offset2 < dataUrl.length; offset2 += packetSize) {
|
|
44004
|
+
const packetData2 = dataUrl.slice(offset2, offset2 + packetSize);
|
|
44005
|
+
packets.push({
|
|
44006
|
+
packetId: packets.length,
|
|
44007
|
+
packetData: encodeURIComponent(packetData2),
|
|
44008
|
+
isLastPacket: offset2 + packetSize >= dataUrl.length,
|
|
44009
|
+
filePanaroma: options.filePanaroma || "NO"
|
|
44010
|
+
});
|
|
44011
|
+
}
|
|
44012
|
+
if (!packets.length) throw new TevrocError("Cannot upload an empty file", { code: "empty_file" });
|
|
44013
|
+
let clientId = "";
|
|
44014
|
+
const endpoint = `${client.serviceUrl.replace(/\/$/, "")}/receivePacket`;
|
|
44015
|
+
for (const packet of packets) {
|
|
44016
|
+
const payload = {
|
|
44017
|
+
...packet,
|
|
44018
|
+
clientId,
|
|
44019
|
+
tableName: options.tableName || "",
|
|
44020
|
+
tableIdx: options.tableIdx ?? "",
|
|
44021
|
+
tableGallery: options.gallery === true || options.gallery === "YES",
|
|
44022
|
+
fileName,
|
|
44023
|
+
fileSize: resolvedFile.size,
|
|
44024
|
+
fileMime: contentType,
|
|
44025
|
+
server: options.server || "test",
|
|
44026
|
+
session: options.session || client.token || ""
|
|
44027
|
+
};
|
|
44028
|
+
let result;
|
|
44029
|
+
const bridge = typeof window !== "undefined" ? window : null;
|
|
44030
|
+
if (bridge && typeof bridge.syncRequest === "function") {
|
|
44031
|
+
const rawResult = bridge.syncRequest(endpoint, "POST", payload);
|
|
44032
|
+
if (!rawResult) throw new TevrocError("Electron upload failed", { code: "electron_upload_failed" });
|
|
44033
|
+
try {
|
|
44034
|
+
result = JSON.parse(rawResult);
|
|
44035
|
+
} catch (error) {
|
|
44036
|
+
throw new TevrocError("Electron upload returned invalid JSON", { code: "electron_upload_failed" });
|
|
44037
|
+
}
|
|
44038
|
+
} else {
|
|
44039
|
+
const response = await client.fetch(endpoint, {
|
|
43993
44040
|
method: "POST",
|
|
43994
|
-
headers,
|
|
43995
|
-
body:
|
|
43996
|
-
|
|
43997
|
-
|
|
43998
|
-
|
|
43999
|
-
|
|
44000
|
-
}
|
|
44001
|
-
|
|
44002
|
-
|
|
44003
|
-
|
|
44041
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
44042
|
+
body: JSON.stringify(payload)
|
|
44043
|
+
});
|
|
44044
|
+
if (!response.ok) {
|
|
44045
|
+
const text2 = await response.text();
|
|
44046
|
+
throw new TevrocError(text2 || "Electron upload failed", { status: response.status, code: "electron_upload_failed" });
|
|
44047
|
+
}
|
|
44048
|
+
result = await response.json();
|
|
44049
|
+
}
|
|
44050
|
+
clientId = result.clientId || clientId;
|
|
44051
|
+
if (typeof options.onProgress === "function") {
|
|
44052
|
+
options.onProgress({ uploaded: Math.min(offset + packetData.length, dataUrl.length), total: dataUrl.length, progress: Math.round((offset + packetData.length) / dataUrl.length * 100) });
|
|
44053
|
+
}
|
|
44054
|
+
}
|
|
44055
|
+
return { success: true, clientId, fileName, fileSize: resolvedFile.size, runtime: "electron" };
|
|
44056
|
+
}
|
|
44057
|
+
async function uploadViaGoogleStorage(client, file, options = {}) {
|
|
44058
|
+
const contentType = options.contentType || "application/octet-stream";
|
|
44059
|
+
const fileName = options.filename || "upload";
|
|
44060
|
+
const body = file instanceof Blob ? file : new Blob([String(file ?? "")], { type: contentType });
|
|
44061
|
+
const serviceUrl = client.serviceUrl.replace(/\/$/, "");
|
|
44062
|
+
const initResponse = await client.fetch(`${serviceUrl}/api/uploads/create`, {
|
|
44063
|
+
method: "POST",
|
|
44064
|
+
headers: {
|
|
44065
|
+
"Content-Type": "application/json",
|
|
44066
|
+
Accept: "application/json"
|
|
44067
|
+
},
|
|
44068
|
+
body: JSON.stringify({
|
|
44069
|
+
filename: fileName,
|
|
44070
|
+
contentType,
|
|
44071
|
+
size: body.size,
|
|
44072
|
+
userId: options.userId || "anon"
|
|
44073
|
+
})
|
|
44074
|
+
});
|
|
44075
|
+
if (!initResponse.ok) {
|
|
44076
|
+
const text2 = await initResponse.text();
|
|
44077
|
+
throw new TevrocError(text2 || "Create upload session failed", { status: initResponse.status, code: "gcs_create_failed" });
|
|
44078
|
+
}
|
|
44079
|
+
const init = await initResponse.json();
|
|
44080
|
+
const uploadUrl = init && init.uploadUrl ? init.uploadUrl : null;
|
|
44081
|
+
const uploadId = init && init.uploadId ? init.uploadId : null;
|
|
44082
|
+
if (!uploadUrl || !uploadId) {
|
|
44083
|
+
throw new TevrocError("Google storage upload session is missing uploadUrl or uploadId", { code: "gcs_invalid_session" });
|
|
44084
|
+
}
|
|
44085
|
+
const chunkSize = options.chunkSize || 10 * 1024 * 1024;
|
|
44086
|
+
for (let offset2 = 0; offset2 < body.size; offset2 += chunkSize) {
|
|
44087
|
+
const end = Math.min(offset2 + chunkSize, body.size) - 1;
|
|
44088
|
+
let uploadResponse;
|
|
44089
|
+
for (let attempt = 1; attempt <= (options.retries || 5); attempt += 1) {
|
|
44090
|
+
try {
|
|
44091
|
+
uploadResponse = await client.fetch(uploadUrl, {
|
|
44092
|
+
method: "PUT",
|
|
44093
|
+
body: body.slice(offset2, end + 1),
|
|
44094
|
+
headers: {
|
|
44095
|
+
"Content-Length": String(end - offset2 + 1),
|
|
44096
|
+
"Content-Range": `bytes ${offset2}-${end}/${body.size}`,
|
|
44097
|
+
"Content-Type": contentType
|
|
44098
|
+
}
|
|
44099
|
+
});
|
|
44100
|
+
if (uploadResponse.ok || uploadResponse.status === 308) break;
|
|
44101
|
+
throw new Error(`HTTP ${uploadResponse.status}`);
|
|
44102
|
+
} catch (error) {
|
|
44103
|
+
if (attempt === (options.retries || 5)) throw new TevrocError(error.message, { code: "gcs_upload_failed" });
|
|
44104
|
+
await new Promise((resolve3) => setTimeout(resolve3, 1e3 * attempt));
|
|
44105
|
+
}
|
|
44106
|
+
}
|
|
44107
|
+
if (!uploadResponse || !uploadResponse.ok && uploadResponse.status !== 308) {
|
|
44108
|
+
throw new TevrocError("Google storage upload failed", { code: "gcs_upload_failed" });
|
|
44004
44109
|
}
|
|
44110
|
+
if (typeof options.onProgress === "function") options.onProgress({ uploaded: end + 1, total: body.size, progress: Math.round((end + 1) / body.size * 100) });
|
|
44005
44111
|
}
|
|
44006
|
-
|
|
44007
|
-
|
|
44112
|
+
const finalizeResponse = await client.fetch(`${serviceUrl}/api/uploads/${encodeURIComponent(uploadId)}/complete`, {
|
|
44113
|
+
method: "POST",
|
|
44114
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
44115
|
+
body: JSON.stringify({ storageKey: init.storageKey, userId: options.userId || "anon" })
|
|
44116
|
+
});
|
|
44117
|
+
if (!finalizeResponse.ok) {
|
|
44118
|
+
const text2 = await finalizeResponse.text();
|
|
44119
|
+
throw new TevrocError(text2 || "Finalize upload failed", { status: finalizeResponse.status, code: "gcs_finalize_failed" });
|
|
44120
|
+
}
|
|
44121
|
+
const result = await finalizeResponse.json();
|
|
44122
|
+
if (options.tableName && options.tableIdx !== void 0) {
|
|
44123
|
+
await client.fetch(`${serviceUrl}/api/files/gcs-store`, {
|
|
44124
|
+
method: "POST",
|
|
44125
|
+
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
|
44126
|
+
body: JSON.stringify({ storageKey: result.storageKey || init.storageKey, tableName: options.tableName, tableIdx: options.tableIdx, fileName, fileSize: body.size, fileMime: contentType, gallery: options.gallery ? "YES" : "NO", filePanaroma: options.filePanaroma || "NO" })
|
|
44127
|
+
});
|
|
44008
44128
|
}
|
|
44009
|
-
|
|
44010
|
-
return result;
|
|
44129
|
+
return { ...result, runtime: "gcs" };
|
|
44011
44130
|
}
|
|
44012
44131
|
async function parseResponse(response, parseAs) {
|
|
44013
44132
|
if (parseAs === "response") return response;
|
|
@@ -44277,3 +44396,4 @@ jspdf/dist/jspdf.es.min.js:
|
|
|
44277
44396
|
* ====================================================================
|
|
44278
44397
|
*)
|
|
44279
44398
|
*/
|
|
44399
|
+
//# sourceMappingURL=tevroc-sdk.esm.js.map
|