Skip to content

Commit 62ced1b

Browse files
authored
Merge pull request #26 from 2ik/main
Main to dev
2 parents 343fb7c + 0c33950 commit 62ced1b

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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',

django_editorjs_fields/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
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',

django_editorjs_fields/urls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.contrib.admin.views.decorators import staff_member_required
22
from django.urls import path
33

4-
from .views import ImageUploadView, LinkToolView
4+
from .views import ImageUploadView, LinkToolView, ImageByUrl
55

66
urlpatterns = [
77
path(
@@ -14,4 +14,9 @@
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
]

django_editorjs_fields/views.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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})

0 commit comments

Comments
 (0)