Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
孙永强 committed Jul 1, 2024
1 parent b056eb5 commit 7a7a9c4
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 55 deletions.
19 changes: 1 addition & 18 deletions seahub/api2/endpoints/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,32 +562,15 @@ def delete(self, request, repo_id, format=None):
username = request.user.username
parent_dir = os.path.dirname(path)
dir_name = os.path.basename(path)
dir_obj = seafile_api.get_dirent_by_path(repo_id, path)

record = {
'op_user': username,
'obj_type': 'dir',
'obj_id': dir_obj.obj_id,
'obj_name': dir_name,
'timestamp': datetime.utcfromtimestamp(dir_obj.mtime),
'repo_id': repo_id,
'path': parent_dir,
'commit_id': repo.head_cmmt_id,
'size': dir_obj.size
}
try:
from seahub.utils import SeafEventsSession, seafevents_api
session = SeafEventsSession()

seafile_api.del_file(repo_id, parent_dir,
json.dumps([dir_name]), username)
seafevents_api.save_repo_trash(session, record)
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
except ImportError:
seafile_api.del_file(repo_id, parent_dir,
json.dumps([dir_name]), username)

result = {}
result['success'] = True
Expand Down
20 changes: 0 additions & 20 deletions seahub/api2/endpoints/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,34 +861,14 @@ def delete(self, request, repo_id, format=None):

# delete file
file_name = os.path.basename(path)
file_size = seafile_api.get_file_size(repo_id, repo.version, file_id)

record = {
'op_user': username,
'obj_type': 'file',
'obj_id': file_id,
'obj_name': file_name,
'timestamp': datetime.datetime.utcfromtimestamp(int(time.time())),
'repo_id': repo_id,
'path': parent_dir,
'commit_id': repo.head_cmmt_id,
'size': file_size
}
try:
from seahub.utils import SeafEventsSession, seafevents_api
session = SeafEventsSession()
seafile_api.del_file(repo_id, parent_dir,
json.dumps([file_name]),
request.user.username)
seafevents_api.save_repo_trash(session, record)
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
except ImportError:
seafile_api.del_file(repo_id, parent_dir,
json.dumps([file_name]),
request.user.username)

try: # rm sdoc fileuuid
filetype, fileext = get_file_type_and_ext(file_name)
Expand Down
2 changes: 1 addition & 1 deletion seahub/api2/endpoints/repo_trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class RepoTrash2(APIView):
def get_item_info(self, trash_item):

item_info = {
'parent_dir': '/' if trash_item.path == '/' else trash_item.path + '/',
'parent_dir': '/' if trash_item.path == '/' else trash_item.path,
'obj_name': trash_item.obj_name,
'deleted_time': timestamp_to_isoformat_timestr(int(trash_item.delete_time.timestamp())),
'commit_id': trash_item.commit_id,
Expand Down
17 changes: 1 addition & 16 deletions seahub/api2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3349,20 +3349,12 @@ def put(self, request, repo_id, format=None):
return api_error(status.HTTP_403_FORBIDDEN, error_msg)

username = request.user.username
file_name = os.path.basename(path)
parent_path = os.path.dirname(path)
try:
from seahub.utils import SeafEventsSession, seafevents_api
session = SeafEventsSession()
seafile_api.revert_file(repo_id, commit_id, path, username)
seafevents_api.restore_repo_trash(session, repo_id, file_name, parent_path)
session.close()
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
except ImportError:
seafile_api.revert_file(repo_id, commit_id, path, username)

return Response({'success': True})

Expand Down Expand Up @@ -3858,21 +3850,14 @@ def put(self, request, repo_id):
if check_folder_permission(request, repo_id, '/') != 'rw':
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
parent_dir = os.path.dirname(path)
dir_name = os.path.basename(path)

username = request.user.username
try:
from seahub.utils import SeafEventsSession, seafevents_api
session = SeafEventsSession()
seafile_api.revert_dir(repo_id, commit_id, path, username)
seafevents_api.restore_repo_trash(session, repo_id, dir_name, parent_dir)
session.close()
except SearpcError as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
except ImportError:
seafile_api.revert_dir(repo_id, commit_id, path, username)

return Response({'success': True})

Expand Down

0 comments on commit 7a7a9c4

Please sign in to comment.