serlo / editor-plugins

Editor Plugins for the Open Learning Platform serlo.org
https://serlo-editor-plugins.netlify.com
Apache License 2.0
5 stars 5 forks source link

edtr image plugin doesn't work #64

Closed simonkoehl closed 5 years ago

simonkoehl commented 5 years ago

image upload attempt fails on serlo.org/jobs image does not appear in the content after selecting the image and clicking on upload no helpful information in the console

Knorrke commented 5 years ago

caused by: https://github.com/serlo/editor-plugins/blob/0020bd4acc80fcda1fa7b2ca712140885ca7a519/plugins/image/src/upload.tsx#L94-L99

Result of the upload request doesn't contain an url field but looks like the following:

{
  "success": true,
  "id": 129765,
  "type": "file",
  "files": [
    {
      "location": "https:\/\/assets.serlo.org\/5c596062dd4fc_157398fce371414c1a35e651ca5ae01782d9fa6e.png",
      "size": 16978,
      "id": 14585,
      "type": "image\/png",
      "filename": "document-27567_1280.png"
    }
  ]
}
Knorrke commented 5 years ago

A solution would probably be to pass the handler (e.g.getStateFromResponse) through upload config and change the mentioned lines to:

onComplete={({ response }: any) => {
  const uploaded = config.getStateFromResponse(response)
  this.props.onImageUploaded(uploaded)
}

and change ImageUploaded interface for onImageUploaded to Partial<ImagePluginState>