1111
1212from app .utils .get_db import get_db
1313from app .utils .auth import get_current_user
14- from app .curd .article import crud_upload_to_self_folder , crud_get_self_folders , crud_get_articles_in_folder , crud_self_create_folder , crud_self_article_to_recycle_bin , crud_self_folder_to_recycle_bin , crud_read_article , crud_import_self_folder , crud_export_self_folder ,crud_create_tag , crud_delete_tag , crud_get_article_tags , crud_all_tags_order , crud_change_folder_name , crud_change_article_name
14+ from app .curd .article import crud_upload_to_self_folder , crud_get_self_folders , crud_get_articles_in_folder , crud_self_create_folder , crud_self_article_to_recycle_bin , crud_self_folder_to_recycle_bin , crud_read_article , crud_import_self_folder , crud_export_self_folder ,crud_create_tag , crud_delete_tag , crud_get_article_tags , crud_all_tags_order , crud_change_folder_name , crud_change_article_name , crud_article_statistic
1515from app .schemas .article import SelfCreateFolder
1616
1717router = APIRouter ()
@@ -25,10 +25,9 @@ async def upload_to_self_folder(folder_id: int = Query(...), article: UploadFile
2525 # 新建 Article 记录
2626 article_id = await crud_upload_to_self_folder (name , folder_id , db )
2727
28- # 存储文件,暂时存储到本地
29- save_dir = "articles"
30- os .makedirs (save_dir , exist_ok = True ) # 如果目录不存在则创建
31- save_path = os .path .join (save_dir , f"{ article_id } .pdf" )
28+ # 存储到云存储位置
29+ os .makedirs ("/lhcos-data" , exist_ok = True )
30+ save_path = os .path .join ("/lhcos-data" , f"{ article_id } .pdf" )
3231 with open (save_path , "wb" ) as f :
3332 content = await article .read ()
3433 f .write (content )
@@ -82,10 +81,8 @@ async def self_folder_to_recycle_bin(folder_id: int = Query(...), db: AsyncSessi
8281
8382@router .post ("/annotateSelfArticle" , response_model = "dict" )
8483async def annotate_self_article (article_id : int = Query (...), article : UploadFile = File (...)):
85- # 存储文件,将新文件暂时存储到本地
86- save_dir = "articles"
87- os .makedirs (save_dir , exist_ok = True ) # 如果目录不存在则创建
88- save_path = os .path .join (save_dir , f"{ article_id } .pdf" )
84+ # 将新文件存储到云存储位置
85+ save_path = os .path .join ("/lhcos-data" , f"{ article_id } .pdf" )
8986 with open (save_path , "wb" ) as f :
9087 content = await article .read ()
9188 f .write (content )
@@ -95,7 +92,7 @@ async def annotate_self_article(article_id: int = Query(...), article: UploadFil
9592@router .get ("/readArticle" , response_class = FileResponse )
9693async def read_article (article_id : int = Query (...), db : AsyncSession = Depends (get_db )):
9794
98- file_path = f"articles /{ article_id } .pdf"
95+ file_path = f"/lhcos-data /{ article_id } .pdf"
9996
10097 # 查询文件名
10198 article_name = await crud_read_article (article_id , db )
@@ -119,14 +116,13 @@ async def import_self_folder(folder_name: str = Query(...), zip: UploadFile = Fi
119116 # 记入数据库
120117 result = await crud_import_self_folder (folder_name , article_names , user_id , db )
121118
122- # 存储文献,暂时存储到本地
123- os .makedirs ("articles" , exist_ok = True )
119+ # 存储文献到云存储
124120 for i in range (0 , len (result ), 2 ):
125121 article_id = result [i ]
126122 article_name = result [i + 1 ]
127123 pdf_filename_in_zip = f"{ article_name } .pdf"
128124 with zip_file .open (pdf_filename_in_zip ) as source_file :
129- target_path = os .path .join ("articles " , f"{ article_id } .pdf" )
125+ target_path = os .path .join ("/lhcos-data " , f"{ article_id } .pdf" )
130126 with open (target_path , "wb" ) as out_file :
131127 out_file .write (source_file .read ())
132128
@@ -141,7 +137,7 @@ async def export_self_folder(background_tasks: BackgroundTasks, folder_id: int =
141137
142138 with zipfile .ZipFile (zip_path , "w" , zipfile .ZIP_DEFLATED ) as zipf :
143139 for article_id , article_name in zip (article_ids , article_names ):
144- pdf_path = os .path .join ("articles " , f"{ article_id } .pdf" )
140+ pdf_path = os .path .join ("/lhcos-data " , f"{ article_id } .pdf" )
145141 arcname = f"{ article_name } .pdf" # 压缩包内的文件名
146142 zipf .write (pdf_path , arcname = arcname )
147143
0 commit comments