From 1967811822519f1723b85a626caca51a37ddfdf5 Mon Sep 17 00:00:00 2001 From: Fantasy lee <129943055+Fantasylee21@users.noreply.github.com> Date: Sat, 7 Jun 2025 11:34:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[fix]:=20=E5=AE=8C=E6=88=90=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E8=BD=AC=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/endpoints/group.py | 35 ++++++++++++++++++++++++++++++++++- app/curd/article.py | 12 +++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/api/v1/endpoints/group.py b/app/api/v1/endpoints/group.py index ad93b33..d3ac5f9 100644 --- a/app/api/v1/endpoints/group.py +++ b/app/api/v1/endpoints/group.py @@ -264,4 +264,37 @@ async def disband(group_id: int, db: AsyncSession = Depends(get_db), user: dict os.remove(article_url) if avatar_url != "/lhcos-data/group-avatar/default.png": os.remove(avatar_url) - return {"msg": "Group disbanded successfully"} \ No newline at end of file + return {"msg": "Group disbanded successfully"} + + +from app.curd.article import get_article_info_in_db_by_id, crud_upload_to_self_folder +@router.put("/copy", response_model=dict) +async def copy_article(folder_id: int, article_id: int, is_group: Optional[bool] = None, db : AsyncSession = Depends(get_db), user: dict = Depends(get_current_user)): + """ + Copy an article file by its ID to a specified directory. + """ + # 根据 ID 查询文章信息 + file_path, title = await get_article_info_in_db_by_id(db=db, article_id=article_id) + if not file_path: + raise HTTPException(status_code=404, detail="File not found") + + old_file_path = file_path + + if is_group is not None and is_group is True: + # 表示从群组转存到个人目录 + new_article_id = await crud_new_article( + user_id= user.get("id"), + folder_id=folder_id, + article_name=title, + url=old_file_path, + db=db + ) + return {"msg": "Article copied successfully", "new_article_id": new_article_id} + else: + new_article_id = await crud_upload_to_self_folder( + name=title, + folder_id=folder_id, + url=old_file_path, + db=db + ) + return {"msg": "Article copied successfully", "new_article_id": new_article_id} diff --git a/app/curd/article.py b/app/curd/article.py index b5ebd87..d3bb78f 100644 --- a/app/curd/article.py +++ b/app/curd/article.py @@ -473,4 +473,14 @@ async def crud_recover(type: int, id: int, db: AsyncSession): folder.visible = True await db.commit() await db.refresh(folder) - return {"info": "Folder recovered successfully"} \ No newline at end of file + return {"info": "Folder recovered successfully"} + +async def get_article_info_in_db_by_id(db: AsyncSession, article_id: int): + """ + Get an article by its ID. + """ + result = await db.execute(select(Article).where(Article.id == article_id)) + article = result.scalars().first() + if not article: + return None, None + return article.url, article.name \ No newline at end of file From 1bf936ca795815a76bb2626fc55c031019715ee3 Mon Sep 17 00:00:00 2001 From: Fantasy lee <129943055+Fantasylee21@users.noreply.github.com> Date: Sat, 7 Jun 2025 11:40:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[fix]:=20=E8=BF=9B=E4=B8=80=E6=AD=A5?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=BD=9C=E5=9C=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/endpoints/group.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/api/v1/endpoints/group.py b/app/api/v1/endpoints/group.py index d3ac5f9..e536ae1 100644 --- a/app/api/v1/endpoints/group.py +++ b/app/api/v1/endpoints/group.py @@ -279,14 +279,19 @@ async def copy_article(folder_id: int, article_id: int, is_group: Optional[bool] raise HTTPException(status_code=404, detail="File not found") old_file_path = file_path + new_file_path = f"/lhcos-data/{uuid.uuid4()}.pdf" + with open(old_file_path, "rb") as source_file: + with open(new_file_path, "wb") as dest_file: + dest_file.write(source_file.read()) + if is_group is not None and is_group is True: # 表示从群组转存到个人目录 new_article_id = await crud_new_article( user_id= user.get("id"), folder_id=folder_id, article_name=title, - url=old_file_path, + url=new_file_path, db=db ) return {"msg": "Article copied successfully", "new_article_id": new_article_id} @@ -294,7 +299,7 @@ async def copy_article(folder_id: int, article_id: int, is_group: Optional[bool] new_article_id = await crud_upload_to_self_folder( name=title, folder_id=folder_id, - url=old_file_path, + url=new_file_path, db=db ) return {"msg": "Article copied successfully", "new_article_id": new_article_id}