mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-14 15:14:31 -04:00
support adding urls with tags directly via CLI and add page
This commit is contained in:
parent
5fb9ca389f
commit
f3a3d76439
6 changed files with 25 additions and 14 deletions
|
@ -20,6 +20,7 @@ ARCHIVE_METHODS = [
|
||||||
|
|
||||||
class AddLinkForm(forms.Form):
|
class AddLinkForm(forms.Form):
|
||||||
url = forms.RegexField(label="URLs (one per line)", regex=URL_REGEX, min_length='6', strip=True, widget=forms.Textarea, required=True)
|
url = forms.RegexField(label="URLs (one per line)", regex=URL_REGEX, min_length='6', strip=True, widget=forms.Textarea, required=True)
|
||||||
|
tag = forms.CharField(label="Tags (comma separated tag1,tag2,tag3)", strip=True, required=False)
|
||||||
depth = forms.ChoiceField(label="Archive depth", choices=CHOICES, initial='0', widget=forms.RadioSelect(attrs={"class": "depth-selection"}))
|
depth = forms.ChoiceField(label="Archive depth", choices=CHOICES, initial='0', widget=forms.RadioSelect(attrs={"class": "depth-selection"}))
|
||||||
archive_methods = forms.MultipleChoiceField(
|
archive_methods = forms.MultipleChoiceField(
|
||||||
label="Archive methods (select at least 1, otherwise all will be used by default)",
|
label="Archive methods (select at least 1, otherwise all will be used by default)",
|
||||||
|
|
|
@ -116,9 +116,13 @@ class Snapshot(models.Model):
|
||||||
from ..index import load_link_details
|
from ..index import load_link_details
|
||||||
return load_link_details(self.as_link())
|
return load_link_details(self.as_link())
|
||||||
|
|
||||||
def tags_str(self) -> str:
|
def tags_str(self, nocache=True) -> str:
|
||||||
cache_key = f'{self.id}-{(self.updated or self.added).timestamp()}-tags'
|
cache_key = f'{self.id}-{(self.updated or self.added).timestamp()}-tags'
|
||||||
calc_tags_str = lambda: ','.join(self.tags.order_by('name').values_list('name', flat=True))
|
calc_tags_str = lambda: ','.join(self.tags.order_by('name').values_list('name', flat=True))
|
||||||
|
if nocache:
|
||||||
|
tags_str = calc_tags_str()
|
||||||
|
cache.set(cache_key, tags_str)
|
||||||
|
return tags_str
|
||||||
return cache.get_or_set(cache_key, calc_tags_str)
|
return cache.get_or_set(cache_key, calc_tags_str)
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
|
|
@ -267,10 +267,12 @@ class AddView(UserPassesTestMixin, FormView):
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
url = form.cleaned_data["url"]
|
url = form.cleaned_data["url"]
|
||||||
print(f'[+] Adding URL: {url}')
|
print(f'[+] Adding URL: {url}')
|
||||||
|
tag = form.cleaned_data["tag"]
|
||||||
depth = 0 if form.cleaned_data["depth"] == "0" else 1
|
depth = 0 if form.cleaned_data["depth"] == "0" else 1
|
||||||
extractors = ','.join(form.cleaned_data["archive_methods"])
|
extractors = ','.join(form.cleaned_data["archive_methods"])
|
||||||
input_kwargs = {
|
input_kwargs = {
|
||||||
"urls": url,
|
"urls": url,
|
||||||
|
"tag": tag,
|
||||||
"depth": depth,
|
"depth": depth,
|
||||||
"update_all": False,
|
"update_all": False,
|
||||||
"out_dir": OUTPUT_DIR,
|
"out_dir": OUTPUT_DIR,
|
||||||
|
|
|
@ -611,17 +611,6 @@ def add(urls: Union[str, List[str]],
|
||||||
write_main_index(links=new_links, out_dir=out_dir)
|
write_main_index(links=new_links, out_dir=out_dir)
|
||||||
all_links = load_main_index(out_dir=out_dir)
|
all_links = load_main_index(out_dir=out_dir)
|
||||||
|
|
||||||
# add any tags to imported links
|
|
||||||
tags = [
|
|
||||||
Tag.objects.get_or_create(name=name.strip())
|
|
||||||
for name in tag.split(',')
|
|
||||||
if name.strip()
|
|
||||||
]
|
|
||||||
if tags:
|
|
||||||
for link in imported_links:
|
|
||||||
link.as_snapshot().tags.add(*tags)
|
|
||||||
|
|
||||||
|
|
||||||
if index_only:
|
if index_only:
|
||||||
# mock archive all the links using the fake index_only extractor method in order to update their state
|
# mock archive all the links using the fake index_only extractor method in order to update their state
|
||||||
if overwrite:
|
if overwrite:
|
||||||
|
@ -644,6 +633,21 @@ def add(urls: Union[str, List[str]],
|
||||||
archive_links(new_links, overwrite=False, **archive_kwargs)
|
archive_links(new_links, overwrite=False, **archive_kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
# add any tags to imported links
|
||||||
|
tags = [
|
||||||
|
Tag.objects.get_or_create(name=name.strip())[0]
|
||||||
|
for name in tag.split(',')
|
||||||
|
if name.strip()
|
||||||
|
]
|
||||||
|
if tags:
|
||||||
|
for link in imported_links:
|
||||||
|
snapshot = link.as_snapshot()
|
||||||
|
snapshot.tags.add(*tags)
|
||||||
|
tags_str = snapshot.tags_str(nocache=True)
|
||||||
|
snapshot.save()
|
||||||
|
# print(f' √ Tagged {len(imported_links)} Snapshots with {len(tags)} tags {tags_str}')
|
||||||
|
|
||||||
|
|
||||||
return all_links
|
return all_links
|
||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div style="max-width: 550px; margin: auto; float: none">
|
<div style="max-width: 1440px; margin: auto; float: none">
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
{% if stdout %}
|
{% if stdout %}
|
||||||
<h1>Add new URLs to your archive: results</h1>
|
<h1>Add new URLs to your archive: results</h1>
|
||||||
|
|
|
@ -42,7 +42,7 @@ header {
|
||||||
background-color: #f5dd5d;
|
background-color: #f5dd5d;
|
||||||
}
|
}
|
||||||
#stdout {
|
#stdout {
|
||||||
background-color: #ded;
|
background-color: #fbfbfb;
|
||||||
padding: 10px 10px;
|
padding: 10px 10px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue