This commit is contained in:
112
node_modules/decap-cms-core/dist/esm/actions/auth.js
generated
vendored
Normal file
112
node_modules/decap-cms-core/dist/esm/actions/auth.js
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.USE_OPEN_AUTHORING = exports.LOGOUT = exports.AUTH_SUCCESS = exports.AUTH_REQUEST_DONE = exports.AUTH_REQUEST = exports.AUTH_FAILURE = void 0;
|
||||
exports.authError = authError;
|
||||
exports.authenticate = authenticate;
|
||||
exports.authenticateUser = authenticateUser;
|
||||
exports.authenticating = authenticating;
|
||||
exports.doneAuthenticating = doneAuthenticating;
|
||||
exports.loginUser = loginUser;
|
||||
exports.logout = logout;
|
||||
exports.logoutUser = logoutUser;
|
||||
exports.useOpenAuthoring = useOpenAuthoring;
|
||||
var _backend = require("../backend");
|
||||
var _notifications = require("./notifications");
|
||||
const AUTH_REQUEST = exports.AUTH_REQUEST = 'AUTH_REQUEST';
|
||||
const AUTH_SUCCESS = exports.AUTH_SUCCESS = 'AUTH_SUCCESS';
|
||||
const AUTH_FAILURE = exports.AUTH_FAILURE = 'AUTH_FAILURE';
|
||||
const AUTH_REQUEST_DONE = exports.AUTH_REQUEST_DONE = 'AUTH_REQUEST_DONE';
|
||||
const USE_OPEN_AUTHORING = exports.USE_OPEN_AUTHORING = 'USE_OPEN_AUTHORING';
|
||||
const LOGOUT = exports.LOGOUT = 'LOGOUT';
|
||||
function authenticating() {
|
||||
return {
|
||||
type: AUTH_REQUEST
|
||||
};
|
||||
}
|
||||
function authenticate(userData) {
|
||||
return {
|
||||
type: AUTH_SUCCESS,
|
||||
payload: userData
|
||||
};
|
||||
}
|
||||
function authError(error) {
|
||||
return {
|
||||
type: AUTH_FAILURE,
|
||||
error: 'Failed to authenticate',
|
||||
payload: error
|
||||
};
|
||||
}
|
||||
function doneAuthenticating() {
|
||||
return {
|
||||
type: AUTH_REQUEST_DONE
|
||||
};
|
||||
}
|
||||
function useOpenAuthoring() {
|
||||
return {
|
||||
type: USE_OPEN_AUTHORING
|
||||
};
|
||||
}
|
||||
function logout() {
|
||||
return {
|
||||
type: LOGOUT
|
||||
};
|
||||
}
|
||||
|
||||
// Check if user data token is cached and is valid
|
||||
function authenticateUser() {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
dispatch(authenticating());
|
||||
return Promise.resolve(backend.currentUser()).then(user => {
|
||||
if (user) {
|
||||
if (user.useOpenAuthoring) {
|
||||
dispatch(useOpenAuthoring());
|
||||
}
|
||||
dispatch(authenticate(user));
|
||||
} else {
|
||||
dispatch(doneAuthenticating());
|
||||
}
|
||||
}).catch(error => {
|
||||
dispatch(authError(error));
|
||||
dispatch(logoutUser());
|
||||
});
|
||||
};
|
||||
}
|
||||
function loginUser(credentials) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
dispatch(authenticating());
|
||||
return backend.authenticate(credentials).then(user => {
|
||||
if (user.useOpenAuthoring) {
|
||||
dispatch(useOpenAuthoring());
|
||||
}
|
||||
dispatch(authenticate(user));
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
details: error.message,
|
||||
key: 'ui.toast.onFailToAuth'
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
dispatch(authError(error));
|
||||
});
|
||||
};
|
||||
}
|
||||
function logoutUser() {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
Promise.resolve(backend.logout()).then(() => {
|
||||
dispatch(logout());
|
||||
dispatch((0, _notifications.clearNotifications)());
|
||||
});
|
||||
};
|
||||
}
|
||||
23
node_modules/decap-cms-core/dist/esm/actions/collections.js
generated
vendored
Normal file
23
node_modules/decap-cms-core/dist/esm/actions/collections.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createNewEntry = createNewEntry;
|
||||
exports.searchCollections = searchCollections;
|
||||
exports.showCollection = showCollection;
|
||||
var _history = require("../routing/history");
|
||||
var _urlHelper = require("../lib/urlHelper");
|
||||
function searchCollections(query, collection) {
|
||||
if (collection) {
|
||||
_history.history.push(`/collections/${collection}/search/${query}`);
|
||||
} else {
|
||||
_history.history.push(`/search/${query}`);
|
||||
}
|
||||
}
|
||||
function showCollection(collectionName) {
|
||||
_history.history.push((0, _urlHelper.getCollectionUrl)(collectionName));
|
||||
}
|
||||
function createNewEntry(collectionName) {
|
||||
_history.history.push((0, _urlHelper.getNewEntryUrl)(collectionName));
|
||||
}
|
||||
479
node_modules/decap-cms-core/dist/esm/actions/config.js
generated
vendored
Normal file
479
node_modules/decap-cms-core/dist/esm/actions/config.js
generated
vendored
Normal file
@@ -0,0 +1,479 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.CONFIG_SUCCESS = exports.CONFIG_REQUEST = exports.CONFIG_FAILURE = void 0;
|
||||
exports.applyDefaults = applyDefaults;
|
||||
exports.configFailed = configFailed;
|
||||
exports.configLoaded = configLoaded;
|
||||
exports.configLoading = configLoading;
|
||||
exports.detectProxyServer = detectProxyServer;
|
||||
exports.handleLocalBackend = handleLocalBackend;
|
||||
exports.loadConfig = loadConfig;
|
||||
exports.normalizeConfig = normalizeConfig;
|
||||
exports.parseConfig = parseConfig;
|
||||
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
||||
var _trim2 = _interopRequireDefault(require("lodash/trim"));
|
||||
var _trimStart2 = _interopRequireDefault(require("lodash/trimStart"));
|
||||
var _yaml = _interopRequireDefault(require("yaml"));
|
||||
var _immutable = require("immutable");
|
||||
var _deepmerge = _interopRequireDefault(require("deepmerge"));
|
||||
var _immer = require("immer");
|
||||
var _publishModes = require("../constants/publishModes");
|
||||
var _configSchema = require("../constants/configSchema");
|
||||
var _collections = require("../reducers/collections");
|
||||
var _integrations = require("../reducers/integrations");
|
||||
var _backend = require("../backend");
|
||||
var _i18n = require("../lib/i18n");
|
||||
var _collectionTypes = require("../constants/collectionTypes");
|
||||
const _excluded = ["sortableFields"];
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
||||
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
||||
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
||||
const CONFIG_REQUEST = exports.CONFIG_REQUEST = 'CONFIG_REQUEST';
|
||||
const CONFIG_SUCCESS = exports.CONFIG_SUCCESS = 'CONFIG_SUCCESS';
|
||||
const CONFIG_FAILURE = exports.CONFIG_FAILURE = 'CONFIG_FAILURE';
|
||||
function isObjectField(field) {
|
||||
return 'fields' in field;
|
||||
}
|
||||
function isFieldList(field) {
|
||||
return 'types' in field || 'field' in field;
|
||||
}
|
||||
function traverseFieldsJS(fields, updater) {
|
||||
return fields.map(field => {
|
||||
const newField = updater(field);
|
||||
if (isObjectField(newField)) {
|
||||
return _objectSpread(_objectSpread({}, newField), {}, {
|
||||
fields: traverseFieldsJS(newField.fields, updater)
|
||||
});
|
||||
} else if (isFieldList(newField) && newField.field) {
|
||||
return _objectSpread(_objectSpread({}, newField), {}, {
|
||||
field: traverseFieldsJS([newField.field], updater)[0]
|
||||
});
|
||||
} else if (isFieldList(newField) && newField.types) {
|
||||
return _objectSpread(_objectSpread({}, newField), {}, {
|
||||
types: traverseFieldsJS(newField.types, updater)
|
||||
});
|
||||
}
|
||||
return newField;
|
||||
});
|
||||
}
|
||||
function getConfigUrl() {
|
||||
const validTypes = {
|
||||
'text/yaml': 'yaml',
|
||||
'application/x-yaml': 'yaml'
|
||||
};
|
||||
const configLinkEl = document.querySelector('link[rel="cms-config-url"]');
|
||||
if (configLinkEl && validTypes[configLinkEl.type] && configLinkEl.href) {
|
||||
console.log(`Using config file path: "${configLinkEl.href}"`);
|
||||
return configLinkEl.href;
|
||||
}
|
||||
return 'config.yml';
|
||||
}
|
||||
function setDefaultPublicFolderForField(field) {
|
||||
if ('media_folder' in field && !('public_folder' in field)) {
|
||||
return _objectSpread(_objectSpread({}, field), {}, {
|
||||
public_folder: field.media_folder
|
||||
});
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
// Mapping between existing camelCase and its snake_case counterpart
|
||||
const WIDGET_KEY_MAP = {
|
||||
dateFormat: 'date_format',
|
||||
timeFormat: 'time_format',
|
||||
pickerUtc: 'picker_utc',
|
||||
editorComponents: 'editor_components',
|
||||
valueType: 'value_type',
|
||||
valueField: 'value_field',
|
||||
searchFields: 'search_fields',
|
||||
displayFields: 'display_fields',
|
||||
optionsLength: 'options_length'
|
||||
};
|
||||
function setSnakeCaseConfig(field) {
|
||||
const deprecatedKeys = Object.keys(WIDGET_KEY_MAP).filter(camel => camel in field);
|
||||
const snakeValues = deprecatedKeys.map(camel => {
|
||||
const snake = WIDGET_KEY_MAP[camel];
|
||||
console.warn(`Field ${field.name} is using a deprecated configuration '${camel}'. Please use '${snake}'`);
|
||||
return {
|
||||
[snake]: field[camel]
|
||||
};
|
||||
});
|
||||
return Object.assign({}, field, ...snakeValues);
|
||||
}
|
||||
function setI18nField(field) {
|
||||
if (field[_i18n.I18N] === true) {
|
||||
return _objectSpread(_objectSpread({}, field), {}, {
|
||||
[_i18n.I18N]: _i18n.I18N_FIELD.TRANSLATE
|
||||
});
|
||||
} else if (field[_i18n.I18N] === false || !field[_i18n.I18N]) {
|
||||
return _objectSpread(_objectSpread({}, field), {}, {
|
||||
[_i18n.I18N]: _i18n.I18N_FIELD.NONE
|
||||
});
|
||||
}
|
||||
return field;
|
||||
}
|
||||
function getI18nDefaults(collectionOrFileI18n, defaultI18n) {
|
||||
if (typeof collectionOrFileI18n === 'boolean') {
|
||||
return defaultI18n;
|
||||
} else {
|
||||
const locales = collectionOrFileI18n.locales || defaultI18n.locales;
|
||||
const defaultLocale = collectionOrFileI18n.default_locale || locales[0];
|
||||
const mergedI18n = (0, _deepmerge.default)(defaultI18n, collectionOrFileI18n);
|
||||
mergedI18n.locales = locales;
|
||||
mergedI18n.default_locale = defaultLocale;
|
||||
throwOnMissingDefaultLocale(mergedI18n);
|
||||
return mergedI18n;
|
||||
}
|
||||
}
|
||||
function setI18nDefaultsForFields(collectionOrFileFields, hasI18n) {
|
||||
if (hasI18n) {
|
||||
return traverseFieldsJS(collectionOrFileFields, setI18nField);
|
||||
} else {
|
||||
return traverseFieldsJS(collectionOrFileFields, field => {
|
||||
const newField = _objectSpread({}, field);
|
||||
delete newField[_i18n.I18N];
|
||||
return newField;
|
||||
});
|
||||
}
|
||||
}
|
||||
function throwOnInvalidFileCollectionStructure(i18n) {
|
||||
if (i18n && i18n.structure !== _i18n.I18N_STRUCTURE.SINGLE_FILE) {
|
||||
throw new Error(`i18n configuration for files collections is limited to ${_i18n.I18N_STRUCTURE.SINGLE_FILE} structure`);
|
||||
}
|
||||
}
|
||||
function throwOnMissingDefaultLocale(i18n) {
|
||||
if (i18n && i18n.default_locale && !i18n.locales.includes(i18n.default_locale)) {
|
||||
throw new Error(`i18n locales '${i18n.locales.join(', ')}' are missing the default locale ${i18n.default_locale}`);
|
||||
}
|
||||
}
|
||||
function hasIntegration(config, collection) {
|
||||
// TODO remove fromJS when Immutable is removed from the integrations state slice
|
||||
const integrations = (0, _integrations.getIntegrations)((0, _immutable.fromJS)(config));
|
||||
const integration = (0, _integrations.selectIntegration)(integrations, collection.name, 'listEntries');
|
||||
return !!integration;
|
||||
}
|
||||
function normalizeConfig(config) {
|
||||
const {
|
||||
collections = []
|
||||
} = config;
|
||||
const normalizedCollections = collections.map(collection => {
|
||||
const {
|
||||
fields,
|
||||
files
|
||||
} = collection;
|
||||
let normalizedCollection = collection;
|
||||
if (fields) {
|
||||
const normalizedFields = traverseFieldsJS(fields, setSnakeCaseConfig);
|
||||
normalizedCollection = _objectSpread(_objectSpread({}, normalizedCollection), {}, {
|
||||
fields: normalizedFields
|
||||
});
|
||||
}
|
||||
if (files) {
|
||||
const normalizedFiles = files.map(file => {
|
||||
const normalizedFileFields = traverseFieldsJS(file.fields, setSnakeCaseConfig);
|
||||
return _objectSpread(_objectSpread({}, file), {}, {
|
||||
fields: normalizedFileFields
|
||||
});
|
||||
});
|
||||
normalizedCollection = _objectSpread(_objectSpread({}, normalizedCollection), {}, {
|
||||
files: normalizedFiles
|
||||
});
|
||||
}
|
||||
if (normalizedCollection.sortableFields) {
|
||||
const {
|
||||
sortableFields
|
||||
} = normalizedCollection,
|
||||
rest = _objectWithoutProperties(normalizedCollection, _excluded);
|
||||
normalizedCollection = _objectSpread(_objectSpread({}, rest), {}, {
|
||||
sortable_fields: sortableFields
|
||||
});
|
||||
console.warn(`Collection ${collection.name} is using a deprecated configuration 'sortableFields'. Please use 'sortable_fields'`);
|
||||
}
|
||||
return normalizedCollection;
|
||||
});
|
||||
return _objectSpread(_objectSpread({}, config), {}, {
|
||||
collections: normalizedCollections
|
||||
});
|
||||
}
|
||||
function applyDefaults(originalConfig) {
|
||||
return (0, _immer.produce)(originalConfig, config => {
|
||||
config.publish_mode = config.publish_mode || _publishModes.SIMPLE;
|
||||
config.slug = config.slug || {};
|
||||
config.collections = config.collections || [];
|
||||
|
||||
// Use `site_url` as default `display_url`.
|
||||
if (!config.display_url && config.site_url) {
|
||||
config.display_url = config.site_url;
|
||||
}
|
||||
|
||||
// Use media_folder as default public_folder.
|
||||
const defaultPublicFolder = `/${(0, _trimStart2.default)(config.media_folder, '/')}`;
|
||||
if (!('public_folder' in config)) {
|
||||
config.public_folder = defaultPublicFolder;
|
||||
}
|
||||
|
||||
// default values for the slug config
|
||||
if (!('encoding' in config.slug)) {
|
||||
config.slug.encoding = 'unicode';
|
||||
}
|
||||
if (!('clean_accents' in config.slug)) {
|
||||
config.slug.clean_accents = false;
|
||||
}
|
||||
if (!('sanitize_replacement' in config.slug)) {
|
||||
config.slug.sanitize_replacement = '-';
|
||||
}
|
||||
const i18n = config[_i18n.I18N];
|
||||
if (i18n) {
|
||||
i18n.default_locale = i18n.default_locale || i18n.locales[0];
|
||||
}
|
||||
throwOnMissingDefaultLocale(i18n);
|
||||
const backend = (0, _backend.resolveBackend)(config);
|
||||
for (const collection of config.collections) {
|
||||
if (!('publish' in collection)) {
|
||||
collection.publish = true;
|
||||
}
|
||||
let collectionI18n = collection[_i18n.I18N];
|
||||
if (i18n && collectionI18n) {
|
||||
collectionI18n = getI18nDefaults(collectionI18n, i18n);
|
||||
collection[_i18n.I18N] = collectionI18n;
|
||||
} else {
|
||||
collectionI18n = undefined;
|
||||
delete collection[_i18n.I18N];
|
||||
}
|
||||
if (collection.fields) {
|
||||
collection.fields = setI18nDefaultsForFields(collection.fields, Boolean(collectionI18n));
|
||||
}
|
||||
const {
|
||||
folder,
|
||||
files,
|
||||
view_filters,
|
||||
view_groups,
|
||||
meta
|
||||
} = collection;
|
||||
if (folder) {
|
||||
collection.type = _collectionTypes.FOLDER;
|
||||
if (collection.path && !collection.media_folder) {
|
||||
// default value for media folder when using the path config
|
||||
collection.media_folder = '';
|
||||
}
|
||||
if ('media_folder' in collection && !('public_folder' in collection)) {
|
||||
collection.public_folder = collection.media_folder;
|
||||
}
|
||||
if (collection.fields) {
|
||||
collection.fields = traverseFieldsJS(collection.fields, setDefaultPublicFolderForField);
|
||||
}
|
||||
collection.folder = (0, _trim2.default)(folder, '/');
|
||||
if (meta && meta.path) {
|
||||
const metaField = _objectSpread({
|
||||
name: 'path',
|
||||
meta: true,
|
||||
required: true
|
||||
}, meta.path);
|
||||
collection.fields = [metaField, ...(collection.fields || [])];
|
||||
}
|
||||
}
|
||||
if (files) {
|
||||
collection.type = _collectionTypes.FILES;
|
||||
throwOnInvalidFileCollectionStructure(collectionI18n);
|
||||
delete collection.nested;
|
||||
delete collection.meta;
|
||||
for (const file of files) {
|
||||
file.file = (0, _trimStart2.default)(file.file, '/');
|
||||
if ('media_folder' in file && !('public_folder' in file)) {
|
||||
file.public_folder = file.media_folder;
|
||||
}
|
||||
if (file.fields) {
|
||||
file.fields = traverseFieldsJS(file.fields, setDefaultPublicFolderForField);
|
||||
}
|
||||
let fileI18n = file[_i18n.I18N];
|
||||
if (fileI18n && collectionI18n) {
|
||||
fileI18n = getI18nDefaults(fileI18n, collectionI18n);
|
||||
file[_i18n.I18N] = fileI18n;
|
||||
} else {
|
||||
fileI18n = undefined;
|
||||
delete file[_i18n.I18N];
|
||||
}
|
||||
throwOnInvalidFileCollectionStructure(fileI18n);
|
||||
if (file.fields) {
|
||||
file.fields = setI18nDefaultsForFields(file.fields, Boolean(fileI18n));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!collection.sortable_fields) {
|
||||
collection.sortable_fields = (0, _collections.selectDefaultSortableFields)(
|
||||
// TODO remove fromJS when Immutable is removed from the collections state slice
|
||||
(0, _immutable.fromJS)(collection), backend, hasIntegration(config, collection));
|
||||
}
|
||||
collection.view_filters = (view_filters || []).map(filter => {
|
||||
return _objectSpread(_objectSpread({}, filter), {}, {
|
||||
id: `${filter.field}__${filter.pattern}`
|
||||
});
|
||||
});
|
||||
collection.view_groups = (view_groups || []).map(group => {
|
||||
return _objectSpread(_objectSpread({}, group), {}, {
|
||||
id: `${group.field}__${group.pattern}`
|
||||
});
|
||||
});
|
||||
if (config.editor && !collection.editor) {
|
||||
collection.editor = {
|
||||
preview: config.editor.preview
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function parseConfig(data) {
|
||||
const config = _yaml.default.parse(data, {
|
||||
maxAliasCount: -1,
|
||||
prettyErrors: true,
|
||||
merge: true
|
||||
});
|
||||
if (typeof window !== 'undefined' && typeof window.CMS_ENV === 'string' && config[window.CMS_ENV]) {
|
||||
const configKeys = Object.keys(config[window.CMS_ENV]);
|
||||
for (const key of configKeys) {
|
||||
config[key] = config[window.CMS_ENV][key];
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
async function getConfigYaml(file, hasManualConfig) {
|
||||
const response = await fetch(file, {
|
||||
credentials: 'same-origin'
|
||||
}).catch(error => error);
|
||||
if (response instanceof Error || response.status !== 200) {
|
||||
if (hasManualConfig) {
|
||||
return {};
|
||||
}
|
||||
const message = response instanceof Error ? response.message : response.status;
|
||||
throw new Error(`Failed to load config.yml (${message})`);
|
||||
}
|
||||
const contentType = response.headers.get('Content-Type') || 'Not-Found';
|
||||
const isYaml = contentType.indexOf('yaml') !== -1;
|
||||
if (!isYaml) {
|
||||
console.log(`Response for ${file} was not yaml. (Content-Type: ${contentType})`);
|
||||
if (hasManualConfig) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return parseConfig(await response.text());
|
||||
}
|
||||
function configLoaded(config) {
|
||||
return {
|
||||
type: CONFIG_SUCCESS,
|
||||
payload: config
|
||||
};
|
||||
}
|
||||
function configLoading() {
|
||||
return {
|
||||
type: CONFIG_REQUEST
|
||||
};
|
||||
}
|
||||
function configFailed(err) {
|
||||
return {
|
||||
type: CONFIG_FAILURE,
|
||||
error: 'Error loading config',
|
||||
payload: err
|
||||
};
|
||||
}
|
||||
async function detectProxyServer(localBackend) {
|
||||
const allowedHosts = ['localhost', '127.0.0.1', ...(typeof localBackend === 'boolean' ? [] : (localBackend === null || localBackend === void 0 ? void 0 : localBackend.allowed_hosts) || [])];
|
||||
if (!allowedHosts.includes(location.hostname) || !localBackend) {
|
||||
return {};
|
||||
}
|
||||
const defaultUrl = 'http://localhost:8081/api/v1';
|
||||
const proxyUrl = localBackend === true ? defaultUrl : localBackend.url || defaultUrl.replace('localhost', location.hostname);
|
||||
try {
|
||||
console.log(`Looking for Decap CMS Proxy Server at '${proxyUrl}'`);
|
||||
const res = await fetch(`${proxyUrl}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
action: 'info'
|
||||
})
|
||||
});
|
||||
const {
|
||||
repo,
|
||||
publish_modes,
|
||||
type
|
||||
} = await res.json();
|
||||
if (typeof repo === 'string' && Array.isArray(publish_modes) && typeof type === 'string') {
|
||||
console.log(`Detected Decap CMS Proxy Server at '${proxyUrl}' with repo: '${repo}'`);
|
||||
return {
|
||||
proxyUrl,
|
||||
publish_modes,
|
||||
type
|
||||
};
|
||||
} else {
|
||||
console.log(`Decap CMS Proxy Server not detected at '${proxyUrl}'`);
|
||||
return {};
|
||||
}
|
||||
} catch {
|
||||
console.log(`Decap CMS Proxy Server not detected at '${proxyUrl}'`);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
function getPublishMode(config, publishModes, backendType) {
|
||||
if (config.publish_mode && publishModes && !publishModes.includes(config.publish_mode)) {
|
||||
const newPublishMode = publishModes[0];
|
||||
console.log(`'${config.publish_mode}' is not supported by '${backendType}' backend, switching to '${newPublishMode}'`);
|
||||
return newPublishMode;
|
||||
}
|
||||
return config.publish_mode;
|
||||
}
|
||||
async function handleLocalBackend(originalConfig) {
|
||||
if (!originalConfig.local_backend) {
|
||||
return originalConfig;
|
||||
}
|
||||
const {
|
||||
proxyUrl,
|
||||
publish_modes: publishModes,
|
||||
type: backendType
|
||||
} = await detectProxyServer(originalConfig.local_backend);
|
||||
if (!proxyUrl) {
|
||||
return originalConfig;
|
||||
}
|
||||
return (0, _immer.produce)(originalConfig, config => {
|
||||
config.backend.name = 'proxy';
|
||||
config.backend.proxy_url = proxyUrl;
|
||||
if (config.publish_mode) {
|
||||
config.publish_mode = getPublishMode(config, publishModes, backendType);
|
||||
}
|
||||
});
|
||||
}
|
||||
function loadConfig(manualConfig = {}, onLoad) {
|
||||
if (window.CMS_CONFIG) {
|
||||
return configLoaded(window.CMS_CONFIG);
|
||||
}
|
||||
return async dispatch => {
|
||||
dispatch(configLoading());
|
||||
try {
|
||||
const configUrl = getConfigUrl();
|
||||
const hasManualConfig = !(0, _isEmpty2.default)(manualConfig);
|
||||
const configYaml = manualConfig.load_config_file === false ? {} : await getConfigYaml(configUrl, hasManualConfig);
|
||||
|
||||
// Merge manual config into the config.yml one
|
||||
const mergedConfig = (0, _deepmerge.default)(configYaml, manualConfig);
|
||||
(0, _configSchema.validateConfig)(mergedConfig);
|
||||
const withLocalBackend = await handleLocalBackend(mergedConfig);
|
||||
const normalizedConfig = normalizeConfig(withLocalBackend);
|
||||
const config = applyDefaults(normalizedConfig);
|
||||
dispatch(configLoaded(config));
|
||||
if (typeof onLoad === 'function') {
|
||||
onLoad();
|
||||
}
|
||||
} catch (err) {
|
||||
dispatch(configFailed(err));
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
}
|
||||
86
node_modules/decap-cms-core/dist/esm/actions/deploys.js
generated
vendored
Normal file
86
node_modules/decap-cms-core/dist/esm/actions/deploys.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.DEPLOY_PREVIEW_SUCCESS = exports.DEPLOY_PREVIEW_REQUEST = exports.DEPLOY_PREVIEW_FAILURE = void 0;
|
||||
exports.loadDeployPreview = loadDeployPreview;
|
||||
var _backend = require("../backend");
|
||||
var _reducers = require("../reducers");
|
||||
var _notifications = require("./notifications");
|
||||
const DEPLOY_PREVIEW_REQUEST = exports.DEPLOY_PREVIEW_REQUEST = 'DEPLOY_PREVIEW_REQUEST';
|
||||
const DEPLOY_PREVIEW_SUCCESS = exports.DEPLOY_PREVIEW_SUCCESS = 'DEPLOY_PREVIEW_SUCCESS';
|
||||
const DEPLOY_PREVIEW_FAILURE = exports.DEPLOY_PREVIEW_FAILURE = 'DEPLOY_PREVIEW_FAILURE';
|
||||
function deployPreviewLoading(collection, slug) {
|
||||
return {
|
||||
type: DEPLOY_PREVIEW_REQUEST,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function deployPreviewLoaded(collection, slug, deploy) {
|
||||
const {
|
||||
url,
|
||||
status
|
||||
} = deploy;
|
||||
return {
|
||||
type: DEPLOY_PREVIEW_SUCCESS,
|
||||
payload: {
|
||||
collection,
|
||||
slug,
|
||||
url,
|
||||
status
|
||||
}
|
||||
};
|
||||
}
|
||||
function deployPreviewError(collection, slug) {
|
||||
return {
|
||||
type: DEPLOY_PREVIEW_FAILURE,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a deploy preview object from the registered backend.
|
||||
*/
|
||||
function loadDeployPreview(collection, slug, entry, published, opts) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const collectionName = collection.get('name');
|
||||
|
||||
// Exit if currently fetching
|
||||
const deployState = (0, _reducers.selectDeployPreview)(state, collectionName, slug);
|
||||
if (deployState && deployState.isFetching) {
|
||||
return;
|
||||
}
|
||||
dispatch(deployPreviewLoading(collectionName, slug));
|
||||
try {
|
||||
/**
|
||||
* `getDeploy` is for published entries, while `getDeployPreview` is for
|
||||
* unpublished entries.
|
||||
*/
|
||||
const deploy = published ? backend.getDeploy(collection, slug, entry) : await backend.getDeployPreview(collection, slug, entry, opts);
|
||||
if (deploy) {
|
||||
return dispatch(deployPreviewLoaded(collectionName, slug, deploy));
|
||||
}
|
||||
return dispatch(deployPreviewError(collectionName, slug));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
details: error.message,
|
||||
key: 'ui.toast.onFailToLoadDeployPreview'
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
dispatch(deployPreviewError(collectionName, slug));
|
||||
}
|
||||
};
|
||||
}
|
||||
494
node_modules/decap-cms-core/dist/esm/actions/editorialWorkflow.js
generated
vendored
Normal file
494
node_modules/decap-cms-core/dist/esm/actions/editorialWorkflow.js
generated
vendored
Normal file
@@ -0,0 +1,494 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.UNPUBLISHED_ENTRY_SUCCESS = exports.UNPUBLISHED_ENTRY_STATUS_CHANGE_SUCCESS = exports.UNPUBLISHED_ENTRY_STATUS_CHANGE_REQUEST = exports.UNPUBLISHED_ENTRY_STATUS_CHANGE_FAILURE = exports.UNPUBLISHED_ENTRY_REQUEST = exports.UNPUBLISHED_ENTRY_REDIRECT = exports.UNPUBLISHED_ENTRY_PUBLISH_SUCCESS = exports.UNPUBLISHED_ENTRY_PUBLISH_REQUEST = exports.UNPUBLISHED_ENTRY_PUBLISH_FAILURE = exports.UNPUBLISHED_ENTRY_PERSIST_SUCCESS = exports.UNPUBLISHED_ENTRY_PERSIST_REQUEST = exports.UNPUBLISHED_ENTRY_PERSIST_FAILURE = exports.UNPUBLISHED_ENTRY_DELETE_SUCCESS = exports.UNPUBLISHED_ENTRY_DELETE_REQUEST = exports.UNPUBLISHED_ENTRY_DELETE_FAILURE = exports.UNPUBLISHED_ENTRIES_SUCCESS = exports.UNPUBLISHED_ENTRIES_REQUEST = exports.UNPUBLISHED_ENTRIES_FAILURE = void 0;
|
||||
exports.deleteUnpublishedEntry = deleteUnpublishedEntry;
|
||||
exports.loadUnpublishedEntries = loadUnpublishedEntries;
|
||||
exports.loadUnpublishedEntry = loadUnpublishedEntry;
|
||||
exports.persistUnpublishedEntry = persistUnpublishedEntry;
|
||||
exports.publishUnpublishedEntry = publishUnpublishedEntry;
|
||||
exports.unpublishPublishedEntry = unpublishPublishedEntry;
|
||||
exports.updateUnpublishedEntryStatus = updateUnpublishedEntryStatus;
|
||||
var _get2 = _interopRequireDefault(require("lodash/get"));
|
||||
var _immutable = require("immutable");
|
||||
var _decapCmsLibUtil = require("decap-cms-lib-util");
|
||||
var _backend = require("../backend");
|
||||
var _reducers = require("../reducers");
|
||||
var _entries = require("../reducers/entries");
|
||||
var _publishModes = require("../constants/publishModes");
|
||||
var _entries2 = require("./entries");
|
||||
var _AssetProxy = require("../valueObjects/AssetProxy");
|
||||
var _media = require("./media");
|
||||
var _mediaLibrary = require("./mediaLibrary");
|
||||
var _validationErrorTypes = _interopRequireDefault(require("../constants/validationErrorTypes"));
|
||||
var _history = require("../routing/history");
|
||||
var _notifications = require("./notifications");
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
/*
|
||||
* Constant Declarations
|
||||
*/
|
||||
const UNPUBLISHED_ENTRY_REQUEST = exports.UNPUBLISHED_ENTRY_REQUEST = 'UNPUBLISHED_ENTRY_REQUEST';
|
||||
const UNPUBLISHED_ENTRY_SUCCESS = exports.UNPUBLISHED_ENTRY_SUCCESS = 'UNPUBLISHED_ENTRY_SUCCESS';
|
||||
const UNPUBLISHED_ENTRY_REDIRECT = exports.UNPUBLISHED_ENTRY_REDIRECT = 'UNPUBLISHED_ENTRY_REDIRECT';
|
||||
const UNPUBLISHED_ENTRIES_REQUEST = exports.UNPUBLISHED_ENTRIES_REQUEST = 'UNPUBLISHED_ENTRIES_REQUEST';
|
||||
const UNPUBLISHED_ENTRIES_SUCCESS = exports.UNPUBLISHED_ENTRIES_SUCCESS = 'UNPUBLISHED_ENTRIES_SUCCESS';
|
||||
const UNPUBLISHED_ENTRIES_FAILURE = exports.UNPUBLISHED_ENTRIES_FAILURE = 'UNPUBLISHED_ENTRIES_FAILURE';
|
||||
const UNPUBLISHED_ENTRY_PERSIST_REQUEST = exports.UNPUBLISHED_ENTRY_PERSIST_REQUEST = 'UNPUBLISHED_ENTRY_PERSIST_REQUEST';
|
||||
const UNPUBLISHED_ENTRY_PERSIST_SUCCESS = exports.UNPUBLISHED_ENTRY_PERSIST_SUCCESS = 'UNPUBLISHED_ENTRY_PERSIST_SUCCESS';
|
||||
const UNPUBLISHED_ENTRY_PERSIST_FAILURE = exports.UNPUBLISHED_ENTRY_PERSIST_FAILURE = 'UNPUBLISHED_ENTRY_PERSIST_FAILURE';
|
||||
const UNPUBLISHED_ENTRY_STATUS_CHANGE_REQUEST = exports.UNPUBLISHED_ENTRY_STATUS_CHANGE_REQUEST = 'UNPUBLISHED_ENTRY_STATUS_CHANGE_REQUEST';
|
||||
const UNPUBLISHED_ENTRY_STATUS_CHANGE_SUCCESS = exports.UNPUBLISHED_ENTRY_STATUS_CHANGE_SUCCESS = 'UNPUBLISHED_ENTRY_STATUS_CHANGE_SUCCESS';
|
||||
const UNPUBLISHED_ENTRY_STATUS_CHANGE_FAILURE = exports.UNPUBLISHED_ENTRY_STATUS_CHANGE_FAILURE = 'UNPUBLISHED_ENTRY_STATUS_CHANGE_FAILURE';
|
||||
const UNPUBLISHED_ENTRY_PUBLISH_REQUEST = exports.UNPUBLISHED_ENTRY_PUBLISH_REQUEST = 'UNPUBLISHED_ENTRY_PUBLISH_REQUEST';
|
||||
const UNPUBLISHED_ENTRY_PUBLISH_SUCCESS = exports.UNPUBLISHED_ENTRY_PUBLISH_SUCCESS = 'UNPUBLISHED_ENTRY_PUBLISH_SUCCESS';
|
||||
const UNPUBLISHED_ENTRY_PUBLISH_FAILURE = exports.UNPUBLISHED_ENTRY_PUBLISH_FAILURE = 'UNPUBLISHED_ENTRY_PUBLISH_FAILURE';
|
||||
const UNPUBLISHED_ENTRY_DELETE_REQUEST = exports.UNPUBLISHED_ENTRY_DELETE_REQUEST = 'UNPUBLISHED_ENTRY_DELETE_REQUEST';
|
||||
const UNPUBLISHED_ENTRY_DELETE_SUCCESS = exports.UNPUBLISHED_ENTRY_DELETE_SUCCESS = 'UNPUBLISHED_ENTRY_DELETE_SUCCESS';
|
||||
const UNPUBLISHED_ENTRY_DELETE_FAILURE = exports.UNPUBLISHED_ENTRY_DELETE_FAILURE = 'UNPUBLISHED_ENTRY_DELETE_FAILURE';
|
||||
|
||||
/*
|
||||
* Simple Action Creators (Internal)
|
||||
*/
|
||||
|
||||
function unpublishedEntryLoading(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_REQUEST,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryLoaded(collection, entry) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_SUCCESS,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
entry
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryRedirected(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_REDIRECT,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntriesLoading() {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRIES_REQUEST
|
||||
};
|
||||
}
|
||||
function unpublishedEntriesLoaded(entries, pagination) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRIES_SUCCESS,
|
||||
payload: {
|
||||
entries,
|
||||
pages: pagination
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntriesFailed(error) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRIES_FAILURE,
|
||||
error: 'Failed to load entries',
|
||||
payload: error
|
||||
};
|
||||
}
|
||||
function unpublishedEntryPersisting(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_PERSIST_REQUEST,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryPersisted(collection, entry) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_PERSIST_SUCCESS,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
entry
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryPersistedFail(error, collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_PERSIST_FAILURE,
|
||||
payload: {
|
||||
error,
|
||||
collection: collection.get('name'),
|
||||
slug
|
||||
},
|
||||
error
|
||||
};
|
||||
}
|
||||
function unpublishedEntryStatusChangeRequest(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_STATUS_CHANGE_REQUEST,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryStatusChangePersisted(collection, slug, newStatus) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_STATUS_CHANGE_SUCCESS,
|
||||
payload: {
|
||||
collection,
|
||||
slug,
|
||||
newStatus
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryStatusChangeError(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_STATUS_CHANGE_FAILURE,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryPublishRequest(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_PUBLISH_REQUEST,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryPublished(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_PUBLISH_SUCCESS,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryPublishError(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_PUBLISH_FAILURE,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryDeleteRequest(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_DELETE_REQUEST,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryDeleted(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_DELETE_SUCCESS,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishedEntryDeleteError(collection, slug) {
|
||||
return {
|
||||
type: UNPUBLISHED_ENTRY_DELETE_FAILURE,
|
||||
payload: {
|
||||
collection,
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Exported Thunk Action Creators
|
||||
*/
|
||||
|
||||
function loadUnpublishedEntry(collection, slug) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const entriesLoaded = (0, _get2.default)(state.editorialWorkflow.toJS(), 'pages.ids', false);
|
||||
//run possible unpublishedEntries migration
|
||||
if (!entriesLoaded) {
|
||||
try {
|
||||
const {
|
||||
entries,
|
||||
pagination
|
||||
} = await backend.unpublishedEntries(state.collections);
|
||||
dispatch(unpublishedEntriesLoaded(entries, pagination));
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (e) {}
|
||||
}
|
||||
dispatch(unpublishedEntryLoading(collection, slug));
|
||||
try {
|
||||
const entry = await backend.unpublishedEntry(state, collection, slug);
|
||||
const assetProxies = await Promise.all(entry.mediaFiles.filter(file => file.draft).map(({
|
||||
url,
|
||||
file,
|
||||
path
|
||||
}) => (0, _AssetProxy.createAssetProxy)({
|
||||
path,
|
||||
url,
|
||||
file
|
||||
})));
|
||||
dispatch((0, _media.addAssets)(assetProxies));
|
||||
dispatch(unpublishedEntryLoaded(collection, entry));
|
||||
dispatch((0, _entries2.createDraftFromEntry)(entry));
|
||||
} catch (error) {
|
||||
if (error.name === _decapCmsLibUtil.EDITORIAL_WORKFLOW_ERROR && error.notUnderEditorialWorkflow) {
|
||||
dispatch(unpublishedEntryRedirected(collection, slug));
|
||||
dispatch((0, _entries2.loadEntry)(collection, slug));
|
||||
} else {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.onFailToLoadEntries',
|
||||
details: error
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function loadUnpublishedEntries(collections) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const entriesLoaded = (0, _get2.default)(state.editorialWorkflow.toJS(), 'pages.ids', false);
|
||||
if (state.config.publish_mode !== _publishModes.EDITORIAL_WORKFLOW || entriesLoaded) {
|
||||
return;
|
||||
}
|
||||
dispatch(unpublishedEntriesLoading());
|
||||
backend.unpublishedEntries(collections).then(response => dispatch(unpublishedEntriesLoaded(response.entries, response.pagination))).catch(error => {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.onFailToLoadEntries',
|
||||
details: error
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
dispatch(unpublishedEntriesFailed(error));
|
||||
Promise.reject(error);
|
||||
});
|
||||
};
|
||||
}
|
||||
function persistUnpublishedEntry(collection, existingUnpublishedEntry) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const entryDraft = state.entryDraft;
|
||||
const fieldsErrors = entryDraft.get('fieldsErrors');
|
||||
const unpublishedSlugs = (0, _reducers.selectUnpublishedSlugs)(state, collection.get('name'));
|
||||
const publishedSlugs = (0, _reducers.selectPublishedSlugs)(state, collection.get('name'));
|
||||
const usedSlugs = publishedSlugs.concat(unpublishedSlugs);
|
||||
const entriesLoaded = (0, _get2.default)(state.editorialWorkflow.toJS(), 'pages.ids', false);
|
||||
|
||||
//load unpublishedEntries
|
||||
!entriesLoaded && dispatch(loadUnpublishedEntries(state.collections));
|
||||
|
||||
// Early return if draft contains validation errors
|
||||
if (!fieldsErrors.isEmpty()) {
|
||||
const hasPresenceErrors = fieldsErrors.some(errors => errors.some(error => error.type && error.type === _validationErrorTypes.default.PRESENCE));
|
||||
if (hasPresenceErrors) {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.missingRequiredField'
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
}
|
||||
return Promise.reject();
|
||||
}
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const entry = entryDraft.get('entry');
|
||||
const assetProxies = (0, _entries2.getMediaAssets)({
|
||||
entry
|
||||
});
|
||||
const serializedEntry = (0, _entries2.getSerializedEntry)(collection, entry);
|
||||
const serializedEntryDraft = entryDraft.set('entry', serializedEntry);
|
||||
dispatch(unpublishedEntryPersisting(collection, entry.get('slug')));
|
||||
const persistAction = existingUnpublishedEntry ? backend.persistUnpublishedEntry : backend.persistEntry;
|
||||
try {
|
||||
const newSlug = await persistAction.call(backend, {
|
||||
config: state.config,
|
||||
collection,
|
||||
entryDraft: serializedEntryDraft,
|
||||
assetProxies,
|
||||
usedSlugs
|
||||
});
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.entrySaved'
|
||||
},
|
||||
type: 'success',
|
||||
dismissAfter: 4000
|
||||
}));
|
||||
dispatch(unpublishedEntryPersisted(collection, serializedEntry));
|
||||
if (entry.get('slug') !== newSlug) {
|
||||
await dispatch(loadUnpublishedEntry(collection, newSlug));
|
||||
(0, _history.navigateToEntry)(collection.get('name'), newSlug);
|
||||
}
|
||||
} catch (error) {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.onFailToPersist',
|
||||
details: error
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
return Promise.reject(dispatch(unpublishedEntryPersistedFail(error, collection, entry.get('slug'))));
|
||||
}
|
||||
};
|
||||
}
|
||||
function updateUnpublishedEntryStatus(collection, slug, oldStatus, newStatus) {
|
||||
return (dispatch, getState) => {
|
||||
if (oldStatus === newStatus) return;
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
dispatch(unpublishedEntryStatusChangeRequest(collection, slug));
|
||||
backend.updateUnpublishedEntryStatus(collection, slug, newStatus).then(() => {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.entryUpdated'
|
||||
},
|
||||
type: 'success',
|
||||
dismissAfter: 4000
|
||||
}));
|
||||
dispatch(unpublishedEntryStatusChangePersisted(collection, slug, newStatus));
|
||||
}).catch(error => {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.onFailToUpdateStatus',
|
||||
details: error
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
dispatch(unpublishedEntryStatusChangeError(collection, slug));
|
||||
});
|
||||
};
|
||||
}
|
||||
function deleteUnpublishedEntry(collection, slug) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
dispatch(unpublishedEntryDeleteRequest(collection, slug));
|
||||
return backend.deleteUnpublishedEntry(collection, slug).then(() => {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.onDeleteUnpublishedChanges'
|
||||
},
|
||||
type: 'success',
|
||||
dismissAfter: 4000
|
||||
}));
|
||||
dispatch(unpublishedEntryDeleted(collection, slug));
|
||||
}).catch(error => {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.onDeleteUnpublishedChanges',
|
||||
details: error
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
dispatch(unpublishedEntryDeleteError(collection, slug));
|
||||
});
|
||||
};
|
||||
}
|
||||
function publishUnpublishedEntry(collectionName, slug) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const collections = state.collections;
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const entry = (0, _reducers.selectUnpublishedEntry)(state, collectionName, slug);
|
||||
dispatch(unpublishedEntryPublishRequest(collectionName, slug));
|
||||
try {
|
||||
await backend.publishUnpublishedEntry(entry);
|
||||
// re-load media after entry was published
|
||||
dispatch((0, _mediaLibrary.loadMedia)());
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.entryPublished'
|
||||
},
|
||||
type: 'success',
|
||||
dismissAfter: 4000
|
||||
}));
|
||||
dispatch(unpublishedEntryPublished(collectionName, slug));
|
||||
const collection = collections.get(collectionName);
|
||||
if (collection.has('nested')) {
|
||||
dispatch((0, _entries2.loadEntries)(collection));
|
||||
const newSlug = (0, _backend.slugFromCustomPath)(collection, entry.get('path'));
|
||||
(0, _entries2.loadEntry)(collection, newSlug);
|
||||
if (slug !== newSlug && (0, _entries.selectEditingDraft)(state.entryDraft)) {
|
||||
(0, _history.navigateToEntry)(collection.get('name'), newSlug);
|
||||
}
|
||||
} else {
|
||||
return dispatch((0, _entries2.loadEntry)(collection, slug));
|
||||
}
|
||||
} catch (error) {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.onFailToPublishEntry',
|
||||
details: error
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
dispatch(unpublishedEntryPublishError(collectionName, slug));
|
||||
}
|
||||
};
|
||||
}
|
||||
function unpublishPublishedEntry(collection, slug) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const entry = (0, _reducers.selectEntry)(state, collection.get('name'), slug);
|
||||
const entryDraft = (0, _immutable.Map)().set('entry', entry);
|
||||
dispatch(unpublishedEntryPersisting(collection, slug));
|
||||
return backend.deleteEntry(state, collection, slug).then(() => backend.persistEntry({
|
||||
config: state.config,
|
||||
collection,
|
||||
entryDraft,
|
||||
assetProxies: [],
|
||||
usedSlugs: (0, _immutable.List)(),
|
||||
status: _publishModes.status.get('PENDING_PUBLISH')
|
||||
})).then(() => {
|
||||
dispatch(unpublishedEntryPersisted(collection, entry));
|
||||
dispatch((0, _entries2.entryDeleted)(collection, slug));
|
||||
dispatch(loadUnpublishedEntry(collection, slug));
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.entryUnpublished'
|
||||
},
|
||||
type: 'success',
|
||||
dismissAfter: 4000
|
||||
}));
|
||||
}).catch(error => {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.onFailToUnpublishEntry',
|
||||
details: error
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
dispatch(unpublishedEntryPersistedFail(error, collection, entry.get('slug')));
|
||||
});
|
||||
};
|
||||
}
|
||||
908
node_modules/decap-cms-core/dist/esm/actions/entries.js
generated
vendored
Normal file
908
node_modules/decap-cms-core/dist/esm/actions/entries.js
generated
vendored
Normal file
@@ -0,0 +1,908 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.SORT_ENTRIES_SUCCESS = exports.SORT_ENTRIES_REQUEST = exports.SORT_ENTRIES_FAILURE = exports.REMOVE_DRAFT_ENTRY_MEDIA_FILE = exports.GROUP_ENTRIES_SUCCESS = exports.GROUP_ENTRIES_REQUEST = exports.GROUP_ENTRIES_FAILURE = exports.FILTER_ENTRIES_SUCCESS = exports.FILTER_ENTRIES_REQUEST = exports.FILTER_ENTRIES_FAILURE = exports.ENTRY_SUCCESS = exports.ENTRY_REQUEST = exports.ENTRY_PERSIST_SUCCESS = exports.ENTRY_PERSIST_REQUEST = exports.ENTRY_PERSIST_FAILURE = exports.ENTRY_FAILURE = exports.ENTRY_DELETE_SUCCESS = exports.ENTRY_DELETE_REQUEST = exports.ENTRY_DELETE_FAILURE = exports.ENTRIES_SUCCESS = exports.ENTRIES_REQUEST = exports.ENTRIES_FAILURE = exports.DRAFT_VALIDATION_ERRORS = exports.DRAFT_LOCAL_BACKUP_RETRIEVED = exports.DRAFT_DISCARD = exports.DRAFT_CREATE_FROM_LOCAL_BACKUP = exports.DRAFT_CREATE_FROM_ENTRY = exports.DRAFT_CREATE_EMPTY = exports.DRAFT_CREATE_DUPLICATE_FROM_ENTRY = exports.DRAFT_CLEAR_ERRORS = exports.DRAFT_CHANGE_FIELD = exports.CHANGE_VIEW_STYLE = exports.ADD_DRAFT_ENTRY_MEDIA_FILE = void 0;
|
||||
exports.addDraftEntryMediaFile = addDraftEntryMediaFile;
|
||||
exports.changeDraftField = changeDraftField;
|
||||
exports.changeDraftFieldValidation = changeDraftFieldValidation;
|
||||
exports.changeViewStyle = changeViewStyle;
|
||||
exports.clearFieldErrors = clearFieldErrors;
|
||||
exports.createDraftDuplicateFromEntry = createDraftDuplicateFromEntry;
|
||||
exports.createDraftFromEntry = createDraftFromEntry;
|
||||
exports.createEmptyDraft = createEmptyDraft;
|
||||
exports.createEmptyDraftData = createEmptyDraftData;
|
||||
exports.deleteEntry = deleteEntry;
|
||||
exports.deleteLocalBackup = deleteLocalBackup;
|
||||
exports.discardDraft = discardDraft;
|
||||
exports.draftDuplicateEntry = draftDuplicateEntry;
|
||||
exports.emptyDraftCreated = emptyDraftCreated;
|
||||
exports.entriesFailed = entriesFailed;
|
||||
exports.entriesLoaded = entriesLoaded;
|
||||
exports.entriesLoading = entriesLoading;
|
||||
exports.entryDeleteFail = entryDeleteFail;
|
||||
exports.entryDeleted = entryDeleted;
|
||||
exports.entryDeleting = entryDeleting;
|
||||
exports.entryLoadError = entryLoadError;
|
||||
exports.entryLoaded = entryLoaded;
|
||||
exports.entryLoading = entryLoading;
|
||||
exports.entryPersistFail = entryPersistFail;
|
||||
exports.entryPersisted = entryPersisted;
|
||||
exports.entryPersisting = entryPersisting;
|
||||
exports.filterByField = filterByField;
|
||||
exports.getAllEntries = getAllEntries;
|
||||
exports.getMediaAssets = getMediaAssets;
|
||||
exports.getSerializedEntry = getSerializedEntry;
|
||||
exports.groupByField = groupByField;
|
||||
exports.loadEntries = loadEntries;
|
||||
exports.loadEntry = loadEntry;
|
||||
exports.loadLocalBackup = loadLocalBackup;
|
||||
exports.localBackupRetrieved = localBackupRetrieved;
|
||||
exports.persistEntry = persistEntry;
|
||||
exports.persistLocalBackup = persistLocalBackup;
|
||||
exports.removeDraftEntryMediaFile = removeDraftEntryMediaFile;
|
||||
exports.retrieveLocalBackup = retrieveLocalBackup;
|
||||
exports.sortByField = sortByField;
|
||||
exports.traverseCollectionCursor = traverseCollectionCursor;
|
||||
exports.tryLoadEntry = tryLoadEntry;
|
||||
exports.validateMetaField = validateMetaField;
|
||||
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
||||
var _immutable = require("immutable");
|
||||
var _decapCmsLibUtil = require("decap-cms-lib-util");
|
||||
var _cursors = require("../reducers/cursors");
|
||||
var _collections = require("../reducers/collections");
|
||||
var _reducers = require("../reducers");
|
||||
var _integrations = require("../integrations");
|
||||
var _backend = require("../backend");
|
||||
var _serializeEntryValues = require("../lib/serializeEntryValues");
|
||||
var _Entry = require("../valueObjects/Entry");
|
||||
var _AssetProxy = require("../valueObjects/AssetProxy");
|
||||
var _validationErrorTypes = _interopRequireDefault(require("../constants/validationErrorTypes"));
|
||||
var _media = require("./media");
|
||||
var _redux = require("../types/redux");
|
||||
var _mediaLibrary = require("./mediaLibrary");
|
||||
var _waitUntil = require("./waitUntil");
|
||||
var _entries = require("../reducers/entries");
|
||||
var _entryDraft = require("../reducers/entryDraft");
|
||||
var _history = require("../routing/history");
|
||||
var _formatters = require("../lib/formatters");
|
||||
var _i18n = require("../lib/i18n");
|
||||
var _notifications = require("./notifications");
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
||||
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
||||
/*
|
||||
* Constant Declarations
|
||||
*/
|
||||
const ENTRY_REQUEST = exports.ENTRY_REQUEST = 'ENTRY_REQUEST';
|
||||
const ENTRY_SUCCESS = exports.ENTRY_SUCCESS = 'ENTRY_SUCCESS';
|
||||
const ENTRY_FAILURE = exports.ENTRY_FAILURE = 'ENTRY_FAILURE';
|
||||
const ENTRIES_REQUEST = exports.ENTRIES_REQUEST = 'ENTRIES_REQUEST';
|
||||
const ENTRIES_SUCCESS = exports.ENTRIES_SUCCESS = 'ENTRIES_SUCCESS';
|
||||
const ENTRIES_FAILURE = exports.ENTRIES_FAILURE = 'ENTRIES_FAILURE';
|
||||
const SORT_ENTRIES_REQUEST = exports.SORT_ENTRIES_REQUEST = 'SORT_ENTRIES_REQUEST';
|
||||
const SORT_ENTRIES_SUCCESS = exports.SORT_ENTRIES_SUCCESS = 'SORT_ENTRIES_SUCCESS';
|
||||
const SORT_ENTRIES_FAILURE = exports.SORT_ENTRIES_FAILURE = 'SORT_ENTRIES_FAILURE';
|
||||
const FILTER_ENTRIES_REQUEST = exports.FILTER_ENTRIES_REQUEST = 'FILTER_ENTRIES_REQUEST';
|
||||
const FILTER_ENTRIES_SUCCESS = exports.FILTER_ENTRIES_SUCCESS = 'FILTER_ENTRIES_SUCCESS';
|
||||
const FILTER_ENTRIES_FAILURE = exports.FILTER_ENTRIES_FAILURE = 'FILTER_ENTRIES_FAILURE';
|
||||
const GROUP_ENTRIES_REQUEST = exports.GROUP_ENTRIES_REQUEST = 'GROUP_ENTRIES_REQUEST';
|
||||
const GROUP_ENTRIES_SUCCESS = exports.GROUP_ENTRIES_SUCCESS = 'GROUP_ENTRIES_SUCCESS';
|
||||
const GROUP_ENTRIES_FAILURE = exports.GROUP_ENTRIES_FAILURE = 'GROUP_ENTRIES_FAILURE';
|
||||
const DRAFT_CREATE_FROM_ENTRY = exports.DRAFT_CREATE_FROM_ENTRY = 'DRAFT_CREATE_FROM_ENTRY';
|
||||
const DRAFT_CREATE_EMPTY = exports.DRAFT_CREATE_EMPTY = 'DRAFT_CREATE_EMPTY';
|
||||
const DRAFT_DISCARD = exports.DRAFT_DISCARD = 'DRAFT_DISCARD';
|
||||
const DRAFT_CHANGE_FIELD = exports.DRAFT_CHANGE_FIELD = 'DRAFT_CHANGE_FIELD';
|
||||
const DRAFT_VALIDATION_ERRORS = exports.DRAFT_VALIDATION_ERRORS = 'DRAFT_VALIDATION_ERRORS';
|
||||
const DRAFT_CLEAR_ERRORS = exports.DRAFT_CLEAR_ERRORS = 'DRAFT_CLEAR_ERRORS';
|
||||
const DRAFT_LOCAL_BACKUP_RETRIEVED = exports.DRAFT_LOCAL_BACKUP_RETRIEVED = 'DRAFT_LOCAL_BACKUP_RETRIEVED';
|
||||
const DRAFT_CREATE_FROM_LOCAL_BACKUP = exports.DRAFT_CREATE_FROM_LOCAL_BACKUP = 'DRAFT_CREATE_FROM_LOCAL_BACKUP';
|
||||
const DRAFT_CREATE_DUPLICATE_FROM_ENTRY = exports.DRAFT_CREATE_DUPLICATE_FROM_ENTRY = 'DRAFT_CREATE_DUPLICATE_FROM_ENTRY';
|
||||
const ENTRY_PERSIST_REQUEST = exports.ENTRY_PERSIST_REQUEST = 'ENTRY_PERSIST_REQUEST';
|
||||
const ENTRY_PERSIST_SUCCESS = exports.ENTRY_PERSIST_SUCCESS = 'ENTRY_PERSIST_SUCCESS';
|
||||
const ENTRY_PERSIST_FAILURE = exports.ENTRY_PERSIST_FAILURE = 'ENTRY_PERSIST_FAILURE';
|
||||
const ENTRY_DELETE_REQUEST = exports.ENTRY_DELETE_REQUEST = 'ENTRY_DELETE_REQUEST';
|
||||
const ENTRY_DELETE_SUCCESS = exports.ENTRY_DELETE_SUCCESS = 'ENTRY_DELETE_SUCCESS';
|
||||
const ENTRY_DELETE_FAILURE = exports.ENTRY_DELETE_FAILURE = 'ENTRY_DELETE_FAILURE';
|
||||
const ADD_DRAFT_ENTRY_MEDIA_FILE = exports.ADD_DRAFT_ENTRY_MEDIA_FILE = 'ADD_DRAFT_ENTRY_MEDIA_FILE';
|
||||
const REMOVE_DRAFT_ENTRY_MEDIA_FILE = exports.REMOVE_DRAFT_ENTRY_MEDIA_FILE = 'REMOVE_DRAFT_ENTRY_MEDIA_FILE';
|
||||
const CHANGE_VIEW_STYLE = exports.CHANGE_VIEW_STYLE = 'CHANGE_VIEW_STYLE';
|
||||
|
||||
/*
|
||||
* Simple Action Creators (Internal)
|
||||
* We still need to export them for tests
|
||||
*/
|
||||
function entryLoading(collection, slug) {
|
||||
return {
|
||||
type: ENTRY_REQUEST,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function entryLoaded(collection, entry) {
|
||||
return {
|
||||
type: ENTRY_SUCCESS,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
entry
|
||||
}
|
||||
};
|
||||
}
|
||||
function entryLoadError(error, collection, slug) {
|
||||
return {
|
||||
type: ENTRY_FAILURE,
|
||||
payload: {
|
||||
error,
|
||||
collection: collection.get('name'),
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function entriesLoading(collection) {
|
||||
return {
|
||||
type: ENTRIES_REQUEST,
|
||||
payload: {
|
||||
collection: collection.get('name')
|
||||
}
|
||||
};
|
||||
}
|
||||
function entriesLoaded(collection, entries, pagination, cursor, append = true) {
|
||||
return {
|
||||
type: ENTRIES_SUCCESS,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
entries,
|
||||
page: pagination,
|
||||
cursor: _decapCmsLibUtil.Cursor.create(cursor),
|
||||
append
|
||||
}
|
||||
};
|
||||
}
|
||||
function entriesFailed(collection, error) {
|
||||
return {
|
||||
type: ENTRIES_FAILURE,
|
||||
error: 'Failed to load entries',
|
||||
payload: error.toString(),
|
||||
meta: {
|
||||
collection: collection.get('name')
|
||||
}
|
||||
};
|
||||
}
|
||||
async function getAllEntries(state, collection) {
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const integration = (0, _reducers.selectIntegration)(state, collection.get('name'), 'listEntries');
|
||||
const provider = integration ? (0, _integrations.getIntegrationProvider)(state.integrations, backend.getToken, integration) : backend;
|
||||
const entries = await provider.listAllEntries(collection);
|
||||
return entries;
|
||||
}
|
||||
function sortByField(collection, key, direction = _redux.SortDirection.Ascending) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
// if we're already fetching we update the sort key, but skip loading entries
|
||||
const isFetching = (0, _entries.selectIsFetching)(state.entries, collection.get('name'));
|
||||
dispatch({
|
||||
type: SORT_ENTRIES_REQUEST,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
key,
|
||||
direction
|
||||
}
|
||||
});
|
||||
if (isFetching) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const entries = await getAllEntries(state, collection);
|
||||
dispatch({
|
||||
type: SORT_ENTRIES_SUCCESS,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
key,
|
||||
direction,
|
||||
entries
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: SORT_ENTRIES_FAILURE,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
key,
|
||||
direction,
|
||||
error
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
function filterByField(collection, filter) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
// if we're already fetching we update the filter key, but skip loading entries
|
||||
const isFetching = (0, _entries.selectIsFetching)(state.entries, collection.get('name'));
|
||||
dispatch({
|
||||
type: FILTER_ENTRIES_REQUEST,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
filter
|
||||
}
|
||||
});
|
||||
if (isFetching) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const entries = await getAllEntries(state, collection);
|
||||
dispatch({
|
||||
type: FILTER_ENTRIES_SUCCESS,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
filter,
|
||||
entries
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: FILTER_ENTRIES_FAILURE,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
filter,
|
||||
error
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
function groupByField(collection, group) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const isFetching = (0, _entries.selectIsFetching)(state.entries, collection.get('name'));
|
||||
dispatch({
|
||||
type: GROUP_ENTRIES_REQUEST,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
group
|
||||
}
|
||||
});
|
||||
if (isFetching) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const entries = await getAllEntries(state, collection);
|
||||
dispatch({
|
||||
type: GROUP_ENTRIES_SUCCESS,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
group,
|
||||
entries
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: GROUP_ENTRIES_FAILURE,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
group,
|
||||
error
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
function changeViewStyle(viewStyle) {
|
||||
return {
|
||||
type: CHANGE_VIEW_STYLE,
|
||||
payload: {
|
||||
style: viewStyle
|
||||
}
|
||||
};
|
||||
}
|
||||
function entryPersisting(collection, entry) {
|
||||
return {
|
||||
type: ENTRY_PERSIST_REQUEST,
|
||||
payload: {
|
||||
collectionName: collection.get('name'),
|
||||
entrySlug: entry.get('slug')
|
||||
}
|
||||
};
|
||||
}
|
||||
function entryPersisted(collection, entry, slug) {
|
||||
return {
|
||||
type: ENTRY_PERSIST_SUCCESS,
|
||||
payload: {
|
||||
collectionName: collection.get('name'),
|
||||
entrySlug: entry.get('slug'),
|
||||
/**
|
||||
* Pass slug from backend for newly created entries.
|
||||
*/
|
||||
slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function entryPersistFail(collection, entry, error) {
|
||||
return {
|
||||
type: ENTRY_PERSIST_FAILURE,
|
||||
error: 'Failed to persist entry',
|
||||
payload: {
|
||||
collectionName: collection.get('name'),
|
||||
entrySlug: entry.get('slug'),
|
||||
error: error.toString()
|
||||
}
|
||||
};
|
||||
}
|
||||
function entryDeleting(collection, slug) {
|
||||
return {
|
||||
type: ENTRY_DELETE_REQUEST,
|
||||
payload: {
|
||||
collectionName: collection.get('name'),
|
||||
entrySlug: slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function entryDeleted(collection, slug) {
|
||||
return {
|
||||
type: ENTRY_DELETE_SUCCESS,
|
||||
payload: {
|
||||
collectionName: collection.get('name'),
|
||||
entrySlug: slug
|
||||
}
|
||||
};
|
||||
}
|
||||
function entryDeleteFail(collection, slug, error) {
|
||||
return {
|
||||
type: ENTRY_DELETE_FAILURE,
|
||||
payload: {
|
||||
collectionName: collection.get('name'),
|
||||
entrySlug: slug,
|
||||
error: error.toString()
|
||||
}
|
||||
};
|
||||
}
|
||||
function emptyDraftCreated(entry) {
|
||||
return {
|
||||
type: DRAFT_CREATE_EMPTY,
|
||||
payload: entry
|
||||
};
|
||||
}
|
||||
/*
|
||||
* Exported simple Action Creators
|
||||
*/
|
||||
function createDraftFromEntry(entry) {
|
||||
return {
|
||||
type: DRAFT_CREATE_FROM_ENTRY,
|
||||
payload: {
|
||||
entry
|
||||
}
|
||||
};
|
||||
}
|
||||
function draftDuplicateEntry(entry) {
|
||||
return {
|
||||
type: DRAFT_CREATE_DUPLICATE_FROM_ENTRY,
|
||||
payload: (0, _Entry.createEntry)(entry.get('collection'), '', '', {
|
||||
data: entry.get('data'),
|
||||
mediaFiles: entry.get('mediaFiles').toJS()
|
||||
})
|
||||
};
|
||||
}
|
||||
function discardDraft() {
|
||||
return {
|
||||
type: DRAFT_DISCARD
|
||||
};
|
||||
}
|
||||
function changeDraftField({
|
||||
field,
|
||||
value,
|
||||
metadata,
|
||||
entries,
|
||||
i18n
|
||||
}) {
|
||||
return {
|
||||
type: DRAFT_CHANGE_FIELD,
|
||||
payload: {
|
||||
field,
|
||||
value,
|
||||
metadata,
|
||||
entries,
|
||||
i18n
|
||||
}
|
||||
};
|
||||
}
|
||||
function changeDraftFieldValidation(uniquefieldId, errors) {
|
||||
return {
|
||||
type: DRAFT_VALIDATION_ERRORS,
|
||||
payload: {
|
||||
uniquefieldId,
|
||||
errors
|
||||
}
|
||||
};
|
||||
}
|
||||
function clearFieldErrors() {
|
||||
return {
|
||||
type: DRAFT_CLEAR_ERRORS
|
||||
};
|
||||
}
|
||||
function localBackupRetrieved(entry) {
|
||||
return {
|
||||
type: DRAFT_LOCAL_BACKUP_RETRIEVED,
|
||||
payload: {
|
||||
entry
|
||||
}
|
||||
};
|
||||
}
|
||||
function loadLocalBackup() {
|
||||
return {
|
||||
type: DRAFT_CREATE_FROM_LOCAL_BACKUP
|
||||
};
|
||||
}
|
||||
function addDraftEntryMediaFile(file) {
|
||||
return {
|
||||
type: ADD_DRAFT_ENTRY_MEDIA_FILE,
|
||||
payload: file
|
||||
};
|
||||
}
|
||||
function removeDraftEntryMediaFile({
|
||||
id
|
||||
}) {
|
||||
return {
|
||||
type: REMOVE_DRAFT_ENTRY_MEDIA_FILE,
|
||||
payload: {
|
||||
id
|
||||
}
|
||||
};
|
||||
}
|
||||
function persistLocalBackup(entry, collection) {
|
||||
return (_dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
return backend.persistLocalDraftBackup(entry, collection);
|
||||
};
|
||||
}
|
||||
function createDraftDuplicateFromEntry(entry) {
|
||||
return dispatch => {
|
||||
dispatch((0, _waitUntil.waitUntil)({
|
||||
predicate: ({
|
||||
type
|
||||
}) => type === DRAFT_CREATE_EMPTY,
|
||||
run: () => dispatch(draftDuplicateEntry(entry))
|
||||
}));
|
||||
};
|
||||
}
|
||||
function retrieveLocalBackup(collection, slug) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const {
|
||||
entry
|
||||
} = await backend.getLocalDraftBackup(collection, slug);
|
||||
if (entry) {
|
||||
// load assets from backup
|
||||
const mediaFiles = entry.mediaFiles || [];
|
||||
const assetProxies = await Promise.all(mediaFiles.map(file => {
|
||||
if (file.file || file.url) {
|
||||
return (0, _AssetProxy.createAssetProxy)({
|
||||
path: file.path,
|
||||
file: file.file,
|
||||
url: file.url,
|
||||
field: file.field
|
||||
});
|
||||
} else {
|
||||
return (0, _media.getAsset)({
|
||||
collection,
|
||||
entry: (0, _immutable.fromJS)(entry),
|
||||
path: file.path,
|
||||
field: file.field
|
||||
})(dispatch, getState);
|
||||
}
|
||||
}));
|
||||
dispatch((0, _media.addAssets)(assetProxies));
|
||||
return dispatch(localBackupRetrieved(entry));
|
||||
}
|
||||
};
|
||||
}
|
||||
function deleteLocalBackup(collection, slug) {
|
||||
return (_dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
return backend.deleteLocalDraftBackup(collection, slug);
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Exported Thunk Action Creators
|
||||
*/
|
||||
|
||||
function loadEntry(collection, slug) {
|
||||
return async (dispatch, getState) => {
|
||||
await (0, _mediaLibrary.waitForMediaLibraryToLoad)(dispatch, getState());
|
||||
dispatch(entryLoading(collection, slug));
|
||||
try {
|
||||
const loadedEntry = await tryLoadEntry(getState(), collection, slug);
|
||||
dispatch(entryLoaded(collection, loadedEntry));
|
||||
dispatch(createDraftFromEntry(loadedEntry));
|
||||
} catch (error) {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
details: error.message,
|
||||
key: 'ui.toast.onFailToLoadEntries'
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
dispatch(entryLoadError(error, collection, slug));
|
||||
}
|
||||
};
|
||||
}
|
||||
async function tryLoadEntry(state, collection, slug) {
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const loadedEntry = await backend.getEntry(state, collection, slug);
|
||||
return loadedEntry;
|
||||
}
|
||||
const appendActions = (0, _immutable.fromJS)({
|
||||
['append_next']: {
|
||||
action: 'next',
|
||||
append: true
|
||||
}
|
||||
});
|
||||
function addAppendActionsToCursor(cursor) {
|
||||
return _decapCmsLibUtil.Cursor.create(cursor).updateStore('actions', actions => {
|
||||
return actions.union(appendActions.filter(v => actions.has(v.get('action'))).keySeq());
|
||||
});
|
||||
}
|
||||
function loadEntries(collection, page = 0) {
|
||||
return async (dispatch, getState) => {
|
||||
if (collection.get('isFetching')) {
|
||||
return;
|
||||
}
|
||||
const state = getState();
|
||||
const sortFields = (0, _entries.selectEntriesSortFields)(state.entries, collection.get('name'));
|
||||
if (sortFields && sortFields.length > 0) {
|
||||
const field = sortFields[0];
|
||||
return dispatch(sortByField(collection, field.get('key'), field.get('direction')));
|
||||
}
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const integration = (0, _reducers.selectIntegration)(state, collection.get('name'), 'listEntries');
|
||||
const provider = integration ? (0, _integrations.getIntegrationProvider)(state.integrations, backend.getToken, integration) : backend;
|
||||
const append = !!(page && !isNaN(page) && page > 0);
|
||||
dispatch(entriesLoading(collection));
|
||||
try {
|
||||
const loadAllEntries = collection.has('nested') || (0, _i18n.hasI18n)(collection);
|
||||
let response = await (loadAllEntries ?
|
||||
// nested collections require all entries to construct the tree
|
||||
provider.listAllEntries(collection).then(entries => ({
|
||||
entries
|
||||
})) : provider.listEntries(collection, page));
|
||||
response = _objectSpread(_objectSpread({}, response), {}, {
|
||||
// The only existing backend using the pagination system is the
|
||||
// Algolia integration, which is also the only integration used
|
||||
// to list entries. Thus, this checking for an integration can
|
||||
// determine whether or not this is using the old integer-based
|
||||
// pagination API. Other backends will simply store an empty
|
||||
// cursor, which behaves identically to no cursor at all.
|
||||
cursor: integration ? _decapCmsLibUtil.Cursor.create({
|
||||
actions: ['next'],
|
||||
meta: {
|
||||
usingOldPaginationAPI: true
|
||||
},
|
||||
data: {
|
||||
nextPage: page + 1
|
||||
}
|
||||
}) : _decapCmsLibUtil.Cursor.create(response.cursor)
|
||||
});
|
||||
dispatch(entriesLoaded(collection, response.cursor.meta.get('usingOldPaginationAPI') ? response.entries.reverse() : response.entries, response.pagination, addAppendActionsToCursor(response.cursor), append));
|
||||
} catch (err) {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
details: err,
|
||||
key: 'ui.toast.onFailToLoadEntries'
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
return Promise.reject(dispatch(entriesFailed(collection, err)));
|
||||
}
|
||||
};
|
||||
}
|
||||
function traverseCursor(backend, cursor, action) {
|
||||
if (!cursor.actions.has(action)) {
|
||||
throw new Error(`The current cursor does not support the pagination action "${action}".`);
|
||||
}
|
||||
return backend.traverseCursor(cursor, action);
|
||||
}
|
||||
function traverseCollectionCursor(collection, action) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const collectionName = collection.get('name');
|
||||
if (state.entries.getIn(['pages', `${collectionName}`, 'isFetching'])) {
|
||||
return;
|
||||
}
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const {
|
||||
action: realAction,
|
||||
append
|
||||
} = appendActions.has(action) ? appendActions.get(action).toJS() : {
|
||||
action,
|
||||
append: false
|
||||
};
|
||||
const cursor = (0, _cursors.selectCollectionEntriesCursor)(state.cursors, collection.get('name'));
|
||||
|
||||
// Handle cursors representing pages in the old, integer-based
|
||||
// pagination API
|
||||
if (cursor.meta.get('usingOldPaginationAPI', false)) {
|
||||
return dispatch(loadEntries(collection, cursor.data.get('nextPage')));
|
||||
}
|
||||
try {
|
||||
var _newCursor$meta;
|
||||
dispatch(entriesLoading(collection));
|
||||
const {
|
||||
entries,
|
||||
cursor: newCursor
|
||||
} = await traverseCursor(backend, cursor, realAction);
|
||||
const pagination = (_newCursor$meta = newCursor.meta) === null || _newCursor$meta === void 0 ? void 0 : _newCursor$meta.get('page');
|
||||
return dispatch(entriesLoaded(collection, entries, pagination, addAppendActionsToCursor(newCursor), append));
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
details: err,
|
||||
key: 'ui.toast.onFailToLoadEntries'
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
return Promise.reject(dispatch(entriesFailed(collection, err)));
|
||||
}
|
||||
};
|
||||
}
|
||||
function escapeHtml(unsafe) {
|
||||
return unsafe.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
||||
}
|
||||
function processValue(unsafe) {
|
||||
if (['true', 'True', 'TRUE'].includes(unsafe)) {
|
||||
return true;
|
||||
}
|
||||
if (['false', 'False', 'FALSE'].includes(unsafe)) {
|
||||
return false;
|
||||
}
|
||||
return escapeHtml(unsafe);
|
||||
}
|
||||
function getDataFields(fields) {
|
||||
return fields.filter(f => !f.get('meta')).toList();
|
||||
}
|
||||
function getMetaFields(fields) {
|
||||
return fields.filter(f => f.get('meta') === true).toList();
|
||||
}
|
||||
function createEmptyDraft(collection, search) {
|
||||
return async (dispatch, getState) => {
|
||||
const params = new URLSearchParams(search);
|
||||
params.forEach((value, key) => {
|
||||
collection = (0, _collections.updateFieldByKey)(collection, key, field => field.set('default', processValue(value)));
|
||||
});
|
||||
const fields = collection.get('fields', (0, _immutable.List)());
|
||||
const dataFields = getDataFields(fields);
|
||||
const data = createEmptyDraftData(dataFields);
|
||||
const metaFields = getMetaFields(fields);
|
||||
const meta = createEmptyDraftData(metaFields);
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
if (!collection.has('media_folder')) {
|
||||
await (0, _mediaLibrary.waitForMediaLibraryToLoad)(dispatch, getState());
|
||||
}
|
||||
const i18nFields = createEmptyDraftI18nData(collection, dataFields);
|
||||
let newEntry = (0, _Entry.createEntry)(collection.get('name'), '', '', {
|
||||
data,
|
||||
i18n: i18nFields,
|
||||
mediaFiles: [],
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
meta: meta
|
||||
});
|
||||
newEntry = await backend.processEntry(state, collection, newEntry);
|
||||
dispatch(emptyDraftCreated(newEntry));
|
||||
};
|
||||
}
|
||||
function createEmptyDraftData(fields, skipField = () => false) {
|
||||
return fields.reduce((reduction, value) => {
|
||||
const acc = reduction;
|
||||
const item = value;
|
||||
if (skipField(item)) {
|
||||
return acc;
|
||||
}
|
||||
const subfields = item.get('field') || item.get('fields');
|
||||
const list = item.get('widget') == 'list';
|
||||
const name = item.get('name');
|
||||
const defaultValue = item.get('default', null);
|
||||
function isEmptyDefaultValue(val) {
|
||||
return [[{}], {}].some(e => (0, _isEqual2.default)(val, e));
|
||||
}
|
||||
const hasSubfields = _immutable.List.isList(subfields) || _immutable.Map.isMap(subfields);
|
||||
if (hasSubfields) {
|
||||
if (list && _immutable.List.isList(defaultValue)) {
|
||||
acc[name] = defaultValue;
|
||||
} else {
|
||||
const asList = _immutable.List.isList(subfields) ? subfields : (0, _immutable.List)([subfields]);
|
||||
const subDefaultValue = list ? [createEmptyDraftData(asList, skipField)] : createEmptyDraftData(asList, skipField);
|
||||
if (!isEmptyDefaultValue(subDefaultValue)) {
|
||||
acc[name] = subDefaultValue;
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
if (defaultValue !== null) {
|
||||
acc[name] = defaultValue;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
function createEmptyDraftI18nData(collection, dataFields) {
|
||||
if (!(0, _i18n.hasI18n)(collection)) {
|
||||
return {};
|
||||
}
|
||||
function skipField(field) {
|
||||
return field.get(_i18n.I18N) !== _i18n.I18N_FIELD.DUPLICATE && field.get(_i18n.I18N) !== _i18n.I18N_FIELD.TRANSLATE;
|
||||
}
|
||||
const i18nData = createEmptyDraftData(dataFields, skipField);
|
||||
return (0, _i18n.duplicateDefaultI18nFields)(collection, i18nData);
|
||||
}
|
||||
function getMediaAssets({
|
||||
entry
|
||||
}) {
|
||||
const filesArray = entry.get('mediaFiles').toArray();
|
||||
const assets = filesArray.filter(file => file.get('draft')).map(file => (0, _AssetProxy.createAssetProxy)({
|
||||
path: file.get('path'),
|
||||
file: file.get('file'),
|
||||
url: file.get('url'),
|
||||
field: file.get('field')
|
||||
}));
|
||||
return assets;
|
||||
}
|
||||
function getSerializedEntry(collection, entry) {
|
||||
/**
|
||||
* Serialize the values of any fields with registered serializers, and
|
||||
* update the entry and entryDraft with the serialized values.
|
||||
*/
|
||||
const fields = (0, _collections.selectFields)(collection, entry.get('slug'));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function serializeData(data) {
|
||||
return (0, _serializeEntryValues.serializeValues)(data, fields);
|
||||
}
|
||||
const serializedData = serializeData(entry.get('data'));
|
||||
let serializedEntry = entry.set('data', serializedData);
|
||||
if ((0, _i18n.hasI18n)(collection)) {
|
||||
serializedEntry = (0, _i18n.serializeI18n)(collection, serializedEntry, serializeData);
|
||||
}
|
||||
return serializedEntry;
|
||||
}
|
||||
function persistEntry(collection) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const entryDraft = state.entryDraft;
|
||||
const fieldsErrors = entryDraft.get('fieldsErrors');
|
||||
const usedSlugs = (0, _reducers.selectPublishedSlugs)(state, collection.get('name'));
|
||||
|
||||
// Early return if draft contains validation errors
|
||||
if (!fieldsErrors.isEmpty()) {
|
||||
const hasPresenceErrors = fieldsErrors.some(errors => errors.some(error => error.type && error.type === _validationErrorTypes.default.PRESENCE));
|
||||
if (hasPresenceErrors) {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.missingRequiredField'
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
}
|
||||
return Promise.reject();
|
||||
}
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const entry = entryDraft.get('entry');
|
||||
const assetProxies = getMediaAssets({
|
||||
entry
|
||||
});
|
||||
const serializedEntry = getSerializedEntry(collection, entry);
|
||||
const serializedEntryDraft = entryDraft.set('entry', serializedEntry);
|
||||
dispatch(entryPersisting(collection, serializedEntry));
|
||||
return backend.persistEntry({
|
||||
config: state.config,
|
||||
collection,
|
||||
entryDraft: serializedEntryDraft,
|
||||
assetProxies,
|
||||
usedSlugs
|
||||
}).then(async newSlug => {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.entrySaved'
|
||||
},
|
||||
type: 'success',
|
||||
dismissAfter: 4000
|
||||
}));
|
||||
|
||||
// re-load media library if entry had media files
|
||||
if (assetProxies.length > 0) {
|
||||
await dispatch((0, _mediaLibrary.loadMedia)());
|
||||
}
|
||||
dispatch(entryPersisted(collection, serializedEntry, newSlug));
|
||||
if (collection.has('nested')) {
|
||||
await dispatch(loadEntries(collection));
|
||||
}
|
||||
if (entry.get('slug') !== newSlug) {
|
||||
await dispatch(loadEntry(collection, newSlug));
|
||||
(0, _history.navigateToEntry)(collection.get('name'), newSlug);
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
details: error,
|
||||
key: 'ui.toast.onFailToPersist'
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
return Promise.reject(dispatch(entryPersistFail(collection, serializedEntry, error)));
|
||||
});
|
||||
};
|
||||
}
|
||||
function deleteEntry(collection, slug) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
dispatch(entryDeleting(collection, slug));
|
||||
return backend.deleteEntry(state, collection, slug).then(() => {
|
||||
return dispatch(entryDeleted(collection, slug));
|
||||
}).catch(error => {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
details: error,
|
||||
key: 'ui.toast.onFailToDelete'
|
||||
},
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
console.error(error);
|
||||
return Promise.reject(dispatch(entryDeleteFail(collection, slug, error)));
|
||||
});
|
||||
};
|
||||
}
|
||||
function getPathError(path, key, t) {
|
||||
return {
|
||||
error: {
|
||||
type: _validationErrorTypes.default.CUSTOM,
|
||||
message: t(`editor.editorControlPane.widget.${key}`, {
|
||||
path
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
function validateMetaField(state, collection, field, value, t) {
|
||||
if (field.get('meta') && field.get('name') === 'path') {
|
||||
var _state$entryDraft;
|
||||
if (!value) {
|
||||
return getPathError(value, 'invalidPath', t);
|
||||
}
|
||||
const sanitizedPath = value.split('/').map((0, _formatters.getProcessSegment)(state.config.slug)).join('/');
|
||||
if (value !== sanitizedPath) {
|
||||
return getPathError(value, 'invalidPath', t);
|
||||
}
|
||||
const customPath = (0, _entryDraft.selectCustomPath)(collection, (0, _immutable.fromJS)({
|
||||
entry: {
|
||||
meta: {
|
||||
path: value
|
||||
}
|
||||
}
|
||||
}));
|
||||
const existingEntry = customPath ? (0, _entries.selectEntryByPath)(state.entries, collection.get('name'), customPath) : undefined;
|
||||
const existingEntryPath = existingEntry === null || existingEntry === void 0 ? void 0 : existingEntry.get('path');
|
||||
const draftPath = (_state$entryDraft = state.entryDraft) === null || _state$entryDraft === void 0 ? void 0 : _state$entryDraft.getIn(['entry', 'path']);
|
||||
if (existingEntryPath && existingEntryPath !== draftPath) {
|
||||
return getPathError(value, 'pathExists', t);
|
||||
}
|
||||
}
|
||||
return {
|
||||
error: false
|
||||
};
|
||||
}
|
||||
162
node_modules/decap-cms-core/dist/esm/actions/media.js
generated
vendored
Normal file
162
node_modules/decap-cms-core/dist/esm/actions/media.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.REMOVE_ASSET = exports.LOAD_ASSET_SUCCESS = exports.LOAD_ASSET_REQUEST = exports.LOAD_ASSET_FAILURE = exports.ADD_ASSETS = exports.ADD_ASSET = void 0;
|
||||
exports.addAsset = addAsset;
|
||||
exports.addAssets = addAssets;
|
||||
exports.boundGetAsset = boundGetAsset;
|
||||
exports.getAsset = getAsset;
|
||||
exports.loadAsset = loadAsset;
|
||||
exports.loadAssetFailure = loadAssetFailure;
|
||||
exports.loadAssetRequest = loadAssetRequest;
|
||||
exports.loadAssetSuccess = loadAssetSuccess;
|
||||
exports.removeAsset = removeAsset;
|
||||
var _decapCmsLibUtil = require("decap-cms-lib-util");
|
||||
var _AssetProxy = require("../valueObjects/AssetProxy");
|
||||
var _entries = require("../reducers/entries");
|
||||
var _mediaLibrary = require("../reducers/mediaLibrary");
|
||||
var _mediaLibrary2 = require("./mediaLibrary");
|
||||
const ADD_ASSETS = exports.ADD_ASSETS = 'ADD_ASSETS';
|
||||
const ADD_ASSET = exports.ADD_ASSET = 'ADD_ASSET';
|
||||
const REMOVE_ASSET = exports.REMOVE_ASSET = 'REMOVE_ASSET';
|
||||
const LOAD_ASSET_REQUEST = exports.LOAD_ASSET_REQUEST = 'LOAD_ASSET_REQUEST';
|
||||
const LOAD_ASSET_SUCCESS = exports.LOAD_ASSET_SUCCESS = 'LOAD_ASSET_SUCCESS';
|
||||
const LOAD_ASSET_FAILURE = exports.LOAD_ASSET_FAILURE = 'LOAD_ASSET_FAILURE';
|
||||
function addAssets(assets) {
|
||||
return {
|
||||
type: ADD_ASSETS,
|
||||
payload: assets
|
||||
};
|
||||
}
|
||||
function addAsset(assetProxy) {
|
||||
return {
|
||||
type: ADD_ASSET,
|
||||
payload: assetProxy
|
||||
};
|
||||
}
|
||||
function removeAsset(path) {
|
||||
return {
|
||||
type: REMOVE_ASSET,
|
||||
payload: path
|
||||
};
|
||||
}
|
||||
function loadAssetRequest(path) {
|
||||
return {
|
||||
type: LOAD_ASSET_REQUEST,
|
||||
payload: {
|
||||
path
|
||||
}
|
||||
};
|
||||
}
|
||||
function loadAssetSuccess(path) {
|
||||
return {
|
||||
type: LOAD_ASSET_SUCCESS,
|
||||
payload: {
|
||||
path
|
||||
}
|
||||
};
|
||||
}
|
||||
function loadAssetFailure(path, error) {
|
||||
return {
|
||||
type: LOAD_ASSET_FAILURE,
|
||||
payload: {
|
||||
path,
|
||||
error
|
||||
}
|
||||
};
|
||||
}
|
||||
function loadAsset(resolvedPath) {
|
||||
return async (dispatch, getState) => {
|
||||
try {
|
||||
dispatch(loadAssetRequest(resolvedPath));
|
||||
// load asset url from backend
|
||||
await (0, _mediaLibrary2.waitForMediaLibraryToLoad)(dispatch, getState());
|
||||
const file = (0, _mediaLibrary.selectMediaFileByPath)(getState(), resolvedPath);
|
||||
if (file) {
|
||||
const url = await (0, _mediaLibrary2.getMediaDisplayURL)(dispatch, getState(), file);
|
||||
const asset = (0, _AssetProxy.createAssetProxy)({
|
||||
path: resolvedPath,
|
||||
url: url || resolvedPath
|
||||
});
|
||||
dispatch(addAsset(asset));
|
||||
} else {
|
||||
const {
|
||||
url
|
||||
} = await (0, _mediaLibrary2.getMediaFile)(getState(), resolvedPath);
|
||||
const asset = (0, _AssetProxy.createAssetProxy)({
|
||||
path: resolvedPath,
|
||||
url
|
||||
});
|
||||
dispatch(addAsset(asset));
|
||||
}
|
||||
dispatch(loadAssetSuccess(resolvedPath));
|
||||
} catch (e) {
|
||||
dispatch(loadAssetFailure(resolvedPath, e));
|
||||
}
|
||||
};
|
||||
}
|
||||
const emptyAsset = (0, _AssetProxy.createAssetProxy)({
|
||||
path: 'empty.svg',
|
||||
file: new File([`<svg xmlns="http://www.w3.org/2000/svg"></svg>`], 'empty.svg', {
|
||||
type: 'image/svg+xml'
|
||||
})
|
||||
});
|
||||
function boundGetAsset(dispatch, collection, entry) {
|
||||
function bound(path, field) {
|
||||
const asset = dispatch(getAsset({
|
||||
collection,
|
||||
entry,
|
||||
path,
|
||||
field
|
||||
}));
|
||||
return asset;
|
||||
}
|
||||
return bound;
|
||||
}
|
||||
function getAsset({
|
||||
collection,
|
||||
entry,
|
||||
path,
|
||||
field
|
||||
}) {
|
||||
return (dispatch, getState) => {
|
||||
if (!path) return emptyAsset;
|
||||
const state = getState();
|
||||
const resolvedPath = (0, _entries.selectMediaFilePath)(state.config, collection, entry, path, field);
|
||||
let {
|
||||
asset,
|
||||
isLoading,
|
||||
error
|
||||
} = state.medias[resolvedPath] || {};
|
||||
if (isLoading) {
|
||||
return emptyAsset;
|
||||
}
|
||||
if (asset) {
|
||||
// There is already an AssetProxy in memory for this path. Use it.
|
||||
return asset;
|
||||
}
|
||||
if ((0, _decapCmsLibUtil.isAbsolutePath)(resolvedPath)) {
|
||||
// asset path is a public url so we can just use it as is
|
||||
asset = (0, _AssetProxy.createAssetProxy)({
|
||||
path: resolvedPath,
|
||||
url: path
|
||||
});
|
||||
dispatch(addAsset(asset));
|
||||
} else {
|
||||
if (error) {
|
||||
// on load error default back to original path
|
||||
asset = (0, _AssetProxy.createAssetProxy)({
|
||||
path: resolvedPath,
|
||||
url: path
|
||||
});
|
||||
dispatch(addAsset(asset));
|
||||
} else {
|
||||
dispatch(loadAsset(resolvedPath));
|
||||
asset = emptyAsset;
|
||||
}
|
||||
}
|
||||
return asset;
|
||||
};
|
||||
}
|
||||
589
node_modules/decap-cms-core/dist/esm/actions/mediaLibrary.js
generated
vendored
Normal file
589
node_modules/decap-cms-core/dist/esm/actions/mediaLibrary.js
generated
vendored
Normal file
@@ -0,0 +1,589 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.MEDIA_REMOVE_INSERTED = exports.MEDIA_PERSIST_SUCCESS = exports.MEDIA_PERSIST_REQUEST = exports.MEDIA_PERSIST_FAILURE = exports.MEDIA_LOAD_SUCCESS = exports.MEDIA_LOAD_REQUEST = exports.MEDIA_LOAD_FAILURE = exports.MEDIA_LIBRARY_OPEN = exports.MEDIA_LIBRARY_CREATE = exports.MEDIA_LIBRARY_CLOSE = exports.MEDIA_INSERT = exports.MEDIA_DISPLAY_URL_SUCCESS = exports.MEDIA_DISPLAY_URL_REQUEST = exports.MEDIA_DISPLAY_URL_FAILURE = exports.MEDIA_DELETE_SUCCESS = exports.MEDIA_DELETE_REQUEST = exports.MEDIA_DELETE_FAILURE = void 0;
|
||||
exports.clearMediaControl = clearMediaControl;
|
||||
exports.closeMediaLibrary = closeMediaLibrary;
|
||||
exports.createMediaLibrary = createMediaLibrary;
|
||||
exports.deleteMedia = deleteMedia;
|
||||
exports.getMediaDisplayURL = getMediaDisplayURL;
|
||||
exports.getMediaFile = getMediaFile;
|
||||
exports.insertMedia = insertMedia;
|
||||
exports.loadMedia = loadMedia;
|
||||
exports.loadMediaDisplayURL = loadMediaDisplayURL;
|
||||
exports.mediaDeleteFailed = mediaDeleteFailed;
|
||||
exports.mediaDeleted = mediaDeleted;
|
||||
exports.mediaDeleting = mediaDeleting;
|
||||
exports.mediaDisplayURLFailure = mediaDisplayURLFailure;
|
||||
exports.mediaDisplayURLRequest = mediaDisplayURLRequest;
|
||||
exports.mediaDisplayURLSuccess = mediaDisplayURLSuccess;
|
||||
exports.mediaLoadFailed = mediaLoadFailed;
|
||||
exports.mediaLoaded = mediaLoaded;
|
||||
exports.mediaLoading = mediaLoading;
|
||||
exports.mediaPersistFailed = mediaPersistFailed;
|
||||
exports.mediaPersisted = mediaPersisted;
|
||||
exports.mediaPersisting = mediaPersisting;
|
||||
exports.openMediaLibrary = openMediaLibrary;
|
||||
exports.persistMedia = persistMedia;
|
||||
exports.removeInsertedMedia = removeInsertedMedia;
|
||||
exports.removeMediaControl = removeMediaControl;
|
||||
exports.waitForMediaLibraryToLoad = waitForMediaLibraryToLoad;
|
||||
var _immutable = require("immutable");
|
||||
var _decapCmsLibUtil = require("decap-cms-lib-util");
|
||||
var _backend = require("../backend");
|
||||
var _AssetProxy = require("../valueObjects/AssetProxy");
|
||||
var _reducers = require("../reducers");
|
||||
var _entries = require("../reducers/entries");
|
||||
var _mediaLibrary = require("../reducers/mediaLibrary");
|
||||
var _integrations = require("../integrations");
|
||||
var _media = require("./media");
|
||||
var _entries2 = require("./entries");
|
||||
var _urlHelper = require("../lib/urlHelper");
|
||||
var _waitUntil = require("./waitUntil");
|
||||
var _notifications = require("./notifications");
|
||||
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
||||
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
||||
const MEDIA_LIBRARY_OPEN = exports.MEDIA_LIBRARY_OPEN = 'MEDIA_LIBRARY_OPEN';
|
||||
const MEDIA_LIBRARY_CLOSE = exports.MEDIA_LIBRARY_CLOSE = 'MEDIA_LIBRARY_CLOSE';
|
||||
const MEDIA_LIBRARY_CREATE = exports.MEDIA_LIBRARY_CREATE = 'MEDIA_LIBRARY_CREATE';
|
||||
const MEDIA_INSERT = exports.MEDIA_INSERT = 'MEDIA_INSERT';
|
||||
const MEDIA_REMOVE_INSERTED = exports.MEDIA_REMOVE_INSERTED = 'MEDIA_REMOVE_INSERTED';
|
||||
const MEDIA_LOAD_REQUEST = exports.MEDIA_LOAD_REQUEST = 'MEDIA_LOAD_REQUEST';
|
||||
const MEDIA_LOAD_SUCCESS = exports.MEDIA_LOAD_SUCCESS = 'MEDIA_LOAD_SUCCESS';
|
||||
const MEDIA_LOAD_FAILURE = exports.MEDIA_LOAD_FAILURE = 'MEDIA_LOAD_FAILURE';
|
||||
const MEDIA_PERSIST_REQUEST = exports.MEDIA_PERSIST_REQUEST = 'MEDIA_PERSIST_REQUEST';
|
||||
const MEDIA_PERSIST_SUCCESS = exports.MEDIA_PERSIST_SUCCESS = 'MEDIA_PERSIST_SUCCESS';
|
||||
const MEDIA_PERSIST_FAILURE = exports.MEDIA_PERSIST_FAILURE = 'MEDIA_PERSIST_FAILURE';
|
||||
const MEDIA_DELETE_REQUEST = exports.MEDIA_DELETE_REQUEST = 'MEDIA_DELETE_REQUEST';
|
||||
const MEDIA_DELETE_SUCCESS = exports.MEDIA_DELETE_SUCCESS = 'MEDIA_DELETE_SUCCESS';
|
||||
const MEDIA_DELETE_FAILURE = exports.MEDIA_DELETE_FAILURE = 'MEDIA_DELETE_FAILURE';
|
||||
const MEDIA_DISPLAY_URL_REQUEST = exports.MEDIA_DISPLAY_URL_REQUEST = 'MEDIA_DISPLAY_URL_REQUEST';
|
||||
const MEDIA_DISPLAY_URL_SUCCESS = exports.MEDIA_DISPLAY_URL_SUCCESS = 'MEDIA_DISPLAY_URL_SUCCESS';
|
||||
const MEDIA_DISPLAY_URL_FAILURE = exports.MEDIA_DISPLAY_URL_FAILURE = 'MEDIA_DISPLAY_URL_FAILURE';
|
||||
function createMediaLibrary(instance) {
|
||||
const api = {
|
||||
show: instance.show || (() => undefined),
|
||||
hide: instance.hide || (() => undefined),
|
||||
onClearControl: instance.onClearControl || (() => undefined),
|
||||
onRemoveControl: instance.onRemoveControl || (() => undefined),
|
||||
enableStandalone: instance.enableStandalone || (() => undefined)
|
||||
};
|
||||
return {
|
||||
type: MEDIA_LIBRARY_CREATE,
|
||||
payload: api
|
||||
};
|
||||
}
|
||||
function clearMediaControl(id) {
|
||||
return (_dispatch, getState) => {
|
||||
const state = getState();
|
||||
const mediaLibrary = state.mediaLibrary.get('externalLibrary');
|
||||
if (mediaLibrary) {
|
||||
mediaLibrary.onClearControl({
|
||||
id
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
function removeMediaControl(id) {
|
||||
return (_dispatch, getState) => {
|
||||
const state = getState();
|
||||
const mediaLibrary = state.mediaLibrary.get('externalLibrary');
|
||||
if (mediaLibrary) {
|
||||
mediaLibrary.onRemoveControl({
|
||||
id
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
function openMediaLibrary(payload = {}) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const mediaLibrary = state.mediaLibrary.get('externalLibrary');
|
||||
if (mediaLibrary) {
|
||||
const {
|
||||
controlID: id,
|
||||
value,
|
||||
config = (0, _immutable.Map)(),
|
||||
allowMultiple,
|
||||
forImage
|
||||
} = payload;
|
||||
mediaLibrary.show({
|
||||
id,
|
||||
value,
|
||||
config: config.toJS(),
|
||||
allowMultiple,
|
||||
imagesOnly: forImage
|
||||
});
|
||||
}
|
||||
dispatch(mediaLibraryOpened(payload));
|
||||
};
|
||||
}
|
||||
function closeMediaLibrary() {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const mediaLibrary = state.mediaLibrary.get('externalLibrary');
|
||||
if (mediaLibrary) {
|
||||
mediaLibrary.hide();
|
||||
}
|
||||
dispatch(mediaLibraryClosed());
|
||||
};
|
||||
}
|
||||
function insertMedia(mediaPath, field) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const config = state.config;
|
||||
const entry = state.entryDraft.get('entry');
|
||||
const collectionName = state.entryDraft.getIn(['entry', 'collection']);
|
||||
const collection = state.collections.get(collectionName);
|
||||
if (Array.isArray(mediaPath)) {
|
||||
mediaPath = mediaPath.map(path => (0, _entries.selectMediaFilePublicPath)(config, collection, path, entry, field));
|
||||
} else {
|
||||
mediaPath = (0, _entries.selectMediaFilePublicPath)(config, collection, mediaPath, entry, field);
|
||||
}
|
||||
dispatch(mediaInserted(mediaPath));
|
||||
};
|
||||
}
|
||||
function removeInsertedMedia(controlID) {
|
||||
return {
|
||||
type: MEDIA_REMOVE_INSERTED,
|
||||
payload: {
|
||||
controlID
|
||||
}
|
||||
};
|
||||
}
|
||||
function loadMedia(opts = {}) {
|
||||
const {
|
||||
delay = 0,
|
||||
query = '',
|
||||
page = 1,
|
||||
privateUpload
|
||||
} = opts;
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const integration = (0, _reducers.selectIntegration)(state, null, 'assetStore');
|
||||
if (integration) {
|
||||
const provider = (0, _integrations.getIntegrationProvider)(state.integrations, backend.getToken, integration);
|
||||
dispatch(mediaLoading(page));
|
||||
try {
|
||||
const files = await provider.retrieve(query, page, privateUpload);
|
||||
const mediaLoadedOpts = {
|
||||
page,
|
||||
canPaginate: true,
|
||||
dynamicSearch: true,
|
||||
dynamicSearchQuery: query,
|
||||
privateUpload
|
||||
};
|
||||
return dispatch(mediaLoaded(files, mediaLoadedOpts));
|
||||
} catch (error) {
|
||||
return dispatch(mediaLoadFailed({
|
||||
privateUpload
|
||||
}));
|
||||
}
|
||||
}
|
||||
dispatch(mediaLoading(page));
|
||||
function loadFunction() {
|
||||
return backend.getMedia().then(files => dispatch(mediaLoaded(files))).catch(error => {
|
||||
console.error(error);
|
||||
if (error.status === 404) {
|
||||
console.log('This 404 was expected and handled appropriately.');
|
||||
dispatch(mediaLoaded([]));
|
||||
} else {
|
||||
dispatch(mediaLoadFailed());
|
||||
}
|
||||
});
|
||||
}
|
||||
if (delay > 0) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => resolve(loadFunction()), delay);
|
||||
});
|
||||
} else {
|
||||
return loadFunction();
|
||||
}
|
||||
};
|
||||
}
|
||||
function createMediaFileFromAsset({
|
||||
id,
|
||||
file,
|
||||
assetProxy,
|
||||
draft
|
||||
}) {
|
||||
const mediaFile = {
|
||||
id,
|
||||
name: (0, _decapCmsLibUtil.basename)(assetProxy.path),
|
||||
displayURL: assetProxy.url,
|
||||
draft,
|
||||
file,
|
||||
size: file.size,
|
||||
url: assetProxy.url,
|
||||
path: assetProxy.path,
|
||||
field: assetProxy.field
|
||||
};
|
||||
return mediaFile;
|
||||
}
|
||||
function persistMedia(file, opts = {}) {
|
||||
const {
|
||||
privateUpload,
|
||||
field
|
||||
} = opts;
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const integration = (0, _reducers.selectIntegration)(state, null, 'assetStore');
|
||||
const files = (0, _mediaLibrary.selectMediaFiles)(state, field);
|
||||
const fileName = (0, _urlHelper.sanitizeSlug)(file.name.toLowerCase(), state.config.slug);
|
||||
const existingFile = files.find(existingFile => existingFile.name.toLowerCase() === fileName);
|
||||
const editingDraft = (0, _entries.selectEditingDraft)(state.entryDraft);
|
||||
|
||||
/**
|
||||
* Check for existing files of the same name before persisting. If no asset
|
||||
* store integration is used, files are being stored in Git, so we can
|
||||
* expect file names to be unique. If an asset store is in use, file names
|
||||
* may not be unique, so we forego this check.
|
||||
*/
|
||||
if (!integration && existingFile) {
|
||||
if (!window.confirm(`${existingFile.name} already exists. Do you want to replace it?`)) {
|
||||
return;
|
||||
} else {
|
||||
await dispatch(deleteMedia(existingFile, {
|
||||
privateUpload
|
||||
}));
|
||||
}
|
||||
}
|
||||
if (integration || !editingDraft) {
|
||||
dispatch(mediaPersisting());
|
||||
}
|
||||
try {
|
||||
let assetProxy;
|
||||
if (integration) {
|
||||
try {
|
||||
const provider = (0, _integrations.getIntegrationProvider)(state.integrations, backend.getToken, integration);
|
||||
const response = await provider.upload(file, privateUpload);
|
||||
assetProxy = (0, _AssetProxy.createAssetProxy)({
|
||||
url: response.asset.url,
|
||||
path: response.asset.url
|
||||
});
|
||||
} catch (error) {
|
||||
assetProxy = (0, _AssetProxy.createAssetProxy)({
|
||||
file,
|
||||
path: fileName
|
||||
});
|
||||
}
|
||||
} else if (privateUpload) {
|
||||
throw new Error('The Private Upload option is only available for Asset Store Integration');
|
||||
} else {
|
||||
const entry = state.entryDraft.get('entry');
|
||||
const collection = state.collections.get(entry === null || entry === void 0 ? void 0 : entry.get('collection'));
|
||||
const path = (0, _entries.selectMediaFilePath)(state.config, collection, entry, fileName, field);
|
||||
assetProxy = (0, _AssetProxy.createAssetProxy)({
|
||||
file,
|
||||
path,
|
||||
field
|
||||
});
|
||||
}
|
||||
dispatch((0, _media.addAsset)(assetProxy));
|
||||
let mediaFile;
|
||||
if (integration) {
|
||||
const id = await (0, _decapCmsLibUtil.getBlobSHA)(file);
|
||||
// integration assets are persisted immediately, thus draft is false
|
||||
mediaFile = createMediaFileFromAsset({
|
||||
id,
|
||||
file,
|
||||
assetProxy,
|
||||
draft: false
|
||||
});
|
||||
} else if (editingDraft) {
|
||||
const id = await (0, _decapCmsLibUtil.getBlobSHA)(file);
|
||||
mediaFile = createMediaFileFromAsset({
|
||||
id,
|
||||
file,
|
||||
assetProxy,
|
||||
draft: editingDraft
|
||||
});
|
||||
return dispatch((0, _entries2.addDraftEntryMediaFile)(mediaFile));
|
||||
} else {
|
||||
mediaFile = await backend.persistMedia(state.config, assetProxy);
|
||||
}
|
||||
return dispatch(mediaPersisted(mediaFile, {
|
||||
privateUpload
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: `Failed to persist media: ${error}`,
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
return dispatch(mediaPersistFailed({
|
||||
privateUpload
|
||||
}));
|
||||
}
|
||||
};
|
||||
}
|
||||
function deleteMedia(file, opts = {}) {
|
||||
const {
|
||||
privateUpload
|
||||
} = opts;
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const integration = (0, _reducers.selectIntegration)(state, null, 'assetStore');
|
||||
if (integration) {
|
||||
const provider = (0, _integrations.getIntegrationProvider)(state.integrations, backend.getToken, integration);
|
||||
dispatch(mediaDeleting());
|
||||
try {
|
||||
await provider.delete(file.id);
|
||||
return dispatch(mediaDeleted(file, {
|
||||
privateUpload
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: `Failed to delete media: ${error.message}`,
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
return dispatch(mediaDeleteFailed({
|
||||
privateUpload
|
||||
}));
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (file.draft) {
|
||||
dispatch((0, _media.removeAsset)(file.path));
|
||||
dispatch((0, _entries2.removeDraftEntryMediaFile)({
|
||||
id: file.id
|
||||
}));
|
||||
} else {
|
||||
const editingDraft = (0, _entries.selectEditingDraft)(state.entryDraft);
|
||||
dispatch(mediaDeleting());
|
||||
dispatch((0, _media.removeAsset)(file.path));
|
||||
await backend.deleteMedia(state.config, file.path);
|
||||
dispatch(mediaDeleted(file));
|
||||
if (editingDraft) {
|
||||
dispatch((0, _entries2.removeDraftEntryMediaFile)({
|
||||
id: file.id
|
||||
}));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: `Failed to delete media: ${error.message}`,
|
||||
type: 'error',
|
||||
dismissAfter: 8000
|
||||
}));
|
||||
return dispatch(mediaDeleteFailed());
|
||||
}
|
||||
};
|
||||
}
|
||||
async function getMediaFile(state, path) {
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const {
|
||||
url
|
||||
} = await backend.getMediaFile(path);
|
||||
return {
|
||||
url
|
||||
};
|
||||
}
|
||||
function loadMediaDisplayURL(file) {
|
||||
return async (dispatch, getState) => {
|
||||
const {
|
||||
displayURL,
|
||||
id
|
||||
} = file;
|
||||
const state = getState();
|
||||
const displayURLState = (0, _mediaLibrary.selectMediaDisplayURL)(state, id);
|
||||
if (!id || !displayURL || displayURLState.get('url') || displayURLState.get('isFetching') || displayURLState.get('err')) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (typeof displayURL === 'string') {
|
||||
dispatch(mediaDisplayURLRequest(id));
|
||||
dispatch(mediaDisplayURLSuccess(id, displayURL));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
dispatch(mediaDisplayURLRequest(id));
|
||||
const newURL = await backend.getMediaDisplayURL(displayURL);
|
||||
if (newURL) {
|
||||
dispatch(mediaDisplayURLSuccess(id, newURL));
|
||||
} else {
|
||||
throw new Error('No display URL was returned!');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
dispatch(mediaDisplayURLFailure(id, err));
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaLibraryOpened(payload) {
|
||||
return {
|
||||
type: MEDIA_LIBRARY_OPEN,
|
||||
payload
|
||||
};
|
||||
}
|
||||
function mediaLibraryClosed() {
|
||||
return {
|
||||
type: MEDIA_LIBRARY_CLOSE
|
||||
};
|
||||
}
|
||||
function mediaInserted(mediaPath) {
|
||||
return {
|
||||
type: MEDIA_INSERT,
|
||||
payload: {
|
||||
mediaPath
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaLoading(page) {
|
||||
return {
|
||||
type: MEDIA_LOAD_REQUEST,
|
||||
payload: {
|
||||
page
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaLoaded(files, opts = {}) {
|
||||
return {
|
||||
type: MEDIA_LOAD_SUCCESS,
|
||||
payload: _objectSpread({
|
||||
files
|
||||
}, opts)
|
||||
};
|
||||
}
|
||||
function mediaLoadFailed(opts = {}) {
|
||||
const {
|
||||
privateUpload
|
||||
} = opts;
|
||||
return {
|
||||
type: MEDIA_LOAD_FAILURE,
|
||||
payload: {
|
||||
privateUpload
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaPersisting() {
|
||||
return {
|
||||
type: MEDIA_PERSIST_REQUEST
|
||||
};
|
||||
}
|
||||
function mediaPersisted(file, opts = {}) {
|
||||
const {
|
||||
privateUpload
|
||||
} = opts;
|
||||
return {
|
||||
type: MEDIA_PERSIST_SUCCESS,
|
||||
payload: {
|
||||
file,
|
||||
privateUpload
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaPersistFailed(opts = {}) {
|
||||
const {
|
||||
privateUpload
|
||||
} = opts;
|
||||
return {
|
||||
type: MEDIA_PERSIST_FAILURE,
|
||||
payload: {
|
||||
privateUpload
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaDeleting() {
|
||||
return {
|
||||
type: MEDIA_DELETE_REQUEST
|
||||
};
|
||||
}
|
||||
function mediaDeleted(file, opts = {}) {
|
||||
const {
|
||||
privateUpload
|
||||
} = opts;
|
||||
return {
|
||||
type: MEDIA_DELETE_SUCCESS,
|
||||
payload: {
|
||||
file,
|
||||
privateUpload
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaDeleteFailed(opts = {}) {
|
||||
const {
|
||||
privateUpload
|
||||
} = opts;
|
||||
return {
|
||||
type: MEDIA_DELETE_FAILURE,
|
||||
payload: {
|
||||
privateUpload
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaDisplayURLRequest(key) {
|
||||
return {
|
||||
type: MEDIA_DISPLAY_URL_REQUEST,
|
||||
payload: {
|
||||
key
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaDisplayURLSuccess(key, url) {
|
||||
return {
|
||||
type: MEDIA_DISPLAY_URL_SUCCESS,
|
||||
payload: {
|
||||
key,
|
||||
url
|
||||
}
|
||||
};
|
||||
}
|
||||
function mediaDisplayURLFailure(key, err) {
|
||||
return {
|
||||
type: MEDIA_DISPLAY_URL_FAILURE,
|
||||
payload: {
|
||||
key,
|
||||
err
|
||||
}
|
||||
};
|
||||
}
|
||||
async function waitForMediaLibraryToLoad(dispatch, state) {
|
||||
if (state.mediaLibrary.get('isLoading') !== false && !state.mediaLibrary.get('externalLibrary')) {
|
||||
await (0, _waitUntil.waitUntilWithTimeout)(dispatch, resolve => ({
|
||||
predicate: ({
|
||||
type
|
||||
}) => type === MEDIA_LOAD_SUCCESS || type === MEDIA_LOAD_FAILURE,
|
||||
run: () => resolve()
|
||||
}));
|
||||
}
|
||||
}
|
||||
async function getMediaDisplayURL(dispatch, state, file) {
|
||||
const displayURLState = (0, _mediaLibrary.selectMediaDisplayURL)(state, file.id);
|
||||
let url;
|
||||
if (displayURLState.get('url')) {
|
||||
// url was already loaded
|
||||
url = displayURLState.get('url');
|
||||
} else if (displayURLState.get('err')) {
|
||||
// url loading had an error
|
||||
url = null;
|
||||
} else {
|
||||
var _await$promise;
|
||||
const key = file.id;
|
||||
const promise = (0, _waitUntil.waitUntilWithTimeout)(dispatch, resolve => ({
|
||||
predicate: ({
|
||||
type,
|
||||
payload
|
||||
}) => (type === MEDIA_DISPLAY_URL_SUCCESS || type === MEDIA_DISPLAY_URL_FAILURE) && payload.key === key,
|
||||
run: (_dispatch, _getState, action) => resolve(action.payload.url)
|
||||
}));
|
||||
if (!displayURLState.get('isFetching')) {
|
||||
// load display url
|
||||
dispatch(loadMediaDisplayURL(file));
|
||||
}
|
||||
url = (_await$promise = await promise) !== null && _await$promise !== void 0 ? _await$promise : null;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
29
node_modules/decap-cms-core/dist/esm/actions/notifications.js
generated
vendored
Normal file
29
node_modules/decap-cms-core/dist/esm/actions/notifications.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.NOTIFICATION_SEND = exports.NOTIFICATION_DISMISS = exports.NOTIFICATIONS_CLEAR = void 0;
|
||||
exports.addNotification = addNotification;
|
||||
exports.clearNotifications = clearNotifications;
|
||||
exports.dismissNotification = dismissNotification;
|
||||
const NOTIFICATION_SEND = exports.NOTIFICATION_SEND = 'NOTIFICATION_SEND';
|
||||
const NOTIFICATION_DISMISS = exports.NOTIFICATION_DISMISS = 'NOTIFICATION_DISMISS';
|
||||
const NOTIFICATIONS_CLEAR = exports.NOTIFICATIONS_CLEAR = 'NOTIFICATION_CLEAR';
|
||||
function addNotification(notification) {
|
||||
return {
|
||||
type: NOTIFICATION_SEND,
|
||||
payload: notification
|
||||
};
|
||||
}
|
||||
function dismissNotification(id) {
|
||||
return {
|
||||
type: NOTIFICATION_DISMISS,
|
||||
id
|
||||
};
|
||||
}
|
||||
function clearNotifications() {
|
||||
return {
|
||||
type: NOTIFICATIONS_CLEAR
|
||||
};
|
||||
}
|
||||
166
node_modules/decap-cms-core/dist/esm/actions/search.js
generated
vendored
Normal file
166
node_modules/decap-cms-core/dist/esm/actions/search.js
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.SEARCH_ENTRIES_SUCCESS = exports.SEARCH_ENTRIES_REQUEST = exports.SEARCH_ENTRIES_FAILURE = exports.SEARCH_CLEAR = exports.QUERY_SUCCESS = exports.QUERY_REQUEST = exports.QUERY_FAILURE = exports.CLEAR_REQUESTS = void 0;
|
||||
exports.clearRequests = clearRequests;
|
||||
exports.clearSearch = clearSearch;
|
||||
exports.query = query;
|
||||
exports.queryFailure = queryFailure;
|
||||
exports.querySuccess = querySuccess;
|
||||
exports.querying = querying;
|
||||
exports.searchEntries = searchEntries;
|
||||
exports.searchFailure = searchFailure;
|
||||
exports.searchSuccess = searchSuccess;
|
||||
exports.searchingEntries = searchingEntries;
|
||||
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
||||
var _backend = require("../backend");
|
||||
var _integrations = require("../integrations");
|
||||
var _reducers = require("../reducers");
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
/*
|
||||
* Constant Declarations
|
||||
*/
|
||||
const SEARCH_ENTRIES_REQUEST = exports.SEARCH_ENTRIES_REQUEST = 'SEARCH_ENTRIES_REQUEST';
|
||||
const SEARCH_ENTRIES_SUCCESS = exports.SEARCH_ENTRIES_SUCCESS = 'SEARCH_ENTRIES_SUCCESS';
|
||||
const SEARCH_ENTRIES_FAILURE = exports.SEARCH_ENTRIES_FAILURE = 'SEARCH_ENTRIES_FAILURE';
|
||||
const QUERY_REQUEST = exports.QUERY_REQUEST = 'QUERY_REQUEST';
|
||||
const QUERY_SUCCESS = exports.QUERY_SUCCESS = 'QUERY_SUCCESS';
|
||||
const QUERY_FAILURE = exports.QUERY_FAILURE = 'QUERY_FAILURE';
|
||||
const SEARCH_CLEAR = exports.SEARCH_CLEAR = 'SEARCH_CLEAR';
|
||||
const CLEAR_REQUESTS = exports.CLEAR_REQUESTS = 'CLEAR_REQUESTS';
|
||||
|
||||
/*
|
||||
* Simple Action Creators (Internal)
|
||||
* We still need to export them for tests
|
||||
*/
|
||||
function searchingEntries(searchTerm, searchCollections, page) {
|
||||
return {
|
||||
type: SEARCH_ENTRIES_REQUEST,
|
||||
payload: {
|
||||
searchTerm,
|
||||
searchCollections,
|
||||
page
|
||||
}
|
||||
};
|
||||
}
|
||||
function searchSuccess(entries, page) {
|
||||
return {
|
||||
type: SEARCH_ENTRIES_SUCCESS,
|
||||
payload: {
|
||||
entries,
|
||||
page
|
||||
}
|
||||
};
|
||||
}
|
||||
function searchFailure(error) {
|
||||
return {
|
||||
type: SEARCH_ENTRIES_FAILURE,
|
||||
payload: {
|
||||
error
|
||||
}
|
||||
};
|
||||
}
|
||||
function querying(searchTerm, request) {
|
||||
return {
|
||||
type: QUERY_REQUEST,
|
||||
payload: {
|
||||
searchTerm,
|
||||
request
|
||||
}
|
||||
};
|
||||
}
|
||||
function querySuccess(namespace, hits) {
|
||||
return {
|
||||
type: QUERY_SUCCESS,
|
||||
payload: {
|
||||
namespace,
|
||||
hits
|
||||
}
|
||||
};
|
||||
}
|
||||
function queryFailure(error) {
|
||||
return {
|
||||
type: QUERY_FAILURE,
|
||||
payload: {
|
||||
error
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Exported simple Action Creators
|
||||
*/
|
||||
|
||||
function clearSearch() {
|
||||
return {
|
||||
type: SEARCH_CLEAR
|
||||
};
|
||||
}
|
||||
function clearRequests() {
|
||||
return {
|
||||
type: CLEAR_REQUESTS
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Exported Thunk Action Creators
|
||||
*/
|
||||
|
||||
// SearchEntries will search for complete entries in all collections.
|
||||
function searchEntries(searchTerm, searchCollections, page = 0) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const {
|
||||
search
|
||||
} = state;
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const allCollections = searchCollections || state.collections.keySeq().toArray();
|
||||
const collections = allCollections.filter(collection => (0, _reducers.selectIntegration)(state, collection, 'search'));
|
||||
const integration = (0, _reducers.selectIntegration)(state, collections[0], 'search');
|
||||
|
||||
// avoid duplicate searches
|
||||
if (search.isFetching && search.term === searchTerm && (0, _isEqual2.default)(allCollections, search.collections) && (
|
||||
// if an integration doesn't exist, 'page' is not used
|
||||
search.page === page || !integration)) {
|
||||
return;
|
||||
}
|
||||
dispatch(searchingEntries(searchTerm, allCollections, page));
|
||||
const searchPromise = integration ? (0, _integrations.getIntegrationProvider)(state.integrations, backend.getToken, integration).search(collections, searchTerm, page) : backend.search(state.collections.filter((_, key) => allCollections.indexOf(key) !== -1).valueSeq().toArray(), searchTerm);
|
||||
try {
|
||||
const response = await searchPromise;
|
||||
return dispatch(searchSuccess(response.entries, response.pagination));
|
||||
} catch (error) {
|
||||
return dispatch(searchFailure(error));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Instead of searching for complete entries, query will search for specific fields
|
||||
// in specific collections and return raw data (no entries).
|
||||
function query(namespace, collectionName, searchFields, searchTerm, file, limit) {
|
||||
return async (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const integration = (0, _reducers.selectIntegration)(state, collectionName, 'search');
|
||||
const collection = state.collections.find(collection => collection.get('name') === collectionName);
|
||||
dispatch(clearRequests());
|
||||
const queryIdentifier = `${collectionName}-${searchFields.join()}-${searchTerm}-${file}-${limit}`;
|
||||
const queuedQueryPromise = state.search.requests.find(({
|
||||
id
|
||||
}) => id == queryIdentifier);
|
||||
const queryPromise = queuedQueryPromise ? queuedQueryPromise.queryResponse : integration ? (0, _integrations.getIntegrationProvider)(state.integrations, backend.getToken, integration).searchBy(searchFields.map(f => `data.${f}`), collectionName, searchTerm) : backend.query(collection, searchFields, searchTerm, file, limit);
|
||||
dispatch(querying(searchTerm, queuedQueryPromise ? undefined : {
|
||||
id: queryIdentifier,
|
||||
expires: new Date(new Date().getTime() + 10 * 1000),
|
||||
queryResponse: queryPromise
|
||||
}));
|
||||
try {
|
||||
const response = await queryPromise;
|
||||
return dispatch(querySuccess(namespace, response.hits));
|
||||
} catch (error) {
|
||||
return dispatch(queryFailure(error));
|
||||
}
|
||||
};
|
||||
}
|
||||
90
node_modules/decap-cms-core/dist/esm/actions/status.js
generated
vendored
Normal file
90
node_modules/decap-cms-core/dist/esm/actions/status.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.STATUS_SUCCESS = exports.STATUS_REQUEST = exports.STATUS_FAILURE = void 0;
|
||||
exports.checkBackendStatus = checkBackendStatus;
|
||||
exports.statusFailure = statusFailure;
|
||||
exports.statusRequest = statusRequest;
|
||||
exports.statusSuccess = statusSuccess;
|
||||
var _backend = require("../backend");
|
||||
var _notifications = require("./notifications");
|
||||
const STATUS_REQUEST = exports.STATUS_REQUEST = 'STATUS_REQUEST';
|
||||
const STATUS_SUCCESS = exports.STATUS_SUCCESS = 'STATUS_SUCCESS';
|
||||
const STATUS_FAILURE = exports.STATUS_FAILURE = 'STATUS_FAILURE';
|
||||
function statusRequest() {
|
||||
return {
|
||||
type: STATUS_REQUEST
|
||||
};
|
||||
}
|
||||
function statusSuccess(status) {
|
||||
return {
|
||||
type: STATUS_SUCCESS,
|
||||
payload: {
|
||||
status
|
||||
}
|
||||
};
|
||||
}
|
||||
function statusFailure(error) {
|
||||
return {
|
||||
type: STATUS_FAILURE,
|
||||
payload: {
|
||||
error
|
||||
}
|
||||
};
|
||||
}
|
||||
function checkBackendStatus() {
|
||||
return async (dispatch, getState) => {
|
||||
try {
|
||||
const state = getState();
|
||||
if (state.status.isFetching) {
|
||||
return;
|
||||
}
|
||||
dispatch(statusRequest());
|
||||
const backend = (0, _backend.currentBackend)(state.config);
|
||||
const status = await backend.status();
|
||||
const backendDownKey = 'ui.toast.onBackendDown';
|
||||
const previousBackendDownNotifications = state.notifications.notifications.filter(n => {
|
||||
var _n$message;
|
||||
return typeof n.message != 'string' && ((_n$message = n.message) === null || _n$message === void 0 ? void 0 : _n$message.key) === backendDownKey;
|
||||
});
|
||||
if (status.api.status === false) {
|
||||
if (previousBackendDownNotifications.length === 0) {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
details: status.api.statusPage,
|
||||
key: 'ui.toast.onBackendDown'
|
||||
},
|
||||
type: 'error'
|
||||
}));
|
||||
}
|
||||
return dispatch(statusSuccess(status));
|
||||
} else if (status.api.status === true && previousBackendDownNotifications.length > 0) {
|
||||
// If backend is up, clear all the danger messages
|
||||
previousBackendDownNotifications.forEach(notification => {
|
||||
dispatch((0, _notifications.dismissNotification)(notification.id));
|
||||
});
|
||||
}
|
||||
const authError = status.auth.status === false;
|
||||
if (authError) {
|
||||
const key = 'ui.toast.onLoggedOut';
|
||||
const existingNotification = state.notifications.notifications.find(n => {
|
||||
var _n$message2;
|
||||
return typeof n.message != 'string' && ((_n$message2 = n.message) === null || _n$message2 === void 0 ? void 0 : _n$message2.key) === key;
|
||||
});
|
||||
if (!existingNotification) {
|
||||
dispatch((0, _notifications.addNotification)({
|
||||
message: {
|
||||
key: 'ui.toast.onLoggedOut'
|
||||
},
|
||||
type: 'error'
|
||||
}));
|
||||
}
|
||||
}
|
||||
dispatch(statusSuccess(status));
|
||||
} catch (error) {
|
||||
dispatch(statusFailure(error));
|
||||
}
|
||||
};
|
||||
}
|
||||
39
node_modules/decap-cms-core/dist/esm/actions/waitUntil.js
generated
vendored
Normal file
39
node_modules/decap-cms-core/dist/esm/actions/waitUntil.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.waitUntil = waitUntil;
|
||||
exports.waitUntilWithTimeout = waitUntilWithTimeout;
|
||||
var _waitUntilAction = require("../redux/middleware/waitUntilAction");
|
||||
function waitUntil({
|
||||
predicate,
|
||||
run
|
||||
}) {
|
||||
return {
|
||||
type: _waitUntilAction.WAIT_UNTIL_ACTION,
|
||||
predicate,
|
||||
run
|
||||
};
|
||||
}
|
||||
async function waitUntilWithTimeout(dispatch, waitActionArgs, timeout = 30000) {
|
||||
let waitDone = false;
|
||||
const waitPromise = new Promise(resolve => {
|
||||
dispatch(waitUntil(waitActionArgs(resolve)));
|
||||
});
|
||||
const timeoutPromise = new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
if (waitDone) {
|
||||
resolve();
|
||||
} else {
|
||||
console.warn('Wait Action timed out');
|
||||
resolve(null);
|
||||
}
|
||||
}, timeout);
|
||||
});
|
||||
const result = await Promise.race([waitPromise.then(result => {
|
||||
waitDone = true;
|
||||
return result;
|
||||
}).catch(null), timeoutPromise]);
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user