mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-19 21:24:27 +00:00
Improve summary
This commit is contained in:
parent
3b767eae11
commit
ae28cf2294
5 changed files with 35 additions and 30 deletions
|
@ -12,6 +12,7 @@ from app import config
|
|||
from app.config import AP_CONTENT_TYPE # noqa: F401
|
||||
from app.httpsig import auth
|
||||
from app.key import get_pubkey_as_pem
|
||||
from app.source import hashtagify
|
||||
from app.utils.url import check_url
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@ -81,6 +82,8 @@ class VisibilityEnum(str, enum.Enum):
|
|||
}[key]
|
||||
|
||||
|
||||
_LOCAL_ACTOR_SUMMARY, _LOCAL_ACTOR_TAGS = hashtagify(config.CONFIG.summary)
|
||||
|
||||
ME = {
|
||||
"@context": AS_EXTENDED_CTX,
|
||||
"type": "Person",
|
||||
|
@ -92,7 +95,7 @@ ME = {
|
|||
"outbox": config.BASE_URL + "/outbox",
|
||||
"preferredUsername": config.USERNAME,
|
||||
"name": config.CONFIG.name,
|
||||
"summary": config.CONFIG.summary,
|
||||
"summary": markdown(_LOCAL_ACTOR_SUMMARY, extensions=["mdx_linkify"]),
|
||||
"endpoints": {
|
||||
# For compat with servers expecting a sharedInbox...
|
||||
"sharedInbox": config.BASE_URL
|
||||
|
@ -120,6 +123,7 @@ ME = {
|
|||
"owner": config.ID,
|
||||
"publicKeyPem": get_pubkey_as_pem(config.KEY_PATH),
|
||||
},
|
||||
"tag": _LOCAL_ACTOR_TAGS,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -215,10 +215,13 @@ async def httpsig_checker(
|
|||
logger.exception(f'Failed to fetch HTTP sig key {hsig["keyId"]}')
|
||||
return HTTPSigInfo(has_valid_signature=False)
|
||||
|
||||
has_valid_signature = _verify_h(
|
||||
signed_string, base64.b64decode(hsig["signature"]), k.pubkey
|
||||
)
|
||||
# FIXME: fetch/update the user if the signature is wrong
|
||||
|
||||
httpsig_info = HTTPSigInfo(
|
||||
has_valid_signature=_verify_h(
|
||||
signed_string, base64.b64decode(hsig["signature"]), k.pubkey
|
||||
),
|
||||
has_valid_signature=has_valid_signature,
|
||||
signed_by_ap_actor_id=k.owner,
|
||||
server=server,
|
||||
)
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
import re
|
||||
import typing
|
||||
|
||||
from markdown import markdown
|
||||
from sqlalchemy import select
|
||||
|
||||
from app import models
|
||||
from app import webfinger
|
||||
from app.actor import Actor
|
||||
from app.actor import fetch_actor
|
||||
from app.config import BASE_URL
|
||||
from app.database import AsyncSession
|
||||
from app.utils import emoji
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from app.actor import Actor
|
||||
|
||||
|
||||
def _set_a_attrs(attrs, new=False):
|
||||
attrs[(None, "target")] = "_blank"
|
||||
|
@ -24,9 +25,7 @@ _HASHTAG_REGEX = re.compile(r"(#[\d\w]+)")
|
|||
_MENTION_REGEX = re.compile(r"@[\d\w_.+-]+@[\d\w-]+\.[\d\w\-.]+")
|
||||
|
||||
|
||||
async def _hashtagify(
|
||||
db_session: AsyncSession, content: str
|
||||
) -> tuple[str, list[dict[str, str]]]:
|
||||
def hashtagify(content: str) -> tuple[str, list[dict[str, str]]]:
|
||||
tags = []
|
||||
hashtags = re.findall(_HASHTAG_REGEX, content)
|
||||
hashtags = sorted(set(hashtags), reverse=True) # unique tags, longest first
|
||||
|
@ -41,7 +40,10 @@ async def _hashtagify(
|
|||
async def _mentionify(
|
||||
db_session: AsyncSession,
|
||||
content: str,
|
||||
) -> tuple[str, list[dict[str, str]], list[Actor]]:
|
||||
) -> tuple[str, list[dict[str, str]], list["Actor"]]:
|
||||
from app import models
|
||||
from app.actor import fetch_actor
|
||||
|
||||
tags = []
|
||||
mentioned_actors = []
|
||||
for mention in re.findall(_MENTION_REGEX, content):
|
||||
|
@ -69,19 +71,19 @@ async def _mentionify(
|
|||
async def markdownify(
|
||||
db_session: AsyncSession,
|
||||
content: str,
|
||||
mentionify: bool = True,
|
||||
hashtagify: bool = True,
|
||||
) -> tuple[str, list[dict[str, str]], list[Actor]]:
|
||||
enable_mentionify: bool = True,
|
||||
enable_hashtagify: bool = True,
|
||||
) -> tuple[str, list[dict[str, str]], list["Actor"]]:
|
||||
"""
|
||||
>>> content, tags = markdownify("Hello")
|
||||
|
||||
"""
|
||||
tags = []
|
||||
mentioned_actors: list[Actor] = []
|
||||
if hashtagify:
|
||||
content, hashtag_tags = await _hashtagify(db_session, content)
|
||||
mentioned_actors: list["Actor"] = []
|
||||
if enable_hashtagify:
|
||||
content, hashtag_tags = hashtagify(content)
|
||||
tags.extend(hashtag_tags)
|
||||
if mentionify:
|
||||
if enable_mentionify:
|
||||
content, mention_tags, mentioned_actors = await _mentionify(db_session, content)
|
||||
tags.extend(mention_tags)
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ from typing import Any
|
|||
|
||||
import bcrypt
|
||||
import tomli_w
|
||||
from markdown import markdown # type: ignore
|
||||
|
||||
from app.key import generate_key
|
||||
|
||||
|
@ -44,7 +43,7 @@ def setup_config_file(
|
|||
dat["username"] = username
|
||||
dat["admin_password"] = bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
|
||||
dat["name"] = name
|
||||
dat["summary"] = markdown(summary)
|
||||
dat["summary"] = summary
|
||||
dat["https"] = True
|
||||
proto = "https"
|
||||
dat["icon_url"] = f'{proto}://{dat["domain"]}/static/nopic.png'
|
||||
|
|
|
@ -6,7 +6,6 @@ from typing import Any
|
|||
|
||||
import bcrypt
|
||||
import tomli_w
|
||||
from markdown import markdown # type: ignore
|
||||
from prompt_toolkit import prompt
|
||||
from prompt_toolkit.key_binding import KeyBindings
|
||||
|
||||
|
@ -58,15 +57,13 @@ def main() -> None:
|
|||
prompt("admin password: ", is_password=True).encode(), bcrypt.gensalt()
|
||||
).decode()
|
||||
dat["name"] = prompt("name (e.g. John Doe): ", default=dat["username"])
|
||||
dat["summary"] = markdown(
|
||||
prompt(
|
||||
(
|
||||
"summary (short description, in markdown, "
|
||||
"press [CTRL] + [SPACE] to submit):\n"
|
||||
),
|
||||
key_bindings=_kb,
|
||||
multiline=True,
|
||||
)
|
||||
dat["summary"] = prompt(
|
||||
(
|
||||
"summary (short description, in markdown, "
|
||||
"press [CTRL] + [SPACE] to submit):\n"
|
||||
),
|
||||
key_bindings=_kb,
|
||||
multiline=True,
|
||||
)
|
||||
dat["https"] = True
|
||||
proto = "https"
|
||||
|
|
Loading…
Reference in a new issue