Skip to content

Commit

Permalink
[feature] normalized pasted image url before send to server
Browse files Browse the repository at this point in the history
  • Loading branch information
lencyforce committed Jun 24, 2020
1 parent 3f360e7 commit 735dc23
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 8 additions & 5 deletions modules/miks-clipboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Quill from "quill";
import EditorEvents from "../editor-events";
import normalizeUrl from "normalize-url";
const Clipboard = Quill.import("modules/clipboard");
const Delta = Quill.import("delta");

Expand Down Expand Up @@ -72,15 +73,17 @@ class MiksClipboard extends Clipboard {
let func;
let imageHandlers = this.editor.imageHandlers;

if(imageHandlers.isDataURI(src)) {
let normalizedSrc = normalizeUrl(src)

if(imageHandlers.isDataURI(normalizedSrc)) {
func = this.editor.options.image.handlers.imageDataURIUpload;
}else if(imageHandlers.isImageSrc(src)) {
}else if(imageHandlers.isImageSrc(normalizedSrc)) {
func = this.editor.options.image.handlers.imageSrcUpload;
} else {
// Local files
// Browser has no access to local files
// So skip this file and send a message to editor
this.editor.dispatchEvent(EditorEvents.imageSkipped, src);
this.editor.dispatchEvent(EditorEvents.imageSkipped, normalizedSrc);
}

if(func) {
Expand All @@ -90,9 +93,9 @@ class MiksClipboard extends Clipboard {
let deltaId = imageHandlers.insertImagePlaceholder(placeholderId, index);

setTimeout(() => {
imageHandlers.previewInImagePlaceholder(placeholderId, src);
imageHandlers.previewInImagePlaceholder(placeholderId, normalizedSrc);

func(src)
func(normalizedSrc)
.then(
(imageUrl) => {
imageHandlers.replaceImagePlaceholderWithImage(placeholderId, deltaId, imageUrl, appliedDeltas);
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"homepage": "https://github.com/we-miks/collaborative-editor#readme",
"dependencies": {
"lodash": "^4.17.15",
"normalize-url": "^5.0.0",
"quill": "^1.3.7",
"quill-image-drop-and-paste": "^1.0.4",
"reconnecting-websocket": "^4.4.0",
Expand Down

0 comments on commit 735dc23

Please sign in to comment.