mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-06 07:47:53 +10:00
Tighten API typing and add return values
This commit is contained in:
@@ -25,8 +25,8 @@ class CLIScheduleAPITests(TestCase):
|
||||
def test_schedule_api_creates_schedule(self):
|
||||
request = RequestFactory().post('/api/v1/cli/schedule')
|
||||
request.user = self.user
|
||||
request.stdout = StringIO()
|
||||
request.stderr = StringIO()
|
||||
setattr(request, 'stdout', StringIO())
|
||||
setattr(request, 'stderr', StringIO())
|
||||
args = ScheduleCommandSchema(
|
||||
every='daily',
|
||||
import_path='https://example.com/feed.xml',
|
||||
|
||||
@@ -112,7 +112,7 @@ class RemoveCommandSchema(Schema):
|
||||
def cli_add(request: HttpRequest, args: AddCommandSchema):
|
||||
from archivebox.cli.archivebox_add import add
|
||||
|
||||
result = add(
|
||||
crawl, snapshots = add(
|
||||
urls=args.urls,
|
||||
tag=args.tag,
|
||||
depth=args.depth,
|
||||
@@ -125,9 +125,9 @@ def cli_add(request: HttpRequest, args: AddCommandSchema):
|
||||
created_by_id=request.user.pk,
|
||||
)
|
||||
|
||||
snapshot_ids = [str(snapshot_id) for snapshot_id in result.values_list('id', flat=True)]
|
||||
snapshot_ids = [str(snapshot_id) for snapshot_id in snapshots.values_list('id', flat=True)]
|
||||
result_payload = {
|
||||
"crawl_id": getattr(result, "crawl_id", None),
|
||||
"crawl_id": str(crawl.id),
|
||||
"num_snapshots": len(snapshot_ids),
|
||||
"snapshot_ids": snapshot_ids,
|
||||
"queued_urls": args.urls,
|
||||
|
||||
@@ -427,7 +427,7 @@ def get_any(request: HttpRequest, id: str):
|
||||
try:
|
||||
response = getter(request, id)
|
||||
if isinstance(response, Model):
|
||||
return redirect(f"/api/v1/{response._meta.app_label}/{response._meta.model_name}/{response.id}?{request.META['QUERY_STRING']}")
|
||||
return redirect(f"/api/v1/{response._meta.app_label}/{response._meta.model_name}/{response.pk}?{request.META['QUERY_STRING']}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -435,7 +435,7 @@ def get_any(request: HttpRequest, id: str):
|
||||
from archivebox.api.v1_crawls import get_crawl
|
||||
response = get_crawl(request, id)
|
||||
if isinstance(response, Model):
|
||||
return redirect(f"/api/v1/{response._meta.app_label}/{response._meta.model_name}/{response.id}?{request.META['QUERY_STRING']}")
|
||||
return redirect(f"/api/v1/{response._meta.app_label}/{response._meta.model_name}/{response.pk}?{request.META['QUERY_STRING']}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user