Skip to content

Commit 1967811

Browse files
committed
[fix]: 完成组织转存
1 parent 2ab444a commit 1967811

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

app/api/v1/endpoints/group.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,37 @@ async def disband(group_id: int, db: AsyncSession = Depends(get_db), user: dict
264264
os.remove(article_url)
265265
if avatar_url != "/lhcos-data/group-avatar/default.png":
266266
os.remove(avatar_url)
267-
return {"msg": "Group disbanded successfully"}
267+
return {"msg": "Group disbanded successfully"}
268+
269+
270+
from app.curd.article import get_article_info_in_db_by_id, crud_upload_to_self_folder
271+
@router.put("/copy", response_model=dict)
272+
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)):
273+
"""
274+
Copy an article file by its ID to a specified directory.
275+
"""
276+
# 根据 ID 查询文章信息
277+
file_path, title = await get_article_info_in_db_by_id(db=db, article_id=article_id)
278+
if not file_path:
279+
raise HTTPException(status_code=404, detail="File not found")
280+
281+
old_file_path = file_path
282+
283+
if is_group is not None and is_group is True:
284+
# 表示从群组转存到个人目录
285+
new_article_id = await crud_new_article(
286+
user_id= user.get("id"),
287+
folder_id=folder_id,
288+
article_name=title,
289+
url=old_file_path,
290+
db=db
291+
)
292+
return {"msg": "Article copied successfully", "new_article_id": new_article_id}
293+
else:
294+
new_article_id = await crud_upload_to_self_folder(
295+
name=title,
296+
folder_id=folder_id,
297+
url=old_file_path,
298+
db=db
299+
)
300+
return {"msg": "Article copied successfully", "new_article_id": new_article_id}

app/curd/article.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,14 @@ async def crud_recover(type: int, id: int, db: AsyncSession):
473473
folder.visible = True
474474
await db.commit()
475475
await db.refresh(folder)
476-
return {"info": "Folder recovered successfully"}
476+
return {"info": "Folder recovered successfully"}
477+
478+
async def get_article_info_in_db_by_id(db: AsyncSession, article_id: int):
479+
"""
480+
Get an article by its ID.
481+
"""
482+
result = await db.execute(select(Article).where(Article.id == article_id))
483+
article = result.scalars().first()
484+
if not article:
485+
return None, None
486+
return article.url, article.name

0 commit comments

Comments
 (0)