feat: Handle empty URL case

This commit is contained in:
Cristian 2020-07-01 12:29:56 -05:00
parent c971e00c9c
commit 364c5752d8
2 changed files with 218 additions and 235 deletions

View file

@ -57,19 +57,22 @@ class AddLinks(View):
def post(self, request): def post(self, request):
url = request.POST['url'] url = request.POST['url']
print(f'[+] Adding URL: {url}') if url:
add_stdout = StringIO() print(f'[+] Adding URL: {url}')
with redirect_stdout(add_stdout): add_stdout = StringIO()
extracted_links = add( with redirect_stdout(add_stdout):
import_str=url, extracted_links = add(
update_all=False, import_str=url,
out_dir=OUTPUT_DIR, update_all=False,
) out_dir=OUTPUT_DIR,
print(add_stdout.getvalue()) )
print(add_stdout.getvalue())
context = { context = {
"stdout": ansi_to_html(add_stdout.getvalue()) "stdout": ansi_to_html(add_stdout.getvalue())
} }
else:
context = {"stdout": "Please enter a URL"}
return render(template_name=self.template, request=request, context=context) return render(template_name=self.template, request=request, context=context)

View file

@ -2,231 +2,211 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>Archived Sites</title> <title>Archived Sites</title>
<meta <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
charset="utf-8" <style>
name="viewport" html, body {
content="width=device-width, initial-scale=1" width: 100%;
/> height: 100%;
<style> font-size: 18px;
html, font-weight: 200;
body { text-align: center;
width: 100%; margin: 0px;
height: 100%; padding: 0px;
font-size: 18px; font-family: "Gill Sans", Helvetica, sans-serif;
font-weight: 200; }
text-align: center; .header-top small {
margin: 0px; font-weight: 200;
padding: 0px; color: #efefef;
font-family: "Gill Sans", Helvetica, sans-serif; }
}
.header-top small {
font-weight: 200;
color: #efefef;
}
.header-top { .header-top {
width: 100%; width: 100%;
height: auto; height: auto;
min-height: 40px; min-height: 40px;
margin: 0px; margin: 0px;
text-align: center; text-align: center;
color: white; color: white;
font-size: calc(11px + 0.84vw); font-size: calc(11px + 0.84vw);
font-weight: 200; font-weight: 200;
padding: 4px 4px; padding: 4px 4px;
border-bottom: 3px solid #aa1e55; border-bottom: 3px solid #aa1e55;
background-color: #aa1e55; background-color: #aa1e55;
} }
input[type="search"] { input[type=search] {
width: 22vw; width: 22vw;
border-radius: 4px; border-radius: 4px;
border: 1px solid #aeaeae; border: 1px solid #aeaeae;
padding: 3px 5px; padding: 3px 5px;
} }
.nav > div { .nav > div {
min-height: 30px; min-height: 30px;
} }
.header-top a { .header-top a {
text-decoration: none; text-decoration: none;
color: rgba(0, 0, 0, 0.6); color: rgba(0,0,0,0.6);
} }
.header-top a:hover { .header-top a:hover {
text-decoration: none; text-decoration: none;
color: rgba(0, 0, 0, 0.9); color: rgba(0,0,0,0.9);
} }
.header-top .col-lg-4 { .header-top .col-lg-4 {
text-align: center; text-align: center;
padding-top: 4px; padding-top: 4px;
padding-bottom: 4px; padding-bottom: 4px;
} }
.header-archivebox img { .header-archivebox img {
display: inline-block; display: inline-block;
margin-right: 3px; margin-right: 3px;
height: 30px; height: 30px;
margin-left: 12px; margin-left: 12px;
margin-top: -4px; margin-top: -4px;
margin-bottom: 2px; margin-bottom: 2px;
} }
.header-archivebox img:hover { .header-archivebox img:hover {
opacity: 0.5; opacity: 0.5;
} }
#table-bookmarks_length, #table-bookmarks_length, #table-bookmarks_filter {
#table-bookmarks_filter { padding-top: 12px;
padding-top: 12px; opacity: 0.8;
opacity: 0.8; padding-left: 24px;
padding-left: 24px; padding-right: 22px;
padding-right: 22px; margin-bottom: -16px;
margin-bottom: -16px; }
} table {
table { padding: 6px;
padding: 6px; width: 100%;
width: 100%; }
} table thead th {
table thead th { font-weight: 400;
font-weight: 400; }
} table tr {
table tr { height: 35px;
height: 35px; }
} tbody tr:nth-child(odd) {
tbody tr:nth-child(odd) { background-color: #ffebeb !important;
background-color: #ffebeb !important; }
} table tr td {
table tr td { white-space: nowrap;
white-space: nowrap; overflow: hidden;
overflow: hidden; /*padding-bottom: 0.4em;*/
/*padding-bottom: 0.4em;*/ /*padding-top: 0.4em;*/
/*padding-top: 0.4em;*/ padding-left: 2px;
padding-left: 2px; text-align: center;
text-align: center; }
} table tr td a {
table tr td a { text-decoration: none;
text-decoration: none; }
} table tr td img, table tr td object {
table tr td img, display: inline-block;
table tr td object { margin: auto;
display: inline-block; height: 24px;
margin: auto; width: 24px;
height: 24px; padding: 0px;
width: 24px; padding-right: 5px;
padding: 0px; vertical-align: middle;
padding-right: 5px; margin-left: 4px;
vertical-align: middle; }
margin-left: 4px; #table-bookmarks {
} width: 100%;
#table-bookmarks { overflow-y: scroll;
width: 100%; table-layout: fixed;
overflow-y: scroll; }
table-layout: fixed; .dataTables_wrapper {
} background-color: #fafafa;
.dataTables_wrapper { }
background-color: #fafafa; table tr a span[data-archived~=False] {
} opacity: 0.4;
table tr a span[data-archived~="False"] { }
opacity: 0.4; .files-spinner {
} height: 15px;
.files-spinner { width: auto;
height: 15px; opacity: 0.5;
width: auto; vertical-align: -2px;
opacity: 0.5; }
vertical-align: -2px; .in-progress {
} display: none;
.in-progress { }
display: none; body[data-status~=finished] .files-spinner {
} display: none;
body[data-status~="finished"] .files-spinner { }
display: none; /*body[data-status~=running] .in-progress {
}
/*body[data-status~=running] .in-progress {
display: inline-block; display: inline-block;
}*/ }*/
tr td a.favicon img { tr td a.favicon img {
padding-left: 6px; padding-left: 6px;
padding-right: 12px; padding-right: 12px;
vertical-align: -4px; vertical-align: -4px;
} }
tr td a.title { tr td a.title {
font-size: 1.4em; font-size: 1.4em;
text-decoration: none; text-decoration:none;
color: black; color:black;
} }
tr td a.title small { tr td a.title small {
background-color: #efefef; background-color: #efefef;
border-radius: 4px; border-radius: 4px;
float: right; float:right
} }
input[type="search"]::-webkit-search-cancel-button { input[type=search]::-webkit-search-cancel-button {
-webkit-appearance: searchfield-cancel-button; -webkit-appearance: searchfield-cancel-button;
} }
.title-col { .title-col {
text-align: left; text-align: left;
} }
.title-col a { .title-col a {
color: black; color: black;
} }
</style> </style>
<link rel="stylesheet" href="{% static 'bootstrap.min.css' %}" /> <link rel="stylesheet" href="{% static 'bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'jquery.dataTables.min.css' %}" /> <link rel="stylesheet" href="{% static 'jquery.dataTables.min.css' %}"/>
<script src="{% static 'jquery.min.js' %}"></script> <script src="{% static 'jquery.min.js' %}"></script>
<script src="{% static 'jquery.dataTables.min.js' %}"></script> <script src="{% static 'jquery.dataTables.min.js' %}"></script>
<script> <script>
document.addEventListener( document.addEventListener('error', function(e) {
"error", e.target.style.opacity = 0;
function (e) { }, true)
e.target.style.opacity = 0; jQuery(document).ready(function() {
}, jQuery('#table-bookmarks').DataTable({
true stateSave: true, // save state (filtered input, number of entries shown, etc) in localStorage
); dom: '<lf<t>ip>', // how to show the table and its helpers (filter, etc) in the DOM
jQuery(document).ready(function () { order: [[0, 'desc']],
jQuery("#table-bookmarks").DataTable({ iDisplayLength: 100,
stateSave: true, // save state (filtered input, number of entries shown, etc) in localStorage });
dom: "<lf<t>ip>", // how to show the table and its helpers (filter, etc) in the DOM });
order: [[0, "desc"]], </script>
iDisplayLength: 100, </head>
}); <body data-status="finished">
}); <header>
</script> <div class="header-top container-fluid">
</head> <div class="row nav">
<body data-status="finished"> <div class="col-sm-2">
<header> <a href="/" class="header-archivebox" title="Last updated: {{updated}}">
<div class="header-top container-fluid"> <img src="{% static 'archive.png' %}" alt="Logo"/>
<div class="row nav"> ArchiveBox: Add
<div class="col-sm-2"> </a>
<a </div>
href="/" <div class="col-sm-10" style="text-align: right">
class="header-archivebox" <a href="/">Main Index</a> &nbsp; | &nbsp;
title="Last updated: {{updated}}" <a href="/admin/">Admin</a> &nbsp; | &nbsp;
> <a href="https://github.com/pirate/ArchiveBox/wiki">Docs</a>
<img src="{% static 'archive.png' %}" alt="Logo" /> </div>
ArchiveBox: Add </div>
</a> </div>
</div> </header>
<div class="col-sm-10" style="text-align: right;"> <center>
<a href="/">Main Index</a> &nbsp; | &nbsp; {{ stdout | safe }}
<a href="/admin/">Admin</a> &nbsp; | &nbsp; <br/><br/>
<a href="https://github.com/pirate/ArchiveBox/wiki">Docs</a> <form action="?" method="POST">{% csrf_token %}
</div> Add new links...<br/>
</div> <input type="text" name="url" placeholder="URL of page or feed..."/><br/>
</div> <button role="submit">Add</button>
</header> </form>
<center> </center>
{{ stdout | safe }}
<br /><br />
<form action="?" method="POST">
{% csrf_token %} Add new links...<br />
<input
type="text"
name="url"
placeholder="URL of page or feed..."
/><br />
<button role="submit">Add</button>
</form>
<a href="{% url 'admin:core_snapshot_changelist' %}" <a href="{% url 'admin:core_snapshot_changelist' %}">Go back to Snapshot list</a>
>Go back to Snapshot list</a
> </body>
</center>
</body>
</html> </html>