diff --git a/archivebox/api/v1_api.py b/archivebox/api/v1_api.py index d82490d4..0b33b8ef 100644 --- a/archivebox/api/v1_api.py +++ b/archivebox/api/v1_api.py @@ -6,18 +6,19 @@ from traceback import format_exception from contextlib import redirect_stdout, redirect_stderr from django.http import HttpRequest, HttpResponse -from django.views.decorators.csrf import csrf_exempt from django.core.exceptions import ObjectDoesNotExist, EmptyResultSet, PermissionDenied from ninja import NinjaAPI, Swagger # TODO: explore adding https://eadwincode.github.io/django-ninja-extra/ +import archivebox +from plugins_sys.config.apps import SHELL_CONFIG + from api.auth import API_AUTH_METHODS -from ..config import VERSION, COMMIT_HASH -COMMIT_HASH = COMMIT_HASH or 'unknown' +COMMIT_HASH = SHELL_CONFIG.COMMIT_HASH or 'unknown' html_description=f'''

Welcome to your ArchiveBox server's REST API [v1 ALPHA] homepage!

@@ -31,7 +32,7 @@ html_description=f'''
  • 📚 ArchiveBox Documentation: Github Wiki
  • 📜 See the API source code: archivebox/api/
  • -Served by ArchiveBox v{VERSION} ({COMMIT_HASH[:8]}), API powered by django-ninja. +Served by ArchiveBox v{archivebox.VERSION} ({COMMIT_HASH[:8]}), API powered by django-ninja. ''' diff --git a/archivebox/core/models.py b/archivebox/core/models.py index 6d377ac1..0b70f17a 100644 --- a/archivebox/core/models.py +++ b/archivebox/core/models.py @@ -17,6 +17,8 @@ from django.db.models import Case, When, Value, IntegerField from django.contrib import admin from django.conf import settings +import archivebox + from abid_utils.models import ABIDModel, ABIDField, AutoDateTimeField from queues.tasks import bg_archive_snapshot @@ -259,11 +261,11 @@ class Snapshot(ABIDModel): @cached_property def link_dir(self): - return str(settings.CONFIG.ARCHIVE_DIR / self.timestamp) + return str(archivebox.CONSTANTS.ARCHIVE_DIR / self.timestamp) @cached_property def archive_path(self): - return '{}/{}'.format(settings.CONFIG.ARCHIVE_DIR_NAME, self.timestamp) + return '{}/{}'.format(archivebox.CONSTANTS.ARCHIVE_DIR_NAME, self.timestamp) @cached_property def archive_size(self): @@ -373,17 +375,17 @@ class Snapshot(ABIDModel): # def get_storage_dir(self, create=True, symlink=True) -> Path: # date_str = self.bookmarked_at.strftime('%Y%m%d') # domain_str = domain(self.url) - # abs_storage_dir = Path(settings.CONFIG.ARCHIVE_DIR) / 'snapshots' / date_str / domain_str / str(self.ulid) + # abs_storage_dir = Path(archivebox.CONSTANTS.ARCHIVE_DIR) / 'snapshots' / date_str / domain_str / str(self.ulid) # if create and not abs_storage_dir.is_dir(): # abs_storage_dir.mkdir(parents=True, exist_ok=True) # if symlink: # LINK_PATHS = [ - # Path(settings.CONFIG.ARCHIVE_DIR).parent / 'index' / 'all_by_id' / str(self.ulid), - # # Path(settings.CONFIG.ARCHIVE_DIR).parent / 'index' / 'snapshots_by_id' / str(self.ulid), - # Path(settings.CONFIG.ARCHIVE_DIR).parent / 'index' / 'snapshots_by_date' / date_str / domain_str / str(self.ulid), - # Path(settings.CONFIG.ARCHIVE_DIR).parent / 'index' / 'snapshots_by_domain' / domain_str / date_str / str(self.ulid), + # Path(archivebox.CONSTANTS.ARCHIVE_DIR).parent / 'index' / 'all_by_id' / str(self.ulid), + # # Path(archivebox.CONSTANTS.ARCHIVE_DIR).parent / 'index' / 'snapshots_by_id' / str(self.ulid), + # Path(archivebox.CONSTANTS.ARCHIVE_DIR).parent / 'index' / 'snapshots_by_date' / date_str / domain_str / str(self.ulid), + # Path(archivebox.CONSTANTS.ARCHIVE_DIR).parent / 'index' / 'snapshots_by_domain' / domain_str / date_str / str(self.ulid), # ] # for link_path in LINK_PATHS: # link_path.parent.mkdir(parents=True, exist_ok=True) @@ -522,18 +524,18 @@ class ArchiveResult(ABIDModel): # def get_storage_dir(self, create=True, symlink=True): # date_str = self.snapshot.bookmarked_at.strftime('%Y%m%d') # domain_str = domain(self.snapshot.url) - # abs_storage_dir = Path(settings.CONFIG.ARCHIVE_DIR) / 'results' / date_str / domain_str / self.extractor / str(self.ulid) + # abs_storage_dir = Path(archivebox.CONSTANTS.ARCHIVE_DIR) / 'results' / date_str / domain_str / self.extractor / str(self.ulid) # if create and not abs_storage_dir.is_dir(): # abs_storage_dir.mkdir(parents=True, exist_ok=True) # if symlink: # LINK_PATHS = [ - # Path(settings.CONFIG.ARCHIVE_DIR).parent / 'index' / 'all_by_id' / str(self.ulid), - # # Path(settings.CONFIG.ARCHIVE_DIR).parent / 'index' / 'results_by_id' / str(self.ulid), - # # Path(settings.CONFIG.ARCHIVE_DIR).parent / 'index' / 'results_by_date' / date_str / domain_str / self.extractor / str(self.ulid), - # Path(settings.CONFIG.ARCHIVE_DIR).parent / 'index' / 'results_by_domain' / domain_str / date_str / self.extractor / str(self.ulid), - # Path(settings.CONFIG.ARCHIVE_DIR).parent / 'index' / 'results_by_type' / self.extractor / date_str / domain_str / str(self.ulid), + # Path(archivebox.CONSTANTS.ARCHIVE_DIR).parent / 'index' / 'all_by_id' / str(self.ulid), + # # Path(archivebox.CONSTANTS.ARCHIVE_DIR).parent / 'index' / 'results_by_id' / str(self.ulid), + # # Path(archivebox.CONSTANTS.ARCHIVE_DIR).parent / 'index' / 'results_by_date' / date_str / domain_str / self.extractor / str(self.ulid), + # Path(archivebox.CONSTANTS.ARCHIVE_DIR).parent / 'index' / 'results_by_domain' / domain_str / date_str / self.extractor / str(self.ulid), + # Path(archivebox.CONSTANTS.ARCHIVE_DIR).parent / 'index' / 'results_by_type' / self.extractor / date_str / domain_str / str(self.ulid), # ] # for link_path in LINK_PATHS: # link_path.parent.mkdir(parents=True, exist_ok=True)