| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 796c1d1 commit 9e82d33
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -140,7 +140,7 @@ | |||
| 140 | 140 | "@mapbox/mapbox-gl-style-spec": "^14.3.0", | |
| 141 | 141 | "@mapbox/vector-tile": "1.3.1", | |
| 142 | 142 | "@supermap/iclient-common": "file:src/common", | |
| 143 | - "@supermap/tile-decryptor": "^0.0.2", | ||
| 143 | + "@supermapgis/tile-decryptor": "^1.0.0", | ||
| 144 | 144 | "@turf/center": "^6.5.0", | |
| 145 | 145 | "@turf/turf": "6.5.0", | |
| 146 | 146 | "canvg": "3.0.10", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,6 @@ | |||
| 15 | 15 | "license": "Apache-2.0", | |
| 16 | 16 | "dependencies": { | |
| 17 | 17 | "@antv/g6": "^4.8.14", | |
| 18 | - "@supermap/tile-decryptor": "^0.0.2", | ||
| 19 | 18 | "echarts": "5.5.0", | |
| 20 | 19 | "fetch-ie8": "1.5.0", | |
| 21 | 20 | "fetch-jsonp": "1.1.3", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,7 +147,7 @@ export class EncryptRequest { | |||
| 147 | 147 | * @category iServer Core | |
| 148 | 148 | * @description 获取矢量瓦片解密密钥 | |
| 149 | 149 | * @param {string} serviceUrl - iServer 服务地址。例如:http://127.0.0.1:8090/iserver/services/xxx、http://127.0.0.1:8090/iserver/services/xxx/rest/maps、http://127.0.0.1:8090/iserver/services/xxx/restjsr/v1/vectortile。 | |
| 150 | - * @return {Promise} key - 矢量瓦片密钥。 | ||
| 150 | + * @return {Promise} options - 矢量瓦片密钥和加密算法类型。例如 { serviceKey, algorithm }。 | ||
| 151 | 151 | * @usage | |
| 152 | 152 | * ``` | |
| 153 | 153 | * // 浏览器 | |
@@ -166,7 +166,7 @@ export class EncryptRequest { | |||
| 166 | 166 | export async function getServiceKey(serviceUrl) { | |
| 167 | 167 | try { | |
| 168 | 168 | const workspaceServerUrl = ((serviceUrl && | |
| 169 | - serviceUrl.match(/.+(?=(\/restjsr\/v1\/vectortile\/|\/rest\/maps\/))/)) || | ||
| 169 | + serviceUrl.match(/.+(?=(\/restjsr\/v1\/vectortile\/|\/rest\/maps\/|\/rest\/data\/))/)) || | ||
| 170 | 170 | [])[0]; | |
| 171 | 171 | if (!workspaceServerUrl) { | |
| 172 | 172 | return; | |
@@ -187,7 +187,14 @@ export async function getServiceKey(serviceUrl) { | |||
| 187 | 187 | method: 'get', | |
| 188 | 188 | url: svckeyUrl | |
| 189 | 189 | }); | |
| 190 | - return svcReponse.json(); | ||
| 190 | + const serviceKey = await svcReponse.json(); | ||
| 191 | + if (!serviceKey) { | ||
| 192 | + return; | ||
| 193 | + } | ||
| 194 | + return { | ||
| 195 | + serviceKey, | ||
| 196 | + algorithm: matchRestData.serviceEncryptInfo.encrptSpec.algorithm | ||
| 197 | + }; | ||
| 191 | 198 | } catch (error) { | |
| 192 | 199 | console.error(error); | |
| 193 | 200 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,8 +16,13 @@ export var MapExtend = (function () { | |||
| 16 | 16 | mapboxgl.VectorTileSource.prototype.beforeLoad = async function (id, options) { | |
| 17 | 17 | const url = options && options.tiles && options.tiles[0]; | |
| 18 | 18 | if (decryptSources.values.includes(id) && url) { | |
| 19 | - const decryptKey = await getServiceKey(url); | ||
| 20 | - this.decryptKey = decryptKey; | ||
| 19 | + const res = await getServiceKey(url); | ||
| 20 | + if (res) { | ||
| 21 | + this.decryptOptions = { | ||
| 22 | + key: res.serviceKey, | ||
| 23 | + algorithm: res.algorithm | ||
| 24 | + }; | ||
| 25 | + } | ||
| 21 | 26 | } | |
| 22 | 27 | this.beforeLoadBak(id, options); | |
| 23 | 28 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ import GeoJSON from 'ol/format/GeoJSON'; | |||
| 17 | 17 | import * as olSize from 'ol/size'; | |
| 18 | 18 | import Projection from 'ol/proj/Projection'; | |
| 19 | 19 | import TileGrid from 'ol/tilegrid/TileGrid'; | |
| 20 | - import decryptTileUtil from '@supermap/tile-decryptor'; | ||
| 20 | + import decryptTileUtil from '@supermapgis/tile-decryptor'; | ||
| 21 | 21 | ||
| 22 | 22 | /** | |
| 23 | 23 | * @class VectorTileSuperMapRest | |
@@ -34,7 +34,8 @@ import decryptTileUtil from '@supermap/tile-decryptor'; | |||
| 34 | 34 | * @param {(string|Object)} [options.attributions='Tile Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>'] - 版权描述信息。 | |
| 35 | 35 | * @param {Object} [options.format] - 瓦片的要素格式化。 | |
| 36 | 36 | * @param {boolean} [options.withCredentials] - 请求是否携带 cookie。 | |
| 37 | - * @param {boolean} [options.decrypt] - 瓦片是否需要解密。 | ||
| 37 | + * @param {boolean|Function} [options.decrypt] - 瓦片解密。如果是 true 表示用内置的解密方法, 如 decrypt: true;如果是function 则是自定义解密如 decrypt: function ({ key, bytes })。 | ||
| 38 | + * @param {Function} [options.decryptCompletedFunction] - 解密完成后触发。如 decryptCompletedFunction(completeData)。 | ||
| 38 | 39 | * @extends {ol.source.VectorTile} | |
| 39 | 40 | * @usage | |
| 40 | 41 | */ | |
@@ -386,15 +387,23 @@ export class VectorTileSuperMapRest extends VectorTile { | |||
| 386 | 387 | const firstSource = Object.keys(options.style.sources)[0]; | |
| 387 | 388 | serviceUrl = options.style.sources[firstSource].tiles[0]; | |
| 388 | 389 | } | |
| 389 | - this.serviceKey = await getServiceKey(serviceUrl); | ||
| 390 | + const res = await getServiceKey(serviceUrl); | ||
| 391 | + if (res) { | ||
| 392 | + this.decryptOptions = { | ||
| 393 | + key: res.serviceKey, | ||
| 394 | + algorithm: res.algorithm, | ||
| 395 | + decrypt: typeof options.decrypt === 'boolean' ? undefined : options.decrypt, | ||
| 396 | + decryptCompletedFunction: options.decryptCompletedFunction | ||
| 397 | + }; | ||
| 398 | + } | ||
| 390 | 399 | } catch (error) { | |
| 391 | 400 | console.error(error); | |
| 392 | 401 | } | |
| 393 | 402 | } | |
| 394 | 403 | ||
| 395 | 404 | _decryptMvt(mvtData) { | |
| 396 | - if (this.serviceKey) { | ||
| 397 | - return decryptTileUtil(mvtData, this.serviceKey); | ||
| 405 | + if (this.decryptOptions) { | ||
| 406 | + return decryptTileUtil({ ...this.decryptOptions, arrayBuffer: mvtData }); | ||
| 398 | 407 | } | |
| 399 | 408 | return mvtData; | |
| 400 | 409 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,10 +15,11 @@ | |||
| 15 | 15 | "author": "SuperMap", | |
| 16 | 16 | "license": "Apache-2.0", | |
| 17 | 17 | "dependencies": { | |
| 18 | + "@supermap/iclient-common": "11.2.0", | ||
| 19 | + "@supermapgis/tile-decryptor": "^1.0.0", | ||
| 18 | 20 | "@turf/turf": "6.5.0", | |
| 19 | 21 | "mapv": "2.0.62", | |
| 20 | 22 | "ol": "7.5.2", | |
| 21 | - "@supermap/iclient-common": "11.2.0", | ||
| 22 | 23 | "proj4": "2.11.0", | |
| 23 | 24 | "canvg": "3.0.10", | |
| 24 | 25 | "lodash.remove": "^4.7.0", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | import { FetchRequest } from '../../../src/common/util/FetchRequest'; | |
| 2 | - import { EncryptRequest } from '../../../src/common/util/EncryptRequest'; | ||
| 2 | + import { EncryptRequest, getServiceKey } from '../../../src/common/util/EncryptRequest'; | ||
| 3 | 3 | ||
| 4 | 4 | describe('EncryptRequest', () => { | |
| 5 | 5 | const serverUrl = 'http://fake.iserver.com/iserver'; | |
@@ -71,4 +71,63 @@ describe('EncryptRequest', () => { | |||
| 71 | 71 | }); | |
| 72 | 72 | }); | |
| 73 | 73 | }); | |
| 74 | + | ||
| 75 | + it('getServiceKey', (done) => { | ||
| 76 | + const serviceKey = 'l3nQtAUM4li87qMfO68exInHVFQ5gS3a6pb8ySIbib8='; | ||
| 77 | + const encrptSpec = { | ||
| 78 | + keyLength: 256, | ||
| 79 | + attributes: 'abcd', | ||
| 80 | + version: '1.1', | ||
| 81 | + algorithm: 'AES' | ||
| 82 | + }; | ||
| 83 | + const spyEncrypt = spyOn(EncryptRequest.prototype, 'request').and.callFake((options) => { | ||
| 84 | + if (options.url.includes('keyID1')) { | ||
| 85 | + return { json: () => Promise.resolve(serviceKey)}; | ||
| 86 | + } | ||
| 87 | + return { json: () => Promise.resolve(null)}; | ||
| 88 | + }); | ||
| 89 | + const spyGet = spyOn(FetchRequest, 'get').and.callFake((url) => { | ||
| 90 | + if (url.includes('map-China100')) { | ||
| 91 | + return Promise.resolve( | ||
| 92 | + new Response( | ||
| 93 | + JSON.stringify([ | ||
| 94 | + { | ||
| 95 | + serviceEncryptInfo: { | ||
| 96 | + encrptSpec, | ||
| 97 | + updateTime: 'Fri Mar 15 08:52:15 CST 2024', | ||
| 98 | + encrptKeyID: 'keyID1' | ||
| 99 | + }, | ||
| 100 | + name: 'map-China100/rest' | ||
| 101 | + } | ||
| 102 | + ]) | ||
| 103 | + ) | ||
| 104 | + ); | ||
| 105 | + } | ||
| 106 | + return Promise.resolve( | ||
| 107 | + new Response( | ||
| 108 | + JSON.stringify([ | ||
| 109 | + { | ||
| 110 | + serviceEncryptInfo: { | ||
| 111 | + encrptSpec, | ||
| 112 | + updateTime: 'Fri Mar 15 08:52:15 CST 2024', | ||
| 113 | + encrptKeyID: 'keyID2' | ||
| 114 | + }, | ||
| 115 | + name: 'data-china100/rest' | ||
| 116 | + } | ||
| 117 | + ]) | ||
| 118 | + ) | ||
| 119 | + ); | ||
| 120 | + }); | ||
| 121 | + getServiceKey('http://localhost:8090/iserver/services/map-China100/rest/maps/China').then(res => { | ||
| 122 | + expect(res).not.toBeUndefined(); | ||
| 123 | + expect(res.serviceKey).toBe(serviceKey); | ||
| 124 | + expect(res.algorithm).toBe(encrptSpec.algorithm); | ||
| 125 | + getServiceKey('http://localhost:8090/iserver/services/data-China100/rest/data/datasources/China/datasets/Airport_pt').then(res => { | ||
| 126 | + expect(res).toBeUndefined(); | ||
| 127 | + spyGet.calls.reset(); | ||
| 128 | + spyEncrypt.calls.reset(); | ||
| 129 | + done(); | ||
| 130 | + }); | ||
| 131 | + }); | ||
| 132 | + }); | ||
| 74 | 133 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,7 +236,8 @@ describe('MapExtend mapboxgl', () => { | |||
| 236 | 236 | decryptSources.add('B'); | |
| 237 | 237 | expect(decryptSources.values).toEqual(['A', 'B']); | |
| 238 | 238 | await vectorSource.beforeLoad('A', source); | |
| 239 | - expect(vectorSource.decryptKey).toEqual('P8h08GonNjuCB4+CAykAGmLYwNsiv4G6H8KFrFi7Afk='); | ||
| 239 | + expect(vectorSource.decryptOptions.key).toBe('P8h08GonNjuCB4+CAykAGmLYwNsiv4G6H8KFrFi7Afk='); | ||
| 240 | + expect(vectorSource.decryptOptions.algorithm).toBe('AES'); | ||
| 240 | 241 | } catch (error) { | |
| 241 | 242 | expect(error).toEqual(new Error('mapbox-gl cannot support plane coordinate system.')); | |
| 242 | 243 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,19 +59,20 @@ const mapObject = { | |||
| 59 | 59 | }; | |
| 60 | 60 | describe('openlayers_VectorTileSuperMapRest', () => { | |
| 61 | 61 | var testDiv, map, vectorTileOptions, vectorTileSource, originalTimeout, vectorLayer, spyGet, spyPost, spyCommit; | |
| 62 | + const encrptSpec = { | ||
| 63 | + keyLength: 256, | ||
| 64 | + attributes: 'abcd', | ||
| 65 | + version: '1.1', | ||
| 66 | + algorithm: 'AES' | ||
| 67 | + }; | ||
| 62 | 68 | const mockCallback = (testUrl) => { | |
| 63 | 69 | if ((url.match(/.+(?=(\/restjsr\/v1\/vectortile\/|\/rest\/maps\/))/) || [])[0] === testUrl) { | |
| 64 | 70 | return Promise.resolve( | |
| 65 | 71 | new Response( | |
| 66 | 72 | JSON.stringify([ | |
| 67 | 73 | { | |
| 68 | 74 | serviceEncryptInfo: { | |
| 69 | - encrptSpec: { | ||
| 70 | - keyLength: 256, | ||
| 71 | - attributes: 'abcd', | ||
| 72 | - version: '1.1', | ||
| 73 | - algorithm: 'AES' | ||
| 74 | - }, | ||
| 75 | + encrptSpec, | ||
| 75 | 76 | updateTime: 'Fri Mar 15 08:52:15 CST 2024', | |
| 76 | 77 | encrptKeyID: 'keyIDNAME' | |
| 77 | 78 | }, | |
@@ -175,7 +176,8 @@ describe('openlayers_VectorTileSuperMapRest', () => { | |||
| 175 | 176 | ||
| 176 | 177 | it('mvt_decrypt ', (done) => { | |
| 177 | 178 | const spy = jasmine.createSpy('test'); | |
| 178 | - const spyEncrypt = spyOn(EncryptRequest.prototype, 'request').and.callFake(() => ({ json: () => Promise.resolve('l3nQtAUM4li87qMfO68exInHVFQ5gS3a6pb8ySIbib8=')})); | ||
| 179 | + const serviceKey = 'l3nQtAUM4li87qMfO68exInHVFQ5gS3a6pb8ySIbib8='; | ||
| 180 | + const spyEncrypt = spyOn(EncryptRequest.prototype, 'request').and.callFake(() => ({ json: () => Promise.resolve(serviceKey)})); | ||
| 179 | 181 | new MapService(url).getMapInfo((serviceResult) => { | |
| 180 | 182 | map = new Map({ | |
| 181 | 183 | target: 'map', | |
@@ -185,10 +187,11 @@ describe('openlayers_VectorTileSuperMapRest', () => { | |||
| 185 | 187 | }) | |
| 186 | 188 | }); | |
| 187 | 189 | vectorTileOptions = VectorTileSuperMapRest.optionsFromMapJSON(url, serviceResult.result); | |
| 188 | - vectorTileOptions.decrypt = true; | ||
| 189 | 190 | vectorTileOptions.format = new MVT({ | |
| 190 | 191 | featureClass: Feature | |
| 191 | 192 | }); | |
| 193 | + vectorTileOptions.decrypt = function() { return []}; | ||
| 194 | + vectorTileOptions.decryptCompletedFunction = function() {}; | ||
| 192 | 195 | vectorTileOptions.tileLoadFunction = (tile) => { | |
| 193 | 196 | tile.setLoader(() => { | |
| 194 | 197 | spy(); | |
@@ -204,7 +207,18 @@ describe('openlayers_VectorTileSuperMapRest', () => { | |||
| 204 | 207 | expect(vectorTileOptions).not.toBeNull(); | |
| 205 | 208 | expect(spy.calls.count()).toBe(1); | |
| 206 | 209 | expect(spyEncrypt).toHaveBeenCalled(); | |
| 207 | - expect(vectorTileSource.serviceKey).not.toBeUndefined(); | ||
| 210 | + expect(vectorTileSource.decryptOptions).not.toBeUndefined(); | ||
| 211 | + expect(vectorTileSource.decryptOptions.key).toBe(serviceKey); | ||
| 212 | + expect(vectorTileSource.decryptOptions.algorithm).toEqual(encrptSpec.algorithm); | ||
| 213 | + expect(vectorTileSource.decryptOptions.decrypt).not.toBeUndefined(); | ||
| 214 | + expect(vectorTileSource.decryptOptions.decryptCompletedFunction).not.toBeUndefined(); | ||
| 215 | + let testData = new Uint8Array(); | ||
| 216 | + let resultData = vectorTileSource._decryptMvt(testData); | ||
| 217 | + expect(resultData.slice(0).join(',')).toEqual(testData.slice(0).join(',')); | ||
| 218 | + vectorTileSource.decryptOptions = null; | ||
| 219 | + testData = new Uint8Array([5, 10]); | ||
| 220 | + resultData = vectorTileSource._decryptMvt(testData); | ||
| 221 | + expect(resultData.slice(0).join(',')).toEqual(testData.slice(0).join(',')); | ||
| 208 | 222 | spy.calls.reset(); | |
| 209 | 223 | spyEncrypt.calls.reset(); | |
| 210 | 224 | done(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments