Reformat files
This commit is contained in:
parent
caef26ed4b
commit
fda095c195
5 changed files with 52 additions and 49 deletions
|
@ -44,8 +44,8 @@ CREATE TABLE IF NOT EXISTS CHANNEL
|
||||||
-- CREATE INDEX IF NOT EXISTS CHANNEL_COMMENT_INDEX ON COMMENT (ChannelId, CommentId);
|
-- CREATE INDEX IF NOT EXISTS CHANNEL_COMMENT_INDEX ON COMMENT (ChannelId, CommentId);
|
||||||
|
|
||||||
-- VIEWS
|
-- VIEWS
|
||||||
CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS AS SELECT
|
CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS AS
|
||||||
C.CommentId AS comment_id,
|
SELECT C.CommentId AS comment_id,
|
||||||
C.Body AS comment,
|
C.Body AS comment,
|
||||||
C.LbryClaimId AS claim_id,
|
C.LbryClaimId AS claim_id,
|
||||||
C.Timestamp AS timestamp,
|
C.Timestamp AS timestamp,
|
||||||
|
@ -56,9 +56,9 @@ CREATE VIEW IF NOT EXISTS COMMENTS_ON_CLAIMS AS SELECT
|
||||||
C.SigningTs AS signing_ts,
|
C.SigningTs AS signing_ts,
|
||||||
C.ParentId AS parent_id,
|
C.ParentId AS parent_id,
|
||||||
C.IsHidden AS is_hidden
|
C.IsHidden AS is_hidden
|
||||||
FROM COMMENT AS C
|
FROM COMMENT AS C
|
||||||
LEFT OUTER JOIN CHANNEL CHAN ON C.ChannelId = CHAN.ClaimId
|
LEFT OUTER JOIN CHANNEL CHAN ON C.ChannelId = CHAN.ClaimId
|
||||||
ORDER BY C.Timestamp DESC;
|
ORDER BY C.Timestamp DESC;
|
||||||
|
|
||||||
|
|
||||||
DROP VIEW IF EXISTS COMMENT_REPLIES;
|
DROP VIEW IF EXISTS COMMENT_REPLIES;
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
import atexit
|
import atexit
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
import math
|
|
||||||
import nacl.hash
|
import nacl.hash
|
||||||
|
|
||||||
from src.database.schema import CREATE_TABLES_QUERY
|
from src.database.schema import CREATE_TABLES_QUERY
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
SELECT_COMMENTS_ON_CLAIMS = """
|
SELECT_COMMENTS_ON_CLAIMS = """
|
||||||
SELECT comment, comment_id, channel_name, channel_id, channel_url,
|
SELECT comment, comment_id, channel_name, channel_id, channel_url,
|
||||||
timestamp, signature, signing_ts, parent_id, is_hidden
|
timestamp, signature, signing_ts, parent_id, is_hidden
|
||||||
|
@ -95,7 +94,7 @@ def get_claim_hidden_comments(conn: sqlite3.Connection, claim_id: str, hidden=Tr
|
||||||
'items': results,
|
'items': results,
|
||||||
'page': page,
|
'page': page,
|
||||||
'page_size': page_size,
|
'page_size': page_size,
|
||||||
'total_pages': math.ceil(count/page_size),
|
'total_pages': math.ceil(count / page_size),
|
||||||
'total_items': count,
|
'total_items': count,
|
||||||
'has_hidden_comments': claim_has_hidden_comments(conn, claim_id)
|
'has_hidden_comments': claim_has_hidden_comments(conn, claim_id)
|
||||||
}
|
}
|
||||||
|
@ -157,7 +156,7 @@ def get_comment_ids(conn: sqlite3.Connection, claim_id: str, parent_id: str = No
|
||||||
curs = conn.execute("""
|
curs = conn.execute("""
|
||||||
SELECT comment_id FROM COMMENTS_ON_CLAIMS
|
SELECT comment_id FROM COMMENTS_ON_CLAIMS
|
||||||
WHERE claim_id = ? AND parent_id IS NULL LIMIT ? OFFSET ?
|
WHERE claim_id = ? AND parent_id IS NULL LIMIT ? OFFSET ?
|
||||||
""", (claim_id, page_size, page_size*abs(page - 1),)
|
""", (claim_id, page_size, page_size * abs(page - 1),)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
curs = conn.execute("""
|
curs = conn.execute("""
|
||||||
|
|
|
@ -74,4 +74,3 @@ CREATE_TABLES_QUERY = (
|
||||||
CREATE_COMMENTS_ON_CLAIMS_VIEW +
|
CREATE_COMMENTS_ON_CLAIMS_VIEW +
|
||||||
CREATE_COMMENT_REPLIES_VIEW
|
CREATE_COMMENT_REPLIES_VIEW
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
from asyncio import coroutine
|
from asyncio import coroutine
|
||||||
|
|
||||||
from src.database.queries import delete_comment_by_id, get_comments_by_id
|
from src.database.queries import delete_comment_by_id, get_comments_by_id
|
||||||
|
@ -38,7 +37,7 @@ def create_comment_or_error(conn, comment, claim_id, channel_id=None, channel_na
|
||||||
|
|
||||||
def insert_channel_or_error(conn: sqlite3.Connection, channel_name: str, channel_id: str):
|
def insert_channel_or_error(conn: sqlite3.Connection, channel_name: str, channel_id: str):
|
||||||
try:
|
try:
|
||||||
channel_matches_pattern_or_error(channel_id, channel_name)
|
is_valid_channel(channel_id, channel_name)
|
||||||
insert_channel(conn, channel_name, channel_id)
|
insert_channel(conn, channel_name, channel_id)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
logger.exception('Invalid channel values given')
|
logger.exception('Invalid channel values given')
|
||||||
|
@ -63,17 +62,6 @@ async def abandon_comment(app, comment_id): # DELETE
|
||||||
""" Core Functions called by request handlers """
|
""" Core Functions called by request handlers """
|
||||||
|
|
||||||
|
|
||||||
async def abandon_comment_if_authorized(app, comment_id, channel_id, signature, signing_ts, **kwargs):
|
|
||||||
claim = await get_claim_from_id(app, channel_id)
|
|
||||||
if not validate_signature_from_claim(claim, signature, signing_ts, comment_id):
|
|
||||||
return False
|
|
||||||
|
|
||||||
comment = get_comment_or_none(app['reader'], comment_id)
|
|
||||||
job = await app['comment_scheduler'].spawn(abandon_comment(app, comment_id))
|
|
||||||
await app['webhooks'].spawn(send_notification(app, 'DELETE', comment))
|
|
||||||
return await job.wait()
|
|
||||||
|
|
||||||
|
|
||||||
async def create_comment(app, params):
|
async def create_comment(app, params):
|
||||||
if is_valid_base_comment(**params) and is_valid_credential_input(**params):
|
if is_valid_base_comment(**params) and is_valid_credential_input(**params):
|
||||||
job = await app['comment_scheduler'].spawn(write_comment(app, params))
|
job = await app['comment_scheduler'].spawn(write_comment(app, params))
|
||||||
|
@ -113,3 +101,20 @@ async def hide_comments_where_authorized(app, pieces: list) -> list:
|
||||||
|
|
||||||
await job.wait()
|
await job.wait()
|
||||||
return comment_ids
|
return comment_ids
|
||||||
|
|
||||||
|
|
||||||
|
async def edit_comment(app, comment_id, new_comment, channel_id,
|
||||||
|
channel_name, new_signature, new_signing_ts):
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
async def abandon_comment_if_authorized(app, comment_id, channel_id, signature, signing_ts, **kwargs):
|
||||||
|
channel = await get_claim_from_id(app, channel_id)
|
||||||
|
if not validate_signature_from_claim(channel, signature, signing_ts, comment_id):
|
||||||
|
return False
|
||||||
|
|
||||||
|
comment = get_comment_or_none(app['reader'], comment_id)
|
||||||
|
job = await app['comment_scheduler'].spawn(abandon_comment(app, comment_id))
|
||||||
|
await app['webhooks'].spawn(send_notification(app, 'DELETE', comment))
|
||||||
|
return await job.wait()
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import logging.config
|
|
||||||
import logging
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
import logging.config
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from src.settings import config
|
|
||||||
from src.server.app import run_app
|
from src.server.app import run_app
|
||||||
|
from src.settings import config
|
||||||
|
|
||||||
|
|
||||||
def config_logging_from_settings(conf):
|
def config_logging_from_settings(conf):
|
||||||
|
|
Loading…
Reference in a new issue