@atlaskit/media-client 33.1.1 → 33.3.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 +311 -116
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/models/file-state.js +4 -1
- package/dist/es2019/client/file-fetcher/index.js +84 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/models/file-state.js +1 -0
- package/dist/esm/client/file-fetcher/index.js +311 -116
- package/dist/esm/index.js +1 -1
- package/dist/esm/models/file-state.js +3 -0
- package/dist/types/client/file-fetcher/index.d.ts +13 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/models/file-state.d.ts +4 -1
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +13 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/models/file-state.d.ts +4 -1
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -171,6 +171,12 @@ Object.defineProperty(exports, "globalMediaEventEmitter", {
|
|
|
171
171
|
return _globalMediaEventEmitter.globalMediaEventEmitter;
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
|
+
Object.defineProperty(exports, "hasArtifacts", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function get() {
|
|
177
|
+
return _fileState.hasArtifacts;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
174
180
|
Object.defineProperty(exports, "imageResizeModeToFileImageMode", {
|
|
175
181
|
enumerable: true,
|
|
176
182
|
get: function get() {
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.mapMediaItemToFileState = exports.mapMediaFileToFileState = exports.isUploadingFileState = exports.isProcessingFileState = exports.isProcessedFileState = exports.isPreviewableFileState = exports.isNonErrorFinalFileState = exports.isImageRepresentationReady = exports.isFinalFileState = exports.isErrorFileState = void 0;
|
|
7
|
+
exports.mapMediaItemToFileState = exports.mapMediaFileToFileState = exports.isUploadingFileState = exports.isProcessingFileState = exports.isProcessedFileState = exports.isPreviewableFileState = exports.isNonErrorFinalFileState = exports.isImageRepresentationReady = exports.isFinalFileState = exports.isErrorFileState = exports.hasArtifacts = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
10
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -29,6 +29,9 @@ var isFinalFileState = exports.isFinalFileState = function isFinalFileState(file
|
|
|
29
29
|
var isNonErrorFinalFileState = exports.isNonErrorFinalFileState = function isNonErrorFinalFileState(fileState) {
|
|
30
30
|
return ['processed', 'failed-processing'].includes(fileState.status);
|
|
31
31
|
};
|
|
32
|
+
var hasArtifacts = exports.hasArtifacts = function hasArtifacts(fileState) {
|
|
33
|
+
return 'artifacts' in fileState && fileState.artifacts !== undefined;
|
|
34
|
+
};
|
|
32
35
|
var isImageRepresentationReady = exports.isImageRepresentationReady = function isImageRepresentationReady(fileState) {
|
|
33
36
|
switch (fileState.status) {
|
|
34
37
|
case 'processing':
|
|
@@ -155,6 +155,90 @@ export class FileFetcherImpl {
|
|
|
155
155
|
this.setFileState(id, mapMediaItemToFileState(id, itemDetails));
|
|
156
156
|
return data;
|
|
157
157
|
});
|
|
158
|
+
_defineProperty(this, "getOrFetchFileState", async (id, collectionName) => {
|
|
159
|
+
let fileState = this.store.getState().files[id];
|
|
160
|
+
return fileState !== null && fileState !== void 0 ? fileState : await this.getCurrentState(id, {
|
|
161
|
+
collectionName
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
_defineProperty(this, "getDurationOfVideo", async (id, collectionName) => {
|
|
165
|
+
const fileState = await this.getOrFetchFileState(id, collectionName);
|
|
166
|
+
if (fileState.status !== 'processed' || fileState.mediaType !== 'video' || !fileState.artifacts['video.mp4']) {
|
|
167
|
+
throw new Error('File is not a video');
|
|
168
|
+
}
|
|
169
|
+
const aritfactUrl = await this.getArtifactURL(fileState.artifacts, 'video.mp4');
|
|
170
|
+
const artifactPath = new URL(aritfactUrl).pathname;
|
|
171
|
+
const res = await this.mediaApi.request(artifactPath, {
|
|
172
|
+
headers: {
|
|
173
|
+
Range: 'bytes=0-199'
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// Get the response as ArrayBuffer
|
|
178
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
179
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
180
|
+
const mvhdBytes = new Uint8Array([109, 118, 104, 100]); // "mvhd" in ASCII
|
|
181
|
+
|
|
182
|
+
let mvhdIndex = -1;
|
|
183
|
+
for (let i = 0; i <= uint8Array.length - mvhdBytes.length; i++) {
|
|
184
|
+
mvhdIndex = i;
|
|
185
|
+
for (let j = 0; j < mvhdBytes.length; j++) {
|
|
186
|
+
if (uint8Array[i + j] !== mvhdBytes[j]) {
|
|
187
|
+
mvhdIndex = -1;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (mvhdIndex !== -1) {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (mvhdIndex === -1) {
|
|
196
|
+
throw new Error('Unable to find mvhd bytes');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Create DataView for reading big-endian integers
|
|
200
|
+
const dataView = new DataView(arrayBuffer);
|
|
201
|
+
const start = mvhdIndex + 16; // Skip atom header and version/flags
|
|
202
|
+
|
|
203
|
+
// Check if we have enough bytes to read timescale and duration
|
|
204
|
+
if (start + 8 > arrayBuffer.byteLength) {
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// flase as second parameter indicates big-endian 32-bit integers
|
|
209
|
+
const timeScale = dataView.getUint32(start, false);
|
|
210
|
+
const duration = dataView.getUint32(start + 4, false);
|
|
211
|
+
if (timeScale === 0) {
|
|
212
|
+
throw new Error('Timescale is invalid');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// get the video length in seconds
|
|
216
|
+
const videoLength = Math.floor(duration / timeScale);
|
|
217
|
+
return videoLength;
|
|
218
|
+
});
|
|
219
|
+
_defineProperty(this, "getVideoDurations", async files => {
|
|
220
|
+
// get all the duration promises
|
|
221
|
+
const promises = files.map(async ({
|
|
222
|
+
id,
|
|
223
|
+
collectionName
|
|
224
|
+
}) => {
|
|
225
|
+
try {
|
|
226
|
+
return await this.getDurationOfVideo(id, collectionName);
|
|
227
|
+
} catch (_err) {
|
|
228
|
+
return -1;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
const durations = await Promise.all(promises);
|
|
232
|
+
|
|
233
|
+
// only return the durations that are present;
|
|
234
|
+
return durations.reduce((acc, curr, i) => {
|
|
235
|
+
if (curr !== -1) {
|
|
236
|
+
const id = files[i].id;
|
|
237
|
+
acc[id] = curr;
|
|
238
|
+
}
|
|
239
|
+
return acc;
|
|
240
|
+
}, {});
|
|
241
|
+
});
|
|
158
242
|
this.mediaApi = mediaApi;
|
|
159
243
|
this.store = store;
|
|
160
244
|
this.dataloader = createFileDataloader(mediaApi);
|
package/dist/es2019/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { UploadController } from './upload-controller';
|
|
|
3
3
|
export { isPreviewableType } from './models/media';
|
|
4
4
|
export { getArtifactUrl } from './models/artifacts';
|
|
5
5
|
export { isMediaClientError, getMediaClientErrorReason, isCommonMediaClientError, toCommonMediaClientError } from './models/errors';
|
|
6
|
-
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState } from './models/file-state';
|
|
6
|
+
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, isNonErrorFinalFileState, mapMediaFileToFileState, mapMediaItemToFileState, hasArtifacts } from './models/file-state';
|
|
7
7
|
export { uploadFile } from './uploader';
|
|
8
8
|
export { request, RequestError, isRequestError, isRateLimitedError, createRequestErrorReason } from './utils/request';
|
|
9
9
|
export { isAbortedRequestError, createUrl } from './utils/request/helpers';
|
|
@@ -5,6 +5,7 @@ export const isErrorFileState = fileState => fileState.status === 'error';
|
|
|
5
5
|
export const isPreviewableFileState = fileState => !isErrorFileState(fileState) && !!fileState.preview;
|
|
6
6
|
export const isFinalFileState = fileState => ['processed', 'failed-processing', 'error'].includes(fileState.status);
|
|
7
7
|
export const isNonErrorFinalFileState = fileState => ['processed', 'failed-processing'].includes(fileState.status);
|
|
8
|
+
export const hasArtifacts = fileState => 'artifacts' in fileState && fileState.artifacts !== undefined;
|
|
8
9
|
export const isImageRepresentationReady = fileState => {
|
|
9
10
|
switch (fileState.status) {
|
|
10
11
|
case 'processing':
|