mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 23:29:49 +00:00
improve file history list (#4586)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# Copyright (c) 2012-2016 Seafile Ltd.
|
# Copyright (c) 2012-2016 Seafile Ltd.
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from rest_framework.authentication import SessionAuthentication
|
from rest_framework.authentication import SessionAuthentication
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
@@ -108,6 +109,14 @@ class FileHistoryView(APIView):
|
|||||||
error_msg = 'Permission denied.'
|
error_msg = 'Permission denied.'
|
||||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
|
# get repo history limit
|
||||||
|
try:
|
||||||
|
keep_days = seafile_api.get_repo_history_limit(repo_id)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
error_msg = 'Internal Server Error'
|
||||||
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||||
|
|
||||||
# get file history
|
# get file history
|
||||||
limit = request.GET.get('limit', 50)
|
limit = request.GET.get('limit', 50)
|
||||||
try:
|
try:
|
||||||
@@ -125,9 +134,14 @@ class FileHistoryView(APIView):
|
|||||||
|
|
||||||
result = []
|
result = []
|
||||||
for commit in file_revisions:
|
for commit in file_revisions:
|
||||||
info = get_file_history_info(commit, avatar_size)
|
present_time = datetime.utcnow()
|
||||||
info['path'] = path
|
history_time = datetime.utcfromtimestamp(commit.ctime)
|
||||||
result.append(info)
|
if (keep_days == -1) or ((present_time - history_time).days < keep_days):
|
||||||
|
info = get_file_history_info(commit, avatar_size)
|
||||||
|
info['path'] = path
|
||||||
|
result.append(info)
|
||||||
|
|
||||||
|
next_start_commit = next_start_commit if result else False
|
||||||
|
|
||||||
return Response({
|
return Response({
|
||||||
"data": result,
|
"data": result,
|
||||||
@@ -182,11 +196,19 @@ class NewFileHistoryView(APIView):
|
|||||||
error_msg = 'Permission denied.'
|
error_msg = 'Permission denied.'
|
||||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
|
# get repo history limit
|
||||||
|
try:
|
||||||
|
history_limit = seafile_api.get_repo_history_limit(repo_id)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(e)
|
||||||
|
error_msg = 'Internal Server Error'
|
||||||
|
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||||
|
|
||||||
start = (page - 1) * per_page
|
start = (page - 1) * per_page
|
||||||
count = per_page
|
count = per_page
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file_revisions, total_count = get_file_history(repo_id, path, start, count)
|
file_revisions, total_count = get_file_history(repo_id, path, start, count, history_limit)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
error_msg = 'Internal Server Error'
|
error_msg = 'Internal Server Error'
|
||||||
|
@@ -712,11 +712,11 @@ if EVENTS_CONFIG_FILE:
|
|||||||
def get_org_user_events(org_id, username, start, count):
|
def get_org_user_events(org_id, username, start, count):
|
||||||
return _get_events(username, start, count, org_id=org_id)
|
return _get_events(username, start, count, org_id=org_id)
|
||||||
|
|
||||||
def get_file_history(repo_id, path, start, count):
|
def get_file_history(repo_id, path, start, count, history_limit=-1):
|
||||||
"""Return file histories
|
"""Return file histories
|
||||||
"""
|
"""
|
||||||
with _get_seafevents_session() as session:
|
with _get_seafevents_session() as session:
|
||||||
res = seafevents.get_file_history(session, repo_id, path, start, count)
|
res = seafevents.get_file_history(session, repo_id, path, start, count, history_limit)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def get_log_events_by_time(log_type, tstart, tend):
|
def get_log_events_by_time(log_type, tstart, tend):
|
||||||
|
Reference in New Issue
Block a user