@atlaskit/media-client 32.0.2 → 33.1.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/CHANGELOG.md +21 -0
- package/dist/cjs/client/file-fetcher/index.js +143 -114
- package/dist/cjs/client/media-client.js +1 -1
- package/dist/cjs/client/media-store/MediaStore.js +227 -138
- package/dist/cjs/utils/hashing/hasherCreator.js +20 -32
- package/dist/cjs/utils/request/helpers.js +1 -1
- package/dist/es2019/client/file-fetcher/index.js +15 -0
- package/dist/es2019/client/media-client.js +1 -1
- package/dist/es2019/client/media-store/MediaStore.js +63 -7
- package/dist/es2019/utils/hashing/hasherCreator.js +19 -23
- package/dist/es2019/utils/request/helpers.js +1 -1
- package/dist/esm/client/file-fetcher/index.js +143 -114
- package/dist/esm/client/media-client.js +1 -1
- package/dist/esm/client/media-store/MediaStore.js +227 -138
- package/dist/esm/utils/hashing/hasherCreator.js +19 -29
- package/dist/esm/utils/request/helpers.js +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +4 -1
- package/dist/types/client/media-store/MediaStore.d.ts +3 -1
- package/dist/types/client/media-store/types.d.ts +13 -0
- package/dist/types/utils/hashing/hasherCreator.d.ts +1 -1
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +4 -1
- package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +3 -1
- package/dist/types-ts4.5/client/media-store/types.d.ts +13 -0
- package/dist/types-ts4.5/utils/hashing/hasherCreator.d.ts +1 -1
- package/package.json +5 -5
- package/dist/cjs/utils/hashing/workerHasher.js +0 -113
- package/dist/es2019/utils/hashing/workerHasher.js +0 -89
- package/dist/esm/utils/hashing/workerHasher.js +0 -106
- package/dist/types/utils/hashing/workerHasher.d.ts +0 -16
- package/dist/types-ts4.5/utils/hashing/workerHasher.d.ts +0 -16
|
@@ -3,18 +3,19 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
3
3
|
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
4
4
|
var hasher = null;
|
|
5
5
|
var sha256Hasher = null;
|
|
6
|
-
export var
|
|
7
|
-
|
|
6
|
+
export var destroyHashers = function destroyHashers() {
|
|
7
|
+
hasher = null;
|
|
8
|
+
sha256Hasher = null;
|
|
8
9
|
};
|
|
9
10
|
export var createHasher = /*#__PURE__*/function () {
|
|
10
11
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(algorithm) {
|
|
11
|
-
var
|
|
12
|
+
var _yield$import, _SimpleHasher, _yield$import2, SimpleHasher;
|
|
12
13
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
13
14
|
while (1) switch (_context.prev = _context.next) {
|
|
14
15
|
case 0:
|
|
15
|
-
|
|
16
|
+
_context.prev = 0;
|
|
16
17
|
if (!(algorithm === ChunkHashAlgorithm.Sha256)) {
|
|
17
|
-
_context.next =
|
|
18
|
+
_context.next = 9;
|
|
18
19
|
break;
|
|
19
20
|
}
|
|
20
21
|
if (sha256Hasher) {
|
|
@@ -25,40 +26,29 @@ export var createHasher = /*#__PURE__*/function () {
|
|
|
25
26
|
return import('./sha256SimpleHasher');
|
|
26
27
|
case 5:
|
|
27
28
|
_yield$import = _context.sent;
|
|
28
|
-
|
|
29
|
-
sha256Hasher = new
|
|
29
|
+
_SimpleHasher = _yield$import.SimpleHasher;
|
|
30
|
+
sha256Hasher = new _SimpleHasher();
|
|
30
31
|
case 8:
|
|
31
32
|
return _context.abrupt("return", sha256Hasher);
|
|
33
|
+
case 9:
|
|
34
|
+
_context.next = 13;
|
|
35
|
+
break;
|
|
32
36
|
case 11:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
_context.prev = 12;
|
|
37
|
+
_context.prev = 11;
|
|
38
|
+
_context.t0 = _context["catch"](0);
|
|
39
|
+
case 13:
|
|
38
40
|
_context.next = 15;
|
|
39
|
-
return import('./
|
|
41
|
+
return import('./simpleHasher');
|
|
40
42
|
case 15:
|
|
41
43
|
_yield$import2 = _context.sent;
|
|
42
|
-
|
|
43
|
-
hasher = new
|
|
44
|
-
_context.next = 27;
|
|
45
|
-
break;
|
|
46
|
-
case 20:
|
|
47
|
-
_context.prev = 20;
|
|
48
|
-
_context.t0 = _context["catch"](12);
|
|
49
|
-
_context.next = 24;
|
|
50
|
-
return import('./simpleHasher');
|
|
51
|
-
case 24:
|
|
52
|
-
_yield$import3 = _context.sent;
|
|
53
|
-
_SimpleHasher = _yield$import3.SimpleHasher;
|
|
54
|
-
hasher = new _SimpleHasher();
|
|
55
|
-
case 27:
|
|
44
|
+
SimpleHasher = _yield$import2.SimpleHasher;
|
|
45
|
+
hasher = new SimpleHasher();
|
|
56
46
|
return _context.abrupt("return", hasher);
|
|
57
|
-
case
|
|
47
|
+
case 19:
|
|
58
48
|
case "end":
|
|
59
49
|
return _context.stop();
|
|
60
50
|
}
|
|
61
|
-
}, _callee, null, [[
|
|
51
|
+
}, _callee, null, [[0, 11]]);
|
|
62
52
|
}));
|
|
63
53
|
return function createHasher(_x) {
|
|
64
54
|
return _ref.apply(this, arguments);
|
|
@@ -73,7 +73,7 @@ export function createUrl(url, _ref2) {
|
|
|
73
73
|
return value != null;
|
|
74
74
|
}).forEach(function (pair) {
|
|
75
75
|
var _parsedUrl$searchPara;
|
|
76
|
-
(_parsedUrl$searchPara = parsedUrl.searchParams).
|
|
76
|
+
(_parsedUrl$searchPara = parsedUrl.searchParams).set.apply(_parsedUrl$searchPara, _toConsumableArray(pair));
|
|
77
77
|
});
|
|
78
78
|
parsedUrl.searchParams.sort();
|
|
79
79
|
return parsedUrl.toString();
|
|
@@ -2,13 +2,14 @@ import { type AuthProvider } from '@atlaskit/media-core';
|
|
|
2
2
|
import { type MediaFileArtifacts } from '@atlaskit/media-state';
|
|
3
3
|
import { MediaStore as MediaApi, type MediaStoreCopyFileWithTokenParams, type TouchedFiles, type TouchFileDescriptor } from '../media-store';
|
|
4
4
|
import { type GetFileOptions } from '../../models/file-state';
|
|
5
|
-
import { type MediaFile } from '../../models/media';
|
|
5
|
+
import { MediaItemDetails, type MediaFile } from '../../models/media';
|
|
6
6
|
import { type UploadableFile, type UploadableFileUpfrontIds } from '../../uploader';
|
|
7
7
|
import { type UploadController } from '../../upload-controller';
|
|
8
8
|
import { type MediaSubscribable } from '../../utils/mediaSubscribable';
|
|
9
9
|
import { type Dimensions } from '../../utils/getDimensionsFromBlob';
|
|
10
10
|
import { type MediaTraceContext } from '@atlaskit/media-common';
|
|
11
11
|
import { type FilePreview, type FileState, type MediaStore } from '@atlaskit/media-state';
|
|
12
|
+
import { UploadArtifactParams } from '../media-store/types';
|
|
12
13
|
export type { FileFetcherErrorAttributes, FileFetcherErrorReason } from './error';
|
|
13
14
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
14
15
|
export interface CopySourceFile {
|
|
@@ -40,6 +41,7 @@ export interface FileFetcher {
|
|
|
40
41
|
copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
|
|
41
42
|
getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
|
|
42
43
|
registerCopyIntent(id: string, collectionName?: string): Promise<void>;
|
|
44
|
+
uploadArtifact(id: string, file: File, params: UploadArtifactParams, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaItemDetails>;
|
|
43
45
|
}
|
|
44
46
|
export declare class FileFetcherImpl implements FileFetcher {
|
|
45
47
|
private readonly mediaApi;
|
|
@@ -64,4 +66,5 @@ export declare class FileFetcherImpl implements FileFetcher {
|
|
|
64
66
|
private copyFileWithToken;
|
|
65
67
|
private copyFileWithIntent;
|
|
66
68
|
copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
|
|
69
|
+
uploadArtifact: FileFetcher['uploadArtifact'];
|
|
67
70
|
}
|
|
@@ -20,7 +20,9 @@ export declare class MediaStore implements MediaApi {
|
|
|
20
20
|
private createFileImageURL;
|
|
21
21
|
getFileBinary(id: string, collectionName?: string, abortController?: AbortController, maxAge?: number): Promise<Blob>;
|
|
22
22
|
getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
|
|
23
|
-
getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
|
|
23
|
+
getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string, maxAge?: number): Promise<string>;
|
|
24
|
+
getArtifactBinary: MediaApi['getArtifactBinary'];
|
|
25
|
+
uploadArtifact: MediaApi['uploadArtifact'];
|
|
24
26
|
getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
|
|
25
27
|
getItems(ids: string[], collectionName?: string, traceContext?: MediaTraceContext, includeHashForDuplicateFiles?: boolean): Promise<MediaStoreResponse<ItemsPayload>>;
|
|
26
28
|
getImageMetadata(id: string, params?: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext): Promise<{
|
|
@@ -152,6 +152,17 @@ export interface EmptyFile {
|
|
|
152
152
|
readonly id: string;
|
|
153
153
|
readonly createdAt: number;
|
|
154
154
|
}
|
|
155
|
+
export type GetArtifactBinaryOptions = {
|
|
156
|
+
collectionName?: string;
|
|
157
|
+
abortController?: AbortController;
|
|
158
|
+
maxAge?: number;
|
|
159
|
+
traceContext?: MediaTraceContext;
|
|
160
|
+
};
|
|
161
|
+
export type UploadArtifactCaptionsParams = {
|
|
162
|
+
type: 'caption';
|
|
163
|
+
language: string;
|
|
164
|
+
};
|
|
165
|
+
export type UploadArtifactParams = UploadArtifactCaptionsParams;
|
|
155
166
|
export interface MediaApi {
|
|
156
167
|
removeCollectionFile: (id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext) => Promise<void>;
|
|
157
168
|
createUpload: (createUpTo: number, collectionName?: string, traceContext?: MediaTraceContext, chunkChunkHashAlgorithm?: ChunkHashAlgorithm) => Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
@@ -165,6 +176,8 @@ export interface MediaApi {
|
|
|
165
176
|
getFileBinary: (id: string, collectionName?: string, abortController?: AbortController) => Promise<Blob>;
|
|
166
177
|
getFileBinaryURL: (id: string, collectionName?: string) => Promise<string>;
|
|
167
178
|
getArtifactURL: (artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string) => Promise<string>;
|
|
179
|
+
getArtifactBinary(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, options: GetArtifactBinaryOptions): Promise<Blob>;
|
|
180
|
+
uploadArtifact(id: string, file: File, params: UploadArtifactParams, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaItemDetails>>;
|
|
168
181
|
getImage: (id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext) => Promise<Blob>;
|
|
169
182
|
getItems: (ids: string[], collectionName?: string, traceContext?: MediaTraceContext, includeHashForDuplicateFiles?: boolean) => Promise<MediaStoreResponse<ItemsPayload>>;
|
|
170
183
|
getImageMetadata: (id: string, params?: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext) => Promise<{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Hasher } from './hasher';
|
|
2
2
|
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const destroyHashers: () => void;
|
|
4
4
|
export declare const createHasher: (algorithm: ChunkHashAlgorithm) => Promise<Hasher>;
|
|
@@ -2,13 +2,14 @@ import { type AuthProvider } from '@atlaskit/media-core';
|
|
|
2
2
|
import { type MediaFileArtifacts } from '@atlaskit/media-state';
|
|
3
3
|
import { MediaStore as MediaApi, type MediaStoreCopyFileWithTokenParams, type TouchedFiles, type TouchFileDescriptor } from '../media-store';
|
|
4
4
|
import { type GetFileOptions } from '../../models/file-state';
|
|
5
|
-
import { type MediaFile } from '../../models/media';
|
|
5
|
+
import { MediaItemDetails, type MediaFile } from '../../models/media';
|
|
6
6
|
import { type UploadableFile, type UploadableFileUpfrontIds } from '../../uploader';
|
|
7
7
|
import { type UploadController } from '../../upload-controller';
|
|
8
8
|
import { type MediaSubscribable } from '../../utils/mediaSubscribable';
|
|
9
9
|
import { type Dimensions } from '../../utils/getDimensionsFromBlob';
|
|
10
10
|
import { type MediaTraceContext } from '@atlaskit/media-common';
|
|
11
11
|
import { type FilePreview, type FileState, type MediaStore } from '@atlaskit/media-state';
|
|
12
|
+
import { UploadArtifactParams } from '../media-store/types';
|
|
12
13
|
export type { FileFetcherErrorAttributes, FileFetcherErrorReason } from './error';
|
|
13
14
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
14
15
|
export interface CopySourceFile {
|
|
@@ -40,6 +41,7 @@ export interface FileFetcher {
|
|
|
40
41
|
copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
|
|
41
42
|
getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
|
|
42
43
|
registerCopyIntent(id: string, collectionName?: string): Promise<void>;
|
|
44
|
+
uploadArtifact(id: string, file: File, params: UploadArtifactParams, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaItemDetails>;
|
|
43
45
|
}
|
|
44
46
|
export declare class FileFetcherImpl implements FileFetcher {
|
|
45
47
|
private readonly mediaApi;
|
|
@@ -64,4 +66,5 @@ export declare class FileFetcherImpl implements FileFetcher {
|
|
|
64
66
|
private copyFileWithToken;
|
|
65
67
|
private copyFileWithIntent;
|
|
66
68
|
copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
|
|
69
|
+
uploadArtifact: FileFetcher['uploadArtifact'];
|
|
67
70
|
}
|
|
@@ -20,7 +20,9 @@ export declare class MediaStore implements MediaApi {
|
|
|
20
20
|
private createFileImageURL;
|
|
21
21
|
getFileBinary(id: string, collectionName?: string, abortController?: AbortController, maxAge?: number): Promise<Blob>;
|
|
22
22
|
getFileBinaryURL(id: string, collectionName?: string, maxAge?: number): Promise<string>;
|
|
23
|
-
getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
|
|
23
|
+
getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string, maxAge?: number): Promise<string>;
|
|
24
|
+
getArtifactBinary: MediaApi['getArtifactBinary'];
|
|
25
|
+
uploadArtifact: MediaApi['uploadArtifact'];
|
|
24
26
|
getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
|
|
25
27
|
getItems(ids: string[], collectionName?: string, traceContext?: MediaTraceContext, includeHashForDuplicateFiles?: boolean): Promise<MediaStoreResponse<ItemsPayload>>;
|
|
26
28
|
getImageMetadata(id: string, params?: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext): Promise<{
|
|
@@ -152,6 +152,17 @@ export interface EmptyFile {
|
|
|
152
152
|
readonly id: string;
|
|
153
153
|
readonly createdAt: number;
|
|
154
154
|
}
|
|
155
|
+
export type GetArtifactBinaryOptions = {
|
|
156
|
+
collectionName?: string;
|
|
157
|
+
abortController?: AbortController;
|
|
158
|
+
maxAge?: number;
|
|
159
|
+
traceContext?: MediaTraceContext;
|
|
160
|
+
};
|
|
161
|
+
export type UploadArtifactCaptionsParams = {
|
|
162
|
+
type: 'caption';
|
|
163
|
+
language: string;
|
|
164
|
+
};
|
|
165
|
+
export type UploadArtifactParams = UploadArtifactCaptionsParams;
|
|
155
166
|
export interface MediaApi {
|
|
156
167
|
removeCollectionFile: (id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext) => Promise<void>;
|
|
157
168
|
createUpload: (createUpTo: number, collectionName?: string, traceContext?: MediaTraceContext, chunkChunkHashAlgorithm?: ChunkHashAlgorithm) => Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
@@ -165,6 +176,8 @@ export interface MediaApi {
|
|
|
165
176
|
getFileBinary: (id: string, collectionName?: string, abortController?: AbortController) => Promise<Blob>;
|
|
166
177
|
getFileBinaryURL: (id: string, collectionName?: string) => Promise<string>;
|
|
167
178
|
getArtifactURL: (artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string) => Promise<string>;
|
|
179
|
+
getArtifactBinary(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, options: GetArtifactBinaryOptions): Promise<Blob>;
|
|
180
|
+
uploadArtifact(id: string, file: File, params: UploadArtifactParams, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaItemDetails>>;
|
|
168
181
|
getImage: (id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext) => Promise<Blob>;
|
|
169
182
|
getItems: (ids: string[], collectionName?: string, traceContext?: MediaTraceContext, includeHashForDuplicateFiles?: boolean) => Promise<MediaStoreResponse<ItemsPayload>>;
|
|
170
183
|
getImageMetadata: (id: string, params?: MediaStoreGetFileImageParams, traceContext?: MediaTraceContext) => Promise<{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Hasher } from './hasher';
|
|
2
2
|
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const destroyHashers: () => void;
|
|
4
4
|
export declare const createHasher: (algorithm: ChunkHashAlgorithm) => Promise<Hasher>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "33.1.0",
|
|
4
4
|
"description": "Media API Web Client Library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
"xstate": "4.20.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@atlaskit/media-core": "^
|
|
53
|
+
"@atlaskit/media-core": "^36.1.0",
|
|
54
54
|
"@atlaskit/media-state": "^1.5.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@atlaskit/media-core": "^
|
|
57
|
+
"@atlaskit/media-core": "^36.1.0",
|
|
58
58
|
"@atlaskit/media-state": "^1.5.0",
|
|
59
|
-
"@atlaskit/ssr": "
|
|
60
|
-
"@atlaskit/tokens": "^4.
|
|
59
|
+
"@atlaskit/ssr": "workspace:^",
|
|
60
|
+
"@atlaskit/tokens": "^4.8.0",
|
|
61
61
|
"@atlassian/feature-flags-test-utils": "^0.3.0",
|
|
62
62
|
"@emotion/react": "^11.7.1",
|
|
63
63
|
"@types/deep-equal": "^1.0.1",
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.WorkerHasher = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
var _v = _interopRequireDefault(require("uuid/v4"));
|
|
12
|
-
var _rusha = _interopRequireDefault(require("rusha"));
|
|
13
|
-
var WorkerHasher = exports.WorkerHasher = /*#__PURE__*/function () {
|
|
14
|
-
function WorkerHasher(numOfWorkers) {
|
|
15
|
-
(0, _classCallCheck2.default)(this, WorkerHasher);
|
|
16
|
-
(0, _defineProperty2.default)(this, "workers", []);
|
|
17
|
-
(0, _defineProperty2.default)(this, "jobs", {});
|
|
18
|
-
for (var i = 0; i < numOfWorkers; ++i) {
|
|
19
|
-
this.workers.push(this.createWorker());
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return (0, _createClass2.default)(WorkerHasher, [{
|
|
23
|
-
key: "hash",
|
|
24
|
-
value: function hash(chunk) {
|
|
25
|
-
return this.calculateHashInWorker(chunk);
|
|
26
|
-
}
|
|
27
|
-
}, {
|
|
28
|
-
key: "createWorker",
|
|
29
|
-
value: function createWorker() {
|
|
30
|
-
var _this = this;
|
|
31
|
-
var worker = _rusha.default.createWorker();
|
|
32
|
-
var hasherWorker = {
|
|
33
|
-
worker: worker,
|
|
34
|
-
activeJobs: 0
|
|
35
|
-
};
|
|
36
|
-
worker.addEventListener('message', function (event) {
|
|
37
|
-
_this.handleWorkerMessage(event, hasherWorker);
|
|
38
|
-
});
|
|
39
|
-
return hasherWorker;
|
|
40
|
-
}
|
|
41
|
-
}, {
|
|
42
|
-
key: "handleWorkerMessage",
|
|
43
|
-
value: function handleWorkerMessage(event, hasherWorker) {
|
|
44
|
-
var id = event.data.id;
|
|
45
|
-
if (this.jobs[id]) {
|
|
46
|
-
var _this$jobs$id = this.jobs[id],
|
|
47
|
-
resolve = _this$jobs$id.resolve,
|
|
48
|
-
reject = _this$jobs$id.reject;
|
|
49
|
-
delete this.jobs[id];
|
|
50
|
-
hasherWorker.activeJobs--;
|
|
51
|
-
if (event.data.error) {
|
|
52
|
-
// TODO previously we were just calling it again.
|
|
53
|
-
// this.calculateHashInWorker(chunk);
|
|
54
|
-
reject(event.data.error);
|
|
55
|
-
} else {
|
|
56
|
-
resolve(event.data.hash);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}, {
|
|
61
|
-
key: "calculateHashInWorker",
|
|
62
|
-
value: function calculateHashInWorker(blob) {
|
|
63
|
-
var _this2 = this;
|
|
64
|
-
var jobId = (0, _v.default)();
|
|
65
|
-
return new Promise(function (resolve, reject) {
|
|
66
|
-
_this2.jobs[jobId] = {
|
|
67
|
-
resolve: resolve,
|
|
68
|
-
reject: reject
|
|
69
|
-
};
|
|
70
|
-
var worker = _this2.getMostRelaxedWorker();
|
|
71
|
-
_this2.dispatch(jobId, worker, blob);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}, {
|
|
75
|
-
key: "dispatch",
|
|
76
|
-
value: function dispatch(jobId, hasherWorker, chunkBlob) {
|
|
77
|
-
hasherWorker.activeJobs++;
|
|
78
|
-
var worker = hasherWorker.worker;
|
|
79
|
-
|
|
80
|
-
/*
|
|
81
|
-
* postMessage() with chunk blob in Safari results in the error
|
|
82
|
-
* "Failed to load resource: The operation could not be completed. (WebKitBlobResource error 1.)"
|
|
83
|
-
*
|
|
84
|
-
* To prevent it, we read the data from the blob using FileReader and pass it via postMessage to the worker.
|
|
85
|
-
*/
|
|
86
|
-
if (navigator.userAgent.indexOf('Safari') > -1 && navigator.userAgent.indexOf('Chrome') === -1) {
|
|
87
|
-
var rd = new FileReader();
|
|
88
|
-
rd.onload = function () {
|
|
89
|
-
worker.postMessage({
|
|
90
|
-
id: jobId,
|
|
91
|
-
data: rd.result
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
rd.readAsBinaryString(chunkBlob);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
worker.postMessage({
|
|
98
|
-
id: jobId,
|
|
99
|
-
data: chunkBlob
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}, {
|
|
103
|
-
key: "getMostRelaxedWorker",
|
|
104
|
-
value: function getMostRelaxedWorker() {
|
|
105
|
-
return this.workers.reduce(function (current, next) {
|
|
106
|
-
if (next.activeJobs < current.activeJobs) {
|
|
107
|
-
return next;
|
|
108
|
-
}
|
|
109
|
-
return current;
|
|
110
|
-
}, this.workers[0]);
|
|
111
|
-
}
|
|
112
|
-
}]);
|
|
113
|
-
}();
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import uuidV4 from 'uuid/v4';
|
|
3
|
-
import Rusha from 'rusha';
|
|
4
|
-
export class WorkerHasher {
|
|
5
|
-
constructor(numOfWorkers) {
|
|
6
|
-
_defineProperty(this, "workers", []);
|
|
7
|
-
_defineProperty(this, "jobs", {});
|
|
8
|
-
for (let i = 0; i < numOfWorkers; ++i) {
|
|
9
|
-
this.workers.push(this.createWorker());
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
hash(chunk) {
|
|
13
|
-
return this.calculateHashInWorker(chunk);
|
|
14
|
-
}
|
|
15
|
-
createWorker() {
|
|
16
|
-
const worker = Rusha.createWorker();
|
|
17
|
-
const hasherWorker = {
|
|
18
|
-
worker,
|
|
19
|
-
activeJobs: 0
|
|
20
|
-
};
|
|
21
|
-
worker.addEventListener('message', event => {
|
|
22
|
-
this.handleWorkerMessage(event, hasherWorker);
|
|
23
|
-
});
|
|
24
|
-
return hasherWorker;
|
|
25
|
-
}
|
|
26
|
-
handleWorkerMessage(event, hasherWorker) {
|
|
27
|
-
const id = event.data.id;
|
|
28
|
-
if (this.jobs[id]) {
|
|
29
|
-
const {
|
|
30
|
-
resolve,
|
|
31
|
-
reject
|
|
32
|
-
} = this.jobs[id];
|
|
33
|
-
delete this.jobs[id];
|
|
34
|
-
hasherWorker.activeJobs--;
|
|
35
|
-
if (event.data.error) {
|
|
36
|
-
// TODO previously we were just calling it again.
|
|
37
|
-
// this.calculateHashInWorker(chunk);
|
|
38
|
-
reject(event.data.error);
|
|
39
|
-
} else {
|
|
40
|
-
resolve(event.data.hash);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
calculateHashInWorker(blob) {
|
|
45
|
-
const jobId = uuidV4();
|
|
46
|
-
return new Promise((resolve, reject) => {
|
|
47
|
-
this.jobs[jobId] = {
|
|
48
|
-
resolve,
|
|
49
|
-
reject
|
|
50
|
-
};
|
|
51
|
-
const worker = this.getMostRelaxedWorker();
|
|
52
|
-
this.dispatch(jobId, worker, blob);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
dispatch(jobId, hasherWorker, chunkBlob) {
|
|
56
|
-
hasherWorker.activeJobs++;
|
|
57
|
-
const worker = hasherWorker.worker;
|
|
58
|
-
|
|
59
|
-
/*
|
|
60
|
-
* postMessage() with chunk blob in Safari results in the error
|
|
61
|
-
* "Failed to load resource: The operation could not be completed. (WebKitBlobResource error 1.)"
|
|
62
|
-
*
|
|
63
|
-
* To prevent it, we read the data from the blob using FileReader and pass it via postMessage to the worker.
|
|
64
|
-
*/
|
|
65
|
-
if (navigator.userAgent.indexOf('Safari') > -1 && navigator.userAgent.indexOf('Chrome') === -1) {
|
|
66
|
-
const rd = new FileReader();
|
|
67
|
-
rd.onload = () => {
|
|
68
|
-
worker.postMessage({
|
|
69
|
-
id: jobId,
|
|
70
|
-
data: rd.result
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
rd.readAsBinaryString(chunkBlob);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
worker.postMessage({
|
|
77
|
-
id: jobId,
|
|
78
|
-
data: chunkBlob
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
getMostRelaxedWorker() {
|
|
82
|
-
return this.workers.reduce((current, next) => {
|
|
83
|
-
if (next.activeJobs < current.activeJobs) {
|
|
84
|
-
return next;
|
|
85
|
-
}
|
|
86
|
-
return current;
|
|
87
|
-
}, this.workers[0]);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
import uuidV4 from 'uuid/v4';
|
|
5
|
-
import Rusha from 'rusha';
|
|
6
|
-
export var WorkerHasher = /*#__PURE__*/function () {
|
|
7
|
-
function WorkerHasher(numOfWorkers) {
|
|
8
|
-
_classCallCheck(this, WorkerHasher);
|
|
9
|
-
_defineProperty(this, "workers", []);
|
|
10
|
-
_defineProperty(this, "jobs", {});
|
|
11
|
-
for (var i = 0; i < numOfWorkers; ++i) {
|
|
12
|
-
this.workers.push(this.createWorker());
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return _createClass(WorkerHasher, [{
|
|
16
|
-
key: "hash",
|
|
17
|
-
value: function hash(chunk) {
|
|
18
|
-
return this.calculateHashInWorker(chunk);
|
|
19
|
-
}
|
|
20
|
-
}, {
|
|
21
|
-
key: "createWorker",
|
|
22
|
-
value: function createWorker() {
|
|
23
|
-
var _this = this;
|
|
24
|
-
var worker = Rusha.createWorker();
|
|
25
|
-
var hasherWorker = {
|
|
26
|
-
worker: worker,
|
|
27
|
-
activeJobs: 0
|
|
28
|
-
};
|
|
29
|
-
worker.addEventListener('message', function (event) {
|
|
30
|
-
_this.handleWorkerMessage(event, hasherWorker);
|
|
31
|
-
});
|
|
32
|
-
return hasherWorker;
|
|
33
|
-
}
|
|
34
|
-
}, {
|
|
35
|
-
key: "handleWorkerMessage",
|
|
36
|
-
value: function handleWorkerMessage(event, hasherWorker) {
|
|
37
|
-
var id = event.data.id;
|
|
38
|
-
if (this.jobs[id]) {
|
|
39
|
-
var _this$jobs$id = this.jobs[id],
|
|
40
|
-
resolve = _this$jobs$id.resolve,
|
|
41
|
-
reject = _this$jobs$id.reject;
|
|
42
|
-
delete this.jobs[id];
|
|
43
|
-
hasherWorker.activeJobs--;
|
|
44
|
-
if (event.data.error) {
|
|
45
|
-
// TODO previously we were just calling it again.
|
|
46
|
-
// this.calculateHashInWorker(chunk);
|
|
47
|
-
reject(event.data.error);
|
|
48
|
-
} else {
|
|
49
|
-
resolve(event.data.hash);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}, {
|
|
54
|
-
key: "calculateHashInWorker",
|
|
55
|
-
value: function calculateHashInWorker(blob) {
|
|
56
|
-
var _this2 = this;
|
|
57
|
-
var jobId = uuidV4();
|
|
58
|
-
return new Promise(function (resolve, reject) {
|
|
59
|
-
_this2.jobs[jobId] = {
|
|
60
|
-
resolve: resolve,
|
|
61
|
-
reject: reject
|
|
62
|
-
};
|
|
63
|
-
var worker = _this2.getMostRelaxedWorker();
|
|
64
|
-
_this2.dispatch(jobId, worker, blob);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}, {
|
|
68
|
-
key: "dispatch",
|
|
69
|
-
value: function dispatch(jobId, hasherWorker, chunkBlob) {
|
|
70
|
-
hasherWorker.activeJobs++;
|
|
71
|
-
var worker = hasherWorker.worker;
|
|
72
|
-
|
|
73
|
-
/*
|
|
74
|
-
* postMessage() with chunk blob in Safari results in the error
|
|
75
|
-
* "Failed to load resource: The operation could not be completed. (WebKitBlobResource error 1.)"
|
|
76
|
-
*
|
|
77
|
-
* To prevent it, we read the data from the blob using FileReader and pass it via postMessage to the worker.
|
|
78
|
-
*/
|
|
79
|
-
if (navigator.userAgent.indexOf('Safari') > -1 && navigator.userAgent.indexOf('Chrome') === -1) {
|
|
80
|
-
var rd = new FileReader();
|
|
81
|
-
rd.onload = function () {
|
|
82
|
-
worker.postMessage({
|
|
83
|
-
id: jobId,
|
|
84
|
-
data: rd.result
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
rd.readAsBinaryString(chunkBlob);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
worker.postMessage({
|
|
91
|
-
id: jobId,
|
|
92
|
-
data: chunkBlob
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}, {
|
|
96
|
-
key: "getMostRelaxedWorker",
|
|
97
|
-
value: function getMostRelaxedWorker() {
|
|
98
|
-
return this.workers.reduce(function (current, next) {
|
|
99
|
-
if (next.activeJobs < current.activeJobs) {
|
|
100
|
-
return next;
|
|
101
|
-
}
|
|
102
|
-
return current;
|
|
103
|
-
}, this.workers[0]);
|
|
104
|
-
}
|
|
105
|
-
}]);
|
|
106
|
-
}();
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type Hasher } from './hasher';
|
|
2
|
-
export interface Deferred {
|
|
3
|
-
resolve: (hash: string) => void;
|
|
4
|
-
reject: (error: any) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare class WorkerHasher implements Hasher {
|
|
7
|
-
private workers;
|
|
8
|
-
private jobs;
|
|
9
|
-
constructor(numOfWorkers: number);
|
|
10
|
-
hash(chunk: Blob): Promise<string>;
|
|
11
|
-
private createWorker;
|
|
12
|
-
private handleWorkerMessage;
|
|
13
|
-
private calculateHashInWorker;
|
|
14
|
-
private dispatch;
|
|
15
|
-
private getMostRelaxedWorker;
|
|
16
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type Hasher } from './hasher';
|
|
2
|
-
export interface Deferred {
|
|
3
|
-
resolve: (hash: string) => void;
|
|
4
|
-
reject: (error: any) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare class WorkerHasher implements Hasher {
|
|
7
|
-
private workers;
|
|
8
|
-
private jobs;
|
|
9
|
-
constructor(numOfWorkers: number);
|
|
10
|
-
hash(chunk: Blob): Promise<string>;
|
|
11
|
-
private createWorker;
|
|
12
|
-
private handleWorkerMessage;
|
|
13
|
-
private calculateHashInWorker;
|
|
14
|
-
private dispatch;
|
|
15
|
-
private getMostRelaxedWorker;
|
|
16
|
-
}
|