Skip to content
Snippets Groups Projects
Commit 58fe4e54 authored by Andreas Domanowski's avatar Andreas Domanowski
Browse files

Refactor archive processing method by extracting free url generation method

parent fb68d8cd
No related branches found
No related tags found
1 merge request!1Hedgedoc import
......@@ -71,24 +71,8 @@ def process_archive_export(archive_file, instance_url, lookup_map, session_id, u
document_content = f.read().decode("UTF-8")
if document_title in lookup_map:
print(
f"You visited your own document \"{document_title}.md\" via the identifier/path " +
f"\"{lookup_map[document_title]}\"")
print(f"Trying to migrate this document and make it available under the already visited path")
try:
new_url = import_single_document(instance_url, lookup_map[document_title], document_content,
session_id)
print(f"Migration was possible. New URL: {instance_url}/{lookup_map[document_title]}")
except HTTPError as error:
if error.status == 409:
print("ATTENTION: Could not migrate document with the same path. Uploading anyways and "
"creating a new, random path")
new_url = import_single_document(instance_url, "", document_content, session_id)
print(f"New URL after document migration without migrating the URL/subpath: {new_url}")
else:
raise SystemExit("Could not create document. Please check your session cookie. Aborting...")
urls_to_visit.append(new_url)
print()
try_generate_free_url_document(document_content, document_title, instance_url, lookup_map, session_id,
urls_to_visit)
else:
print(f"According to your history, you did not visit \"{document_title}.md\" in the CodiMD "
"instance recently. Migrating the document and generating a new, random URL/path for it")
......@@ -97,7 +81,28 @@ def process_archive_export(archive_file, instance_url, lookup_map, session_id, u
print(f"New URL after document migration with new, random URL/subpath: "
f"{generated_url}")
urls_to_visit.append(generated_url)
print()
print()
def try_generate_free_url_document(document_content, document_title, instance_url, lookup_map, session_id,
urls_to_visit):
print(
f"You visited your own document \"{document_title}.md\" via the identifier/path " +
f"\"{lookup_map[document_title]}\"")
print(f"Trying to migrate this document and make it available under the already visited path")
try:
new_url = import_single_document(instance_url, lookup_map[document_title], document_content,
session_id)
print(f"Migration was possible. New URL: {instance_url}/{lookup_map[document_title]}")
except HTTPError as error:
if error.status == 409:
print("ATTENTION: Could not migrate document with the same path. Uploading anyways and "
"creating a new, random path")
new_url = import_single_document(instance_url, "", document_content, session_id)
print(f"New URL after document migration without migrating the URL/subpath: {new_url}")
else:
raise SystemExit("Could not create document. Please check your session cookie. Aborting...")
urls_to_visit.append(new_url)
def create_urls_to_visit_file(filename, urls_to_visit):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment