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 = {
165165 ' Image' : {
166166 ' class' : ' ImageTool' ,
167167 ' 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+ }},
169172 },
170173 ' Header' : {
171174 ' class' : ' Header' ,
Original file line number Diff line number Diff line change 4545 'Image' : {
4646 'class' : 'ImageTool' ,
4747 '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+ }},
4952 },
5053 'Header' : {
5154 'class' : 'Header' ,
Original file line number Diff line number Diff line change 11from django .contrib .admin .views .decorators import staff_member_required
22from django .urls import path
33
4- from .views import ImageUploadView , LinkToolView
4+ from .views import ImageUploadView , LinkToolView , ImageByUrl
55
66urlpatterns = [
77 path (
1414 staff_member_required (LinkToolView .as_view ()),
1515 name = 'editorjs_linktool' ,
1616 ),
17+ path (
18+ 'image_by_url/' ,
19+ ImageByUrl .as_view (),
20+ name = 'editorjs_image_by_url' ,
21+ ),
1722]
Original file line number Diff line number Diff line change @@ -144,3 +144,17 @@ def get(self, request):
144144 })
145145
146146 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