Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CodiMD export script
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stgroup
misc
CodiMD export script
Commits
58fe4e54
Commit
58fe4e54
authored
2 years ago
by
Andreas Domanowski
Browse files
Options
Downloads
Patches
Plain Diff
Refactor archive processing method by extracting free url generation method
parent
fb68d8cd
No related branches found
No related tags found
1 merge request
!1
Hedgedoc import
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
import_md/hedgedoc_import.py
+24
-19
24 additions, 19 deletions
import_md/hedgedoc_import.py
with
24 additions
and
19 deletions
import_md/hedgedoc_import.py
+
24
−
19
View file @
58fe4e54
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment