@sogni-ai/sogni-client 5.84.1 → 5.84.2
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/CHANGELOG.md +7 -0
- package/dist/Projects/index.js +8 -0
- package/dist/Projects/index.js.map +1 -1
- package/dist/Projects/utils/imageUploadBody.d.ts +14 -0
- package/dist/Projects/utils/imageUploadBody.js +88 -0
- package/dist/Projects/utils/imageUploadBody.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist-esm/Projects/index.js +8 -0
- package/dist-esm/Projects/index.js.map +1 -1
- package/dist-esm/Projects/utils/imageUploadBody.js +85 -0
- package/dist-esm/Projects/utils/imageUploadBody.js.map +1 -0
- package/dist-esm/version.js +1 -1
- package/package.json +2 -1
- package/src/Projects/index.ts +8 -0
- package/src/Projects/utils/imageUploadBody.ts +68 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.assertImageUploadBody = assertImageUploadBody;
|
|
13
|
+
const index_js_1 = require("../../ApiClient/index.js");
|
|
14
|
+
/**
|
|
15
|
+
* Refuse an image-slot upload whose contents are text instead of image bytes.
|
|
16
|
+
*
|
|
17
|
+
* An image slot that receives text instead of an image (a file path string,
|
|
18
|
+
* a fetched HTML page, or base64 text) cannot be decoded, so the job fails
|
|
19
|
+
* after it has been submitted. Checking the leading bytes here turns that
|
|
20
|
+
* into an error that names the slot, before any upload URL, upload or job
|
|
21
|
+
* request.
|
|
22
|
+
*
|
|
23
|
+
* Only contents that cannot be an image are refused: a `data:` URL, an HTML
|
|
24
|
+
* page, base64 text, or a string that is not markup. Image bytes, SVG markup
|
|
25
|
+
* and anything this check does not recognise upload as before.
|
|
26
|
+
*/
|
|
27
|
+
function assertImageUploadBody(file, slot) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const found = yield describeTextBody(file);
|
|
30
|
+
if (!found)
|
|
31
|
+
return;
|
|
32
|
+
throw new index_js_1.ApiError(400, {
|
|
33
|
+
status: 'error',
|
|
34
|
+
errorCode: 0,
|
|
35
|
+
message: `${slot} is not image data: ${found}. Upload the image file itself.`
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Enough leading bytes for an HTML doctype after a byte-order mark and some whitespace. */
|
|
40
|
+
const SNIFF_BYTES = 64;
|
|
41
|
+
/** Sixteen base64 characters: no binary image header is made only of them. */
|
|
42
|
+
const BASE64_HEAD = /^[A-Za-z0-9+/]{16}/;
|
|
43
|
+
const DATA_URL_HEAD = /^data:/i;
|
|
44
|
+
/** UTF-8 byte-order mark, read either as one character or as its three bytes. */
|
|
45
|
+
const HTML_HEAD = /^(?:|\xef\xbb\xbf)?\s*<(?:!doctype\s+html|html[\s>])/i;
|
|
46
|
+
const MARKUP_HEAD = /^(?:|\xef\xbb\xbf)?\s*</;
|
|
47
|
+
function describeTextBody(file) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
var _a;
|
|
50
|
+
if (typeof file === 'string') {
|
|
51
|
+
const head = file.slice(0, SNIFF_BYTES);
|
|
52
|
+
// SVG markup is text and still uploads; any other string is not an image.
|
|
53
|
+
return (_a = describeHead(head)) !== null && _a !== void 0 ? _a : (MARKUP_HEAD.test(head) ? null : 'it is a string, not the file');
|
|
54
|
+
}
|
|
55
|
+
const bytes = yield leadingBytes(file);
|
|
56
|
+
return bytes ? describeHead(String.fromCharCode(...bytes)) : null;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function leadingBytes(file) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
try {
|
|
62
|
+
if (typeof Blob !== 'undefined' && file instanceof Blob) {
|
|
63
|
+
return new Uint8Array(yield file.slice(0, SNIFF_BYTES).arrayBuffer());
|
|
64
|
+
}
|
|
65
|
+
if (ArrayBuffer.isView(file)) {
|
|
66
|
+
return new Uint8Array(file.buffer, file.byteOffset, Math.min(file.byteLength, SNIFF_BYTES));
|
|
67
|
+
}
|
|
68
|
+
if (file instanceof ArrayBuffer) {
|
|
69
|
+
return new Uint8Array(file, 0, Math.min(file.byteLength, SNIFF_BYTES));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (_a) {
|
|
73
|
+
// A file that can no longer be read fails at the upload, as it always has.
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function describeHead(head) {
|
|
79
|
+
if (DATA_URL_HEAD.test(head))
|
|
80
|
+
return 'its contents are a data: URL';
|
|
81
|
+
if (HTML_HEAD.test(head))
|
|
82
|
+
return 'its contents are an HTML page';
|
|
83
|
+
// GIF's signature is letters and digits, and its size bytes can be too.
|
|
84
|
+
if (!head.startsWith('GIF8') && BASE64_HEAD.test(head))
|
|
85
|
+
return 'its contents are base64 text';
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=imageUploadBody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageUploadBody.js","sourceRoot":"","sources":["../../../src/Projects/utils/imageUploadBody.ts"],"names":[],"mappings":";;;;;;;;;;;AAeA,sD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K,WAAW,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;gBACxD,OAAO,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;YACxE,CAAC;YACD,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7B,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;YAC9F,CAAC;YACD,IAAI,IAAI,YAAY,WAAW,EAAE,CAAC;gBAChC,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QAAC,WAAM,CAAC;YACP,2EAA2E;QAC7E,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CAAA;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,8BAA8B,CAAC;IACpE,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,+BAA+B,CAAC;IACjE,wEAAwE;IACxE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,8BAA8B,CAAC;IAC9F,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "5.84.
|
|
1
|
+
export declare const LIB_VERSION = "5.84.2";
|
package/dist/version.js
CHANGED
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LIB_VERSION = void 0;
|
|
4
4
|
// AUTO-GENERATED by scripts/generate-version.mjs — do not edit.
|
|
5
5
|
// Source of truth: package.json version.
|
|
6
|
-
exports.LIB_VERSION = '5.84.
|
|
6
|
+
exports.LIB_VERSION = '5.84.2';
|
|
7
7
|
//# sourceMappingURL=version.js.map
|
|
@@ -26,6 +26,7 @@ import Cache from '../lib/Cache.js';
|
|
|
26
26
|
import { enhancementDefaults, seedanceDraftResultFields } from './Job.js';
|
|
27
27
|
import { calculateVideoFrames, getEnhacementStrength, getVideoAssetRequirements, getVideoContextImageSlots, getPixal3dOrbitViewSlots, getMinimaxH3KeyframeSlots, getMinimaxH3ReferenceAudioSlots, getMinimaxH3ReferenceVideoSlots, getVideoWorkflowType, asResultMediaKind, isAudioModel, isModelArtifactModel, isMinimaxH3ReferenceModel, isSegmentationModel, isVideoModel, resultMediaEvidence, usesReferenceMask } from './utils/index.js';
|
|
28
28
|
import { getFileContentType } from './utils/fileContentType.js';
|
|
29
|
+
import { assertImageUploadBody } from './utils/imageUploadBody.js';
|
|
29
30
|
import { imageLayersFromResult } from './utils/imageLayers.js';
|
|
30
31
|
import { getMaxContextImages, validateSampler, isGptImageModel, resolveGptImageGifSize } from '../lib/validation.js';
|
|
31
32
|
import { isAudioTier, isComfyImageTier, isImageTier, isVideoTier } from './types/ModelTiersRaw.js';
|
|
@@ -2755,6 +2756,7 @@ class ProjectsApi extends ApiGroup {
|
|
|
2755
2756
|
const imageId = getUUID();
|
|
2756
2757
|
const assertSession = (_a = this._preparingSessions.get(projectId)) !== null && _a !== void 0 ? _a : captureRequestSession(this.client.auth);
|
|
2757
2758
|
assertSession();
|
|
2759
|
+
yield assertImageUploadBody(file, 'Guide image');
|
|
2758
2760
|
const contentType = getFileContentType(file);
|
|
2759
2761
|
if (yield this._bindSavedUpload(file, contentType, { projectId, type: 'startingImage' }))
|
|
2760
2762
|
return imageId;
|
|
@@ -2791,6 +2793,7 @@ class ProjectsApi extends ApiGroup {
|
|
|
2791
2793
|
const imageId = getUUID();
|
|
2792
2794
|
const assertSession = (_a = this._preparingSessions.get(projectId)) !== null && _a !== void 0 ? _a : captureRequestSession(this.client.auth);
|
|
2793
2795
|
assertSession();
|
|
2796
|
+
yield assertImageUploadBody(file, 'ControlNet image');
|
|
2794
2797
|
const contentType = getFileContentType(file);
|
|
2795
2798
|
if (yield this._bindSavedUpload(file, contentType, { projectId, type: 'cnImage' }))
|
|
2796
2799
|
return imageId;
|
|
@@ -2828,6 +2831,7 @@ class ProjectsApi extends ApiGroup {
|
|
|
2828
2831
|
const imageIndex = (index + 1);
|
|
2829
2832
|
const assertSession = (_a = this._preparingSessions.get(projectId)) !== null && _a !== void 0 ? _a : captureRequestSession(this.client.auth);
|
|
2830
2833
|
assertSession();
|
|
2834
|
+
yield assertImageUploadBody(file, `Context image ${imageIndex}`);
|
|
2831
2835
|
const contentType = getFileContentType(file);
|
|
2832
2836
|
if (yield this._bindSavedUpload(file, contentType, {
|
|
2833
2837
|
projectId,
|
|
@@ -2874,6 +2878,7 @@ class ProjectsApi extends ApiGroup {
|
|
|
2874
2878
|
const type = `keyframeImage${slot}`;
|
|
2875
2879
|
const assertSession = (_a = this._preparingSessions.get(projectId)) !== null && _a !== void 0 ? _a : captureRequestSession(this.client.auth);
|
|
2876
2880
|
assertSession();
|
|
2881
|
+
yield assertImageUploadBody(file, `Keyframe image ${slot}`);
|
|
2877
2882
|
const contentType = getFileContentType(file);
|
|
2878
2883
|
if (yield this._bindSavedUpload(file, contentType, { projectId, type }))
|
|
2879
2884
|
return imageId;
|
|
@@ -2912,6 +2917,7 @@ class ProjectsApi extends ApiGroup {
|
|
|
2912
2917
|
const imageId = getUUID();
|
|
2913
2918
|
const assertSession = (_a = this._preparingSessions.get(projectId)) !== null && _a !== void 0 ? _a : captureRequestSession(this.client.auth);
|
|
2914
2919
|
assertSession();
|
|
2920
|
+
yield assertImageUploadBody(file, 'Reference image');
|
|
2915
2921
|
const contentType = getFileContentType(file);
|
|
2916
2922
|
if (yield this._bindSavedUpload(file, contentType, { projectId, type: 'referenceImage' }))
|
|
2917
2923
|
return imageId;
|
|
@@ -2952,6 +2958,7 @@ class ProjectsApi extends ApiGroup {
|
|
|
2952
2958
|
const imageId = getUUID();
|
|
2953
2959
|
const assertSession = (_a = this._preparingSessions.get(projectId)) !== null && _a !== void 0 ? _a : captureRequestSession(this.client.auth);
|
|
2954
2960
|
assertSession();
|
|
2961
|
+
yield assertImageUploadBody(file, 'Reference mask');
|
|
2955
2962
|
const contentType = getFileContentType(file);
|
|
2956
2963
|
if (yield this._bindSavedUpload(file, contentType, { projectId, type: 'referenceMask' }))
|
|
2957
2964
|
return imageId;
|
|
@@ -2992,6 +2999,7 @@ class ProjectsApi extends ApiGroup {
|
|
|
2992
2999
|
const imageId = getUUID();
|
|
2993
3000
|
const assertSession = (_a = this._preparingSessions.get(projectId)) !== null && _a !== void 0 ? _a : captureRequestSession(this.client.auth);
|
|
2994
3001
|
assertSession();
|
|
3002
|
+
yield assertImageUploadBody(file, 'End reference image');
|
|
2995
3003
|
const contentType = getFileContentType(file);
|
|
2996
3004
|
if (yield this._bindSavedUpload(file, contentType, { projectId, type: 'referenceImageEnd' }))
|
|
2997
3005
|
return imageId;
|