@dajiaoai/algeo-sdk 2.4.2 → 2.5.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/README.md +23 -15
- package/dist/algeo-sdk.cjs.js +49 -1
- package/dist/algeo-sdk.esm.js +49 -1
- package/dist/algeo-sdk.umd.js +49 -1
- package/dist/embedded-presentation.d.ts +4 -1
- package/dist/shared.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
npm install @dajiaoai/algeo-sdk
|
|
12
12
|
|
|
13
13
|
# 安装指定版本(推荐生产环境锁定版本)
|
|
14
|
-
npm install @dajiaoai/algeo-sdk@2.
|
|
14
|
+
npm install @dajiaoai/algeo-sdk@2.5.0
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
在 `package.json` 中:
|
|
@@ -19,7 +19,7 @@ npm install @dajiaoai/algeo-sdk@2.0.0
|
|
|
19
19
|
```json
|
|
20
20
|
{
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dajiaoai/algeo-sdk": "2.
|
|
22
|
+
"@dajiaoai/algeo-sdk": "2.5.0" // 精确版本,生产推荐
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
```
|
|
@@ -29,7 +29,7 @@ npm install @dajiaoai/algeo-sdk@2.0.0
|
|
|
29
29
|
```json
|
|
30
30
|
{
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@dajiaoai/algeo-sdk": "^2.
|
|
32
|
+
"@dajiaoai/algeo-sdk": "^2.5.0" // 兼容 2.x 的更新
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
```
|
|
@@ -39,14 +39,14 @@ npm install @dajiaoai/algeo-sdk@2.0.0
|
|
|
39
39
|
**unpkg**:
|
|
40
40
|
|
|
41
41
|
```html
|
|
42
|
-
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@2.
|
|
42
|
+
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@2.5.0/dist/algeo-sdk.umd.js"></script>
|
|
43
43
|
<script src="https://unpkg.com/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.js"></script>
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
**jsDelivr**:
|
|
47
47
|
|
|
48
48
|
```html
|
|
49
|
-
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@2.
|
|
49
|
+
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@2.5.0/dist/algeo-sdk.umd.js"></script>
|
|
50
50
|
<script src="https://cdn.jsdelivr.net/npm/@dajiaoai/algeo-sdk@latest/dist/algeo-sdk.umd.js"></script>
|
|
51
51
|
```
|
|
52
52
|
|
|
@@ -61,6 +61,7 @@ import { createPresentation } from '@dajiaoai/algeo-sdk';
|
|
|
61
61
|
|
|
62
62
|
const container = document.getElementById('algeo-container');
|
|
63
63
|
const presentation = await createPresentation(container, {
|
|
64
|
+
appId: 'YTVJDQZR',
|
|
64
65
|
shareId: '33TA3484',
|
|
65
66
|
});
|
|
66
67
|
|
|
@@ -87,6 +88,7 @@ presentation.switchSlide(1).then(() => console.log('切换画板'));
|
|
|
87
88
|
id="algeo-embed"
|
|
88
89
|
src="https://dajiaoai.com/e/33TA3484"
|
|
89
90
|
allow="fullscreen"
|
|
91
|
+
referrerpolicy="origin"
|
|
90
92
|
></iframe>
|
|
91
93
|
```
|
|
92
94
|
|
|
@@ -94,6 +96,8 @@ presentation.switchSlide(1).then(() => console.log('切换画板'));
|
|
|
94
96
|
|
|
95
97
|
> **全屏支持**:建议在 iframe 上添加 `allow="fullscreen"`,以便内嵌画板使用全屏功能。SDK 方式创建的 iframe 已自动包含此属性。
|
|
96
98
|
|
|
99
|
+
> **Referrer 透传**:SDK 方式创建的 iframe 会自动设置 `referrerpolicy="origin"`,便于内嵌页稳定获取宿主域名信息;若使用直接 iframe 方式,建议手动补上该属性。
|
|
100
|
+
|
|
97
101
|
### 方式三:编辑模式
|
|
98
102
|
|
|
99
103
|
```javascript
|
|
@@ -209,6 +213,8 @@ create(container, {
|
|
|
209
213
|
|
|
210
214
|
演示模式快捷入口。该函数负责真正创建并初始化 `EmbeddedPresentation`。
|
|
211
215
|
|
|
216
|
+
创建成功后,SDK 会额外调用 `https://open.dajiaoai.com/console/api/whitelist/check`,使用 `options.appId` 与当前页面 `hostname` 做白名单校验。若未命中白名单,iframe 仍会完成初始化并呈现页面,`createPresentation` 仍会成功返回实例,但后续 `loadShareById`、`loadFile`、`switchSlide`、`getSlideCount`、`repl` 等演示模式 API 会被拒绝,并在控制台输出包含方法名的错误,便于接入方感知并处理。
|
|
217
|
+
|
|
212
218
|
```javascript
|
|
213
219
|
create(container, {
|
|
214
220
|
mode: 'presentation',
|
|
@@ -253,9 +259,10 @@ type AlgeoCreateOptions =
|
|
|
253
259
|
|
|
254
260
|
**AlgeoPresentationCreateOptions:**
|
|
255
261
|
|
|
256
|
-
| 属性 | 类型 | 默认值 | 说明
|
|
257
|
-
| --------- | -------- | ------ |
|
|
258
|
-
| `
|
|
262
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
263
|
+
| --------- | -------- | ------ | -------------------------------------------------------- |
|
|
264
|
+
| `appId` | `string` | `''` | 演示模式白名单校验使用的应用标识,SDK 会用它请求校验接口 |
|
|
265
|
+
| `shareId` | `string` | `''` | 演示模式初始分享 ID,会映射到 `/e/:id` |
|
|
259
266
|
|
|
260
267
|
默认路径规则:
|
|
261
268
|
|
|
@@ -268,6 +275,7 @@ type AlgeoCreateOptions =
|
|
|
268
275
|
const presentation = await create(container, {
|
|
269
276
|
mode: 'presentation',
|
|
270
277
|
presentation: {
|
|
278
|
+
appId: 'xxxx',
|
|
271
279
|
shareId: '33TA3484',
|
|
272
280
|
},
|
|
273
281
|
});
|
|
@@ -471,10 +479,10 @@ try {
|
|
|
471
479
|
|
|
472
480
|
**常见错误码:**
|
|
473
481
|
|
|
474
|
-
| 错误码 | 说明
|
|
475
|
-
| ------------------ |
|
|
476
|
-
| `IFRAME_NOT_READY` | iframe 未加载完成即调用方法
|
|
477
|
-
| `TIMEOUT` | 请求或初始化超时(30 秒)
|
|
478
|
-
| `DESTROYED` | SDK 已销毁
|
|
479
|
-
| `MISSING_APP_ID` | 编辑模式缺少 `auth.appId`
|
|
480
|
-
| `BAD_REQUEST` | 非法请求(如重复 init
|
|
482
|
+
| 错误码 | 说明 |
|
|
483
|
+
| ------------------ | ------------------------------------------------- |
|
|
484
|
+
| `IFRAME_NOT_READY` | iframe 未加载完成即调用方法 |
|
|
485
|
+
| `TIMEOUT` | 请求或初始化超时(30 秒) |
|
|
486
|
+
| `DESTROYED` | SDK 已销毁 |
|
|
487
|
+
| `MISSING_APP_ID` | 编辑模式缺少 `auth.appId` |
|
|
488
|
+
| `BAD_REQUEST` | 非法请求(如重复 init、演示模式白名单校验未通过) |
|
package/dist/algeo-sdk.cjs.js
CHANGED
|
@@ -3897,7 +3897,7 @@ objectType({
|
|
|
3897
3897
|
});
|
|
3898
3898
|
|
|
3899
3899
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3900
|
-
const VERSION = '2.
|
|
3900
|
+
const VERSION = '2.5.0';
|
|
3901
3901
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3902
3902
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3903
3903
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4073,6 +4073,7 @@ class EmbeddedTarget {
|
|
|
4073
4073
|
iframe.id = 'algeo-embed';
|
|
4074
4074
|
iframe.src = src;
|
|
4075
4075
|
iframe.allow = 'fullscreen';
|
|
4076
|
+
iframe.referrerPolicy = 'origin';
|
|
4076
4077
|
iframe.style.width = '100%';
|
|
4077
4078
|
iframe.style.height = '100%';
|
|
4078
4079
|
iframe.style.border = 'none';
|
|
@@ -4188,7 +4189,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4188
4189
|
acceptsEventMessage() {
|
|
4189
4190
|
return false;
|
|
4190
4191
|
}
|
|
4192
|
+
setWhitelistError(error) {
|
|
4193
|
+
this.whitelistError = error;
|
|
4194
|
+
}
|
|
4195
|
+
ensureWhitelistAccess(methodName) {
|
|
4196
|
+
if (!this.whitelistError) {
|
|
4197
|
+
return;
|
|
4198
|
+
}
|
|
4199
|
+
const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${this.whitelistError.message}`, this.whitelistError.code, this.whitelistError.details);
|
|
4200
|
+
console.error(error);
|
|
4201
|
+
throw error;
|
|
4202
|
+
}
|
|
4191
4203
|
async loadShareById(id) {
|
|
4204
|
+
this.ensureWhitelistAccess('loadShareById');
|
|
4192
4205
|
const result = await this.post('loadShareById', {
|
|
4193
4206
|
id,
|
|
4194
4207
|
});
|
|
@@ -4198,6 +4211,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4198
4211
|
return result;
|
|
4199
4212
|
}
|
|
4200
4213
|
async loadFile(content) {
|
|
4214
|
+
this.ensureWhitelistAccess('loadFile');
|
|
4201
4215
|
const result = await this.post('loadContent', { content });
|
|
4202
4216
|
this.currentContent = content;
|
|
4203
4217
|
this.currentSlideIndex = 0;
|
|
@@ -4205,16 +4219,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4205
4219
|
return result;
|
|
4206
4220
|
}
|
|
4207
4221
|
async switchSlide(index) {
|
|
4222
|
+
this.ensureWhitelistAccess('switchSlide');
|
|
4208
4223
|
const result = await this.post('switchSlide', { index });
|
|
4209
4224
|
this.currentSlideIndex = index;
|
|
4210
4225
|
return result;
|
|
4211
4226
|
}
|
|
4212
4227
|
async getSlideCount() {
|
|
4228
|
+
this.ensureWhitelistAccess('getSlideCount');
|
|
4213
4229
|
const result = await this.post('getSlideCount', {});
|
|
4214
4230
|
this.slideCount = result.count;
|
|
4215
4231
|
return result;
|
|
4216
4232
|
}
|
|
4217
4233
|
async repl(command) {
|
|
4234
|
+
this.ensureWhitelistAccess('repl');
|
|
4218
4235
|
return this.post('repl', { command });
|
|
4219
4236
|
}
|
|
4220
4237
|
}
|
|
@@ -4407,6 +4424,33 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4407
4424
|
}
|
|
4408
4425
|
}
|
|
4409
4426
|
|
|
4427
|
+
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
4428
|
+
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
4429
|
+
async function checkPresentationWhitelist(options) {
|
|
4430
|
+
const appId = options.appId?.trim() ?? '';
|
|
4431
|
+
const host = window.location.host.trim();
|
|
4432
|
+
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
4433
|
+
url.searchParams.set('appId', appId);
|
|
4434
|
+
url.searchParams.set('host', host);
|
|
4435
|
+
let matched = false;
|
|
4436
|
+
try {
|
|
4437
|
+
const response = await fetch(url.toString(), {
|
|
4438
|
+
method: 'GET',
|
|
4439
|
+
cache: 'no-store',
|
|
4440
|
+
});
|
|
4441
|
+
if (response.ok) {
|
|
4442
|
+
const payload = (await response.json());
|
|
4443
|
+
matched = payload.matched === true;
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
catch {
|
|
4447
|
+
matched = false;
|
|
4448
|
+
}
|
|
4449
|
+
if (matched) {
|
|
4450
|
+
return null;
|
|
4451
|
+
}
|
|
4452
|
+
return new AlgeoError(`白名单校验未通过,appId="${appId || '(empty)'}",host="${host || '(empty)'}"。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4453
|
+
}
|
|
4410
4454
|
async function createEditorInstance(container, options = {}, baseUrl) {
|
|
4411
4455
|
const editor = new EmbeddedEditor(container);
|
|
4412
4456
|
await editor.initialize(options, baseUrl);
|
|
@@ -4415,6 +4459,10 @@ async function createEditorInstance(container, options = {}, baseUrl) {
|
|
|
4415
4459
|
async function createPresentationInstance(container, options = {}, baseUrl) {
|
|
4416
4460
|
const presentation = new EmbeddedPresentation(container);
|
|
4417
4461
|
await presentation.initialize(options, baseUrl);
|
|
4462
|
+
const whitelistError = await checkPresentationWhitelist(options);
|
|
4463
|
+
if (whitelistError) {
|
|
4464
|
+
presentation.setWhitelistError(whitelistError);
|
|
4465
|
+
}
|
|
4418
4466
|
return presentation;
|
|
4419
4467
|
}
|
|
4420
4468
|
function createEmbeddedInstance(container, options) {
|
package/dist/algeo-sdk.esm.js
CHANGED
|
@@ -3895,7 +3895,7 @@ objectType({
|
|
|
3895
3895
|
});
|
|
3896
3896
|
|
|
3897
3897
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3898
|
-
const VERSION = '2.
|
|
3898
|
+
const VERSION = '2.5.0';
|
|
3899
3899
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3900
3900
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3901
3901
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4071,6 +4071,7 @@ class EmbeddedTarget {
|
|
|
4071
4071
|
iframe.id = 'algeo-embed';
|
|
4072
4072
|
iframe.src = src;
|
|
4073
4073
|
iframe.allow = 'fullscreen';
|
|
4074
|
+
iframe.referrerPolicy = 'origin';
|
|
4074
4075
|
iframe.style.width = '100%';
|
|
4075
4076
|
iframe.style.height = '100%';
|
|
4076
4077
|
iframe.style.border = 'none';
|
|
@@ -4186,7 +4187,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4186
4187
|
acceptsEventMessage() {
|
|
4187
4188
|
return false;
|
|
4188
4189
|
}
|
|
4190
|
+
setWhitelistError(error) {
|
|
4191
|
+
this.whitelistError = error;
|
|
4192
|
+
}
|
|
4193
|
+
ensureWhitelistAccess(methodName) {
|
|
4194
|
+
if (!this.whitelistError) {
|
|
4195
|
+
return;
|
|
4196
|
+
}
|
|
4197
|
+
const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${this.whitelistError.message}`, this.whitelistError.code, this.whitelistError.details);
|
|
4198
|
+
console.error(error);
|
|
4199
|
+
throw error;
|
|
4200
|
+
}
|
|
4189
4201
|
async loadShareById(id) {
|
|
4202
|
+
this.ensureWhitelistAccess('loadShareById');
|
|
4190
4203
|
const result = await this.post('loadShareById', {
|
|
4191
4204
|
id,
|
|
4192
4205
|
});
|
|
@@ -4196,6 +4209,7 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4196
4209
|
return result;
|
|
4197
4210
|
}
|
|
4198
4211
|
async loadFile(content) {
|
|
4212
|
+
this.ensureWhitelistAccess('loadFile');
|
|
4199
4213
|
const result = await this.post('loadContent', { content });
|
|
4200
4214
|
this.currentContent = content;
|
|
4201
4215
|
this.currentSlideIndex = 0;
|
|
@@ -4203,16 +4217,19 @@ class EmbeddedPresentation extends EmbeddedTarget {
|
|
|
4203
4217
|
return result;
|
|
4204
4218
|
}
|
|
4205
4219
|
async switchSlide(index) {
|
|
4220
|
+
this.ensureWhitelistAccess('switchSlide');
|
|
4206
4221
|
const result = await this.post('switchSlide', { index });
|
|
4207
4222
|
this.currentSlideIndex = index;
|
|
4208
4223
|
return result;
|
|
4209
4224
|
}
|
|
4210
4225
|
async getSlideCount() {
|
|
4226
|
+
this.ensureWhitelistAccess('getSlideCount');
|
|
4211
4227
|
const result = await this.post('getSlideCount', {});
|
|
4212
4228
|
this.slideCount = result.count;
|
|
4213
4229
|
return result;
|
|
4214
4230
|
}
|
|
4215
4231
|
async repl(command) {
|
|
4232
|
+
this.ensureWhitelistAccess('repl');
|
|
4216
4233
|
return this.post('repl', { command });
|
|
4217
4234
|
}
|
|
4218
4235
|
}
|
|
@@ -4405,6 +4422,33 @@ class EmbeddedEditor extends EmbeddedTarget {
|
|
|
4405
4422
|
}
|
|
4406
4423
|
}
|
|
4407
4424
|
|
|
4425
|
+
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
4426
|
+
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
4427
|
+
async function checkPresentationWhitelist(options) {
|
|
4428
|
+
const appId = options.appId?.trim() ?? '';
|
|
4429
|
+
const host = window.location.host.trim();
|
|
4430
|
+
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
4431
|
+
url.searchParams.set('appId', appId);
|
|
4432
|
+
url.searchParams.set('host', host);
|
|
4433
|
+
let matched = false;
|
|
4434
|
+
try {
|
|
4435
|
+
const response = await fetch(url.toString(), {
|
|
4436
|
+
method: 'GET',
|
|
4437
|
+
cache: 'no-store',
|
|
4438
|
+
});
|
|
4439
|
+
if (response.ok) {
|
|
4440
|
+
const payload = (await response.json());
|
|
4441
|
+
matched = payload.matched === true;
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4444
|
+
catch {
|
|
4445
|
+
matched = false;
|
|
4446
|
+
}
|
|
4447
|
+
if (matched) {
|
|
4448
|
+
return null;
|
|
4449
|
+
}
|
|
4450
|
+
return new AlgeoError(`白名单校验未通过,appId="${appId || '(empty)'}",host="${host || '(empty)'}"。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4451
|
+
}
|
|
4408
4452
|
async function createEditorInstance(container, options = {}, baseUrl) {
|
|
4409
4453
|
const editor = new EmbeddedEditor(container);
|
|
4410
4454
|
await editor.initialize(options, baseUrl);
|
|
@@ -4413,6 +4457,10 @@ async function createEditorInstance(container, options = {}, baseUrl) {
|
|
|
4413
4457
|
async function createPresentationInstance(container, options = {}, baseUrl) {
|
|
4414
4458
|
const presentation = new EmbeddedPresentation(container);
|
|
4415
4459
|
await presentation.initialize(options, baseUrl);
|
|
4460
|
+
const whitelistError = await checkPresentationWhitelist(options);
|
|
4461
|
+
if (whitelistError) {
|
|
4462
|
+
presentation.setWhitelistError(whitelistError);
|
|
4463
|
+
}
|
|
4416
4464
|
return presentation;
|
|
4417
4465
|
}
|
|
4418
4466
|
function createEmbeddedInstance(container, options) {
|
package/dist/algeo-sdk.umd.js
CHANGED
|
@@ -3901,7 +3901,7 @@
|
|
|
3901
3901
|
});
|
|
3902
3902
|
|
|
3903
3903
|
/** SDK 版本号,构建时由 rollup 注入 */
|
|
3904
|
-
const VERSION = '2.
|
|
3904
|
+
const VERSION = '2.5.0';
|
|
3905
3905
|
const DEFAULT_EMBED_BASE = 'https://dajiaoai.com';
|
|
3906
3906
|
const DEFAULT_PRESENTATION_PATH = '/e';
|
|
3907
3907
|
const DEFAULT_EDITOR_PATH = '/embed/edit';
|
|
@@ -4077,6 +4077,7 @@
|
|
|
4077
4077
|
iframe.id = 'algeo-embed';
|
|
4078
4078
|
iframe.src = src;
|
|
4079
4079
|
iframe.allow = 'fullscreen';
|
|
4080
|
+
iframe.referrerPolicy = 'origin';
|
|
4080
4081
|
iframe.style.width = '100%';
|
|
4081
4082
|
iframe.style.height = '100%';
|
|
4082
4083
|
iframe.style.border = 'none';
|
|
@@ -4192,7 +4193,19 @@
|
|
|
4192
4193
|
acceptsEventMessage() {
|
|
4193
4194
|
return false;
|
|
4194
4195
|
}
|
|
4196
|
+
setWhitelistError(error) {
|
|
4197
|
+
this.whitelistError = error;
|
|
4198
|
+
}
|
|
4199
|
+
ensureWhitelistAccess(methodName) {
|
|
4200
|
+
if (!this.whitelistError) {
|
|
4201
|
+
return;
|
|
4202
|
+
}
|
|
4203
|
+
const error = new AlgeoError(`演示模式调用 ${methodName} 被白名单限制。${this.whitelistError.message}`, this.whitelistError.code, this.whitelistError.details);
|
|
4204
|
+
console.error(error);
|
|
4205
|
+
throw error;
|
|
4206
|
+
}
|
|
4195
4207
|
async loadShareById(id) {
|
|
4208
|
+
this.ensureWhitelistAccess('loadShareById');
|
|
4196
4209
|
const result = await this.post('loadShareById', {
|
|
4197
4210
|
id,
|
|
4198
4211
|
});
|
|
@@ -4202,6 +4215,7 @@
|
|
|
4202
4215
|
return result;
|
|
4203
4216
|
}
|
|
4204
4217
|
async loadFile(content) {
|
|
4218
|
+
this.ensureWhitelistAccess('loadFile');
|
|
4205
4219
|
const result = await this.post('loadContent', { content });
|
|
4206
4220
|
this.currentContent = content;
|
|
4207
4221
|
this.currentSlideIndex = 0;
|
|
@@ -4209,16 +4223,19 @@
|
|
|
4209
4223
|
return result;
|
|
4210
4224
|
}
|
|
4211
4225
|
async switchSlide(index) {
|
|
4226
|
+
this.ensureWhitelistAccess('switchSlide');
|
|
4212
4227
|
const result = await this.post('switchSlide', { index });
|
|
4213
4228
|
this.currentSlideIndex = index;
|
|
4214
4229
|
return result;
|
|
4215
4230
|
}
|
|
4216
4231
|
async getSlideCount() {
|
|
4232
|
+
this.ensureWhitelistAccess('getSlideCount');
|
|
4217
4233
|
const result = await this.post('getSlideCount', {});
|
|
4218
4234
|
this.slideCount = result.count;
|
|
4219
4235
|
return result;
|
|
4220
4236
|
}
|
|
4221
4237
|
async repl(command) {
|
|
4238
|
+
this.ensureWhitelistAccess('repl');
|
|
4222
4239
|
return this.post('repl', { command });
|
|
4223
4240
|
}
|
|
4224
4241
|
}
|
|
@@ -4411,6 +4428,33 @@
|
|
|
4411
4428
|
}
|
|
4412
4429
|
}
|
|
4413
4430
|
|
|
4431
|
+
const WHITELIST_CHECK_BASE_URL = 'https://open.dajiaoai.com/console';
|
|
4432
|
+
const WHITELIST_CHECK_PATH = '/api/whitelist/check';
|
|
4433
|
+
async function checkPresentationWhitelist(options) {
|
|
4434
|
+
const appId = options.appId?.trim() ?? '';
|
|
4435
|
+
const host = window.location.host.trim();
|
|
4436
|
+
const url = new URL(`${normalizeBaseUrl(WHITELIST_CHECK_BASE_URL)}${WHITELIST_CHECK_PATH}`);
|
|
4437
|
+
url.searchParams.set('appId', appId);
|
|
4438
|
+
url.searchParams.set('host', host);
|
|
4439
|
+
let matched = false;
|
|
4440
|
+
try {
|
|
4441
|
+
const response = await fetch(url.toString(), {
|
|
4442
|
+
method: 'GET',
|
|
4443
|
+
cache: 'no-store',
|
|
4444
|
+
});
|
|
4445
|
+
if (response.ok) {
|
|
4446
|
+
const payload = (await response.json());
|
|
4447
|
+
matched = payload.matched === true;
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
catch {
|
|
4451
|
+
matched = false;
|
|
4452
|
+
}
|
|
4453
|
+
if (matched) {
|
|
4454
|
+
return null;
|
|
4455
|
+
}
|
|
4456
|
+
return new AlgeoError(`白名单校验未通过,appId="${appId || '(empty)'}",host="${host || '(empty)'}"。`, EMBED_ERROR_CODES.BAD_REQUEST);
|
|
4457
|
+
}
|
|
4414
4458
|
async function createEditorInstance(container, options = {}, baseUrl) {
|
|
4415
4459
|
const editor = new EmbeddedEditor(container);
|
|
4416
4460
|
await editor.initialize(options, baseUrl);
|
|
@@ -4419,6 +4463,10 @@
|
|
|
4419
4463
|
async function createPresentationInstance(container, options = {}, baseUrl) {
|
|
4420
4464
|
const presentation = new EmbeddedPresentation(container);
|
|
4421
4465
|
await presentation.initialize(options, baseUrl);
|
|
4466
|
+
const whitelistError = await checkPresentationWhitelist(options);
|
|
4467
|
+
if (whitelistError) {
|
|
4468
|
+
presentation.setWhitelistError(whitelistError);
|
|
4469
|
+
}
|
|
4422
4470
|
return presentation;
|
|
4423
4471
|
}
|
|
4424
4472
|
function createEmbeddedInstance(container, options) {
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { EmbeddedTarget } from './embedded-target';
|
|
2
|
-
import { type AlgeoPresentationCreateOptions, type EmbeddedPresentationEventListenerMap, type EmbeddedPresentationEventMap, type EmbeddedPresentationEventName, type FileContentV10, type GetSlideCountResult, type LoadFileResult, type LoadShareByIdResult, type ReplResult, type SwitchSlideResult } from './shared';
|
|
2
|
+
import { AlgeoError, type AlgeoPresentationCreateOptions, type EmbeddedPresentationEventListenerMap, type EmbeddedPresentationEventMap, type EmbeddedPresentationEventName, type FileContentV10, type GetSlideCountResult, type LoadFileResult, type LoadShareByIdResult, type ReplResult, type SwitchSlideResult } from './shared';
|
|
3
3
|
export declare class EmbeddedPresentation extends EmbeddedTarget<EmbeddedPresentationEventMap, EmbeddedPresentationEventName, EmbeddedPresentationEventListenerMap> {
|
|
4
4
|
private currentContent?;
|
|
5
5
|
private currentSlideIndex;
|
|
6
6
|
private slideCount;
|
|
7
|
+
private whitelistError?;
|
|
7
8
|
constructor(container: HTMLElement);
|
|
8
9
|
initialize(options?: AlgeoPresentationCreateOptions, baseUrl?: string): Promise<void>;
|
|
9
10
|
protected acceptsEventMessage(): boolean;
|
|
11
|
+
setWhitelistError(error: AlgeoError): void;
|
|
12
|
+
private ensureWhitelistAccess;
|
|
10
13
|
loadShareById(id: string): Promise<LoadShareByIdResult>;
|
|
11
14
|
loadFile(content: FileContentV10): Promise<LoadFileResult>;
|
|
12
15
|
switchSlide(index: number): Promise<SwitchSlideResult>;
|
package/dist/shared.d.ts
CHANGED