@pranaysahith/decap-cms-core 3.9.1
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/@pranaysahith/decap-cms-core.js +52 -0
- package/dist/@pranaysahith/decap-cms-core.js.LICENSE.txt +141 -0
- package/dist/@pranaysahith/decap-cms-core.js.map +1 -0
- package/dist/decap-cms-core.js +47 -0
- package/dist/decap-cms-core.js.LICENSE.txt +116 -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 +493 -0
- package/dist/esm/actions/deploys.js +79 -0
- package/dist/esm/actions/editorialWorkflow.js +480 -0
- package/dist/esm/actions/entries.js +865 -0
- package/dist/esm/actions/media.js +147 -0
- package/dist/esm/actions/mediaLibrary.js +552 -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 +1082 -0
- package/dist/esm/bootstrap.js +101 -0
- package/dist/esm/components/App/App.js +289 -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 +46 -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 +177 -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/FolderRenameControl.js +403 -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 +38 -0
- package/dist/esm/components/Editor/Editor.js +466 -0
- package/dist/esm/components/Editor/EditorControlPane/EditorControl.js +395 -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 +66 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewPane.js +288 -0
- package/dist/esm/components/Editor/EditorPreviewPane/PreviewHOC.js +27 -0
- package/dist/esm/components/Editor/EditorToolbar.js +536 -0
- package/dist/esm/components/Editor/EntryPathEditor.js +272 -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 +93 -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 +32 -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 +123 -0
- package/dist/esm/components/UI/DragDrop.js +67 -0
- package/dist/esm/components/UI/ErrorBoundary.js +173 -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 +644 -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 +51 -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 +191 -0
- package/dist/esm/lib/i18n.js +367 -0
- package/dist/esm/lib/phrases.js +6 -0
- package/dist/esm/lib/polyfill.js +8 -0
- package/dist/esm/lib/registry.js +329 -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 +111 -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 +45 -0
- package/dist/esm/reducers/editorialWorkflow.js +83 -0
- package/dist/esm/reducers/entries.js +568 -0
- package/dist/esm/reducers/entryDraft.js +212 -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 +618 -0
- package/package.json +106 -0
- package/src/__tests__/backend.spec.js +1161 -0
- package/src/actions/__tests__/config.spec.js +1009 -0
- package/src/actions/__tests__/editorialWorkflow.spec.js +216 -0
- package/src/actions/__tests__/entries.spec.js +596 -0
- package/src/actions/__tests__/media.spec.ts +171 -0
- package/src/actions/__tests__/mediaLibrary.spec.js +327 -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 +565 -0
- package/src/actions/deploys.ts +104 -0
- package/src/actions/editorialWorkflow.ts +567 -0
- package/src/actions/entries.ts +1055 -0
- package/src/actions/media.ts +139 -0
- package/src/actions/mediaLibrary.ts +574 -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 +1400 -0
- package/src/bootstrap.js +104 -0
- package/src/components/App/App.js +286 -0
- package/src/components/App/Header.js +266 -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 +246 -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 +50 -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 +452 -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 +74 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js +333 -0
- package/src/components/Editor/EditorPreviewPane/PreviewHOC.js +33 -0
- package/src/components/Editor/EditorToolbar.js +691 -0
- package/src/components/Editor/__tests__/Editor.spec.js +221 -0
- package/src/components/Editor/__tests__/EditorToolbar.spec.js +120 -0
- package/src/components/Editor/__tests__/__snapshots__/Editor.spec.js.snap +45 -0
- package/src/components/Editor/__tests__/__snapshots__/EditorToolbar.spec.js.snap +4233 -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 +136 -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 +143 -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 +214 -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 +103 -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 +611 -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 +441 -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 +429 -0
- package/src/formats/__tests__/toml.spec.js +9 -0
- package/src/formats/__tests__/yaml.spec.js +162 -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 +58 -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 +751 -0
- package/src/lib/__tests__/i18n.spec.js +792 -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 +138 -0
- package/src/lib/consoleError.js +7 -0
- package/src/lib/formatters.ts +286 -0
- package/src/lib/i18n.ts +454 -0
- package/src/lib/phrases.js +8 -0
- package/src/lib/polyfill.js +9 -0
- package/src/lib/registry.js +312 -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 +128 -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__/entries.spec.js +694 -0
- package/src/reducers/__tests__/entryDraft.spec.js +297 -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 +52 -0
- package/src/reducers/editorialWorkflow.ts +163 -0
- package/src/reducers/entries.ts +819 -0
- package/src/reducers/entryDraft.js +260 -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 +827 -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,191 @@
|
|
|
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
|
+
}, isOpenAuthoring) {
|
|
35
|
+
const templates = {
|
|
36
|
+
...commitMessageTemplates,
|
|
37
|
+
...(config.backend.commit_messages || {})
|
|
38
|
+
};
|
|
39
|
+
const commitMessage = templates[type].replace(variableRegex, (_, variable) => {
|
|
40
|
+
switch (variable) {
|
|
41
|
+
case 'slug':
|
|
42
|
+
return slug || '';
|
|
43
|
+
case 'path':
|
|
44
|
+
return path || '';
|
|
45
|
+
case 'collection':
|
|
46
|
+
return collection ? collection.get('label_singular') || collection.get('label') : '';
|
|
47
|
+
case 'author-login':
|
|
48
|
+
return authorLogin || '';
|
|
49
|
+
case 'author-name':
|
|
50
|
+
return authorName || '';
|
|
51
|
+
default:
|
|
52
|
+
console.warn(`Ignoring unknown variable “${variable}” in commit message template.`);
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (!isOpenAuthoring) {
|
|
57
|
+
return commitMessage;
|
|
58
|
+
}
|
|
59
|
+
const message = templates.openAuthoring.replace(variableRegex, (_, variable) => {
|
|
60
|
+
switch (variable) {
|
|
61
|
+
case 'message':
|
|
62
|
+
return commitMessage;
|
|
63
|
+
case 'author-login':
|
|
64
|
+
return authorLogin || '';
|
|
65
|
+
case 'author-name':
|
|
66
|
+
return authorName || '';
|
|
67
|
+
default:
|
|
68
|
+
console.warn(`Ignoring unknown variable “${variable}” in open authoring message template.`);
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return message;
|
|
73
|
+
}
|
|
74
|
+
export function prepareSlug(slug, preserveCase = false) {
|
|
75
|
+
let result = slug.trim();
|
|
76
|
+
|
|
77
|
+
// Convert slug to lower-case (unless preserveCase is true)
|
|
78
|
+
if (!preserveCase) {
|
|
79
|
+
result = result.toLocaleLowerCase();
|
|
80
|
+
}
|
|
81
|
+
return result
|
|
82
|
+
// Remove single quotes.
|
|
83
|
+
.replace(/[']/g, '')
|
|
84
|
+
|
|
85
|
+
// Replace periods with dashes.
|
|
86
|
+
.replace(/[.]/g, '-');
|
|
87
|
+
}
|
|
88
|
+
export function getProcessSegment(slugConfig, ignoreValues, preserveCase = false) {
|
|
89
|
+
return value => ignoreValues && ignoreValues.includes(value) ? value : flow([value => String(value), value => prepareSlug(value, preserveCase), partialRight(sanitizeSlug, slugConfig)])(value);
|
|
90
|
+
}
|
|
91
|
+
export function slugFormatter(collection, entryData, slugConfig) {
|
|
92
|
+
const slugTemplate = collection.get('slug') || '{{slug}}';
|
|
93
|
+
const identifier = entryData.getIn(keyToPathArray(selectIdentifier(collection)));
|
|
94
|
+
if (!identifier) {
|
|
95
|
+
throw new Error('Collection must have a field name that is a valid entry identifier, or must have `identifier_field` set');
|
|
96
|
+
}
|
|
97
|
+
const processSegment = getProcessSegment(slugConfig);
|
|
98
|
+
const date = parseDateFromEntryData(entryData, selectInferredField(collection, 'date')) || new Date(Date.now());
|
|
99
|
+
const slug = compileStringTemplate(slugTemplate, date, identifier, entryData, processSegment);
|
|
100
|
+
if (!collection.has('path')) {
|
|
101
|
+
return slug;
|
|
102
|
+
} else {
|
|
103
|
+
const pathTemplate = prepareSlug(collection.get('path'));
|
|
104
|
+
return compileStringTemplate(pathTemplate, date, slug, entryData, value => value === slug ? value : processSegment(value));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function previewUrlFormatter(baseUrl, collection, slug, entry, slugConfig) {
|
|
108
|
+
/**
|
|
109
|
+
* Preview URL can't be created without `baseUrl`. This makes preview URLs
|
|
110
|
+
* optional for backends that don't support them.
|
|
111
|
+
*/
|
|
112
|
+
if (!baseUrl) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const basePath = trimEnd(baseUrl, '/');
|
|
116
|
+
const isFileCollection = collection.get('type') === FILES;
|
|
117
|
+
const file = isFileCollection ? getFileFromSlug(collection, entry.get('slug')) : undefined;
|
|
118
|
+
function getPathTemplate() {
|
|
119
|
+
return file?.get('preview_path') ?? collection.get('preview_path');
|
|
120
|
+
}
|
|
121
|
+
function getDateField() {
|
|
122
|
+
return file?.get('preview_path_date_field') ?? collection.get('preview_path_date_field');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* If a `previewPath` is provided for the collection/file, use it to construct the
|
|
127
|
+
* URL path.
|
|
128
|
+
*/
|
|
129
|
+
const pathTemplate = getPathTemplate();
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Without a `previewPath` for the collection/file (via config), the preview URL
|
|
133
|
+
* will be the URL provided by the backend.
|
|
134
|
+
*/
|
|
135
|
+
if (!pathTemplate) {
|
|
136
|
+
return baseUrl;
|
|
137
|
+
}
|
|
138
|
+
let fields = entry.get('data');
|
|
139
|
+
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
|
140
|
+
const dateFieldName = getDateField() || selectInferredField(collection, 'date');
|
|
141
|
+
const date = parseDateFromEntry(entry, dateFieldName);
|
|
142
|
+
|
|
143
|
+
// Prepare and sanitize slug variables only, leave the rest of the
|
|
144
|
+
// `preview_path` template as is.
|
|
145
|
+
const processSegment = getProcessSegment(slugConfig, [fields.get('dirname')]);
|
|
146
|
+
let compiledPath;
|
|
147
|
+
try {
|
|
148
|
+
compiledPath = compileStringTemplate(pathTemplate, date, slug, fields, processSegment);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
// Print an error and ignore `preview_path` if both:
|
|
151
|
+
// 1. Date is invalid (according to DayJs), and
|
|
152
|
+
// 2. A date expression (eg. `{{year}}`) is used in `preview_path`
|
|
153
|
+
if (err.name === SLUG_MISSING_REQUIRED_DATE) {
|
|
154
|
+
console.error(stripIndent`
|
|
155
|
+
Collection "${collection.get('name')}" configuration error:
|
|
156
|
+
\`preview_path_date_field\` must be a field with a valid date. Ignoring \`preview_path\`.
|
|
157
|
+
`);
|
|
158
|
+
return basePath;
|
|
159
|
+
}
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
const previewPath = trimStart(compiledPath, ' /');
|
|
163
|
+
return `${basePath}/${previewPath}`;
|
|
164
|
+
}
|
|
165
|
+
export function summaryFormatter(summaryTemplate, entry, collection) {
|
|
166
|
+
let entryData = entry.get('data');
|
|
167
|
+
const date = parseDateFromEntry(entry, selectInferredField(collection, 'date')) || null;
|
|
168
|
+
const identifier = entryData.getIn(keyToPathArray(selectIdentifier(collection)));
|
|
169
|
+
entryData = addFileTemplateFields(entry.get('path'), entryData, collection.get('folder'));
|
|
170
|
+
// allow commit information in summary template
|
|
171
|
+
if (entry.get('author') && !selectField(collection, COMMIT_AUTHOR)) {
|
|
172
|
+
entryData = entryData.set(COMMIT_AUTHOR, entry.get('author'));
|
|
173
|
+
}
|
|
174
|
+
if (entry.get('updatedOn') && !selectField(collection, COMMIT_DATE)) {
|
|
175
|
+
entryData = entryData.set(COMMIT_DATE, entry.get('updatedOn'));
|
|
176
|
+
}
|
|
177
|
+
const summary = compileStringTemplate(summaryTemplate, date, identifier, entryData);
|
|
178
|
+
return summary;
|
|
179
|
+
}
|
|
180
|
+
export function folderFormatter(folderTemplate, entry, collection, defaultFolder, folderKey, slugConfig) {
|
|
181
|
+
if (!entry || !entry.get('data')) {
|
|
182
|
+
return folderTemplate;
|
|
183
|
+
}
|
|
184
|
+
let fields = entry.get('data').set(folderKey, defaultFolder);
|
|
185
|
+
fields = addFileTemplateFields(entry.get('path'), fields, collection.get('folder'));
|
|
186
|
+
const date = parseDateFromEntry(entry, selectInferredField(collection, 'date')) || null;
|
|
187
|
+
const identifier = fields.getIn(keyToPathArray(selectIdentifier(collection)));
|
|
188
|
+
const processSegment = getProcessSegment(slugConfig, [defaultFolder, fields.get('dirname')]);
|
|
189
|
+
const mediaFolder = compileStringTemplate(folderTemplate, date, identifier, fields, processSegment);
|
|
190
|
+
return mediaFolder;
|
|
191
|
+
}
|