Remove mastodon posts on delete and OTP
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
## Copyright © 2026 Olaf Kolkman
|
||||
## SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import json
|
||||
from fastapi import APIRouter, Header, HTTPException, status
|
||||
import logging
|
||||
from pydantic import BaseModel
|
||||
|
||||
from backend.app.services.link_service import create_link, delete_link, get_link_tags, list_public_links, list_tags, mark_mastodon_posted, update_link
|
||||
from backend.app.services.link_service import create_link, delete_link, get_link_tags, get_owned_link, list_public_links, list_tags, mark_mastodon_posted, update_link
|
||||
from backend.app.database import get_connection
|
||||
from backend.app.services.plugin_manager import plugin_manager
|
||||
from backend.app.services.token_service import validate_token
|
||||
@@ -87,6 +88,16 @@ def delete_link_endpoint(
|
||||
info = validate_token(authorization.replace('Bearer ', '', 1))
|
||||
if info is None:
|
||||
raise HTTPException(status_code=401, detail='Token expired or invalid')
|
||||
link = get_owned_link(link_id, info['user_id'])
|
||||
if link is None:
|
||||
raise HTTPException(status_code=404, detail='Link not found or not owned by user')
|
||||
post_ids = json.loads(link['mastodon_post_ids']) if link.get('mastodon_post_ids') else []
|
||||
if not post_ids and link.get('mastodon_post_id'):
|
||||
post_ids = [link['mastodon_post_id']]
|
||||
if post_ids:
|
||||
result = plugin_manager.delete_mastodon_posts({**link, 'mastodon_post_ids': post_ids})
|
||||
if result.get('status') != 'deleted':
|
||||
raise HTTPException(status_code=502, detail=result.get('reason', 'Could not delete Mastodon posts'))
|
||||
if not delete_link(link_id, info['user_id']):
|
||||
raise HTTPException(status_code=404, detail='Link not found or not owned by user')
|
||||
return {'status': 'deleted', 'id': link_id}
|
||||
|
||||
Reference in New Issue
Block a user