mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-16 16:14:28 -04:00
add public add view + toggle setting
This commit is contained in:
parent
6f7cc2b3ef
commit
3288f8579b
3 changed files with 47 additions and 4 deletions
|
@ -69,6 +69,7 @@ CONFIG_DEFAULTS: Dict[str, ConfigDefaultDict] = {
|
||||||
'DEBUG': {'type': bool, 'default': False},
|
'DEBUG': {'type': bool, 'default': False},
|
||||||
'PUBLIC_INDEX': {'type': bool, 'default': True},
|
'PUBLIC_INDEX': {'type': bool, 'default': True},
|
||||||
'PUBLIC_SNAPSHOTS': {'type': bool, 'default': True},
|
'PUBLIC_SNAPSHOTS': {'type': bool, 'default': True},
|
||||||
|
'PUBLIC_ADD_VIEW': {'type': bool, 'default': False},
|
||||||
'FOOTER_INFO': {'type': str, 'default': 'Content is hosted for personal archiving purposes only. Contact server owner for any takedown requests.'},
|
'FOOTER_INFO': {'type': str, 'default': 'Content is hosted for personal archiving purposes only. Contact server owner for any takedown requests.'},
|
||||||
'ACTIVE_THEME': {'type': str, 'default': 'default'},
|
'ACTIVE_THEME': {'type': str, 'default': 'default'},
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.views import static
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.views.generic.base import RedirectView
|
from django.views.generic.base import RedirectView
|
||||||
|
|
||||||
from core.views import MainIndex, OldIndex, LinkDetails, PublicArchiveView, SearchResultsView
|
from core.views import MainIndex, OldIndex, LinkDetails, PublicArchiveView, SearchResultsView, add_view
|
||||||
|
|
||||||
|
|
||||||
# print('DEBUG', settings.DEBUG)
|
# print('DEBUG', settings.DEBUG)
|
||||||
|
@ -18,7 +18,7 @@ urlpatterns = [
|
||||||
|
|
||||||
path('archive/', RedirectView.as_view(url='/')),
|
path('archive/', RedirectView.as_view(url='/')),
|
||||||
path('archive/<path:path>', LinkDetails.as_view(), name='LinkAssets'),
|
path('archive/<path:path>', LinkDetails.as_view(), name='LinkAssets'),
|
||||||
path('add/', RedirectView.as_view(url='/admin/core/snapshot/add/')),
|
path('add/', add_view),
|
||||||
|
|
||||||
path('accounts/login/', RedirectView.as_view(url='/admin/login/')),
|
path('accounts/login/', RedirectView.as_view(url='/admin/login/')),
|
||||||
path('accounts/logout/', RedirectView.as_view(url='/admin/logout/')),
|
path('accounts/logout/', RedirectView.as_view(url='/admin/logout/')),
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
__package__ = 'archivebox.core'
|
__package__ = 'archivebox.core'
|
||||||
|
|
||||||
|
from io import StringIO
|
||||||
|
from contextlib import redirect_stdout
|
||||||
|
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
@ -11,6 +14,8 @@ from django_datatables_view.base_datatable_view import BaseDatatableView
|
||||||
|
|
||||||
from core.models import Snapshot
|
from core.models import Snapshot
|
||||||
from core.utils import get_icons
|
from core.utils import get_icons
|
||||||
|
from core.forms import AddLinkForm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from ..index import load_main_index, load_main_index_meta
|
from ..index import load_main_index, load_main_index_meta
|
||||||
|
@ -20,8 +25,10 @@ from ..config import (
|
||||||
FOOTER_INFO,
|
FOOTER_INFO,
|
||||||
PUBLIC_INDEX,
|
PUBLIC_INDEX,
|
||||||
PUBLIC_SNAPSHOTS,
|
PUBLIC_SNAPSHOTS,
|
||||||
|
PUBLIC_ADD_VIEW
|
||||||
)
|
)
|
||||||
from ..util import base_url
|
from main import add
|
||||||
|
from ..util import base_url, ansi_to_html
|
||||||
|
|
||||||
|
|
||||||
class MainIndex(View):
|
class MainIndex(View):
|
||||||
|
@ -133,4 +140,39 @@ class SearchResultsView(PublicArchiveView):
|
||||||
results = Snapshot.objects.filter(title__icontains=query)
|
results = Snapshot.objects.filter(title__icontains=query)
|
||||||
for snapshot in results:
|
for snapshot in results:
|
||||||
snapshot.icons = get_icons(snapshot)
|
snapshot.icons = get_icons(snapshot)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def add_view(request):
|
||||||
|
if PUBLIC_ADD_VIEW or request.user.is_authenticated:
|
||||||
|
context = {
|
||||||
|
'title': 'Add URLs',
|
||||||
|
}
|
||||||
|
if request.method == 'GET':
|
||||||
|
context['form'] = AddLinkForm()
|
||||||
|
|
||||||
|
elif request.method == 'POST':
|
||||||
|
form = AddLinkForm(request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
url = form.cleaned_data["url"]
|
||||||
|
print(f'[+] Adding URL: {url}')
|
||||||
|
depth = 0 if form.cleaned_data["depth"] == "0" else 1
|
||||||
|
input_kwargs = {
|
||||||
|
"urls": url,
|
||||||
|
"depth": depth,
|
||||||
|
"update_all": False,
|
||||||
|
"out_dir": OUTPUT_DIR,
|
||||||
|
}
|
||||||
|
add_stdout = StringIO()
|
||||||
|
with redirect_stdout(add_stdout):
|
||||||
|
add(**input_kwargs)
|
||||||
|
print(add_stdout.getvalue())
|
||||||
|
|
||||||
|
context.update({
|
||||||
|
"stdout": ansi_to_html(add_stdout.getvalue().strip()),
|
||||||
|
"form": AddLinkForm()
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
context["form"] = form
|
||||||
|
return render(template_name='add_links.html', request=request, context=context)
|
||||||
|
else:
|
||||||
|
return redirect(f'/admin/login/?next={request.path}')
|
Loading…
Add table
Add a link
Reference in a new issue