fix bugs of solo_file_fetcher
This commit is contained in:
parent
b4fb889c5e
commit
05b1b18af8
@ -26,6 +26,7 @@ def listlog():
|
|||||||
|
|
||||||
return jsonify(res), 200
|
return jsonify(res), 200
|
||||||
|
|
||||||
|
|
||||||
# 指定顯示特定一條log
|
# 指定顯示特定一條log
|
||||||
@log.route("/<int:id>", methods = ["GET"])
|
@log.route("/<int:id>", methods = ["GET"])
|
||||||
def getlog(id:int):
|
def getlog(id:int):
|
||||||
|
@ -184,8 +184,9 @@ def solo_article_fetcher(role:str, key) -> Tuple[Dict, int]: # admin, owner, gen
|
|||||||
"content": res[1],
|
"content": res[1],
|
||||||
"files_hash": res[2],
|
"files_hash": res[2],
|
||||||
"igid": res[3],
|
"igid": res[3],
|
||||||
"comments_hash": [ c.sha1 for c in res[4] ]
|
|
||||||
}
|
}
|
||||||
|
if res[4]:
|
||||||
|
one["comments_hash"] = [ c.sha1 for c in res[4] ]
|
||||||
|
|
||||||
if role == "admin":
|
if role == "admin":
|
||||||
one["ip"] = res[6]
|
one["ip"] = res[6]
|
||||||
@ -194,6 +195,7 @@ def solo_article_fetcher(role:str, key) -> Tuple[Dict, int]: # admin, owner, gen
|
|||||||
|
|
||||||
return one, 200
|
return one, 200
|
||||||
|
|
||||||
|
|
||||||
# role (general) (owner) (admin)
|
# role (general) (owner) (admin)
|
||||||
# 獲取單一留言
|
# 獲取單一留言
|
||||||
def solo_comment_fetcher(role:str, key) -> Tuple[Dict, int]: # admin, owner, general
|
def solo_comment_fetcher(role:str, key) -> Tuple[Dict, int]: # admin, owner, general
|
||||||
@ -362,14 +364,14 @@ def solo_comment_remover(role:str, hash:str=None, sha1:str=None) -> Tuple[Dict,
|
|||||||
|
|
||||||
# 獲取檔案
|
# 獲取檔案
|
||||||
def solo_file_fetcher(role:str, fnhash:str) -> Tuple[Response, int]: # general, admin
|
def solo_file_fetcher(role:str, fnhash:str) -> Tuple[Response, int]: # general, admin
|
||||||
article = pgclass.SQLarticle
|
|
||||||
article_mark = pgclass.SQLmark
|
|
||||||
|
|
||||||
with db.getsession() as session:
|
with db.getsession() as session:
|
||||||
arta = session.query(article).join(article_mark, article_mark.hash == article.hash).filter(article.file_list == func.any(fnhash))
|
arta="SELECT posts.id, posts.hash, mark.mark, f FROM posts " \
|
||||||
|
+"JOIN unnest(file_list) AS f ON 1=1 " \
|
||||||
|
+"JOIN mark ON posts.hash = mark.hash " \
|
||||||
|
+"WHERE f = :fnhash "
|
||||||
if role == "general":
|
if role == "general":
|
||||||
arta = arta.filter(article_mark == 'visible')
|
arta += "AND mark.mark = 'visible'"
|
||||||
aeta = arta.first()
|
arta = session.execute(text(arta), {'fnhash':fnhash}).first()
|
||||||
if arta is None: # 檢查文章本體是否存在/可以閱覽
|
if arta is None: # 檢查文章本體是否存在/可以閱覽
|
||||||
return error("File not found"), 404
|
return error("File not found"), 404
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import io
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import minio
|
import minio
|
||||||
|
from minio.deleteobjects import DeleteObject
|
||||||
|
|
||||||
S3_BUCKET = os.getenv("S3_BUCKET")
|
S3_BUCKET = os.getenv("S3_BUCKET")
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ s3 = minio.Minio(endpoint=os.getenv("S3_ENDPOINT"),
|
|||||||
|
|
||||||
# check exist
|
# check exist
|
||||||
if not s3.bucket_exists(S3_BUCKET):
|
if not s3.bucket_exists(S3_BUCKET):
|
||||||
print("[!] Where is S3 bucket \"%s\"?"%S3_BUCKET)
|
print("Where is S3 bucket \"%s\"?"%S3_BUCKET)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# methods
|
# methods
|
||||||
@ -60,8 +61,7 @@ def solo_file_fetcher(fnhash:str) -> Tuple[dict | None, int]:
|
|||||||
|
|
||||||
def multi_file_remover(file_list) -> int:
|
def multi_file_remover(file_list) -> int:
|
||||||
try:
|
try:
|
||||||
for f in file_list:
|
s3.remove_objects(S3_BUCKET, [ DeleteObject(f) for f in file_list ])
|
||||||
s3.remove_object(S3_BUCKET, f)
|
|
||||||
return 0
|
return 0
|
||||||
except:
|
except:
|
||||||
return 1
|
return 1
|
Loading…
Reference in New Issue
Block a user