Repository URL to install this package:
|
Version:
3.12.20 ▾
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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; }
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) { _defineProperty(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; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import createThunk from '@filerobot/utils/lib/createThunk';
import getFileLink from '@filerobot/utils/lib/getFileLink';
import { selectFileByUuid, sliceName as filesSliceName } from '../slices/files.slice';
// We are using the slice name of files.slice, cause we want to trigger the extra reducer of file updating in 'files.slice.js'
// And this is happens by naming the triggered action, with the same matching patterns of that extra reducer.
var actionTypePrefix = filesSliceName;
export var checkVideoTranscodingProcess = createThunk(async function (payload, thunkApi) {
var uuid = payload.uuid,
progressUrl = payload.progressUrl,
i18n = payload.i18n,
noInformer = payload.noInformer;
try {
// Trigger the request to get the progress of the transcoding process.
var _await$thunkApi$extra = await thunkApi.extra.apiClient.get(progressUrl, {
noDefaultHeaders: true,
abortSignal: thunkApi.signal
}),
progress = _await$thunkApi$extra.progress,
ready = _await$thunkApi$extra.ready;
if (!ready) {
setTimeout(function () {
return thunkApi.dispatch(checkVideoTranscodingProcess(payload));
}, 3000);
} else {
if (!noInformer) {
thunkApi.extra.filerobot.info(i18n('explorerTranscodingFinishedInfo'), 'success');
}
return {
uuid: uuid,
transcodingCheckSent: true,
transcodingInProgress: false,
transcodingProgress: i18n('mutualizedYesButton')
};
}
return {
uuid: uuid,
transcodingCheckSent: true,
transcodingProgress: "".concat(progress, "%")
};
} catch (error) {
return {
uuid: uuid,
transcodingProgress: undefined,
transcodingCheckSent: false
};
}
},
// We are appending updateFile to trigger the extra reducer, so it starts with the sliceName, and contains updateFile same as extra reducer's matching needs.
{
actionType: "".concat(actionTypePrefix, "/updateFileByCheckingVideoTranscoding"),
skipPendingDispatch: true
});
export var transcodeVideoResolution = createThunk(async function (payload, thunkApi) {
// We are adding uuid alone for being discovered from the extraReducer in updateFile of (files.slice).
var uuid = payload.uuid,
file = payload.file,
resolution = payload.resolution,
i18n = payload.i18n;
var _thunkApi$extra$filer = thunkApi.extra.filerobot.opts,
container = _thunkApi$extra$filer.container,
apiEndpoint = _thunkApi$extra$filer.apiEndpoint,
sassKey = _thunkApi$extra$filer.sassKey;
var _await$thunkApi$extra2 = await thunkApi.extra.apiClient.post("".concat(apiEndpoint, "/videos/transcode/url"), {
data: [{
url: getFileLink(file, 'public'),
filerobot_file_uuid: uuid,
video_resolutions: resolution
}],
headers: {
'Filerobot-Token': container,
'Filerobot-uuid': uuid,
'X-Filerobot-Key': sassKey
},
abortSignal: thunkApi.signal
}),
progress = _await$thunkApi$extra2.progress,
playlists = _await$thunkApi$extra2.playlists;
// We are adding the playlists here not inside the onload
// for avoiding the delay of the req. and hiding the transcode item ASAP for avoiding re-sending req.
var updatedFile = {
uuid: uuid,
transcodingCheckSent: true,
info: _objectSpread(_objectSpread({}, file.info), {}, {
progress: progress,
playlists: playlists
})
};
thunkApi.dispatch(checkVideoTranscodingProcess({
progressUrl: progress,
uuid: uuid,
i18n: i18n
}));
return updatedFile;
}, {
// We are appending updateFile to trigger the extra reducer, so it starts with the sliceName, and contains updateFile same as extra reducer's matching needs.
actionType: "".concat(actionTypePrefix, "/updateFileByVideoTranscodingResolution"),
condition: function condition(file) {
return !(file.transcodingInProgress || file.transcodingCheckSent);
}
});
export var transcodeEmbedVideo = createThunk(async function (_ref, thunkApi) {
var url = _ref.url,
uuid = _ref.uuid,
protocol = _ref.protocol;
var _thunkApi$extra$filer2 = thunkApi.extra.filerobot.opts,
videoApiEndpoint = _thunkApi$extra$filer2.videoApiEndpoint,
container = _thunkApi$extra$filer2.container,
sassKey = _thunkApi$extra$filer2.sassKey;
var _await$thunkApi$extra3 = await thunkApi.extra.apiClient.post("".concat(videoApiEndpoint, "/transcode/url"), {
data: [{
url: url,
video_protocols: protocol
}],
headers: {
'Filerobot-Token': container,
'Filerobot-uuid': uuid,
'X-Filerobot-Key': sassKey
},
noDefaultHeaders: true,
abortSignal: thunkApi.signal
}),
_await$thunkApi$extra4 = _await$thunkApi$extra3.result,
_await$thunkApi$extra5 = _await$thunkApi$extra4 === void 0 ? [{}] : _await$thunkApi$extra4,
_await$thunkApi$extra6 = _slicedToArray(_await$thunkApi$extra5, 1),
transcoded = _await$thunkApi$extra6[0].transcoded;
var file = selectFileByUuid(thunkApi.getState(), uuid);
return {
uuid: uuid,
info: _objectSpread(_objectSpread({}, file.info), {}, {
playlists: transcoded[0].playlists
})
};
},
// We are appending updateFile to trigger the extra reducer, so it starts with the sliceName, and contains updateFile same as extra reducer's matching needs.
{
actionType: "".concat(actionTypePrefix, "/updateFileByTranscodeEmbedVideo")
});
export var convertVideo = createThunk(async function (_ref2, thunkApi) {
var url = _ref2.url,
isInternal = _ref2.isInternal,
filePath = _ref2.filePath,
uuid = _ref2.uuid,
format = _ref2.format;
var _thunkApi$extra$filer3 = thunkApi.extra.filerobot.opts,
videoApiEndpoint = _thunkApi$extra$filer3.videoApiEndpoint,
container = _thunkApi$extra$filer3.container,
sassKey = _thunkApi$extra$filer3.sassKey;
var _await$thunkApi$extra7 = await thunkApi.extra.apiClient.post("".concat(videoApiEndpoint, "/convert/url?output_format=").concat(format), {
headers: {
'Filerobot-Token': container,
'Filerobot-Uuid': uuid,
'Filerobot-Folder': isInternal ? '/.internal/videos/conversion' : filePath,
'X-Filerobot-Key': sassKey
},
data: [{
url: url
}],
noDefaultHeaders: true,
abortSignal: thunkApi.signal
}),
_await$thunkApi$extra8 = _await$thunkApi$extra7.result,
_await$thunkApi$extra9 = _await$thunkApi$extra8 === void 0 ? [{}] : _await$thunkApi$extra8,
_await$thunkApi$extra10 = _slicedToArray(_await$thunkApi$extra9, 1),
_await$thunkApi$extra11 = _await$thunkApi$extra10[0],
converted = _await$thunkApi$extra11.converted,
hint = _await$thunkApi$extra11.hint;
if (hint) {
return thunkApi.rejectWithValue(hint);
}
var file = selectFileByUuid(thunkApi.getState(), uuid);
return {
uuid: uuid,
info: _objectSpread(_objectSpread({}, file.info), {}, {
converted: converted
})
};
},
// We are appending updateFile to trigger the extra reducer, so it starts with the sliceName, and contains updateFile same as extra reducer's matching needs.
{
actionType: "".concat(actionTypePrefix, "/updateFileByVideoConvert")
});
export var compressVideo = createThunk(async function (_ref3, thunkApi) {
var url = _ref3.url,
isInternal = _ref3.isInternal,
filePath = _ref3.filePath,
uuid = _ref3.uuid,
videoResolutions = _ref3.videoResolutions,
bitrate = _ref3.bitrate;
var _thunkApi$extra$filer4 = thunkApi.extra.filerobot.opts,
videoApiEndpoint = _thunkApi$extra$filer4.videoApiEndpoint,
container = _thunkApi$extra$filer4.container,
sassKey = _thunkApi$extra$filer4.sassKey;
var _await$thunkApi$extra12 = await thunkApi.extra.apiClient.post("".concat(videoApiEndpoint, "/compress/url"), {
headers: {
'Filerobot-Token': container,
'Filerobot-uuid': uuid,
'Filerobot-folder': isInternal ? '/.internal/videos/compression' : filePath,
'X-Filerobot-Key': sassKey
},
data: [{
url: url,
video_resolutions: videoResolutions,
bitrate: bitrate
}],
noDefaultHeaders: true,
abortSignal: thunkApi.signal
}),
_await$thunkApi$extra13 = _await$thunkApi$extra12.result,
_await$thunkApi$extra14 = _await$thunkApi$extra13 === void 0 ? [{}] : _await$thunkApi$extra13,
_await$thunkApi$extra15 = _slicedToArray(_await$thunkApi$extra14, 1),
_await$thunkApi$extra16 = _await$thunkApi$extra15[0].compressed,
compressed = _await$thunkApi$extra16 === void 0 ? [] : _await$thunkApi$extra16;
var file = selectFileByUuid(thunkApi.getState(), uuid);
return {
uuid: uuid,
info: _objectSpread(_objectSpread({}, file.info), {}, {
// here we are using set to avoid duplicating values
compressed: _toConsumableArray(new Set([].concat(_toConsumableArray(compressed), _toConsumableArray(file.info.compressed || []))))
})
};
},
// We are appending updateFile to trigger the extra reducer, so it starts with the sliceName, and contains updateFile same as extra reducer's matching needs.
{
actionType: "".concat(actionTypePrefix, "/updateFileByVideoCompress")
});