@ibm-aspera/sdk 0.2.29 → 0.2.30
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/commonjs/app/core.d.ts +191 -0
- package/dist/commonjs/app/core.js +682 -0
- package/dist/commonjs/app/installer.d.ts +9 -0
- package/dist/commonjs/app/installer.js +50 -0
- package/dist/commonjs/connect/core.d.ts +11 -0
- package/dist/commonjs/connect/core.js +73 -0
- package/dist/commonjs/constants/constants.d.ts +8 -0
- package/dist/commonjs/constants/constants.js +11 -0
- package/dist/commonjs/constants/messages.d.ts +35 -0
- package/dist/commonjs/constants/messages.js +38 -0
- package/dist/commonjs/helpers/client/client.d.ts +5 -0
- package/dist/commonjs/helpers/client/client.js +7 -0
- package/dist/commonjs/helpers/client/http-client.d.ts +42 -0
- package/dist/commonjs/helpers/client/http-client.js +84 -0
- package/dist/commonjs/helpers/client/safari-client.d.ts +101 -0
- package/dist/commonjs/helpers/client/safari-client.js +264 -0
- package/dist/commonjs/helpers/helpers.d.ts +109 -0
- package/dist/commonjs/helpers/helpers.js +249 -0
- package/dist/commonjs/helpers/http.d.ts +16 -0
- package/dist/commonjs/helpers/http.js +42 -0
- package/dist/commonjs/helpers/ws.d.ts +62 -0
- package/dist/commonjs/helpers/ws.js +161 -0
- package/dist/commonjs/http-gateway/core.d.ts +76 -0
- package/dist/commonjs/http-gateway/core.js +254 -0
- package/dist/commonjs/http-gateway/download.d.ts +14 -0
- package/dist/commonjs/http-gateway/download.js +187 -0
- package/dist/commonjs/http-gateway/index.d.ts +11 -0
- package/dist/commonjs/http-gateway/index.js +11 -0
- package/dist/commonjs/http-gateway/models.d.ts +16 -0
- package/dist/commonjs/http-gateway/models.js +2 -0
- package/dist/commonjs/http-gateway/upload.d.ts +14 -0
- package/dist/commonjs/http-gateway/upload.js +124 -0
- package/dist/commonjs/index.d.ts +8 -0
- package/dist/commonjs/index.js +100 -0
- package/dist/commonjs/models/aspera-sdk.model.d.ts +245 -0
- package/dist/commonjs/models/aspera-sdk.model.js +345 -0
- package/dist/commonjs/models/models.d.ts +712 -0
- package/dist/commonjs/models/models.js +2 -0
- package/dist/js/aspera-sdk.js +3 -0
- package/dist/js/aspera-sdk.js.LICENSE.txt +15 -0
- package/dist/js/aspera-sdk.js.map +1 -0
- package/package.json +5 -1
- package/.editorconfig +0 -13
- package/.github/CODEOWNERS +0 -1
- package/.github/CODE_OF_CONDUCT.md +0 -128
- package/.github/CONTRIBUTING.md +0 -147
- package/.github/dependabot.yml +0 -10
- package/.github/workflows/ci.yml +0 -39
- package/.github/workflows/documentation.yml +0 -44
- package/.github/workflows/publish.yml +0 -23
- package/.github/workflows/version.yml +0 -32
- package/.whitesource +0 -3
- package/CHANGELOG.md +0 -204
- package/docs/DEVELOPMENT.md +0 -38
- package/eslint.config.js +0 -104
- package/example/README.md +0 -7
- package/example/index.html +0 -14
- package/example/package-lock.json +0 -2989
- package/example/package.json +0 -30
- package/example/public/404.html +0 -5
- package/example/public/sdk-code.js +0 -326
- package/example/src/App/App.scss +0 -40
- package/example/src/App/index.tsx +0 -196
- package/example/src/Views/AllTogether.tsx +0 -26
- package/example/src/Views/DragDrop.tsx +0 -23
- package/example/src/Views/Home.tsx +0 -10
- package/example/src/Views/Initialize.tsx +0 -31
- package/example/src/Views/Installer.tsx +0 -154
- package/example/src/Views/MonitorTransfers.tsx +0 -88
- package/example/src/Views/Other.tsx +0 -24
- package/example/src/Views/SelectItems.tsx +0 -46
- package/example/src/Views/StartTransfer.tsx +0 -37
- package/example/src/Views/Test.tsx +0 -20
- package/example/src/Views/Views.scss +0 -111
- package/example/src/helpers/index.ts +0 -19
- package/example/src/index.scss +0 -47
- package/example/src/main.tsx +0 -17
- package/example/src/vite-env.d.ts +0 -2
- package/example/tsconfig.json +0 -30
- package/example/vite.config.ts +0 -23
- package/jest.config.js +0 -19
- package/jest.setup.js +0 -0
- package/renovate.json +0 -12
- package/src/app/core.ts +0 -765
- package/src/app/installer.ts +0 -53
- package/src/connect/core.ts +0 -83
- package/src/constants/constants.ts +0 -19
- package/src/constants/messages.ts +0 -35
- package/src/helpers/client/client.ts +0 -11
- package/src/helpers/client/http-client.ts +0 -92
- package/src/helpers/client/safari-client.ts +0 -334
- package/src/helpers/helpers.ts +0 -253
- package/src/helpers/http.ts +0 -39
- package/src/helpers/ws.ts +0 -191
- package/src/http-gateway/core.ts +0 -273
- package/src/http-gateway/download.ts +0 -217
- package/src/http-gateway/index.ts +0 -19
- package/src/http-gateway/models.ts +0 -20
- package/src/http-gateway/upload.ts +0 -148
- package/src/index.ts +0 -72
- package/src/models/aspera-sdk.model.ts +0 -446
- package/src/models/models.ts +0 -740
- package/tests/client.spec.ts +0 -52
- package/tests/core.spec.ts +0 -13
- package/tests/helpers.spec.ts +0 -127
- package/tests/http.spec.ts +0 -14
- package/tests/installer.spec.ts +0 -135
- package/tests/mocks.ts +0 -11
- package/tsconfig.json +0 -14
- package/tsconfig.module.json +0 -16
- package/typedoc.js +0 -7
- package/webpack.config.js +0 -35
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { WebsocketTopics } from '../models/models';
|
|
2
|
+
export declare class WebsocketService {
|
|
3
|
+
/** The main websocket connection to Aspera App*/
|
|
4
|
+
private globalSocket;
|
|
5
|
+
/** A map of requested subscription names and the callback for them */
|
|
6
|
+
private sockets;
|
|
7
|
+
/** The callback for websocket events */
|
|
8
|
+
private eventListener;
|
|
9
|
+
/** Indicator if the websocket is already connected */
|
|
10
|
+
private isConnected;
|
|
11
|
+
/** Global promise object that resolves when init completes */
|
|
12
|
+
private initPromise;
|
|
13
|
+
/** Log call for not being ready */
|
|
14
|
+
private handleNotReady;
|
|
15
|
+
/**
|
|
16
|
+
* This function handles when a connection is opened
|
|
17
|
+
*/
|
|
18
|
+
private handleOpen;
|
|
19
|
+
/**
|
|
20
|
+
* This function handles completed subscription
|
|
21
|
+
*/
|
|
22
|
+
private handleClose;
|
|
23
|
+
/**
|
|
24
|
+
* This function handles errors received from the websocket
|
|
25
|
+
*/
|
|
26
|
+
private handleError;
|
|
27
|
+
/**
|
|
28
|
+
* This function handles messages received from the websocket
|
|
29
|
+
*/
|
|
30
|
+
private handleMessage;
|
|
31
|
+
/**
|
|
32
|
+
* This function joins the channel to be able to subscribe to events
|
|
33
|
+
*/
|
|
34
|
+
private joinChannel;
|
|
35
|
+
/**
|
|
36
|
+
* This function registers clients to listen to a certain message name. Returns any to allow functions to declare proper type
|
|
37
|
+
*
|
|
38
|
+
* @param messageName - the name of messages to listen to (one message name per subscription)
|
|
39
|
+
* @param callback - the callback function
|
|
40
|
+
*/
|
|
41
|
+
registerMessage(messageName: WebsocketTopics, callback: Function): void;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param callback This function registers clients to a certain WebSocket event.
|
|
45
|
+
*
|
|
46
|
+
* @param callback - the callback function to call with the event name.
|
|
47
|
+
*/
|
|
48
|
+
registerEvent(callback: Function): void;
|
|
49
|
+
/**
|
|
50
|
+
* This function starts the websocket subscription with the websocket provider
|
|
51
|
+
*
|
|
52
|
+
* @returns a promise that resolves when the websocket connection is established
|
|
53
|
+
*/
|
|
54
|
+
init(): Promise<unknown>;
|
|
55
|
+
private connect;
|
|
56
|
+
private reconnect;
|
|
57
|
+
private getWebSocketConnection;
|
|
58
|
+
private notifyEvent;
|
|
59
|
+
private updateRpcPort;
|
|
60
|
+
}
|
|
61
|
+
export declare const websocketService: WebsocketService;
|
|
62
|
+
export default WebsocketService;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.websocketService = exports.WebsocketService = void 0;
|
|
4
|
+
var helpers_1 = require("./helpers");
|
|
5
|
+
var messages_1 = require("../constants/messages");
|
|
6
|
+
var index_1 = require("../index");
|
|
7
|
+
var WebsocketService = /** @class */ (function () {
|
|
8
|
+
function WebsocketService() {
|
|
9
|
+
var _this = this;
|
|
10
|
+
/** A map of requested subscription names and the callback for them */
|
|
11
|
+
this.sockets = new Map();
|
|
12
|
+
/** Indicator if the websocket is already connected */
|
|
13
|
+
this.isConnected = false;
|
|
14
|
+
/** Global promise object that resolves when init completes */
|
|
15
|
+
this.initPromise = (0, helpers_1.generatePromiseObjects)();
|
|
16
|
+
/**
|
|
17
|
+
* This function handles when a connection is opened
|
|
18
|
+
*/
|
|
19
|
+
this.handleOpen = function () {
|
|
20
|
+
if (_this.isConnected || !_this.joinChannel()) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
_this.isConnected = true;
|
|
24
|
+
_this.updateRpcPort();
|
|
25
|
+
_this.notifyEvent('RECONNECT');
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* This function handles completed subscription
|
|
29
|
+
*/
|
|
30
|
+
this.handleClose = function () {
|
|
31
|
+
if (_this.isConnected) {
|
|
32
|
+
_this.isConnected = false;
|
|
33
|
+
_this.notifyEvent('CLOSED');
|
|
34
|
+
}
|
|
35
|
+
if (!_this.globalSocket) {
|
|
36
|
+
_this.handleNotReady();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
_this.reconnect();
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* This function handles errors received from the websocket
|
|
43
|
+
*/
|
|
44
|
+
this.handleError = function () {
|
|
45
|
+
(0, helpers_1.errorLog)(messages_1.messages.websocketClosedError);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* This function handles messages received from the websocket
|
|
49
|
+
*/
|
|
50
|
+
this.handleMessage = function (message) {
|
|
51
|
+
var data = (0, helpers_1.safeJsonParse)(message.data);
|
|
52
|
+
// Message we get on subscription
|
|
53
|
+
if (data && data.id === 1) {
|
|
54
|
+
_this.initPromise.resolver(data);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
var socket = _this.sockets.get(data.method);
|
|
58
|
+
if (typeof socket === 'function' && data.params) {
|
|
59
|
+
socket(data.params);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Log call for not being ready */
|
|
64
|
+
WebsocketService.prototype.handleNotReady = function () {
|
|
65
|
+
(0, helpers_1.errorLog)(messages_1.messages.websocketNotReady);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* This function joins the channel to be able to subscribe to events
|
|
69
|
+
*/
|
|
70
|
+
WebsocketService.prototype.joinChannel = function () {
|
|
71
|
+
if (!this.globalSocket) {
|
|
72
|
+
this.handleNotReady();
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
this.globalSocket.send((0, helpers_1.safeJsonString)({ jsonrpc: '2.0', method: 'subscribe_transfer_activity', params: [index_1.asperaSdk.globals.appId], id: 1 }));
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* This function registers clients to listen to a certain message name. Returns any to allow functions to declare proper type
|
|
80
|
+
*
|
|
81
|
+
* @param messageName - the name of messages to listen to (one message name per subscription)
|
|
82
|
+
* @param callback - the callback function
|
|
83
|
+
*/
|
|
84
|
+
WebsocketService.prototype.registerMessage = function (messageName, callback) {
|
|
85
|
+
if (!this.sockets.get(messageName)) {
|
|
86
|
+
this.sockets.set(messageName, function (data) {
|
|
87
|
+
callback(data.result);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* @param callback This function registers clients to a certain WebSocket event.
|
|
94
|
+
*
|
|
95
|
+
* @param callback - the callback function to call with the event name.
|
|
96
|
+
*/
|
|
97
|
+
WebsocketService.prototype.registerEvent = function (callback) {
|
|
98
|
+
this.eventListener = callback;
|
|
99
|
+
this.eventListener(this.isConnected ? 'RECONNECT' : 'CLOSED');
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* This function starts the websocket subscription with the websocket provider
|
|
103
|
+
*
|
|
104
|
+
* @returns a promise that resolves when the websocket connection is established
|
|
105
|
+
*/
|
|
106
|
+
WebsocketService.prototype.init = function () {
|
|
107
|
+
this.connect();
|
|
108
|
+
return this.initPromise.promise;
|
|
109
|
+
};
|
|
110
|
+
WebsocketService.prototype.connect = function () {
|
|
111
|
+
var _this = this;
|
|
112
|
+
this.getWebSocketConnection(index_1.asperaSdk.globals.rpcPort)
|
|
113
|
+
.then(function (webSocket) {
|
|
114
|
+
_this.globalSocket = webSocket;
|
|
115
|
+
_this.globalSocket.onerror = _this.handleError;
|
|
116
|
+
_this.globalSocket.onclose = _this.handleClose;
|
|
117
|
+
_this.globalSocket.onopen = _this.handleOpen;
|
|
118
|
+
_this.globalSocket.onmessage = _this.handleMessage;
|
|
119
|
+
_this.handleOpen();
|
|
120
|
+
}).catch(function () {
|
|
121
|
+
_this.reconnect();
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
WebsocketService.prototype.reconnect = function () {
|
|
125
|
+
var _this = this;
|
|
126
|
+
if (this.globalSocket) {
|
|
127
|
+
this.globalSocket.close();
|
|
128
|
+
}
|
|
129
|
+
setTimeout(function () {
|
|
130
|
+
_this.connect();
|
|
131
|
+
}, 1000);
|
|
132
|
+
};
|
|
133
|
+
WebsocketService.prototype.getWebSocketConnection = function (port) {
|
|
134
|
+
var webSocketUrl = (0, helpers_1.getWebsocketUrl)(index_1.asperaSdk.globals.asperaAppUrl);
|
|
135
|
+
return new Promise(function (resolve, reject) {
|
|
136
|
+
var webSocket = new WebSocket("".concat(webSocketUrl, ":").concat(port));
|
|
137
|
+
webSocket.onopen = function () {
|
|
138
|
+
resolve(webSocket);
|
|
139
|
+
};
|
|
140
|
+
webSocket.onerror = function () {
|
|
141
|
+
reject("Connection failed on port ".concat(port));
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
WebsocketService.prototype.notifyEvent = function (event) {
|
|
146
|
+
if (typeof this.eventListener === 'function') {
|
|
147
|
+
this.eventListener(event);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
WebsocketService.prototype.updateRpcPort = function () {
|
|
151
|
+
if (!this.globalSocket) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
var url = new URL(this.globalSocket.url);
|
|
155
|
+
index_1.asperaSdk.globals.rpcPort = Number(url.port);
|
|
156
|
+
};
|
|
157
|
+
return WebsocketService;
|
|
158
|
+
}());
|
|
159
|
+
exports.WebsocketService = WebsocketService;
|
|
160
|
+
exports.websocketService = new WebsocketService();
|
|
161
|
+
exports.default = WebsocketService;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { FileDialogOptions, DataTransferResponse, TransferSpec, AsperaSdkTransfer } from '../models/models';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP Gateway Core Logic
|
|
4
|
+
* - File/Folder picking
|
|
5
|
+
* - Starting and testing
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Most logic is called directly by Desktop SDK functions
|
|
9
|
+
* You may not need to import anything from this file.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Remove a transfer from HTTP Gateway systems
|
|
13
|
+
* @param id - ID of the transfer
|
|
14
|
+
*
|
|
15
|
+
* @returns Promise indicating success
|
|
16
|
+
*/
|
|
17
|
+
export declare const httpRemoveTransfer: (id: string) => Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the list of http gateway transfers
|
|
20
|
+
*
|
|
21
|
+
* @returns list of HTTP Gateway
|
|
22
|
+
*/
|
|
23
|
+
export declare const httpGetAllTransfers: () => AsperaSdkTransfer[];
|
|
24
|
+
/**
|
|
25
|
+
* Get a HTTP Gateway transfer by ID
|
|
26
|
+
*
|
|
27
|
+
* @returns a transfer or null
|
|
28
|
+
*/
|
|
29
|
+
export declare const httpGetTransfer: (id: string) => AsperaSdkTransfer | null;
|
|
30
|
+
/**
|
|
31
|
+
* Create HTML input element for file picking
|
|
32
|
+
*/
|
|
33
|
+
export declare const createHtmlInputElement: () => HTMLInputElement;
|
|
34
|
+
/**
|
|
35
|
+
* Handle drop events and store files for HTTP Gateway
|
|
36
|
+
* This works on top of desktop.
|
|
37
|
+
*/
|
|
38
|
+
export declare const handleHttpGatewayDrop: (items: DataTransferItemList, callback: (data: {
|
|
39
|
+
event: DragEvent;
|
|
40
|
+
files: DataTransferResponse;
|
|
41
|
+
}) => void, event: DragEvent) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Open native browser file or folder picker for files
|
|
44
|
+
*
|
|
45
|
+
* @param options - File picker options
|
|
46
|
+
* @param folder - Indicate if choosing folders
|
|
47
|
+
*
|
|
48
|
+
* @returns Promise that resolves with info about the files picked
|
|
49
|
+
*/
|
|
50
|
+
export declare const httpGatewaySelectFileFolderDialog: (options?: FileDialogOptions, folder?: boolean) => Promise<DataTransferResponse>;
|
|
51
|
+
/**
|
|
52
|
+
* Get a generic transfer object for HTTP Gateway transfers.
|
|
53
|
+
*
|
|
54
|
+
* @param transferSpec - TransferSpec being provided for the HTTP Gateway transfer
|
|
55
|
+
*
|
|
56
|
+
* @returns a transfer object to track status and send to consumers
|
|
57
|
+
*/
|
|
58
|
+
export declare const getSdkTransfer: (transferSpec: TransferSpec) => AsperaSdkTransfer;
|
|
59
|
+
/**
|
|
60
|
+
* Send a transfer update through the SDK
|
|
61
|
+
*
|
|
62
|
+
* @param transfer - Transsfer object to send to consumers
|
|
63
|
+
*/
|
|
64
|
+
export declare const sendTransferUpdate: (transfer: AsperaSdkTransfer) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Try to parse and get a useful string from API calls for HTTP Gateway
|
|
67
|
+
*
|
|
68
|
+
* @param error - Error from API call for Gateway
|
|
69
|
+
*
|
|
70
|
+
* @returns a string to use for errors
|
|
71
|
+
*/
|
|
72
|
+
export declare const getMessageFromError: (error: any) => {
|
|
73
|
+
message: string;
|
|
74
|
+
code: number;
|
|
75
|
+
};
|
|
76
|
+
export declare const base64Encoding: (jsonString: string) => string;
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.base64Encoding = exports.getMessageFromError = exports.sendTransferUpdate = exports.getSdkTransfer = exports.httpGatewaySelectFileFolderDialog = exports.handleHttpGatewayDrop = exports.createHtmlInputElement = exports.httpGetTransfer = exports.httpGetAllTransfers = exports.httpRemoveTransfer = void 0;
|
|
4
|
+
var messages_1 = require("../constants/messages");
|
|
5
|
+
var helpers_1 = require("../helpers/helpers");
|
|
6
|
+
var index_1 = require("../index");
|
|
7
|
+
var http_gateway_sdk_js_1 = require("@ibm-aspera/http-gateway-sdk-js");
|
|
8
|
+
/**
|
|
9
|
+
* HTTP Gateway Core Logic
|
|
10
|
+
* - File/Folder picking
|
|
11
|
+
* - Starting and testing
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Most logic is called directly by Desktop SDK functions
|
|
15
|
+
* You may not need to import anything from this file.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Remove a transfer from HTTP Gateway systems
|
|
19
|
+
* @param id - ID of the transfer
|
|
20
|
+
*
|
|
21
|
+
* @returns Promise indicating success
|
|
22
|
+
*/
|
|
23
|
+
var httpRemoveTransfer = function (id) {
|
|
24
|
+
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
25
|
+
(0, http_gateway_sdk_js_1.removeTransfer)(id);
|
|
26
|
+
return Promise.resolve({ removed: true });
|
|
27
|
+
}
|
|
28
|
+
var transfer = index_1.asperaSdk.httpGatewayTransferStore.get(id);
|
|
29
|
+
if (transfer) {
|
|
30
|
+
index_1.asperaSdk.httpGatewayTransferStore.delete(id);
|
|
31
|
+
return Promise.resolve({ removed: true });
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return Promise.reject((0, helpers_1.generateErrorBody)(messages_1.messages.removeTransferFailed, { reason: 'Not found' }));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.httpRemoveTransfer = httpRemoveTransfer;
|
|
38
|
+
/**
|
|
39
|
+
* Get the list of http gateway transfers
|
|
40
|
+
*
|
|
41
|
+
* @returns list of HTTP Gateway
|
|
42
|
+
*/
|
|
43
|
+
var httpGetAllTransfers = function () {
|
|
44
|
+
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
45
|
+
return (0, http_gateway_sdk_js_1.getAllTransfers)().transfers;
|
|
46
|
+
}
|
|
47
|
+
return Array.from(index_1.asperaSdk.httpGatewayTransferStore.values());
|
|
48
|
+
};
|
|
49
|
+
exports.httpGetAllTransfers = httpGetAllTransfers;
|
|
50
|
+
/**
|
|
51
|
+
* Get a HTTP Gateway transfer by ID
|
|
52
|
+
*
|
|
53
|
+
* @returns a transfer or null
|
|
54
|
+
*/
|
|
55
|
+
var httpGetTransfer = function (id) {
|
|
56
|
+
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
57
|
+
return (0, http_gateway_sdk_js_1.getTransferById)(id);
|
|
58
|
+
}
|
|
59
|
+
return index_1.asperaSdk.httpGatewayTransferStore.get(id);
|
|
60
|
+
};
|
|
61
|
+
exports.httpGetTransfer = httpGetTransfer;
|
|
62
|
+
/**
|
|
63
|
+
* Create HTML input element for file picking
|
|
64
|
+
*/
|
|
65
|
+
var createHtmlInputElement = function () {
|
|
66
|
+
var element = window.document.createElement('input');
|
|
67
|
+
element.type = 'file';
|
|
68
|
+
element.style = 'display: none;';
|
|
69
|
+
window.document.body.appendChild(element);
|
|
70
|
+
return element;
|
|
71
|
+
};
|
|
72
|
+
exports.createHtmlInputElement = createHtmlInputElement;
|
|
73
|
+
/**
|
|
74
|
+
* Handle drop events and store files for HTTP Gateway
|
|
75
|
+
* This works on top of desktop.
|
|
76
|
+
*/
|
|
77
|
+
var handleHttpGatewayDrop = function (items, callback, event) {
|
|
78
|
+
var files = [];
|
|
79
|
+
var callbackCount = 0;
|
|
80
|
+
var callbackFinishCount = 0;
|
|
81
|
+
var finalCallback = function () {
|
|
82
|
+
if (callbackFinishCount >= callbackCount) {
|
|
83
|
+
var finalFiles = files.map(function (file) {
|
|
84
|
+
index_1.asperaSdk.httpGatewaySelectedFiles.set(file.name, file);
|
|
85
|
+
return {
|
|
86
|
+
lastModified: file.lastModified,
|
|
87
|
+
name: file.name,
|
|
88
|
+
size: file.size,
|
|
89
|
+
type: file.type
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
callback({ event: event, files: { dataTransfer: { files: finalFiles } } });
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var traverse = function (item) {
|
|
96
|
+
if (item.isFile) {
|
|
97
|
+
item.file(function (file) {
|
|
98
|
+
files.push(file);
|
|
99
|
+
callbackFinishCount++;
|
|
100
|
+
finalCallback();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else if (item.isDirectory) {
|
|
104
|
+
var dirReader = item.createReader();
|
|
105
|
+
dirReader.readEntries(function (entries) {
|
|
106
|
+
for (var k = 0; k < entries.length; k++) {
|
|
107
|
+
callbackCount++;
|
|
108
|
+
traverse(entries[k]);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
callbackFinishCount++;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
callbackFinishCount++;
|
|
115
|
+
finalCallback();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
for (var i = 0; i < items.length; i++) {
|
|
119
|
+
var item = items[i].webkitGetAsEntry();
|
|
120
|
+
if (item) {
|
|
121
|
+
callbackCount++;
|
|
122
|
+
traverse(item);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
exports.handleHttpGatewayDrop = handleHttpGatewayDrop;
|
|
127
|
+
/**
|
|
128
|
+
* Open native browser file or folder picker for files
|
|
129
|
+
*
|
|
130
|
+
* @param options - File picker options
|
|
131
|
+
* @param folder - Indicate if choosing folders
|
|
132
|
+
*
|
|
133
|
+
* @returns Promise that resolves with info about the files picked
|
|
134
|
+
*/
|
|
135
|
+
var httpGatewaySelectFileFolderDialog = function (options, folder) {
|
|
136
|
+
if (index_1.asperaSdk.useOldHttpGateway) {
|
|
137
|
+
return (folder ? (0, http_gateway_sdk_js_1.getFoldersForUploadPromise)((options === null || options === void 0 ? void 0 : options.http_gateway_v2_transfer_id) || '') : (0, http_gateway_sdk_js_1.getFilesForUploadPromise)((options === null || options === void 0 ? void 0 : options.http_gateway_v2_transfer_id) || ''));
|
|
138
|
+
}
|
|
139
|
+
var _a = (0, helpers_1.generatePromiseObjects)(), promise = _a.promise, rejecter = _a.rejecter, resolver = _a.resolver;
|
|
140
|
+
var element = (0, exports.createHtmlInputElement)();
|
|
141
|
+
element.multiple = !!(options === null || options === void 0 ? void 0 : options.multiple);
|
|
142
|
+
if (folder) {
|
|
143
|
+
element.webkitdirectory = true;
|
|
144
|
+
}
|
|
145
|
+
element.oncancel = function () {
|
|
146
|
+
rejecter({ debugData: { code: -32002, message: messages_1.messages.filePickerCancel } });
|
|
147
|
+
};
|
|
148
|
+
element.onchange = function () {
|
|
149
|
+
var returnFiles = [];
|
|
150
|
+
for (var i = 0; i < element.files.length; i++) {
|
|
151
|
+
var file = element.files[i];
|
|
152
|
+
returnFiles.push(file);
|
|
153
|
+
index_1.asperaSdk.httpGatewaySelectedFiles.set(file.name, file);
|
|
154
|
+
}
|
|
155
|
+
resolver({
|
|
156
|
+
dataTransfer: {
|
|
157
|
+
files: returnFiles.map(function (file) {
|
|
158
|
+
return {
|
|
159
|
+
size: file.size,
|
|
160
|
+
lastModified: file.lastModified,
|
|
161
|
+
name: file.webkitRelativePath || file.name,
|
|
162
|
+
type: file.type,
|
|
163
|
+
};
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
element.click();
|
|
169
|
+
return promise;
|
|
170
|
+
};
|
|
171
|
+
exports.httpGatewaySelectFileFolderDialog = httpGatewaySelectFileFolderDialog;
|
|
172
|
+
/**
|
|
173
|
+
* Get a generic transfer object for HTTP Gateway transfers.
|
|
174
|
+
*
|
|
175
|
+
* @param transferSpec - TransferSpec being provided for the HTTP Gateway transfer
|
|
176
|
+
*
|
|
177
|
+
* @returns a transfer object to track status and send to consumers
|
|
178
|
+
*/
|
|
179
|
+
var getSdkTransfer = function (transferSpec) {
|
|
180
|
+
return {
|
|
181
|
+
uuid: (0, helpers_1.randomUUID)(),
|
|
182
|
+
transfer_spec: transferSpec,
|
|
183
|
+
current_file: '',
|
|
184
|
+
add_time: new Date().toISOString(),
|
|
185
|
+
file_counts: {
|
|
186
|
+
attempted: 0,
|
|
187
|
+
completed: 0,
|
|
188
|
+
failed: 0,
|
|
189
|
+
skipped: 0,
|
|
190
|
+
},
|
|
191
|
+
end_time: '',
|
|
192
|
+
explorer_path: '',
|
|
193
|
+
status: 'queued',
|
|
194
|
+
bytes_written: 0,
|
|
195
|
+
bytes_expected: 0,
|
|
196
|
+
calculated_rate_kbps: 0,
|
|
197
|
+
elapsed_usec: 0,
|
|
198
|
+
percentage: 0,
|
|
199
|
+
title: '',
|
|
200
|
+
remaining_usec: 0,
|
|
201
|
+
httpGatewayTransfer: true,
|
|
202
|
+
httpDownloadExternalHandle: false,
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
exports.getSdkTransfer = getSdkTransfer;
|
|
206
|
+
/**
|
|
207
|
+
* Send a transfer update through the SDK
|
|
208
|
+
*
|
|
209
|
+
* @param transfer - Transsfer object to send to consumers
|
|
210
|
+
*/
|
|
211
|
+
var sendTransferUpdate = function (transfer) {
|
|
212
|
+
index_1.asperaSdk.httpGatewayTransferStore.set(transfer.uuid, transfer);
|
|
213
|
+
index_1.asperaSdk.activityTracking.handleTransferActivity({
|
|
214
|
+
type: 'transferUpdated',
|
|
215
|
+
data: { transfers: [transfer] },
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
exports.sendTransferUpdate = sendTransferUpdate;
|
|
219
|
+
/**
|
|
220
|
+
* Try to parse and get a useful string from API calls for HTTP Gateway
|
|
221
|
+
*
|
|
222
|
+
* @param error - Error from API call for Gateway
|
|
223
|
+
*
|
|
224
|
+
* @returns a string to use for errors
|
|
225
|
+
*/
|
|
226
|
+
var getMessageFromError = function (error) {
|
|
227
|
+
var data = (0, helpers_1.safeJsonParse)(error);
|
|
228
|
+
var message = messages_1.messages.httpNetworkFail;
|
|
229
|
+
var code = 500;
|
|
230
|
+
if (data && typeof data === 'object') {
|
|
231
|
+
message = data.message || data.description || messages_1.messages.httpNetworkFail;
|
|
232
|
+
code = data.code || 500;
|
|
233
|
+
}
|
|
234
|
+
else if (error && typeof error === 'object') {
|
|
235
|
+
message = error.message || error.description || messages_1.messages.httpNetworkFail;
|
|
236
|
+
code = error.code || 500;
|
|
237
|
+
}
|
|
238
|
+
else if (typeof error === 'string') {
|
|
239
|
+
message = error;
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
message: message,
|
|
243
|
+
code: code,
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
exports.getMessageFromError = getMessageFromError;
|
|
247
|
+
var base64Encoding = function (jsonString) {
|
|
248
|
+
var bytes = new TextEncoder().encode(jsonString);
|
|
249
|
+
var binString = Array.from(bytes, function (byte) {
|
|
250
|
+
return String.fromCodePoint(byte);
|
|
251
|
+
}).join('');
|
|
252
|
+
return btoa(binString);
|
|
253
|
+
};
|
|
254
|
+
exports.base64Encoding = base64Encoding;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AsperaSdkSpec, AsperaSdkTransfer, TransferSpec } from '../models/models';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP Gateway Download Logic
|
|
4
|
+
*
|
|
5
|
+
* @param transferSpec - TransferSpec for the download
|
|
6
|
+
* @param asperaSdkSpec IBM Aspera settings when starting a transfer.
|
|
7
|
+
*
|
|
8
|
+
* @returns Promise that resolves on success invoke or rejects if unable to start
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Most logic is called directly by Desktop SDK functions
|
|
12
|
+
* You may not need to import anything from this file.
|
|
13
|
+
*/
|
|
14
|
+
export declare const httpDownload: (transferSpec: TransferSpec, asperaSdkSpec?: AsperaSdkSpec) => Promise<AsperaSdkTransfer>;
|