mirror of https://gitlab.com/litecord/litecord.git
webhooks: finish impl for webhook_avy_redir
- migration.command: fix apply_migration call
This commit is contained in:
parent
ecfe4fa457
commit
feaef1e463
|
|
@ -18,8 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
from os.path import splitext
|
||||
|
||||
from quart import Blueprint, current_app as app, send_file, redirect
|
||||
|
||||
from litecord.embed.sanitizer import make_md_req_url
|
||||
from litecord.embed.schemas import EmbedURL
|
||||
|
||||
bp = Blueprint('images', __name__)
|
||||
|
||||
|
|
@ -63,7 +66,7 @@ async def _get_default_user_avatar(default_id: int):
|
|||
|
||||
|
||||
async def _handle_webhook_avatar(md_url_redir: str):
|
||||
md_url = make_md_req_url(None, 'img', md_url_redir)
|
||||
md_url = make_md_req_url(app.config, 'img', EmbedURL(md_url_redir))
|
||||
return redirect(md_url)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import secrets
|
|||
import hashlib
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
import asyncpg
|
||||
from quart import Blueprint, jsonify, current_app as app, request
|
||||
|
||||
from litecord.auth import token_check
|
||||
|
|
@ -348,19 +349,22 @@ async def create_message_webhook(guild_id, channel_id, webhook_id, data):
|
|||
return message_id
|
||||
|
||||
|
||||
async def _webhook_avy_redir(webhook_id: int, avatar_url):
|
||||
eu_avatar_url = EmbedURL.from_parsed(avatar_url)
|
||||
url_hash = hashlib.sha256(eu_avatar_url.to_md_path).hexdigest()
|
||||
async def _webhook_avy_redir(webhook_id: int, avatar_url: EmbedURL):
|
||||
"""Create a row on webhook_avatars."""
|
||||
url_hash = hashlib.sha256(avatar_url.to_md_path.encode()).hexdigest()
|
||||
|
||||
await app.db.execute("""
|
||||
INSERT INTO webhook_avatars (webhook_id, hash, md_url_redir)
|
||||
VALUES ($1, $2, $3)
|
||||
""", webhook_id, url_hash, proxify(eu_avatar_url))
|
||||
try:
|
||||
await app.db.execute("""
|
||||
INSERT INTO webhook_avatars (webhook_id, hash, md_url_redir)
|
||||
VALUES ($1, $2, $3)
|
||||
""", webhook_id, url_hash, avatar_url.url)
|
||||
except asyncpg.UniqueViolationError:
|
||||
pass
|
||||
|
||||
return url_hash
|
||||
|
||||
|
||||
async def _create_avatar(webhook_id: int, avatar_url) -> str:
|
||||
async def _create_avatar(webhook_id: int, avatar_url: EmbedURL) -> str:
|
||||
"""Create an avatar for a webhook out of an avatar URL,
|
||||
given when executing the webhook.
|
||||
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ async def migrate_cmd(app, _args):
|
|||
migration = ctx.scripts.get(idx)
|
||||
|
||||
print('applying', migration.id, migration.name)
|
||||
# await apply_migration(app, migration)
|
||||
await apply_migration(app, migration)
|
||||
|
||||
|
||||
def setup(subparser):
|
||||
|
|
|
|||
Loading…
Reference in New Issue