@evfrenkel/decap-cms-core 3.13.0-image-conversions.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/20.decap-cms-core.js +2 -0
- package/dist/20.decap-cms-core.js.map +1 -0
- package/dist/3802306e7b58a11862fb.wasm +0 -0
- package/dist/@evfrenkel/20.decap-cms-core.js +2 -0
- package/dist/@evfrenkel/20.decap-cms-core.js.map +1 -0
- package/dist/@evfrenkel/decap-cms-core.js +44 -0
- package/dist/@evfrenkel/decap-cms-core.js.LICENSE.txt +126 -0
- package/dist/@evfrenkel/decap-cms-core.js.map +1 -0
- package/dist/decap-cms-core.js +47 -0
- package/dist/decap-cms-core.js.LICENSE.txt +126 -0
- package/dist/decap-cms-core.js.map +1 -0
- package/dist/esm/actions/auth.js +97 -0
- package/dist/esm/actions/collections.js +15 -0
- package/dist/esm/actions/config.js +503 -0
- package/dist/esm/actions/deploys.js +80 -0
- package/dist/esm/actions/editorialWorkflow.js +480 -0
- package/dist/esm/actions/entries.js +876 -0
- package/dist/esm/actions/media.js +147 -0
- package/dist/esm/actions/mediaLibrary.js +599 -0
- package/dist/esm/actions/notifications.js +21 -0
- package/dist/esm/actions/search.js +149 -0
- package/dist/esm/actions/status.js +74 -0
- package/dist/esm/actions/waitUntil.js +32 -0
- package/dist/esm/backend.js +1090 -0
- package/dist/esm/bootstrap.js +101 -0
- package/dist/esm/components/App/App.js +296 -0
- package/dist/esm/components/App/Header.js +172 -0
- package/dist/esm/components/App/NotFoundPage.js +19 -0
- package/dist/esm/components/Collection/Collection.js +198 -0
- package/dist/esm/components/Collection/CollectionControls.js +47 -0
- package/dist/esm/components/Collection/CollectionSearch.js +222 -0
- package/dist/esm/components/Collection/CollectionTop.js +68 -0
- package/dist/esm/components/Collection/ControlButton.js +17 -0
- package/dist/esm/components/Collection/Entries/Entries.js +73 -0
- package/dist/esm/components/Collection/Entries/EntriesCollection.js +241 -0
- package/dist/esm/components/Collection/Entries/EntriesSearch.js +113 -0
- package/dist/esm/components/Collection/Entries/EntryCard.js +192 -0
- package/dist/esm/components/Collection/Entries/EntryListing.js +143 -0
- package/dist/esm/components/Collection/FilterControl.js +33 -0
- package/dist/esm/components/Collection/GroupControl.js +33 -0
- package/dist/esm/components/Collection/NestedCollection.js +308 -0
- package/dist/esm/components/Collection/Sidebar.js +91 -0
- package/dist/esm/components/Collection/SortControl.js +59 -0
- package/dist/esm/components/Collection/ViewStyleControl.js +41 -0
- package/dist/esm/components/Editor/Editor.js +466 -0
- package/dist/esm/components/Editor/EditorControlPane/EditorControl.js +398 -0
- package/dist/esm/components/Editor/EditorControlPane/EditorControlPane.js +254 -0
- package/dist/esm/components/Editor/EditorControlPane/Widget.js +374 -0
- package/dist/esm/components/Editor/EditorInterface.js +386 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreview.js +47 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewContent.js +67 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewPane.js +306 -0
- package/dist/esm/components/Editor/EditorPreviewPane/PreviewHOC.js +27 -0
- package/dist/esm/components/Editor/EditorToolbar.js +554 -0
- package/dist/esm/components/Editor/withWorkflow.js +56 -0
- package/dist/esm/components/EditorWidgets/Unknown/UnknownControl.js +18 -0
- package/dist/esm/components/EditorWidgets/Unknown/UnknownPreview.js +20 -0
- package/dist/esm/components/EditorWidgets/index.js +4 -0
- package/dist/esm/components/MediaLibrary/EmptyMessage.js +22 -0
- package/dist/esm/components/MediaLibrary/MediaLibrary.js +446 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryButtons.js +92 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryCard.js +99 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryCardGrid.js +198 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryHeader.js +34 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryModal.js +156 -0
- package/dist/esm/components/MediaLibrary/MediaLibrarySearch.js +51 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryTop.js +124 -0
- package/dist/esm/components/UI/DragDrop.js +67 -0
- package/dist/esm/components/UI/ErrorBoundary.js +170 -0
- package/dist/esm/components/UI/FileUploadButton.js +27 -0
- package/dist/esm/components/UI/Modal.js +104 -0
- package/dist/esm/components/UI/Notifications.js +62 -0
- package/dist/esm/components/UI/SettingsDropdown.js +107 -0
- package/dist/esm/components/UI/index.js +6 -0
- package/dist/esm/components/Workflow/Workflow.js +133 -0
- package/dist/esm/components/Workflow/WorkflowCard.js +128 -0
- package/dist/esm/components/Workflow/WorkflowList.js +204 -0
- package/dist/esm/constants/collectionTypes.js +2 -0
- package/dist/esm/constants/collectionViews.js +2 -0
- package/dist/esm/constants/commitProps.js +2 -0
- package/dist/esm/constants/configSchema.js +695 -0
- package/dist/esm/constants/fieldInference.js +57 -0
- package/dist/esm/constants/publishModes.js +18 -0
- package/dist/esm/constants/validationErrorTypes.js +6 -0
- package/dist/esm/formats/formats.js +83 -0
- package/dist/esm/formats/frontmatter.js +146 -0
- package/dist/esm/formats/helpers.js +12 -0
- package/dist/esm/formats/json.js +8 -0
- package/dist/esm/formats/toml.js +32 -0
- package/dist/esm/formats/yaml.js +60 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/integrations/index.js +28 -0
- package/dist/esm/integrations/providers/algolia/implementation.js +174 -0
- package/dist/esm/integrations/providers/assetStore/implementation.js +165 -0
- package/dist/esm/lib/consoleError.js +3 -0
- package/dist/esm/lib/formatters.js +201 -0
- package/dist/esm/lib/i18n.js +372 -0
- package/dist/esm/lib/imageTransformations.js +143 -0
- package/dist/esm/lib/phrases.js +6 -0
- package/dist/esm/lib/polyfill.js +8 -0
- package/dist/esm/lib/registry.js +332 -0
- package/dist/esm/lib/serializeEntryValues.js +67 -0
- package/dist/esm/lib/stega.js +142 -0
- package/dist/esm/lib/textHelper.js +9 -0
- package/dist/esm/lib/urlHelper.js +129 -0
- package/dist/esm/mediaLibrary.js +37 -0
- package/dist/esm/reducers/auth.js +27 -0
- package/dist/esm/reducers/collections.js +428 -0
- package/dist/esm/reducers/combinedReducer.js +8 -0
- package/dist/esm/reducers/config.js +29 -0
- package/dist/esm/reducers/cursors.js +31 -0
- package/dist/esm/reducers/deploys.js +50 -0
- package/dist/esm/reducers/editorialWorkflow.js +83 -0
- package/dist/esm/reducers/entries.js +568 -0
- package/dist/esm/reducers/entryDraft.js +211 -0
- package/dist/esm/reducers/globalUI.js +25 -0
- package/dist/esm/reducers/index.js +66 -0
- package/dist/esm/reducers/integrations.js +53 -0
- package/dist/esm/reducers/mediaLibrary.js +252 -0
- package/dist/esm/reducers/medias.js +68 -0
- package/dist/esm/reducers/notifications.js +23 -0
- package/dist/esm/reducers/search.js +92 -0
- package/dist/esm/reducers/status.js +30 -0
- package/dist/esm/redux/index.js +7 -0
- package/dist/esm/redux/middleware/waitUntilAction.js +48 -0
- package/dist/esm/routing/history.js +12 -0
- package/dist/esm/types/diacritics.d.js +0 -0
- package/dist/esm/types/global.d.js +1 -0
- package/dist/esm/types/immutable.js +7 -0
- package/dist/esm/types/redux.js +14 -0
- package/dist/esm/types/tomlify-j0.4.d.js +0 -0
- package/dist/esm/valueObjects/AssetProxy.js +44 -0
- package/dist/esm/valueObjects/EditorComponent.js +34 -0
- package/dist/esm/valueObjects/Entry.js +20 -0
- package/index.d.ts +662 -0
- package/package.json +100 -0
- package/src/__tests__/backend.spec.js +1223 -0
- package/src/actions/__tests__/config.spec.js +1023 -0
- package/src/actions/__tests__/editorialWorkflow.spec.js +216 -0
- package/src/actions/__tests__/entries.spec.js +610 -0
- package/src/actions/__tests__/media.spec.ts +171 -0
- package/src/actions/__tests__/mediaLibrary.spec.js +462 -0
- package/src/actions/__tests__/search.spec.js +209 -0
- package/src/actions/auth.ts +127 -0
- package/src/actions/collections.ts +18 -0
- package/src/actions/config.ts +574 -0
- package/src/actions/deploys.ts +105 -0
- package/src/actions/editorialWorkflow.ts +567 -0
- package/src/actions/entries.ts +1070 -0
- package/src/actions/media.ts +139 -0
- package/src/actions/mediaLibrary.ts +639 -0
- package/src/actions/notifications.ts +36 -0
- package/src/actions/search.ts +221 -0
- package/src/actions/status.ts +99 -0
- package/src/actions/waitUntil.ts +49 -0
- package/src/backend.ts +1411 -0
- package/src/bootstrap.js +104 -0
- package/src/components/App/App.js +295 -0
- package/src/components/App/Header.js +291 -0
- package/src/components/App/NotFoundPage.js +23 -0
- package/src/components/Collection/Collection.js +210 -0
- package/src/components/Collection/CollectionControls.js +58 -0
- package/src/components/Collection/CollectionSearch.js +243 -0
- package/src/components/Collection/CollectionTop.js +81 -0
- package/src/components/Collection/ControlButton.js +27 -0
- package/src/components/Collection/Entries/Entries.js +82 -0
- package/src/components/Collection/Entries/EntriesCollection.js +277 -0
- package/src/components/Collection/Entries/EntriesSearch.js +102 -0
- package/src/components/Collection/Entries/EntryCard.js +256 -0
- package/src/components/Collection/Entries/EntryListing.js +151 -0
- package/src/components/Collection/Entries/__tests__/EntriesCollection.spec.js +163 -0
- package/src/components/Collection/Entries/__tests__/__snapshots__/EntriesCollection.spec.js.snap +46 -0
- package/src/components/Collection/FilterControl.js +39 -0
- package/src/components/Collection/GroupControl.js +39 -0
- package/src/components/Collection/NestedCollection.js +330 -0
- package/src/components/Collection/Sidebar.js +136 -0
- package/src/components/Collection/SortControl.js +68 -0
- package/src/components/Collection/ViewStyleControl.js +52 -0
- package/src/components/Collection/__tests__/Collection.spec.js +75 -0
- package/src/components/Collection/__tests__/NestedCollection.spec.js +445 -0
- package/src/components/Collection/__tests__/Sidebar.spec.js +87 -0
- package/src/components/Collection/__tests__/__snapshots__/Collection.spec.js.snap +144 -0
- package/src/components/Collection/__tests__/__snapshots__/NestedCollection.spec.js.snap +550 -0
- package/src/components/Collection/__tests__/__snapshots__/Sidebar.spec.js.snap +312 -0
- package/src/components/Editor/Editor.js +497 -0
- package/src/components/Editor/EditorControlPane/EditorControl.js +453 -0
- package/src/components/Editor/EditorControlPane/EditorControlPane.js +269 -0
- package/src/components/Editor/EditorControlPane/Widget.js +384 -0
- package/src/components/Editor/EditorInterface.js +444 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreview.js +40 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewContent.js +75 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js +337 -0
- package/src/components/Editor/EditorPreviewPane/PreviewHOC.js +33 -0
- package/src/components/Editor/EditorToolbar.js +728 -0
- package/src/components/Editor/__tests__/Editor.spec.js +221 -0
- package/src/components/Editor/__tests__/EditorToolbar.spec.js +166 -0
- package/src/components/Editor/__tests__/__snapshots__/Editor.spec.js.snap +45 -0
- package/src/components/Editor/__tests__/__snapshots__/EditorToolbar.spec.js.snap +4265 -0
- package/src/components/Editor/withWorkflow.js +61 -0
- package/src/components/EditorWidgets/Unknown/UnknownControl.js +17 -0
- package/src/components/EditorWidgets/Unknown/UnknownPreview.js +19 -0
- package/src/components/EditorWidgets/index.js +5 -0
- package/src/components/MediaLibrary/EmptyMessage.js +28 -0
- package/src/components/MediaLibrary/MediaLibrary.js +411 -0
- package/src/components/MediaLibrary/MediaLibraryButtons.js +135 -0
- package/src/components/MediaLibrary/MediaLibraryCard.js +128 -0
- package/src/components/MediaLibrary/MediaLibraryCardGrid.js +199 -0
- package/src/components/MediaLibrary/MediaLibraryHeader.js +48 -0
- package/src/components/MediaLibrary/MediaLibraryModal.js +200 -0
- package/src/components/MediaLibrary/MediaLibrarySearch.js +61 -0
- package/src/components/MediaLibrary/MediaLibraryTop.js +144 -0
- package/src/components/MediaLibrary/__tests__/MediaLibraryButtons.spec.js +45 -0
- package/src/components/MediaLibrary/__tests__/MediaLibraryCard.spec.js +49 -0
- package/src/components/MediaLibrary/__tests__/__snapshots__/MediaLibraryCard.spec.js.snap +264 -0
- package/src/components/UI/DragDrop.js +66 -0
- package/src/components/UI/ErrorBoundary.js +213 -0
- package/src/components/UI/FileUploadButton.js +24 -0
- package/src/components/UI/Modal.js +112 -0
- package/src/components/UI/Notifications.tsx +83 -0
- package/src/components/UI/SettingsDropdown.js +130 -0
- package/src/components/UI/__tests__/ErrorBoundary.spec.js +57 -0
- package/src/components/UI/index.js +6 -0
- package/src/components/Workflow/Workflow.js +169 -0
- package/src/components/Workflow/WorkflowCard.js +177 -0
- package/src/components/Workflow/WorkflowList.js +272 -0
- package/src/constants/__tests__/configSchema.spec.js +644 -0
- package/src/constants/collectionTypes.ts +2 -0
- package/src/constants/collectionViews.js +2 -0
- package/src/constants/commitProps.ts +2 -0
- package/src/constants/configSchema.js +489 -0
- package/src/constants/fieldInference.tsx +78 -0
- package/src/constants/publishModes.ts +22 -0
- package/src/constants/validationErrorTypes.js +6 -0
- package/src/formats/__tests__/formats.spec.js +87 -0
- package/src/formats/__tests__/frontmatter.spec.js +450 -0
- package/src/formats/__tests__/toml.spec.js +9 -0
- package/src/formats/__tests__/yaml.spec.js +189 -0
- package/src/formats/formats.ts +97 -0
- package/src/formats/frontmatter.ts +150 -0
- package/src/formats/helpers.ts +14 -0
- package/src/formats/json.ts +9 -0
- package/src/formats/toml.ts +33 -0
- package/src/formats/yaml.ts +73 -0
- package/src/index.js +8 -0
- package/src/integrations/index.js +35 -0
- package/src/integrations/providers/algolia/implementation.js +176 -0
- package/src/integrations/providers/assetStore/implementation.js +148 -0
- package/src/lib/__tests__/formatters.spec.js +844 -0
- package/src/lib/__tests__/i18n.spec.js +792 -0
- package/src/lib/__tests__/imageTransformations.spec.ts +97 -0
- package/src/lib/__tests__/phrases.spec.js +119 -0
- package/src/lib/__tests__/registry.spec.js +261 -0
- package/src/lib/__tests__/serializeEntryValues.spec.js +22 -0
- package/src/lib/__tests__/urlHelper.spec.js +145 -0
- package/src/lib/consoleError.js +7 -0
- package/src/lib/formatters.ts +297 -0
- package/src/lib/i18n.ts +462 -0
- package/src/lib/imageTransformations.ts +212 -0
- package/src/lib/phrases.js +8 -0
- package/src/lib/polyfill.js +9 -0
- package/src/lib/registry.js +315 -0
- package/src/lib/serializeEntryValues.js +75 -0
- package/src/lib/stega.ts +145 -0
- package/src/lib/textHelper.js +11 -0
- package/src/lib/urlHelper.ts +152 -0
- package/src/mediaLibrary.ts +51 -0
- package/src/reducers/__tests__/auth.spec.ts +38 -0
- package/src/reducers/__tests__/collections.spec.js +610 -0
- package/src/reducers/__tests__/config.spec.js +38 -0
- package/src/reducers/__tests__/deploys.spec.ts +111 -0
- package/src/reducers/__tests__/entries.spec.js +694 -0
- package/src/reducers/__tests__/entryDraft.spec.js +315 -0
- package/src/reducers/__tests__/globalUI.js +43 -0
- package/src/reducers/__tests__/integrations.spec.ts +76 -0
- package/src/reducers/__tests__/mediaLibrary.spec.js +154 -0
- package/src/reducers/__tests__/medias.spec.ts +49 -0
- package/src/reducers/auth.ts +46 -0
- package/src/reducers/collections.ts +535 -0
- package/src/reducers/combinedReducer.ts +11 -0
- package/src/reducers/config.ts +38 -0
- package/src/reducers/cursors.js +36 -0
- package/src/reducers/deploys.ts +54 -0
- package/src/reducers/editorialWorkflow.ts +163 -0
- package/src/reducers/entries.ts +819 -0
- package/src/reducers/entryDraft.js +259 -0
- package/src/reducers/globalUI.ts +45 -0
- package/src/reducers/index.ts +82 -0
- package/src/reducers/integrations.ts +59 -0
- package/src/reducers/mediaLibrary.ts +296 -0
- package/src/reducers/medias.ts +66 -0
- package/src/reducers/notifications.ts +52 -0
- package/src/reducers/search.ts +111 -0
- package/src/reducers/status.ts +40 -0
- package/src/redux/index.ts +18 -0
- package/src/redux/middleware/waitUntilAction.ts +64 -0
- package/src/routing/__tests__/history.spec.ts +49 -0
- package/src/routing/history.ts +17 -0
- package/src/types/diacritics.d.ts +1 -0
- package/src/types/global.d.ts +8 -0
- package/src/types/immutable.ts +49 -0
- package/src/types/redux.ts +875 -0
- package/src/types/tomlify-j0.4.d.ts +13 -0
- package/src/valueObjects/AssetProxy.ts +48 -0
- package/src/valueObjects/EditorComponent.js +38 -0
- package/src/valueObjects/Entry.ts +63 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import pickBy from 'lodash/pickBy';
|
|
2
|
+
import trimEnd from 'lodash/trimEnd';
|
|
3
|
+
import { unsentRequest } from 'decap-cms-lib-util';
|
|
4
|
+
import { addParams } from '../../../lib/urlHelper';
|
|
5
|
+
const {
|
|
6
|
+
fetchWithTimeout: fetch
|
|
7
|
+
} = unsentRequest;
|
|
8
|
+
export default class AssetStore {
|
|
9
|
+
constructor(config, getToken) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
if (config.get('getSignedFormURL') == null) {
|
|
12
|
+
throw 'The AssetStore integration needs the getSignedFormURL in the integration configuration.';
|
|
13
|
+
}
|
|
14
|
+
this.getToken = getToken;
|
|
15
|
+
this.shouldConfirmUpload = config.get('shouldConfirmUpload', false);
|
|
16
|
+
this.getSignedFormURL = trimEnd(config.get('getSignedFormURL'), '/');
|
|
17
|
+
}
|
|
18
|
+
parseJsonResponse(response) {
|
|
19
|
+
return response.json().then(json => {
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
return Promise.reject(json);
|
|
22
|
+
}
|
|
23
|
+
return json;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
urlFor(path, options) {
|
|
27
|
+
const params = [];
|
|
28
|
+
if (options.params) {
|
|
29
|
+
for (const key in options.params) {
|
|
30
|
+
params.push(`${key}=${encodeURIComponent(options.params[key])}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (params.length) {
|
|
34
|
+
path += `?${params.join('&')}`;
|
|
35
|
+
}
|
|
36
|
+
return path;
|
|
37
|
+
}
|
|
38
|
+
requestHeaders(headers = {}) {
|
|
39
|
+
return {
|
|
40
|
+
...headers
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
confirmRequest(assetID) {
|
|
44
|
+
this.getToken().then(token => this.request(`${this.getSignedFormURL}/${assetID}`, {
|
|
45
|
+
method: 'PUT',
|
|
46
|
+
headers: {
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
Authorization: `Bearer ${token}`
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
state: 'uploaded'
|
|
52
|
+
})
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
async request(path, options = {}) {
|
|
56
|
+
const headers = this.requestHeaders(options.headers || {});
|
|
57
|
+
const url = this.urlFor(path, options);
|
|
58
|
+
const response = await fetch(url, {
|
|
59
|
+
...options,
|
|
60
|
+
headers
|
|
61
|
+
});
|
|
62
|
+
const contentType = response.headers.get('Content-Type');
|
|
63
|
+
const isJson = contentType && contentType.match(/json/);
|
|
64
|
+
const content = isJson ? await this.parseJsonResponse(response) : response.text();
|
|
65
|
+
return content;
|
|
66
|
+
}
|
|
67
|
+
async retrieve(query, page, privateUpload) {
|
|
68
|
+
const params = pickBy({
|
|
69
|
+
search: query,
|
|
70
|
+
page,
|
|
71
|
+
filter: privateUpload ? 'private' : 'public'
|
|
72
|
+
}, val => !!val);
|
|
73
|
+
const url = addParams(this.getSignedFormURL, params);
|
|
74
|
+
const token = await this.getToken();
|
|
75
|
+
const headers = {
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
Authorization: `Bearer ${token}`
|
|
78
|
+
};
|
|
79
|
+
const response = await this.request(url, {
|
|
80
|
+
headers
|
|
81
|
+
});
|
|
82
|
+
const files = response.map(({
|
|
83
|
+
id,
|
|
84
|
+
name,
|
|
85
|
+
size,
|
|
86
|
+
url
|
|
87
|
+
}) => {
|
|
88
|
+
return {
|
|
89
|
+
id,
|
|
90
|
+
name,
|
|
91
|
+
size,
|
|
92
|
+
displayURL: url,
|
|
93
|
+
url,
|
|
94
|
+
path: url
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return files;
|
|
98
|
+
}
|
|
99
|
+
delete(assetID) {
|
|
100
|
+
const url = `${this.getSignedFormURL}/${assetID}`;
|
|
101
|
+
return this.getToken().then(token => this.request(url, {
|
|
102
|
+
method: 'DELETE',
|
|
103
|
+
headers: {
|
|
104
|
+
'Content-Type': 'application/json',
|
|
105
|
+
Authorization: `Bearer ${token}`
|
|
106
|
+
}
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
async upload(file, privateUpload = false) {
|
|
110
|
+
const fileData = {
|
|
111
|
+
name: file.name,
|
|
112
|
+
size: file.size
|
|
113
|
+
};
|
|
114
|
+
if (file.type) {
|
|
115
|
+
fileData.content_type = file.type;
|
|
116
|
+
}
|
|
117
|
+
if (privateUpload) {
|
|
118
|
+
fileData.visibility = 'private';
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const token = await this.getToken();
|
|
122
|
+
const response = await this.request(this.getSignedFormURL, {
|
|
123
|
+
method: 'POST',
|
|
124
|
+
headers: {
|
|
125
|
+
'Content-Type': 'application/json',
|
|
126
|
+
Authorization: `Bearer ${token}`
|
|
127
|
+
},
|
|
128
|
+
body: JSON.stringify(fileData)
|
|
129
|
+
});
|
|
130
|
+
const formURL = response.form.url;
|
|
131
|
+
const formFields = response.form.fields;
|
|
132
|
+
const {
|
|
133
|
+
id,
|
|
134
|
+
name,
|
|
135
|
+
size,
|
|
136
|
+
url
|
|
137
|
+
} = response.asset;
|
|
138
|
+
const formData = new FormData();
|
|
139
|
+
Object.keys(formFields).forEach(key => formData.append(key, formFields[key]));
|
|
140
|
+
formData.append('file', file, file.name);
|
|
141
|
+
await this.request(formURL, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
body: formData
|
|
144
|
+
});
|
|
145
|
+
if (this.shouldConfirmUpload) {
|
|
146
|
+
await this.confirmRequest(id);
|
|
147
|
+
}
|
|
148
|
+
const asset = {
|
|
149
|
+
id,
|
|
150
|
+
name,
|
|
151
|
+
size,
|
|
152
|
+
displayURL: url,
|
|
153
|
+
url,
|
|
154
|
+
path: url
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
success: true,
|
|
158
|
+
asset
|
|
159
|
+
};
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error(error);
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import flow from 'lodash/flow';
|
|
2
|
+
import partialRight from 'lodash/partialRight';
|
|
3
|
+
import trimEnd from 'lodash/trimEnd';
|
|
4
|
+
import trimStart from 'lodash/trimStart';
|
|
5
|
+
import { stringTemplate } from 'decap-cms-lib-widgets';
|
|
6
|
+
import { stripIndent } from 'common-tags';
|
|
7
|
+
import { selectIdentifier, selectField, selectInferredField, getFileFromSlug } from '../reducers/collections';
|
|
8
|
+
import { sanitizeSlug } from './urlHelper';
|
|
9
|
+
import { FILES } from '../constants/collectionTypes';
|
|
10
|
+
import { COMMIT_AUTHOR, COMMIT_DATE } from '../constants/commitProps';
|
|
11
|
+
const {
|
|
12
|
+
compileStringTemplate,
|
|
13
|
+
parseDateFromEntry,
|
|
14
|
+
parseDateFromEntryData,
|
|
15
|
+
SLUG_MISSING_REQUIRED_DATE,
|
|
16
|
+
keyToPathArray,
|
|
17
|
+
addFileTemplateFields
|
|
18
|
+
} = stringTemplate;
|
|
19
|
+
const commitMessageTemplates = {
|
|
20
|
+
create: 'Create {{collection}} “{{slug}}”',
|
|
21
|
+
update: 'Update {{collection}} “{{slug}}”',
|
|
22
|
+
delete: 'Delete {{collection}} “{{slug}}”',
|
|
23
|
+
uploadMedia: 'Upload “{{path}}”',
|
|
24
|
+
deleteMedia: 'Delete “{{path}}”',
|
|
25
|
+
openAuthoring: '{{message}}'
|
|
26
|
+
};
|
|
27
|
+
const variableRegex = /\{\{([^}]+)\}\}/g;
|
|
28
|
+
export function commitMessageFormatter(type, config, {
|
|
29
|
+
slug,
|
|
30
|
+
path,
|
|
31
|
+
collection,
|
|
32
|
+
authorLogin,
|
|
33
|
+
authorName,
|
|
34
|
+
authorEmail
|
|
35
|
+
}, isOpenAuthoring) {
|
|
36
|
+
const templates = {
|
|
37
|
+
...commitMessageTemplates,
|
|
38
|
+
...(config.backend.commit_messages || {})
|
|
39
|
+
};
|
|
40
|
+
let trailers = '';
|
|
41
|
+
if (config.backend.signoff_commits) {
|
|
42
|
+
if (!authorName) {
|
|
43
|
+
console.warn('Option signoff_commits is enabled, but author name is unknown');
|
|
44
|
+
} else if (!authorEmail) {
|
|
45
|
+
console.warn('Option signoff_commits is enabled, but author email is unknown');
|
|
46
|
+
} else {
|
|
47
|
+
trailers = `\n\nSigned-off-by: ${authorName} <${authorEmail}>\n`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const commitMessage = templates[type].replace(variableRegex, (_, variable) => {
|
|
51
|
+
switch (variable) {
|
|
52
|
+
case 'slug':
|
|
53
|
+
return slug || '';
|
|
54
|
+
case 'path':
|
|
55
|
+
return path || '';
|
|
56
|
+
case 'collection':
|
|
57
|
+
return collection ? collection.get('label_singular') || collection.get('label') : '';
|
|
58
|
+
case 'author-login':
|
|
59
|
+
return authorLogin || '';
|
|
60
|
+
case 'author-name':
|
|
61
|
+
return authorName || '';
|
|
62
|
+
default:
|
|
63
|
+
console.warn(`Ignoring unknown variable “${variable}” in commit message template.`);
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
if (!isOpenAuthoring) {
|
|
68
|
+
return commitMessage + trailers;
|
|
69
|
+
}
|
|
70
|
+
const message = templates.openAuthoring.replace(variableRegex, (_, variable) => {
|
|
71
|
+
switch (variable) {
|
|
72
|
+
case 'message':
|
|
73
|
+
return commitMessage;
|
|
74
|
+
case 'author-login':
|
|
75
|
+
return authorLogin || '';
|
|
76
|
+
case 'author-name':
|
|
77
|
+
return authorName || '';
|
|
78
|
+
default:
|
|
79
|
+
console.warn(`Ignoring unknown variable “${variable}” in open authoring message template.`);
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return message + trailers;
|
|
84
|
+
}
|
|
85
|
+
export function prepareSlug(slug) {
|
|
86
|
+
return slug.trim()
|
|
87
|
+
// Convert slug to lower-case
|
|
88
|
+
.toLocaleLowerCase()
|
|
89
|
+
|
|
90
|
+
// Remove single quotes.
|
|
91
|
+
.replace(/[']/g, '')
|
|
92
|
+
|
|
93
|
+
// Replace periods with dashes.
|
|
94
|
+
.replace(/[.]/g, '-');
|
|
95
|
+
}
|
|
96
|
+
export function getProcessSegment(slugConfig, ignoreValues, preserveSlashes) {
|
|
97
|
+
return value => ignoreValues && ignoreValues.includes(value) ? value : flow([value => String(value), prepareSlug, partialRight(sanitizeSlug, slugConfig, preserveSlashes)])(value);
|
|
98
|
+
}
|
|
99
|
+
export function slugFormatter(collection, entryData, slugConfig) {
|
|
100
|
+
const slugTemplate = collection.get('slug') || '{{slug}}';
|
|
101
|
+
const identifier = entryData.getIn(keyToPathArray(selectIdentifier(collection)));
|
|
102
|
+
if (!identifier) {
|
|
103
|
+
throw new Error('Collection must have a field name that is a valid entry identifier, or must have `identifier_field` set');
|
|
104
|
+
}
|
|
105
|
+
const processSegment = getProcessSegment(slugConfig);
|
|
106
|
+
const date = parseDateFromEntryData(entryData, selectInferredField(collection, 'date')) || new Date(Date.now());
|
|
107
|
+
const slug = compileStringTemplate(slugTemplate, date, identifier, entryData, processSegment);
|
|
108
|
+
if (!collection.has('path')) {
|
|
109
|
+
return slug;
|
|
110
|
+
} else {
|
|
111
|
+
const pathTemplate = prepareSlug(collection.get('path'));
|
|
112
|
+
return compileStringTemplate(pathTemplate, date, slug, entryData, value => value === slug ? value : processSegment(value));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
|
116
|
+
/**
|
|
117
|
+
* Preview URL can't be created without `baseUrl`. This makes preview URLs
|
|
118
|
+
* optional for backends that don't support them.
|
|
119
|
+
*/
|
|
120
|
+
if (!baseUrl) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const basePath = trimEnd(baseUrl, '/');
|
|
124
|
+
const isFileCollection = collection.get('type') === FILES;
|
|
125
|
+
const file = isFileCollection ? getFileFromSlug(collection, entry.get('slug')) : undefined;
|
|
126
|
+
function getPathTemplate() {
|
|
127
|
+
return file?.get('preview_path') ?? collection.get('preview_path');
|
|
128
|
+
}
|
|
129
|
+
function getDateField() {
|
|
130
|
+
return file?.get('preview_path_date_field') ?? collection.get('preview_path_date_field');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* If a `previewPath` is provided for the collection/file, use it to construct the
|
|
135
|
+
* URL path.
|
|
136
|
+
*/
|
|
137
|
+
const pathTemplate = getPathTemplate();
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Without a `previewPath` for the collection/file (via config), the preview URL
|
|
141
|
+
* will be the URL provided by the backend.
|
|
142
|
+
*/
|
|
143
|
+
if (!pathTemplate) {
|
|
144
|
+
return baseUrl;
|
|
145
|
+
}
|
|
146
|
+
let fields = entry.get('data');
|
|
147
|
+
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
|
148
|
+
const dateFieldName = getDateField() || selectInferredField(collection, 'date');
|
|
149
|
+
const date = parseDateFromEntry(entry, dateFieldName);
|
|
150
|
+
const previewPathPreserveSlashes = collection.get('preview_path_preserve_slashes');
|
|
151
|
+
const preserveSlashes = !!(previewPathPreserveSlashes ?? collection.has('nested'));
|
|
152
|
+
|
|
153
|
+
// Prepare and sanitize slug variables only, leave the rest of the
|
|
154
|
+
// `preview_path` template as is.
|
|
155
|
+
const processSegment = getProcessSegment(slugConfig, [fields.get('dirname')], preserveSlashes);
|
|
156
|
+
let compiledPath;
|
|
157
|
+
try {
|
|
158
|
+
compiledPath = compileStringTemplate(pathTemplate, date, slug, fields, processSegment);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
// Print an error and ignore `preview_path` if both:
|
|
161
|
+
// 1. Date is invalid (according to DayJs), and
|
|
162
|
+
// 2. A date expression (eg. `{{year}}`) is used in `preview_path`
|
|
163
|
+
if (err instanceof Error && err.name === SLUG_MISSING_REQUIRED_DATE) {
|
|
164
|
+
console.error(stripIndent`
|
|
165
|
+
Collection "${collection.get('name')}" configuration error:
|
|
166
|
+
\`preview_path_date_field\` must be a field with a valid date. Ignoring \`preview_path\`.
|
|
167
|
+
`);
|
|
168
|
+
return basePath;
|
|
169
|
+
}
|
|
170
|
+
throw err;
|
|
171
|
+
}
|
|
172
|
+
const previewPath = trimStart(compiledPath, ' /');
|
|
173
|
+
return `${basePath}/${previewPath}`;
|
|
174
|
+
}
|
|
175
|
+
export function summaryFormatter(summaryTemplate, entry, collection) {
|
|
176
|
+
let entryData = entry.get('data');
|
|
177
|
+
const date = parseDateFromEntry(entry, selectInferredField(collection, 'date')) || null;
|
|
178
|
+
const identifier = entryData.getIn(keyToPathArray(selectIdentifier(collection)));
|
|
179
|
+
entryData = addFileTemplateFields(entry.get('path'), entryData, collection.get('folder'));
|
|
180
|
+
// allow commit information in summary template
|
|
181
|
+
if (entry.get('author') && !selectField(collection, COMMIT_AUTHOR)) {
|
|
182
|
+
entryData = entryData.set(COMMIT_AUTHOR, entry.get('author'));
|
|
183
|
+
}
|
|
184
|
+
if (entry.get('updatedOn') && !selectField(collection, COMMIT_DATE)) {
|
|
185
|
+
entryData = entryData.set(COMMIT_DATE, entry.get('updatedOn'));
|
|
186
|
+
}
|
|
187
|
+
const summary = compileStringTemplate(summaryTemplate, date, identifier, entryData);
|
|
188
|
+
return summary;
|
|
189
|
+
}
|
|
190
|
+
export function folderFormatter(folderTemplate, entry, collection, defaultFolder, folderKey, slugConfig) {
|
|
191
|
+
if (!entry || !entry.get('data')) {
|
|
192
|
+
return folderTemplate;
|
|
193
|
+
}
|
|
194
|
+
let fields = entry.get('data').set(folderKey, defaultFolder);
|
|
195
|
+
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
|
196
|
+
const date = parseDateFromEntry(entry, selectInferredField(collection, 'date')) || null;
|
|
197
|
+
const identifier = fields.getIn(keyToPathArray(selectIdentifier(collection)));
|
|
198
|
+
const processSegment = getProcessSegment(slugConfig, [defaultFolder, fields.get('dirname')]);
|
|
199
|
+
const mediaFolder = compileStringTemplate(folderTemplate, date, identifier, fields, processSegment);
|
|
200
|
+
return mediaFolder;
|
|
201
|
+
}
|