Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
孙永强 committed May 31, 2024
1 parent b873339 commit 8b660c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
6 changes: 4 additions & 2 deletions seahub/api2/endpoints/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from seaserv import seafile_api
from pysearpc import SearpcError

from seafevents import seafevents_api
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -577,7 +576,7 @@ def delete(self, request, repo_id, format=None):
'size': dir_obj.size
}
try:
from seahub.utils import SeafEventsSession
from seahub.utils import SeafEventsSession, seafevents_api
session = SeafEventsSession()
seafile_api.del_file(repo_id, parent_dir,
json.dumps([dir_name]), username)
Expand All @@ -586,6 +585,9 @@ def delete(self, request, repo_id, format=None):
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
7 changes: 5 additions & 2 deletions seahub/api2/endpoints/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

from seaserv import seafile_api
from pysearpc import SearpcError
from seafevents import seafevents_api

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -876,7 +875,7 @@ def delete(self, request, repo_id, format=None):
'size': file_size
}
try:
from seahub.utils import SeafEventsSession
from seahub.utils import SeafEventsSession, seafevents_api
session = SeafEventsSession()
seafile_api.del_file(repo_id, parent_dir,
json.dumps([file_name]),
Expand All @@ -886,6 +885,10 @@ def delete(self, request, repo_id, format=None):
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
8 changes: 6 additions & 2 deletions seahub/api2/endpoints/repo_trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from seahub.api2.endpoints.group_owned_libraries import get_group_id_by_repo_owner

from seaserv import seafile_api
from seafevents import seafevents_api
from seahub.utils import SeafEventsSession

from pysearpc import SearpcError
from constance import config
Expand Down Expand Up @@ -389,13 +387,16 @@ def post(self, request, repo_id, format=None):
show_time = show_days

try:
from seahub.utils import SeafEventsSession, seafevents_api
session = SeafEventsSession()
deleted_entries = seafevents_api.get_delete_records(session, repo_id, show_time, path)
session.close()
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
except ImportError:
pass

items = []
if len(deleted_entries) >= 1:
Expand Down Expand Up @@ -456,12 +457,15 @@ def delete(self, request, repo_id, format=None):
return api_error(status.HTTP_403_FORBIDDEN, error_msg)

try:
from seahub.utils import SeafEventsSession, seafevents_api
session = SeafEventsSession()
seafevents_api.clean_up_repo_trash(session, repo_id, keep_days)
session.close()
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
except ImportError:
pass

return Response({'success': True})
9 changes: 7 additions & 2 deletions seahub/api2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@
create_org, ccnet_api

from constance import config
from seafevents import seafevents_api
from seahub.utils import SeafEventsSession


logger = logging.getLogger(__name__)
json_content_type = 'application/json; charset=utf-8'
Expand Down Expand Up @@ -3353,6 +3352,7 @@ def put(self, request, repo_id, format=None):
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)
Expand All @@ -3361,6 +3361,8 @@ def put(self, request, repo_id, format=None):
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 @@ -3860,6 +3862,7 @@ def put(self, request, repo_id):
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)
Expand All @@ -3868,6 +3871,8 @@ def put(self, request, repo_id):
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 8b660c3

Please sign in to comment.