File tree Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,10 @@ EDITORJS_DEFAULT_CONFIG_TOOLS = {
165
165
' Image' : {
166
166
' class' : ' ImageTool' ,
167
167
' inlineToolbar' : True ,
168
- " config" : {" endpoints" : {" byFile" : reverse_lazy(' editorjs_image_upload' )}},
168
+ " config" : {" endpoints" : {
169
+ " byFile" : reverse_lazy(' editorjs_image_upload' ),
170
+ " byUrl" : reverse_lazy(' editorjs_image_by_url' )
171
+ }},
169
172
},
170
173
' Header' : {
171
174
' class' : ' Header' ,
Original file line number Diff line number Diff line change 45
45
'Image' : {
46
46
'class' : 'ImageTool' ,
47
47
'inlineToolbar' : True ,
48
- "config" : {"endpoints" : {"byFile" : reverse_lazy ('editorjs_image_upload' )}},
48
+ "config" : {"endpoints" : {
49
+ "byFile" : reverse_lazy ('editorjs_image_upload' ),
50
+ "byUrl" : reverse_lazy ('editorjs_image_by_url' )
51
+ }},
49
52
},
50
53
'Header' : {
51
54
'class' : 'Header' ,
Original file line number Diff line number Diff line change 1
1
from django .contrib .admin .views .decorators import staff_member_required
2
2
from django .urls import path
3
3
4
- from .views import ImageUploadView , LinkToolView
4
+ from .views import ImageUploadView , LinkToolView , ImageByUrl
5
5
6
6
urlpatterns = [
7
7
path (
14
14
staff_member_required (LinkToolView .as_view ()),
15
15
name = 'editorjs_linktool' ,
16
16
),
17
+ path (
18
+ 'image_by_url/' ,
19
+ ImageByUrl .as_view (),
20
+ name = 'editorjs_image_by_url' ,
21
+ ),
17
22
]
Original file line number Diff line number Diff line change @@ -144,3 +144,17 @@ def get(self, request):
144
144
})
145
145
146
146
return JsonResponse ({'success' : 0 })
147
+
148
+
149
+ class ImageByUrl (View ):
150
+ http_method_names = ["post" ]
151
+
152
+ @method_decorator (csrf_exempt )
153
+ def dispatch (self , request , * args , ** kwargs ):
154
+ return super ().dispatch (request , * args , ** kwargs )
155
+
156
+ def post (self , request ):
157
+ body = json .loads (request .body .decode ())
158
+ if 'url' in body :
159
+ return JsonResponse ({'success' : 1 , 'file' : {"url" : body ['url' ]}})
160
+ return JsonResponse ({'success' : 0 })
You can’t perform that action at this time.
0 commit comments