chore: add code formatting and linting (#952)
This commit is contained in:
@ -4,7 +4,7 @@ import { getIntegrationProvider } from 'Integrations';
|
||||
import { selectIntegration } from 'Reducers';
|
||||
|
||||
let store;
|
||||
export const setStore = (storeObj) => {
|
||||
export const setStore = storeObj => {
|
||||
store = storeObj;
|
||||
};
|
||||
|
||||
@ -14,12 +14,15 @@ export default function AssetProxy(value, fileObj, uploaded = false, asset) {
|
||||
this.fileObj = fileObj;
|
||||
this.uploaded = uploaded;
|
||||
this.sha = null;
|
||||
this.path = config.get('media_folder') && !uploaded ? resolvePath(value, config.get('media_folder')) : value;
|
||||
this.path =
|
||||
config.get('media_folder') && !uploaded
|
||||
? resolvePath(value, config.get('media_folder'))
|
||||
: value;
|
||||
this.public_path = !uploaded ? resolvePath(value, config.get('public_folder')) : value;
|
||||
this.asset = asset;
|
||||
}
|
||||
|
||||
AssetProxy.prototype.toString = function () {
|
||||
AssetProxy.prototype.toString = function() {
|
||||
// Use the deployed image path if we do not have a locally cached copy.
|
||||
if (this.uploaded && !this.fileObj) return this.public_path;
|
||||
try {
|
||||
@ -29,10 +32,10 @@ AssetProxy.prototype.toString = function () {
|
||||
}
|
||||
};
|
||||
|
||||
AssetProxy.prototype.toBase64 = function () {
|
||||
AssetProxy.prototype.toBase64 = function() {
|
||||
return new Promise(resolve => {
|
||||
const fr = new FileReader();
|
||||
fr.onload = (readerEvt) => {
|
||||
fr.onload = readerEvt => {
|
||||
const binaryString = readerEvt.target.result;
|
||||
|
||||
resolve(binaryString.split('base64,')[1]);
|
||||
@ -45,16 +48,23 @@ export function createAssetProxy(value, fileObj, uploaded = false, privateUpload
|
||||
const state = store.getState();
|
||||
const integration = selectIntegration(state, null, 'assetStore');
|
||||
if (integration && !uploaded) {
|
||||
const provider = integration && getIntegrationProvider(state.integrations, currentBackend(state.config).getToken, integration);
|
||||
return provider.upload(fileObj, privateUpload).then(
|
||||
response => (
|
||||
new AssetProxy(response.asset.url.replace(/^(https?):/, ''), null, true, response.asset)
|
||||
),
|
||||
() => new AssetProxy(value, fileObj, false)
|
||||
);
|
||||
const provider =
|
||||
integration &&
|
||||
getIntegrationProvider(
|
||||
state.integrations,
|
||||
currentBackend(state.config).getToken,
|
||||
integration,
|
||||
);
|
||||
return provider
|
||||
.upload(fileObj, privateUpload)
|
||||
.then(
|
||||
response =>
|
||||
new AssetProxy(response.asset.url.replace(/^(https?):/, ''), null, true, response.asset),
|
||||
() => new AssetProxy(value, fileObj, false),
|
||||
);
|
||||
} else if (privateUpload) {
|
||||
throw new Error('The Private Upload option is only avaible for Asset Store Integration');
|
||||
}
|
||||
|
||||
|
||||
return Promise.resolve(new AssetProxy(value, fileObj, uploaded));
|
||||
}
|
||||
|
@ -9,24 +9,31 @@ const EditorComponent = Record({
|
||||
icon: 'exclamation-triangle',
|
||||
fields: [],
|
||||
pattern: catchesNothing,
|
||||
fromBlock(match) { return {}; },
|
||||
toBlock(attributes) { return 'Plugin'; },
|
||||
toPreview(attributes) { return 'Plugin'; },
|
||||
fromBlock(match) {
|
||||
return {};
|
||||
},
|
||||
toBlock(attributes) {
|
||||
return 'Plugin';
|
||||
},
|
||||
toPreview(attributes) {
|
||||
return 'Plugin';
|
||||
},
|
||||
});
|
||||
/* eslint-enable */
|
||||
|
||||
export default function createEditorComponent(config) {
|
||||
const configObj = new EditorComponent({
|
||||
id: config.id || config.label.replace(/[^A-Z0-9]+/ig, '_'),
|
||||
id: config.id || config.label.replace(/[^A-Z0-9]+/gi, '_'),
|
||||
label: config.label,
|
||||
icon: config.icon,
|
||||
fields: fromJS(config.fields),
|
||||
pattern: config.pattern,
|
||||
fromBlock: isFunction(config.fromBlock) ? config.fromBlock.bind(null) : null,
|
||||
toBlock: isFunction(config.toBlock) ? config.toBlock.bind(null) : null,
|
||||
toPreview: isFunction(config.toPreview) ? config.toPreview.bind(null) : config.toBlock.bind(null),
|
||||
toPreview: isFunction(config.toPreview)
|
||||
? config.toPreview.bind(null)
|
||||
: config.toBlock.bind(null),
|
||||
});
|
||||
|
||||
|
||||
return configObj;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { isBoolean } from "lodash";
|
||||
import { isBoolean } from 'lodash';
|
||||
|
||||
export function createEntry(collection, slug = '', path = '', options = {}) {
|
||||
const returnObj = {};
|
||||
@ -10,8 +10,6 @@ export function createEntry(collection, slug = '', path = '', options = {}) {
|
||||
returnObj.data = options.data || {};
|
||||
returnObj.label = options.label || null;
|
||||
returnObj.metaData = options.metaData || null;
|
||||
returnObj.isModification = isBoolean(options.isModification)
|
||||
? options.isModification
|
||||
: null;
|
||||
returnObj.isModification = isBoolean(options.isModification) ? options.isModification : null;
|
||||
return returnObj;
|
||||
}
|
||||
|
Reference in New Issue
Block a user