UNPKG

cozy-dataproxy-lib

Version:

Library meant to be by Cozy Cloud's DataProxy apps for data manipulation

63 lines (48 loc) 2.96 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.shouldKeepFile = exports.normalizeFileWithFolders = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _consts = require("../consts"); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /** * Normalize file for Front usage in <AutoSuggestion> component inside <BarSearchAutosuggest> * * To reduce API call, the fetching of Note URL has been delayed * inside an onSelect function called only if provided to <BarSearchAutosuggest> * see https://github.com/cozy/cozy-drive/pull/2663#discussion_r938671963 * * @param {[IOCozyFile]} folders - all the folders returned by API * @param {IOCozyFile} file - file to normalize * @returns file with normalized field to be used in AutoSuggestion */ var normalizeFileWithFolders = function normalizeFileWithFolders(folders, file) { var isDir = file.type === _consts.TYPE_DIRECTORY; var path = ''; if (isDir) { var _file$path; path = (_file$path = file.path) !== null && _file$path !== void 0 ? _file$path : ''; } else { var parentDir = folders.find(function (folder) { return folder._id === file.dir_id; }); path = parentDir && parentDir.path ? parentDir.path : ''; } return _objectSpread(_objectSpread({}, file), {}, { _type: 'io.cozy.files', path: path }); }; exports.normalizeFileWithFolders = normalizeFileWithFolders; var shouldKeepFile = function shouldKeepFile(file) { var _file$path2; var notInTrash = !file.trashed && !/^\/\.cozy_trash/.test((_file$path2 = file.path) !== null && _file$path2 !== void 0 ? _file$path2 : ''); var notRootDir = file._id !== _consts.ROOT_DIR_ID; // Shared drives folder to be hidden in search. // The files inside it though must appear. Thus only the file with the folder ID is filtered out. var notSharedDrivesDir = file._id !== _consts.SHARED_DRIVES_DIR_ID; return notInTrash && notRootDir && notSharedDrivesDir; }; exports.shouldKeepFile = shouldKeepFile;