-
Notifications
You must be signed in to change notification settings - Fork 10
Align code to the new ckeditor5-cloudservices
package
#8
Changes from 3 commits
fda370d
f09336a
c3391ec
c40ef46
ecccb5e
3f4fcc2
4dc9eb6
d90b425
e155300
cc0bec0
175e329
3764073
7490e97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
"ckeditor5-feature" | ||
], | ||
"dependencies": { | ||
"@ckeditor/ckeditor-cloudservices-core": "^0.1.0", | ||
"@ckeditor/ckeditor-cloudservices-core": "^0.1.1", | ||
"@ckeditor/ckeditor5-cloudservices": "^1.0.0-alpha.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that until we will release it on npm, it should be as:
Otherwise there will be errors. |
||
"@ckeditor/ckeditor5-core": "^1.0.0-alpha.1", | ||
"@ckeditor/ckeditor5-image": "^1.0.0-alpha.1", | ||
"@ckeditor/ckeditor5-upload": "^1.0.0-alpha.1" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository'; | ||
import UploadGateway from '@ckeditor/ckeditor-cloudservices-core/src/uploadgateway/uploadgateway'; | ||
import CloudServices from '@ckeditor/ckeditor5-cloudservices/src/cloudservices'; | ||
|
||
/** | ||
* A plugin which enables upload to Cloud Services. | ||
|
@@ -26,7 +27,7 @@ export default class CloudServicesUploadAdapter extends Plugin { | |
* @inheritDoc | ||
*/ | ||
static get requires() { | ||
return [ FileRepository ]; | ||
return [ FileRepository, CloudServicesUploadAdapter._CloudServices ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use to mock plugins. I would mock There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
} | ||
|
||
/** | ||
|
@@ -36,14 +37,10 @@ export default class CloudServicesUploadAdapter extends Plugin { | |
const editor = this.editor; | ||
const config = editor.config; | ||
|
||
config.define( 'cloudServices.uploadUrl', 'https://files.cke-cs.com/upload/' ); | ||
const cloudServices = editor.plugins.get( CloudServicesUploadAdapter._CloudServices ); | ||
|
||
const token = config.get( 'cloudServices.token' ); | ||
const uploadUrl = config.get( 'cloudServices.uploadUrl' ); | ||
|
||
if ( !token || !uploadUrl ) { | ||
return; | ||
} | ||
const token = cloudServices.token; | ||
const uploadUrl = cloudServices.uploadUrl || 'https://files.cke-cs.com/upload/'; | ||
|
||
this._uploadGateway = new CloudServicesUploadAdapter._UploadGateway( token, uploadUrl ); | ||
|
||
|
@@ -82,6 +79,7 @@ class Adapter { | |
// Store the API in static property to easily overwrite it in tests. | ||
// Too bad dependency injection does not work in Webpack + ES 6 (const) + Babel. | ||
CloudServicesUploadAdapter._UploadGateway = UploadGateway; | ||
CloudServicesUploadAdapter._CloudServices = CloudServices; | ||
|
||
/** | ||
* The configuration of the {@link module:easy-image/cloudservicesuploadadapter~CloudServicesUploadAdapter Cloud Services upload adapter}. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,27 +14,8 @@ import uid from '@ckeditor/ckeditor5-utils/src/uid'; | |
// into a subscription at any moment, allowing you to preserve all uploaded images. | ||
const CLOUD_SERVICES_TOKEN_URL = 'https://j2sns7jmy0.execute-api.eu-central-1.amazonaws.com/prod/token'; | ||
|
||
export default function getToken() { | ||
return new Promise( ( resolve, reject ) => { | ||
const xhr = new XMLHttpRequest(); | ||
const userId = uid(); | ||
export default function getTokenUrl() { | ||
const userId = uid(); | ||
|
||
xhr.open( 'GET', `${ CLOUD_SERVICES_TOKEN_URL }?user.id=${ userId }` ); | ||
|
||
xhr.onload = () => { | ||
if ( xhr.status >= 200 && xhr.status < 300 ) { | ||
const response = JSON.parse( xhr.responseText ); | ||
|
||
resolve( response.token ); | ||
} else { | ||
reject( new Error( `XHR status: ${ xhr.status }` ) ); | ||
} | ||
}; | ||
|
||
xhr.onerror = err => { | ||
reject( err ); | ||
}; | ||
|
||
xhr.send( null ); | ||
} ); | ||
return `${ CLOUD_SERVICES_TOKEN_URL }?user.id=${ userId }`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newest CS should support anonymous users. It means that you don't need to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do something like this in every sample and snippet?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "every sample" Is there more than one? :P I would go with:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used in the snippets in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ach, then I would: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll wait with changes for the correct token URI. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,23 +8,28 @@ | |
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; | ||
import CloudServicesUploadAdapter from '../src/cloudservicesuploadadapter'; | ||
import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository'; | ||
|
||
import UploadGatewayMock from './_utils/uploadgatewaymock'; | ||
import { createNativeFileMock } from '@ckeditor/ckeditor5-upload/tests/_utils/mocks'; | ||
import CloudServicesMock from '@ckeditor/ckeditor5-cloudservices/tests/_utils/cloudservicesmock'; | ||
|
||
// Store original uploader. | ||
const CSUploader = CloudServicesUploadAdapter._UploadGateway; | ||
const CloudServices = CloudServicesUploadAdapter._CloudServices; | ||
|
||
describe( 'CloudServicesUploadAdapter', () => { | ||
let div; | ||
|
||
before( () => { | ||
// Mock uploader. | ||
CloudServicesUploadAdapter._UploadGateway = UploadGatewayMock; | ||
CloudServicesUploadAdapter._CloudServices = CloudServicesMock; | ||
} ); | ||
|
||
after( () => { | ||
// Restore original uploader. | ||
CloudServicesUploadAdapter._UploadGateway = CSUploader; | ||
CloudServicesUploadAdapter._CloudServices = CloudServices; | ||
} ); | ||
|
||
beforeEach( () => { | ||
|
@@ -44,48 +49,31 @@ describe( 'CloudServicesUploadAdapter', () => { | |
.create( div, { | ||
plugins: [ CloudServicesUploadAdapter ], | ||
cloudServices: { | ||
token: 'abc', | ||
tokenUrl: 'abc', | ||
uploadUrl: 'http://upload.mock.url/' | ||
} | ||
} ) | ||
.then( editor => { | ||
expect( UploadGatewayMock.lastToken ).to.equal( 'abc' ); | ||
expect( UploadGatewayMock.lastToken.value ).to.equal( 'token' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not check internals of the token class here. I would remove this assertion since this test is not about it. |
||
expect( UploadGatewayMock.lastUploadUrl ).to.equal( 'http://upload.mock.url/' ); | ||
|
||
return editor.destroy(); | ||
} ); | ||
} ); | ||
|
||
it( 'should not set loader if there is no token', () => { | ||
UploadGatewayMock.lastToken = undefined; | ||
|
||
return ClassicTestEditor | ||
.create( div, { | ||
plugins: [ CloudServicesUploadAdapter ] | ||
} ) | ||
.then( editor => { | ||
expect( UploadGatewayMock.lastToken ).to.be.an( 'undefined' ); | ||
|
||
return editor.destroy(); | ||
} ); | ||
} ); | ||
|
||
it( 'should set the default config.cloudServices.uploadUrl', () => { | ||
it( 'should set the default uploadUrl', () => { | ||
const expectedDefaultUrl = 'https://files.cke-cs.com/upload/'; | ||
|
||
return ClassicTestEditor | ||
.create( div, { | ||
plugins: [ CloudServicesUploadAdapter ], | ||
cloudServices: { | ||
token: 'abc' | ||
tokenUrl: 'abc' | ||
} | ||
} ) | ||
.then( editor => { | ||
expect( UploadGatewayMock.lastToken ).to.equal( 'abc' ); | ||
expect( UploadGatewayMock.lastUploadUrl ).to.equal( expectedDefaultUrl ); | ||
|
||
expect( editor.config.get( 'cloudServices.uploadUrl' ) ).to.equal( expectedDefaultUrl ); | ||
|
||
return editor.destroy(); | ||
} ); | ||
} ); | ||
|
@@ -98,7 +86,7 @@ describe( 'CloudServicesUploadAdapter', () => { | |
return ClassicTestEditor.create( div, { | ||
plugins: [ CloudServicesUploadAdapter ], | ||
cloudServices: { | ||
token: 'abc', | ||
tokenUrl: 'abc', | ||
uploadUrl: 'http://upload.mock.url/' | ||
} | ||
} ).then( _editor => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be changed to "^0.2.0".