Repository URL to install this package:
|
Version:
3.12.16 ▾
|
import createThunk from '@filerobot/utils/lib/createThunk';
import { fetchFiles } from '../../slices/files.slice';
export var fetchFilesUuidsRecursively = createThunk(async function (_ref, thunkApi) {
var folder = _ref.folder,
_ref$filesUuidsToBeSh = _ref.filesUuidsToBeShared,
filesUuidsToBeShared = _ref$filesUuidsToBeSh === void 0 ? [] : _ref$filesUuidsToBeSh,
_ref$offset = _ref.offset,
offset = _ref$offset === void 0 ? 0 : _ref$offset;
var limit = 2000;
try {
var _await$thunkApi$dispa = await thunkApi.dispatch(fetchFiles({
queries: {
folder: folder.path
},
offset: offset,
limit: limit,
skipDispatch: true
})),
_await$thunkApi$dispa2 = _await$thunkApi$dispa.files,
files = _await$thunkApi$dispa2 === void 0 ? [] : _await$thunkApi$dispa2;
files.forEach(function (file) {
return filesUuidsToBeShared.push(file.uuid);
});
var filesToBeSharedLength = filesUuidsToBeShared.length;
// length of files is less then limit, so we can resolve the promise as it means no more files left in the folder
// otherwise means there are more files in the folder, so we need to call the function again
// with offset increased by limit
if (files.length < limit) {
return Promise.resolve(filesUuidsToBeShared);
}
return fetchFilesUuidsRecursively({
folder: folder,
filesUuidsToBeShared: filesUuidsToBeShared,
offset: filesToBeSharedLength
}, thunkApi);
} catch (error) {
return Promise.reject(error);
}
});
export var createSharedAssets = createThunk(async function (_ref2, thunkApi) {
var shareData = _ref2.shareData,
companyName = _ref2.companyName,
shareApiEndpoint = _ref2.shareApiEndpoint,
container = _ref2.container;
var _ref3 = (await thunkApi.extra.apiClient.post('shares', {
data: shareData,
abortSignal: thunkApi.signal
})) || {},
_ref3$share = _ref3.share,
_ref3$share2 = _ref3$share === void 0 ? {} : _ref3$share,
puid = _ref3$share2.puid;
// https://share.filerobot.com/scaleflex/demo/eat3qraddadadw
var shareUri = encodeURI("".concat(shareApiEndpoint, "/").concat(encodeURI(companyName), "/").concat(container, "/").concat(puid));
return shareUri;
});