@atlaskit/media-client 35.7.0 → 35.8.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 +19 -0
- package/dist/cjs/client/file-fetcher/index.js +3 -3
- package/dist/cjs/client/media-client.js +43 -24
- package/dist/cjs/client/media-store/MediaStore.js +189 -148
- package/dist/cjs/models/file-state.js +4 -2
- package/dist/cjs/utils/url.js +3 -1
- package/dist/es2019/client/file-fetcher/index.js +2 -2
- package/dist/es2019/client/media-client.js +3 -0
- package/dist/es2019/client/media-store/MediaStore.js +21 -2
- package/dist/es2019/models/file-state.js +4 -2
- package/dist/es2019/utils/url.js +3 -1
- package/dist/esm/client/file-fetcher/index.js +3 -3
- package/dist/esm/client/media-client.js +43 -24
- package/dist/esm/client/media-store/MediaStore.js +189 -148
- package/dist/esm/models/file-state.js +4 -2
- package/dist/esm/utils/url.js +3 -1
- package/dist/types/client/events.d.ts +1 -0
- package/dist/types/client/file-fetcher/index.d.ts +1 -0
- package/dist/types/client/media-client.d.ts +1 -0
- package/dist/types/client/media-store/MediaStore.d.ts +2 -1
- package/dist/types/models/item.d.ts +2 -0
- package/dist/types/models/media.d.ts +3 -1
- package/dist/types/utils/url.d.ts +1 -0
- package/dist/types-ts4.5/client/events.d.ts +1 -0
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +1 -0
- package/dist/types-ts4.5/client/media-client.d.ts +1 -0
- package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +2 -1
- package/dist/types-ts4.5/models/item.d.ts +2 -0
- package/dist/types-ts4.5/models/media.d.ts +3 -1
- package/dist/types-ts4.5/utils/url.d.ts +1 -0
- package/package.json +4 -3
|
@@ -56,7 +56,8 @@ var mapMediaFileToFileState = exports.mapMediaFileToFileState = function mapMedi
|
|
|
56
56
|
metadataTraceContext = _mediaFile$data.metadataTraceContext,
|
|
57
57
|
hash = _mediaFile$data.hash,
|
|
58
58
|
abuseClassification = _mediaFile$data.abuseClassification,
|
|
59
|
-
mediaMetadata = _mediaFile$data.mediaMetadata
|
|
59
|
+
mediaMetadata = _mediaFile$data.mediaMetadata,
|
|
60
|
+
failReason = _mediaFile$data.failReason;
|
|
60
61
|
var baseState = {
|
|
61
62
|
id: id,
|
|
62
63
|
name: name,
|
|
@@ -83,7 +84,8 @@ var mapMediaFileToFileState = exports.mapMediaFileToFileState = function mapMedi
|
|
|
83
84
|
});
|
|
84
85
|
case 'failed':
|
|
85
86
|
return _objectSpread(_objectSpread({}, baseState), {}, {
|
|
86
|
-
status: 'failed-processing'
|
|
87
|
+
status: 'failed-processing',
|
|
88
|
+
failReason: failReason
|
|
87
89
|
});
|
|
88
90
|
}
|
|
89
91
|
};
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -29,13 +29,15 @@ var getAttrsFromUrl = exports.getAttrsFromUrl = function getAttrsFromUrl(blobUrl
|
|
|
29
29
|
var params = new URLSearchParams(hash);
|
|
30
30
|
var id = params.get('id');
|
|
31
31
|
var contextId = params.get('contextId');
|
|
32
|
-
|
|
32
|
+
var clientId = params.get('clientId');
|
|
33
|
+
// check if we have the required params (clientId is optional for backwards compatibility)
|
|
33
34
|
if (!id || !contextId) {
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
37
|
return {
|
|
37
38
|
id: id,
|
|
38
39
|
contextId: contextId,
|
|
40
|
+
clientId: clientId || undefined,
|
|
39
41
|
collection: getStringFromParams(params, 'collection'),
|
|
40
42
|
alt: getStringFromParams(params, 'alt'),
|
|
41
43
|
height: getNumberFromParams(params, 'height'),
|
|
@@ -249,7 +249,7 @@ export class FileFetcherImpl {
|
|
|
249
249
|
}) => {
|
|
250
250
|
try {
|
|
251
251
|
return await this.getDurationOfVideo(id, collectionName);
|
|
252
|
-
} catch
|
|
252
|
+
} catch {
|
|
253
253
|
return -1;
|
|
254
254
|
}
|
|
255
255
|
});
|
|
@@ -557,7 +557,7 @@ export class FileFetcherImpl {
|
|
|
557
557
|
sourceCollection: source.collection,
|
|
558
558
|
collection: destination.collection,
|
|
559
559
|
replaceFileId: destination.replaceFileId
|
|
560
|
-
}, traceContext);
|
|
560
|
+
}, traceContext, source.clientId);
|
|
561
561
|
const {
|
|
562
562
|
data
|
|
563
563
|
} = res;
|
|
@@ -39,6 +39,9 @@ export class MediaClient {
|
|
|
39
39
|
getImageUrlSync(id, params) {
|
|
40
40
|
return this.mediaStore.getFileImageURLSync(id, params);
|
|
41
41
|
}
|
|
42
|
+
async getClientId(collectionName) {
|
|
43
|
+
return this.mediaStore.getClientId(collectionName);
|
|
44
|
+
}
|
|
42
45
|
async getImageMetadata(id, params) {
|
|
43
46
|
return (await this.mediaStore.getImageMetadata(id, params)).metadata;
|
|
44
47
|
}
|
|
@@ -34,6 +34,9 @@ const cdnFeatureFlag = endpoint => {
|
|
|
34
34
|
}
|
|
35
35
|
return result;
|
|
36
36
|
};
|
|
37
|
+
const decodeJwtToken = token => {
|
|
38
|
+
return JSON.parse(atob(token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/')));
|
|
39
|
+
};
|
|
37
40
|
export class MediaStore {
|
|
38
41
|
constructor(config) {
|
|
39
42
|
_defineProperty(this, "getArtifactBinary", async (artifacts, artifactName, {
|
|
@@ -114,6 +117,21 @@ export class MediaStore {
|
|
|
114
117
|
this.config = config;
|
|
115
118
|
this._chunkHashAlgorithm = config.chunkHashAlgorithm || ChunkHashAlgorithm.Sha256;
|
|
116
119
|
}
|
|
120
|
+
async getClientId(collectionName) {
|
|
121
|
+
const auth = await this.resolveAuth({
|
|
122
|
+
collectionName
|
|
123
|
+
});
|
|
124
|
+
if (!isClientBasedAuth(auth)) {
|
|
125
|
+
// decode JWT token and get clientId from payload
|
|
126
|
+
try {
|
|
127
|
+
const jwtPayload = decodeJwtToken(auth.token);
|
|
128
|
+
return jwtPayload.clientId;
|
|
129
|
+
} catch {
|
|
130
|
+
// leave clientId as undefined
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return isClientBasedAuth(auth) ? auth.clientId : undefined;
|
|
134
|
+
}
|
|
117
135
|
async removeCollectionFile(id, collectionName, occurrenceKey, traceContext) {
|
|
118
136
|
const metadata = {
|
|
119
137
|
method: 'PUT',
|
|
@@ -501,7 +519,7 @@ export class MediaStore {
|
|
|
501
519
|
};
|
|
502
520
|
return this.request('/file/copy/withToken', options).then(createMapResponseToJson(metadata));
|
|
503
521
|
}
|
|
504
|
-
copyFile(id, params, traceContext) {
|
|
522
|
+
copyFile(id, params, traceContext, clientId) {
|
|
505
523
|
const metadata = {
|
|
506
524
|
method: 'POST',
|
|
507
525
|
endpoint: '/v2/file/copy'
|
|
@@ -514,7 +532,8 @@ export class MediaStore {
|
|
|
514
532
|
params,
|
|
515
533
|
headers: jsonHeaders,
|
|
516
534
|
body: JSON.stringify({
|
|
517
|
-
id
|
|
535
|
+
id,
|
|
536
|
+
clientId
|
|
518
537
|
}),
|
|
519
538
|
traceContext,
|
|
520
539
|
clientOptions: {
|
|
@@ -30,7 +30,8 @@ export const mapMediaFileToFileState = mediaFile => {
|
|
|
30
30
|
metadataTraceContext,
|
|
31
31
|
hash,
|
|
32
32
|
abuseClassification,
|
|
33
|
-
mediaMetadata
|
|
33
|
+
mediaMetadata,
|
|
34
|
+
failReason
|
|
34
35
|
} = mediaFile.data;
|
|
35
36
|
const baseState = {
|
|
36
37
|
id,
|
|
@@ -61,7 +62,8 @@ export const mapMediaFileToFileState = mediaFile => {
|
|
|
61
62
|
case 'failed':
|
|
62
63
|
return {
|
|
63
64
|
...baseState,
|
|
64
|
-
status: 'failed-processing'
|
|
65
|
+
status: 'failed-processing',
|
|
66
|
+
failReason
|
|
65
67
|
};
|
|
66
68
|
}
|
|
67
69
|
};
|
package/dist/es2019/utils/url.js
CHANGED
|
@@ -19,13 +19,15 @@ export const getAttrsFromUrl = blobUrl => {
|
|
|
19
19
|
const params = new URLSearchParams(hash);
|
|
20
20
|
const id = params.get('id');
|
|
21
21
|
const contextId = params.get('contextId');
|
|
22
|
-
|
|
22
|
+
const clientId = params.get('clientId');
|
|
23
|
+
// check if we have the required params (clientId is optional for backwards compatibility)
|
|
23
24
|
if (!id || !contextId) {
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
27
|
return {
|
|
27
28
|
id,
|
|
28
29
|
contextId,
|
|
30
|
+
clientId: clientId || undefined,
|
|
29
31
|
collection: getStringFromParams(params, 'collection'),
|
|
30
32
|
alt: getStringFromParams(params, 'alt'),
|
|
31
33
|
height: getNumberFromParams(params, 'height'),
|
|
@@ -59,8 +59,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
59
59
|
var err = new CommonMediaClientError(error);
|
|
60
60
|
return fromCommonMediaClientError(id, occurrenceKey, err);
|
|
61
61
|
} else {
|
|
62
|
-
var
|
|
63
|
-
return fromCommonMediaClientError(id, occurrenceKey,
|
|
62
|
+
var _err = new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown', error === null || error === void 0 ? void 0 : error.metadata, error === null || error === void 0 ? void 0 : error.innerError);
|
|
63
|
+
return fromCommonMediaClientError(id, occurrenceKey, _err);
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
_defineProperty(this, "setFileState", function (id, fileState) {
|
|
@@ -867,7 +867,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
867
867
|
sourceCollection: source.collection,
|
|
868
868
|
collection: destination.collection,
|
|
869
869
|
replaceFileId: destination.replaceFileId
|
|
870
|
-
}, traceContext);
|
|
870
|
+
}, traceContext, source.clientId);
|
|
871
871
|
case 2:
|
|
872
872
|
res = _context12.sent;
|
|
873
873
|
data = res.data;
|
|
@@ -55,23 +55,42 @@ export var MediaClient = /*#__PURE__*/function () {
|
|
|
55
55
|
return this.mediaStore.getFileImageURLSync(id, params);
|
|
56
56
|
}
|
|
57
57
|
}, {
|
|
58
|
-
key: "
|
|
58
|
+
key: "getClientId",
|
|
59
59
|
value: function () {
|
|
60
|
-
var
|
|
60
|
+
var _getClientId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(collectionName) {
|
|
61
61
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
62
62
|
while (1) switch (_context.prev = _context.next) {
|
|
63
63
|
case 0:
|
|
64
|
-
_context.
|
|
64
|
+
return _context.abrupt("return", this.mediaStore.getClientId(collectionName));
|
|
65
|
+
case 1:
|
|
66
|
+
case "end":
|
|
67
|
+
return _context.stop();
|
|
68
|
+
}
|
|
69
|
+
}, _callee, this);
|
|
70
|
+
}));
|
|
71
|
+
function getClientId(_x) {
|
|
72
|
+
return _getClientId.apply(this, arguments);
|
|
73
|
+
}
|
|
74
|
+
return getClientId;
|
|
75
|
+
}()
|
|
76
|
+
}, {
|
|
77
|
+
key: "getImageMetadata",
|
|
78
|
+
value: function () {
|
|
79
|
+
var _getImageMetadata = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, params) {
|
|
80
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
81
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
_context2.next = 2;
|
|
65
84
|
return this.mediaStore.getImageMetadata(id, params);
|
|
66
85
|
case 2:
|
|
67
|
-
return
|
|
86
|
+
return _context2.abrupt("return", _context2.sent.metadata);
|
|
68
87
|
case 3:
|
|
69
88
|
case "end":
|
|
70
|
-
return
|
|
89
|
+
return _context2.stop();
|
|
71
90
|
}
|
|
72
|
-
},
|
|
91
|
+
}, _callee2, this);
|
|
73
92
|
}));
|
|
74
|
-
function getImageMetadata(
|
|
93
|
+
function getImageMetadata(_x2, _x3) {
|
|
75
94
|
return _getImageMetadata.apply(this, arguments);
|
|
76
95
|
}
|
|
77
96
|
return getImageMetadata;
|
|
@@ -79,28 +98,28 @@ export var MediaClient = /*#__PURE__*/function () {
|
|
|
79
98
|
}, {
|
|
80
99
|
key: "mobileUploadPromise",
|
|
81
100
|
value: function () {
|
|
82
|
-
var _mobileUploadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
101
|
+
var _mobileUploadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
83
102
|
var module;
|
|
84
|
-
return _regeneratorRuntime.wrap(function
|
|
85
|
-
while (1) switch (
|
|
103
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
104
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
86
105
|
case 0:
|
|
87
106
|
if (!this.mobileUpload) {
|
|
88
|
-
|
|
107
|
+
_context3.next = 2;
|
|
89
108
|
break;
|
|
90
109
|
}
|
|
91
|
-
return
|
|
110
|
+
return _context3.abrupt("return", this.mobileUpload);
|
|
92
111
|
case 2:
|
|
93
|
-
|
|
112
|
+
_context3.next = 4;
|
|
94
113
|
return import( /* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */'./mobile-upload');
|
|
95
114
|
case 4:
|
|
96
|
-
module =
|
|
115
|
+
module = _context3.sent;
|
|
97
116
|
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore, this.store);
|
|
98
|
-
return
|
|
117
|
+
return _context3.abrupt("return", this.mobileUpload);
|
|
99
118
|
case 7:
|
|
100
119
|
case "end":
|
|
101
|
-
return
|
|
120
|
+
return _context3.stop();
|
|
102
121
|
}
|
|
103
|
-
},
|
|
122
|
+
}, _callee3, this);
|
|
104
123
|
}));
|
|
105
124
|
function mobileUploadPromise() {
|
|
106
125
|
return _mobileUploadPromise.apply(this, arguments);
|
|
@@ -110,19 +129,19 @@ export var MediaClient = /*#__PURE__*/function () {
|
|
|
110
129
|
}, {
|
|
111
130
|
key: "removeFileFromCollection",
|
|
112
131
|
value: function () {
|
|
113
|
-
var _removeFileFromCollection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
114
|
-
return _regeneratorRuntime.wrap(function
|
|
115
|
-
while (1) switch (
|
|
132
|
+
var _removeFileFromCollection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id, collectionName, occurrenceKey, traceContext) {
|
|
133
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
134
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
116
135
|
case 0:
|
|
117
|
-
|
|
136
|
+
_context4.next = 2;
|
|
118
137
|
return this.mediaStore.removeCollectionFile(id, collectionName, occurrenceKey, traceContext);
|
|
119
138
|
case 2:
|
|
120
139
|
case "end":
|
|
121
|
-
return
|
|
140
|
+
return _context4.stop();
|
|
122
141
|
}
|
|
123
|
-
},
|
|
142
|
+
}, _callee4, this);
|
|
124
143
|
}));
|
|
125
|
-
function removeFileFromCollection(
|
|
144
|
+
function removeFileFromCollection(_x4, _x5, _x6, _x7) {
|
|
126
145
|
return _removeFileFromCollection.apply(this, arguments);
|
|
127
146
|
}
|
|
128
147
|
return removeFileFromCollection;
|