migrate body API
This commit is contained in:
parent
5811e0e878
commit
9b16d5017a
|
@ -1,7 +1,7 @@
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import uuid
|
||||||
from .html2text import html2text
|
from .html2text import html2text
|
||||||
|
|
||||||
TOOLTIP_REGEX = r"(\/\/\/(.+)\/\/\/)"
|
TOOLTIP_REGEX = r"(\/\/\/(.+)\/\/\/)"
|
||||||
|
@ -236,18 +236,22 @@ def cleanup(body):
|
||||||
return newbody
|
return newbody
|
||||||
|
|
||||||
|
|
||||||
def extract_md(body, oid):
|
def extract_md(body, oid=""):
|
||||||
newbody = body
|
newbody = body
|
||||||
if newbody:
|
if newbody:
|
||||||
newbody = extract_md_images(newbody, oid)
|
uid = oid or uuid.uuid4()
|
||||||
|
newbody = extract_md_images(newbody, uid)
|
||||||
if not newbody:
|
if not newbody:
|
||||||
raise Exception("extract_images error")
|
raise Exception("extract_images error")
|
||||||
|
|
||||||
newbody = cleanup(newbody)
|
newbody = cleanup(newbody)
|
||||||
if not newbody:
|
if not newbody:
|
||||||
raise Exception("cleanup error")
|
raise Exception("cleanup error")
|
||||||
|
|
||||||
newbody, placed = place_tooltips(newbody)
|
newbody, placed = place_tooltips(newbody)
|
||||||
if not newbody:
|
if not newbody:
|
||||||
raise Exception("place_tooltips error")
|
raise Exception("place_tooltips error")
|
||||||
|
|
||||||
if placed:
|
if placed:
|
||||||
newbody = "import Tooltip from '$/components/Article/Tooltip'\n\n" + newbody
|
newbody = "import Tooltip from '$/components/Article/Tooltip'\n\n" + newbody
|
||||||
return newbody
|
return newbody
|
||||||
|
|
|
@ -15,6 +15,8 @@ from resolvers.community import (
|
||||||
get_communities,
|
get_communities,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from resolvers.migrate import markdown_body
|
||||||
|
|
||||||
# from resolvers.collab import invite_author, remove_author
|
# from resolvers.collab import invite_author, remove_author
|
||||||
from resolvers.editor import create_shout, delete_shout, update_shout
|
from resolvers.editor import create_shout, delete_shout, update_shout
|
||||||
from resolvers.profile import (
|
from resolvers.profile import (
|
||||||
|
@ -89,6 +91,8 @@ __all__ = [
|
||||||
"create_shout",
|
"create_shout",
|
||||||
"update_shout",
|
"update_shout",
|
||||||
"delete_shout",
|
"delete_shout",
|
||||||
|
# migrate
|
||||||
|
"markdown_body",
|
||||||
# collab
|
# collab
|
||||||
"invite_author",
|
"invite_author",
|
||||||
"remove_author",
|
"remove_author",
|
||||||
|
|
11
resolvers/migrate.py
Normal file
11
resolvers/migrate.py
Normal 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
|
|
@ -253,6 +253,9 @@ type Query {
|
||||||
# collab
|
# collab
|
||||||
getCollabs: [Collab]!
|
getCollabs: [Collab]!
|
||||||
|
|
||||||
|
# migrate
|
||||||
|
markdownBody(body: String!): String!
|
||||||
|
|
||||||
# topics
|
# topics
|
||||||
topicsAll: [Topic]!
|
topicsAll: [Topic]!
|
||||||
topicsRandom(amount: Int): [Topic]!
|
topicsRandom(amount: Int): [Topic]!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user