0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Added YAML file support for redirects (#1703)

refs https://github.com/TryGhost/Ghost/issues/11085
refs https://github.com/TryGhost/Ghost/pull/12187

- YAML file support has been added to Ghost's API through referenced above PR. YAML will become a default supported file in the next version of Ghost replacing JSON redirects
This commit is contained in:
Kukhyeon Heo 2021-02-22 09:27:00 +09:00 committed by GitHub
parent d03e1ae0e2
commit 568cd65fb3
3 changed files with 14 additions and 13 deletions

View file

@ -49,8 +49,8 @@ export default Controller.extend({
uploadButtonText: 'Import', uploadButtonText: 'Import',
importMimeType: null, importMimeType: null,
jsonExtension: null, redirectsFileExtensions: null,
jsonMimeType: null, redirectsFileMimeTypes: null,
yamlExtension: null, yamlExtension: null,
yamlMimeType: null, yamlMimeType: null,
@ -59,8 +59,9 @@ export default Controller.extend({
init() { init() {
this._super(...arguments); this._super(...arguments);
this.importMimeType = IMPORT_MIME_TYPES; this.importMimeType = IMPORT_MIME_TYPES;
this.jsonExtension = JSON_EXTENSION; this.redirectsFileExtensions = [...JSON_EXTENSION, ...YAML_EXTENSION];
this.jsonMimeType = JSON_MIME_TYPE; // .yaml is added below for file dialogs to show .yaml by default.
this.redirectsFileMimeTypes = [...JSON_MIME_TYPE, ...YAML_MIME_TYPE, '.yaml'];
this.yamlExtension = YAML_EXTENSION; this.yamlExtension = YAML_EXTENSION;
this.yamlMimeType = YAML_MIME_TYPE; this.yamlMimeType = YAML_MIME_TYPE;
// (macOS) Safari only allows files with the `yml` extension to be selected with the specified MIME types // (macOS) Safari only allows files with the `yml` extension to be selected with the specified MIME types

View file

@ -84,8 +84,8 @@
<div class="gh-expandable"> <div class="gh-expandable">
<div class="gh-expandable-block"> <div class="gh-expandable-block">
<GhUploader <GhUploader
@extensions={{this.jsonExtension}} @extensions={{this.redirectsFileExtensions}}
@uploadUrl="/redirects/json/" @uploadUrl="/redirects/upload/"
@paramName="redirects" @paramName="redirects"
@onUploadSuccess={{perform this.redirectUploadResult true}} @onUploadSuccess={{perform this.redirectUploadResult true}}
@onUploadFailure={{perform this.redirectUploadResult false}} @onUploadFailure={{perform this.redirectUploadResult false}}
@ -112,11 +112,11 @@
{{else if this.redirectFailure}} {{else if this.redirectFailure}}
{{svg-jar "retry"}} Upload Failed {{svg-jar "retry"}} Upload Failed
{{else}} {{else}}
Upload redirects JSON Upload redirects YAML/JSON
{{/if}} {{/if}}
</span> </span>
</button> </button>
<div><a href="#" {{action "downloadFile" "redirects/json"}} data-test-link="download-redirects">Download current redirects</a></div> <div><a href="#" {{action "downloadFile" "redirects/download"}} data-test-link="download-redirects">Download current redirects</a></div>
{{/if}} {{/if}}
{{#each uploader.errors as |error|}} {{#each uploader.errors as |error|}}
@ -124,7 +124,7 @@
{{/each}} {{/each}}
<div style="display:none"> <div style="display:none">
<GhFileInput @multiple={{false}} @action={{uploader.setFiles}} @accept={{this.jsonMimeType}} data-test-file-input="redirects" /> <GhFileInput @multiple={{false}} @action={{uploader.setFiles}} @accept={{this.redirectsFileMimeTypes}} data-test-file-input="redirects" />
</div> </div>
</div> </div>
</div> </div>

View file

@ -82,7 +82,7 @@ describe('Acceptance: Settings - Labs', function () {
await visit('/settings/labs'); await visit('/settings/labs');
// successful upload // successful upload
this.server.post('/redirects/json/', {}, 200); this.server.post('/redirects/upload/', {}, 200);
await fileUpload( await fileUpload(
'[data-test-file-input="redirects"] input', '[data-test-file-input="redirects"] input',
@ -123,7 +123,7 @@ describe('Acceptance: Settings - Labs', function () {
).to.have.string('Upload redirects'); ).to.have.string('Upload redirects');
// failed upload // failed upload
this.server.post('/redirects/json/', { this.server.post('/redirects/upload/', {
errors: [{ errors: [{
type: 'BadRequestError', type: 'BadRequestError',
message: 'Test failure message' message: 'Test failure message'
@ -175,7 +175,7 @@ describe('Acceptance: Settings - Labs', function () {
).to.have.string('Upload redirects'); ).to.have.string('Upload redirects');
// successful upload clears error // successful upload clears error
this.server.post('/redirects/json/', {}, 200); this.server.post('/redirects/upload/', {}, 200);
await fileUpload( await fileUpload(
'[data-test-file-input="redirects"] input', '[data-test-file-input="redirects"] input',
['test'], ['test'],
@ -188,7 +188,7 @@ describe('Acceptance: Settings - Labs', function () {
await click('[data-test-link="download-redirects"]'); await click('[data-test-link="download-redirects"]');
let iframe = document.querySelector('#iframeDownload'); let iframe = document.querySelector('#iframeDownload');
expect(iframe.getAttribute('src')).to.have.string('/redirects/json/'); expect(iframe.getAttribute('src')).to.have.string('/redirects/download/');
}); });
it('can upload/download routes.yaml', async function () { it('can upload/download routes.yaml', async function () {