@perforce-perfecto/scriptless-helpers 1.78.5 → 1.78.7
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/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perforce-perfecto/scriptless-helpers",
|
|
3
|
-
"version": "1.78.
|
|
3
|
+
"version": "1.78.7",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@perforce-perfecto/scriptless-helpers-types": "1.78.
|
|
8
|
+
"@perforce-perfecto/scriptless-helpers-types": "1.78.7",
|
|
9
9
|
"tslib": "^2.3.0",
|
|
10
10
|
"webdriverio": "^9.27.0",
|
|
11
11
|
"axios": "^1.18.0",
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ConstantsHelper } from './constants-helper';
|
|
2
1
|
import { ScriptlessHelper } from '@perforce-perfecto/scriptless-helpers-types';
|
|
3
2
|
export declare class FileTransferHelper extends ScriptlessHelper {
|
|
4
|
-
|
|
5
|
-
constructor(constantsHelperClass: typeof ConstantsHelper, logger?: Console);
|
|
3
|
+
constructor(logger?: Console);
|
|
6
4
|
uploadArtifactToRepository(repositoryFile: string, base64Data: string): Promise<void>;
|
|
7
5
|
downloadArtifactFromRepository(repositoryFile: string): Promise<Buffer>;
|
|
8
6
|
getDeviceFilepath(devicePlatform: string, handsetFile: string): string;
|
|
@@ -12,6 +10,4 @@ export declare class FileTransferHelper extends ScriptlessHelper {
|
|
|
12
10
|
fileName: string;
|
|
13
11
|
fileExtension: string;
|
|
14
12
|
};
|
|
15
|
-
private getRepositoryManagementArtifactUploadUrl;
|
|
16
|
-
private getRepositoryManagementArtifactDownloadUrl;
|
|
17
13
|
}
|
|
@@ -4,38 +4,47 @@ exports.FileTransferHelper = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
+
const constants_helper_1 = require("./constants-helper");
|
|
7
8
|
const file_type_1 = require("file-type");
|
|
8
9
|
const scriptless_helpers_types_1 = require("@perforce-perfecto/scriptless-helpers-types");
|
|
10
|
+
function toRepositoryArtifactType(mime) {
|
|
11
|
+
switch (mime === null || mime === void 0 ? void 0 : mime.split('/')[0]) {
|
|
12
|
+
case 'image':
|
|
13
|
+
return 'IMAGE';
|
|
14
|
+
case 'video':
|
|
15
|
+
return 'VIDEO';
|
|
16
|
+
case 'audio':
|
|
17
|
+
return 'AUDIO';
|
|
18
|
+
default:
|
|
19
|
+
return 'GENERAL';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
9
22
|
class FileTransferHelper extends scriptless_helpers_types_1.ScriptlessHelper {
|
|
10
|
-
constructor(
|
|
23
|
+
constructor(logger) {
|
|
11
24
|
super(logger);
|
|
12
|
-
this.constantsHelperClass = constantsHelperClass;
|
|
13
25
|
}
|
|
14
26
|
uploadArtifactToRepository(repositoryFile, base64Data) {
|
|
15
27
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
|
|
17
|
-
const { fileAccessibility, fileName: repositoryFilePath } = this.getStorageFilepathDetails(repositoryFile);
|
|
28
|
+
const { fileAccessibility, filePath: repositoryFilePath, fileName } = this.getStorageFilepathDetails(repositoryFile);
|
|
18
29
|
const bufferedFile = Buffer.from(base64Data, 'base64');
|
|
19
30
|
const fileTypeResult = yield (0, file_type_1.fileTypeFromBuffer)(new Uint8Array(bufferedFile));
|
|
20
|
-
const artifactType = (
|
|
21
|
-
const
|
|
22
|
-
const payload = {
|
|
23
|
-
contentType,
|
|
24
|
-
artifactType,
|
|
25
|
-
folderType: fileAccessibility,
|
|
26
|
-
keyDetails: {
|
|
27
|
-
version: 'v0',
|
|
28
|
-
artifactId: repositoryFilePath
|
|
29
|
-
},
|
|
30
|
-
override: true,
|
|
31
|
-
userMetadata: { tags: [] },
|
|
32
|
-
hidden: false,
|
|
33
|
-
temporary: false,
|
|
34
|
-
fileName: repositoryFilePath
|
|
35
|
-
};
|
|
31
|
+
const artifactType = toRepositoryArtifactType(fileTypeResult === null || fileTypeResult === void 0 ? void 0 : fileTypeResult.mime);
|
|
32
|
+
const artifactLocator = `${fileAccessibility}:${repositoryFilePath}`;
|
|
36
33
|
try {
|
|
37
|
-
const
|
|
38
|
-
|
|
34
|
+
const requestPart = new Blob([
|
|
35
|
+
JSON.stringify({
|
|
36
|
+
artifactLocator,
|
|
37
|
+
artifactType,
|
|
38
|
+
override: true
|
|
39
|
+
})
|
|
40
|
+
], { type: 'application/json' });
|
|
41
|
+
const inputStream = new Blob([bufferedFile], {
|
|
42
|
+
type: 'application/octet-stream'
|
|
43
|
+
});
|
|
44
|
+
const formData = new FormData();
|
|
45
|
+
formData.append('requestPart', requestPart);
|
|
46
|
+
formData.append('inputStream', inputStream, fileName);
|
|
47
|
+
yield axios_1.default.post(`${constants_helper_1.ConstantsHelper.getRepositoryManagementServiceBaseUrl(constants_helper_1.ConstantsHelper.getShortTenantId())}/artifacts`, formData, { headers: constants_helper_1.ConstantsHelper.getPerfectoAuthHeaders() });
|
|
39
48
|
this.logger.info(`File ${repositoryFilePath} saved successfully in repository.`);
|
|
40
49
|
}
|
|
41
50
|
catch (error) {
|
|
@@ -46,16 +55,12 @@ class FileTransferHelper extends scriptless_helpers_types_1.ScriptlessHelper {
|
|
|
46
55
|
}
|
|
47
56
|
downloadArtifactFromRepository(repositoryFile) {
|
|
48
57
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
const { fileAccessibility,
|
|
50
|
-
const
|
|
51
|
-
artifactId: repositoryFilePath,
|
|
52
|
-
folderType: fileAccessibility,
|
|
53
|
-
repositoryType: scriptless_helpers_types_1.RepositoryArtifactType.MEDIA
|
|
54
|
-
};
|
|
58
|
+
const { fileAccessibility, filePath: repositoryFilePath } = this.getStorageFilepathDetails(repositoryFile);
|
|
59
|
+
const artifactLocator = `${fileAccessibility}:${repositoryFilePath}`;
|
|
55
60
|
try {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
headers:
|
|
61
|
+
const downloadedAsset = yield axios_1.default.get(`${constants_helper_1.ConstantsHelper.getRepositoryManagementServiceBaseUrl(constants_helper_1.ConstantsHelper.getShortTenantId())}/artifacts/artifact`, {
|
|
62
|
+
params: { artifactLocator },
|
|
63
|
+
headers: constants_helper_1.ConstantsHelper.getPerfectoAuthHeaders(),
|
|
59
64
|
responseType: 'arraybuffer'
|
|
60
65
|
});
|
|
61
66
|
const fileBuffer = downloadedAsset.data;
|
|
@@ -107,23 +112,6 @@ class FileTransferHelper extends scriptless_helpers_types_1.ScriptlessHelper {
|
|
|
107
112
|
fileExtension: parsed.ext.toLowerCase()
|
|
108
113
|
};
|
|
109
114
|
}
|
|
110
|
-
getRepositoryManagementArtifactUploadUrl(payload, tenantName, authHeaders) {
|
|
111
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const response = yield axios_1.default.post(`${this.constantsHelperClass.getRepositoryManagementServiceBaseUrl(tenantName)}/artifacts`, payload, {
|
|
113
|
-
headers: authHeaders
|
|
114
|
-
});
|
|
115
|
-
return response.data;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
getRepositoryManagementArtifactDownloadUrl(params, tenantName, authHeaders) {
|
|
119
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
const response = yield axios_1.default.get(`${this.constantsHelperClass.getRepositoryManagementServiceBaseUrl(tenantName)}/artifacts/attachment`, {
|
|
121
|
-
params,
|
|
122
|
-
headers: authHeaders
|
|
123
|
-
});
|
|
124
|
-
return response.data;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
115
|
}
|
|
128
116
|
exports.FileTransferHelper = FileTransferHelper;
|
|
129
117
|
//# sourceMappingURL=file-transfer-helper.js.map
|