move errors to utils lib
This commit is contained in:
parent
4931711892
commit
e491f2a085
@ -6,7 +6,7 @@ import { currentBackend } from 'Backends/backend';
|
|||||||
import { getAsset } from 'Reducers';
|
import { getAsset } from 'Reducers';
|
||||||
import { selectFields } from 'Reducers/collections';
|
import { selectFields } from 'Reducers/collections';
|
||||||
import { status, EDITORIAL_WORKFLOW } from 'Constants/publishModes';
|
import { status, EDITORIAL_WORKFLOW } from 'Constants/publishModes';
|
||||||
import { EditorialWorkflowError } from "ValueObjects/errors";
|
import EditorialWorkflowError from 'netlify-cms-lib-util/EditorialWorkflowError';
|
||||||
import { loadEntry } from './entries';
|
import { loadEntry } from './entries';
|
||||||
import ValidationErrorTypes from 'Constants/validationErrorTypes';
|
import ValidationErrorTypes from 'Constants/validationErrorTypes';
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import GithubAPI from "Backends/github/API";
|
import GithubAPI from "Backends/github/API";
|
||||||
import { APIError } from "ValueObjects/errors";
|
import APIError from "netlify-cms-lib-util/APIError";
|
||||||
|
|
||||||
export default class API extends GithubAPI {
|
export default class API extends GithubAPI {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import GithubAPI from "Backends/github/API";
|
import GithubAPI from "Backends/github/API";
|
||||||
import { APIError } from "ValueObjects/errors";
|
import APIError from "netlify-cms-lib-util/APIError";
|
||||||
|
|
||||||
export default class API extends GithubAPI {
|
export default class API extends GithubAPI {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import localForage from "netlify-cms-lib-util/localForage";
|
import localForage from "netlify-cms-lib-util/localForage";
|
||||||
import { Base64 } from "js-base64";
|
import { Base64 } from "js-base64";
|
||||||
import { uniq, initial, last, get, find, hasIn } from "lodash";
|
import { uniq, initial, last, get, find, hasIn, partial } from "lodash";
|
||||||
import { filterPromises, resolvePromiseProperties } from "netlify-cms-lib-util/promise";
|
import { filterPromises, resolvePromiseProperties } from "netlify-cms-lib-util/promise";
|
||||||
import AssetProxy from "ValueObjects/AssetProxy";
|
import AssetProxy from "ValueObjects/AssetProxy";
|
||||||
import { SIMPLE, EDITORIAL_WORKFLOW, status } from "Constants/publishModes";
|
import { SIMPLE, EDITORIAL_WORKFLOW, status } from "Constants/publishModes";
|
||||||
import { APIError, EditorialWorkflowError } from "ValueObjects/errors";
|
import { APIError, EditorialWorkflowError } from "netlify-cms-lib-util";
|
||||||
|
|
||||||
const CMS_BRANCH_PREFIX = 'cms/';
|
const CMS_BRANCH_PREFIX = 'cms/';
|
||||||
|
|
||||||
@ -713,7 +713,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadBlob(item) {
|
uploadBlob(item) {
|
||||||
const content = item instanceof AssetProxy ? item.toBase64() : this.toBase64(item.raw);
|
const content = get(item, 'toBase64', partial(this.toBase64, item.raw))();
|
||||||
|
|
||||||
return content.then(contentBase64 => this.request(`${ this.repoURL }/git/blobs`, {
|
return content.then(contentBase64 => this.request(`${ this.repoURL }/git/blobs`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import localForage from "netlify-cms-lib-util/localForage";
|
import localForage from "netlify-cms-lib-util/localForage";
|
||||||
import { Base64 } from "js-base64";
|
import { Base64 } from "js-base64";
|
||||||
import { fromJS, List, Map } from "immutable";
|
import { fromJS, List, Map } from "immutable";
|
||||||
import { cond, flow, isString, partial, partialRight, pick, omit, set, update } from "lodash";
|
import { cond, flow, isString, partial, partialRight, pick, omit, set, update, get } from "lodash";
|
||||||
import unsentRequest from "netlify-cms-lib-util/unsentRequest";
|
import unsentRequest from "netlify-cms-lib-util/unsentRequest";
|
||||||
import { then } from "netlify-cms-lib-util/promise";
|
import { then } from "netlify-cms-lib-util/promise";
|
||||||
|
import APIError from "netlify-cms-lib-util/APIError";
|
||||||
import AssetProxy from "ValueObjects/AssetProxy";
|
import AssetProxy from "ValueObjects/AssetProxy";
|
||||||
import { APIError } from "ValueObjects/errors";
|
|
||||||
import Cursor from "ValueObjects/Cursor"
|
import Cursor from "ValueObjects/Cursor"
|
||||||
|
|
||||||
export default class API {
|
export default class API {
|
||||||
@ -17,8 +17,9 @@ export default class API {
|
|||||||
this.repoURL = `/projects/${ encodeURIComponent(this.repo) }`;
|
this.repoURL = `/projects/${ encodeURIComponent(this.repo) }`;
|
||||||
}
|
}
|
||||||
|
|
||||||
withAuthorizationHeaders = req =>
|
withAuthorizationHeaders = req => (
|
||||||
unsentRequest.withHeaders(this.token ? { Authorization: `Bearer ${ this.token }` } : {}, req);
|
unsentRequest.withHeaders(this.token ? { Authorization: `Bearer ${ this.token }` } : {}, req)
|
||||||
|
);
|
||||||
|
|
||||||
buildRequest = req => flow([
|
buildRequest = req => flow([
|
||||||
unsentRequest.withRoot(this.api_root),
|
unsentRequest.withRoot(this.api_root),
|
||||||
@ -189,7 +190,7 @@ export default class API {
|
|||||||
toBase64 = str => Promise.resolve(Base64.encode(str));
|
toBase64 = str => Promise.resolve(Base64.encode(str));
|
||||||
fromBase64 = str => Base64.decode(str);
|
fromBase64 = str => Base64.decode(str);
|
||||||
uploadAndCommit = async (item, { commitMessage, updateFile = false, branch = this.branch, author = this.commitAuthor }) => {
|
uploadAndCommit = async (item, { commitMessage, updateFile = false, branch = this.branch, author = this.commitAuthor }) => {
|
||||||
const content = await (item instanceof AssetProxy ? item.toBase64() : this.toBase64(item.raw));
|
const content = get(item, 'toBase64', partial(this.toBase64, item.raw))();
|
||||||
const file_path = item.path.replace(/^\//, "");
|
const file_path = item.path.replace(/^\//, "");
|
||||||
const action = (updateFile ? "update" : "create");
|
const action = (updateFile ? "update" : "create");
|
||||||
const encoding = "base64";
|
const encoding = "base64";
|
||||||
|
@ -2,7 +2,7 @@ import { remove, attempt, isError, take } from 'lodash';
|
|||||||
import uuid from 'uuid/v4';
|
import uuid from 'uuid/v4';
|
||||||
import { fromJS } from 'immutable';
|
import { fromJS } from 'immutable';
|
||||||
import { EDITORIAL_WORKFLOW, status } from 'Constants/publishModes';
|
import { EDITORIAL_WORKFLOW, status } from 'Constants/publishModes';
|
||||||
import { EditorialWorkflowError } from 'ValueObjects/errors';
|
import EditorialWorkflowError from 'netlify-cms-lib-util/EditorialWorkflowError';
|
||||||
import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from 'ValueObjects/Cursor'
|
import Cursor, { CURSOR_COMPATIBILITY_SYMBOL } from 'ValueObjects/Cursor'
|
||||||
import AuthenticationPage from './AuthenticationPage';
|
import AuthenticationPage from './AuthenticationPage';
|
||||||
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
export { default as APIError } from './APIError';
|
|
||||||
export { default as EditorialWorkflowError } from './EditorialWorkflowError';
|
|
||||||
|
|
@ -2,6 +2,8 @@ import localForage from './localForage';
|
|||||||
import { resolvePath, basename, fileExtensionWithSeparator, fileExtension } from './path';
|
import { resolvePath, basename, fileExtensionWithSeparator, fileExtension } from './path';
|
||||||
import { filterPromises, resolvePromiseProperties, then } from './promise';
|
import { filterPromises, resolvePromiseProperties, then } from './promise';
|
||||||
import unsentRequest from './unsentRequest';
|
import unsentRequest from './unsentRequest';
|
||||||
|
import APIError from './APIError';
|
||||||
|
import EditorialWorkflowError from './EditorialWorkflowError';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
localForage,
|
localForage,
|
||||||
@ -13,4 +15,6 @@ export {
|
|||||||
resolvePromiseProperties,
|
resolvePromiseProperties,
|
||||||
then,
|
then,
|
||||||
unsentRequest,
|
unsentRequest,
|
||||||
|
APIError,
|
||||||
|
EditorialWorkflowError,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user