|
@@ -3,7 +3,8 @@ from typing import Optional, List
|
|
import core.file
|
|
import core.file
|
|
|
|
|
|
|
|
|
|
-def write_blog(auth_id: int, title: str, subtitle:str, context: str, file_list: List[core.file.File]) -> bool:
|
|
|
|
|
|
+def create_blog(auth_id: int, title: str, subtitle:str, context: str, file_list: List[core.file.File]) -> bool:
|
|
|
|
+ """写入新的blog"""
|
|
cur = db.insert(table="blog", columns=["Auth", "Title", "SubTitle", "Context"],
|
|
cur = db.insert(table="blog", columns=["Auth", "Title", "SubTitle", "Context"],
|
|
values=f"{auth_id}, '{title}', '{subtitle}', '{context}'")
|
|
values=f"{auth_id}, '{title}', '{subtitle}', '{context}'")
|
|
if cur is None or cur.rowcount == 0:
|
|
if cur is None or cur.rowcount == 0:
|
|
@@ -18,6 +19,7 @@ def write_blog(auth_id: int, title: str, subtitle:str, context: str, file_list:
|
|
|
|
|
|
|
|
|
|
def read_blog(blog_id: int) -> list:
|
|
def read_blog(blog_id: int) -> list:
|
|
|
|
+ """读取blog内容"""
|
|
cur = db.search(columns=["Auth", "Title", "SubTitle", "Context", "Quote", "Spider", "UpdateTime", "Top"],
|
|
cur = db.search(columns=["Auth", "Title", "SubTitle", "Context", "Quote", "Spider", "UpdateTime", "Top"],
|
|
table="blog",
|
|
table="blog",
|
|
where=f"ID={blog_id}")
|
|
where=f"ID={blog_id}")
|
|
@@ -26,7 +28,21 @@ def read_blog(blog_id: int) -> list:
|
|
return cur.fetchone()
|
|
return cur.fetchone()
|
|
|
|
|
|
|
|
|
|
|
|
+def delete_blog(blog_id: int):
|
|
|
|
+ cur = db.delete(table="blog_file", where=f"BlogID={blog_id}")
|
|
|
|
+ if cur is None:
|
|
|
|
+ return False
|
|
|
|
+ cur = db.delete(table="comment", where=f"BlogID={blog_id}")
|
|
|
|
+ if cur is None:
|
|
|
|
+ return False
|
|
|
|
+ cur = db.delete(table="blog", where=f"ID={blog_id}")
|
|
|
|
+ if cur is None or cur.rowcount == 0:
|
|
|
|
+ return False
|
|
|
|
+ return True
|
|
|
|
+
|
|
|
|
+
|
|
def get_blog_list(limit: Optional[int] = None, offset: Optional[int] = None) -> list:
|
|
def get_blog_list(limit: Optional[int] = None, offset: Optional[int] = None) -> list:
|
|
|
|
+ """获得 blog 列表"""
|
|
cur = db.search(columns=["ID", "Title", "SubTitle", "UpdateTime", "Top"], table="blog_with_top",
|
|
cur = db.search(columns=["ID", "Title", "SubTitle", "UpdateTime", "Top"], table="blog_with_top",
|
|
limit=limit,
|
|
limit=limit,
|
|
offset=offset)
|
|
offset=offset)
|
|
@@ -36,6 +52,7 @@ def get_blog_list(limit: Optional[int] = None, offset: Optional[int] = None) ->
|
|
|
|
|
|
|
|
|
|
def get_blog_list_not_top(limit: Optional[int] = None, offset: Optional[int] = None) -> list:
|
|
def get_blog_list_not_top(limit: Optional[int] = None, offset: Optional[int] = None) -> list:
|
|
|
|
+ """ 获得blog列表 忽略置顶 """
|
|
cur = db.search(columns=["ID", "Title", "SubTitle", "UpdateTime"], table="blog",
|
|
cur = db.search(columns=["ID", "Title", "SubTitle", "UpdateTime"], table="blog",
|
|
order_by=[("UpdateTime", "DESC")],
|
|
order_by=[("UpdateTime", "DESC")],
|
|
limit=limit,
|
|
limit=limit,
|
|
@@ -46,13 +63,15 @@ def get_blog_list_not_top(limit: Optional[int] = None, offset: Optional[int] = N
|
|
|
|
|
|
|
|
|
|
def get_blog_count() -> int:
|
|
def get_blog_count() -> int:
|
|
|
|
+ """ 统计 blog 个数 """
|
|
cur = db.search(columns=["count(ID)"], table="blog")
|
|
cur = db.search(columns=["count(ID)"], table="blog")
|
|
if cur is None or cur.rowcount == 0:
|
|
if cur is None or cur.rowcount == 0:
|
|
return 0
|
|
return 0
|
|
return cur.fetchone()[0]
|
|
return cur.fetchone()[0]
|
|
|
|
|
|
|
|
|
|
-def get_blog_list_with_file(file_id, limit: Optional[int] = None, offset: Optional[int] = None) -> list:
|
|
|
|
|
|
+def get_file_blog_list(file_id, limit: Optional[int] = None, offset: Optional[int] = None) -> list:
|
|
|
|
+ """ 获得指定归档的 blog 列表 """
|
|
cur = db.search(columns=["BlogID", "Title", "SubTitle", "UpdateTime", "Top"], table="blog_with_file",
|
|
cur = db.search(columns=["BlogID", "Title", "SubTitle", "UpdateTime", "Top"], table="blog_with_file",
|
|
where=f"FileID={file_id}",
|
|
where=f"FileID={file_id}",
|
|
limit=limit,
|
|
limit=limit,
|
|
@@ -62,7 +81,8 @@ def get_blog_list_with_file(file_id, limit: Optional[int] = None, offset: Option
|
|
return cur.fetchall()
|
|
return cur.fetchall()
|
|
|
|
|
|
|
|
|
|
-def get_blog_with_file_count(file_id) -> int:
|
|
|
|
|
|
+def get_file_blog_count(file_id) -> int:
|
|
|
|
+ """ 统计指定归档的 blog 个数 """
|
|
cur = db.search(columns=["count(ID)"], table="blog_with_file",
|
|
cur = db.search(columns=["count(ID)"], table="blog_with_file",
|
|
where=f"FileID={file_id}")
|
|
where=f"FileID={file_id}")
|
|
if cur is None or cur.rowcount == 0:
|
|
if cur is None or cur.rowcount == 0:
|
|
@@ -70,7 +90,8 @@ def get_blog_with_file_count(file_id) -> int:
|
|
return cur.fetchone()[0]
|
|
return cur.fetchone()[0]
|
|
|
|
|
|
|
|
|
|
-def get_blog_user_count(user_id: int) -> int:
|
|
|
|
|
|
+def get_user_user_count(user_id: int) -> int:
|
|
|
|
+ """ 获得指定用户的 blog 个数 """
|
|
cur = db.search(columns=["count(ID)"], table="blog",
|
|
cur = db.search(columns=["count(ID)"], table="blog",
|
|
where=f"Auth={user_id}")
|
|
where=f"Auth={user_id}")
|
|
if cur is None or cur.rowcount == 0:
|
|
if cur is None or cur.rowcount == 0:
|