migrate body API

This commit is contained in:
tonyrewin 2022-10-05 12:32:48 +03:00
parent 5811e0e878
commit 9b16d5017a
4 changed files with 25 additions and 3 deletions

View File

@ -1,7 +1,7 @@
import base64
import os
import re
import uuid
from .html2text import html2text
TOOLTIP_REGEX = r"(\/\/\/(.+)\/\/\/)"
@ -236,18 +236,22 @@ def cleanup(body):
return newbody
def extract_md(body, oid):
def extract_md(body, oid=""):
newbody = body
if newbody:
newbody = extract_md_images(newbody, oid)
uid = oid or uuid.uuid4()
newbody = extract_md_images(newbody, uid)
if not newbody:
raise Exception("extract_images error")
newbody = cleanup(newbody)
if not newbody:
raise Exception("cleanup error")
newbody, placed = place_tooltips(newbody)
if not newbody:
raise Exception("place_tooltips error")
if placed:
newbody = "import Tooltip from '$/components/Article/Tooltip'\n\n" + newbody
return newbody

View File

@ -15,6 +15,8 @@ from resolvers.community import (
get_communities,
)
from resolvers.migrate import markdown_body
# from resolvers.collab import invite_author, remove_author
from resolvers.editor import create_shout, delete_shout, update_shout
from resolvers.profile import (
@ -89,6 +91,8 @@ __all__ = [
"create_shout",
"update_shout",
"delete_shout",
# migrate
"markdown_body",
# collab
"invite_author",
"remove_author",

11
resolvers/migrate.py Normal file
View File

@ -0,0 +1,11 @@
from base.orm import query
from resoolvers.auth import login_required
from migration.extract import extract_md
@login_required
@query.field("markdownBody")
def markdown_body(_, info, body):
body = extract_md(body)
return body

View File

@ -253,6 +253,9 @@ type Query {
# collab
getCollabs: [Collab]!
# migrate
markdownBody(body: String!): String!
# topics
topicsAll: [Topic]!
topicsRandom(amount: Int): [Topic]!