1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 10:50:24 +00:00

added /api2/server-info/ endpoint

This commit is contained in:
lins05
2014-12-25 12:27:44 +09:00
parent d0971e4ae9
commit 4a9f7ed454
5 changed files with 57 additions and 5 deletions

View File

@@ -1,12 +1,14 @@
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
from views import * from .views import *
from .views_misc import ServerInfoView
urlpatterns = patterns('', urlpatterns = patterns('',
url(r'^ping/$', Ping.as_view()), url(r'^ping/$', Ping.as_view()),
url(r'^auth/ping/$', AuthPing.as_view()), url(r'^auth/ping/$', AuthPing.as_view()),
url(r'^auth-token/', ObtainAuthToken.as_view()), url(r'^auth-token/', ObtainAuthToken.as_view()),
url(r'^server-info/$', ServerInfoView.as_view()),
# RESTful API # RESTful API
url(r'^accounts/$', Accounts.as_view(), name="accounts"), url(r'^accounts/$', Accounts.as_view(), name="accounts"),
@@ -75,7 +77,7 @@ urlpatterns = patterns('',
url(r'^html/usermsgs/(?P<id_or_email>[^/]+)/$', UserMsgsHtml.as_view()), url(r'^html/usermsgs/(?P<id_or_email>[^/]+)/$', UserMsgsHtml.as_view()),
url(r'^html/more_usermsgs/(?P<id_or_email>[^/]+)/$', AjaxUserMsgs.as_view(), name="api_more_usermsgs"), url(r'^html/more_usermsgs/(?P<id_or_email>[^/]+)/$', AjaxUserMsgs.as_view(), name="api_more_usermsgs"),
# Folowing is only for debug, will be removed # Folowing is only for debug, will be removed
#url(r'^html/newreply2/$', api_new_replies), #url(r'^html/newreply2/$', api_new_replies),
#url(r'^html/events2/$', activity2), #url(r'^html/events2/$', activity2),
#url(r'^html/more_events/$', events2, name="more_events"), #url(r'^html/more_events/$', events2, name="more_events"),
@@ -87,8 +89,7 @@ urlpatterns = patterns('',
#url(r'^html/usermsgs2/(?P<id_or_email>[^/]+)/$', api_usermsgs), #url(r'^html/usermsgs2/(?P<id_or_email>[^/]+)/$', api_usermsgs),
#url(r'^html/more_usermsgs/(?P<id_or_email>[^/]+)/$', api_more_usermsgs, name="api_more_usermsgs"), #url(r'^html/more_usermsgs/(?P<id_or_email>[^/]+)/$', api_more_usermsgs, name="api_more_usermsgs"),
# Deprecated
# Deprecated
url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/fileops/delete/$', OpDeleteView.as_view()), url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/fileops/delete/$', OpDeleteView.as_view()),
url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/fileops/copy/$', OpCopyView.as_view()), url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/fileops/copy/$', OpCopyView.as_view()),
url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/fileops/move/$', OpMoveView.as_view()), url(r'^repos/(?P<repo_id>[-0-9-a-f]{36})/fileops/move/$', OpMoveView.as_view()),

View File

@@ -3,10 +3,13 @@
import os import os
import time import time
import json
from collections import defaultdict from collections import defaultdict
from functools import wraps
from django.core.paginator import EmptyPage, InvalidPage from django.core.paginator import EmptyPage, InvalidPage
from django.http import HttpResponse
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from seaserv import seafile_api, get_commits, server_repo_size, \ from seaserv import seafile_api, get_commits, server_repo_size, \
@@ -505,3 +508,12 @@ def get_diff_details(repo_id, commit1, commit2):
result['deleted_dirs'].append(d.name) result['deleted_dirs'].append(d.name)
return result return result
JSON_CONTENT_TYPE = 'application/json; charset=utf-8'
def json_response(func):
@wraps(func)
def wrapped(*a, **kw):
result = func(*a, **kw)
return HttpResponse(json.dumps(result), status=200,
content_type=JSON_CONTENT_TYPE)
return wrapped

30
seahub/api2/views_misc.py Normal file
View File

@@ -0,0 +1,30 @@
from rest_framework.views import APIView
from seahub.api2.utils import json_response
from seahub import settings
from seahub.utils import HAS_OFFICE_CONVERTER, HAS_FILE_SEARCH
class ServerInfoView(APIView):
"""
Returns the server info (version, supported features).
"""
@json_response
def get(self, request, format=None):
info = {
'version': settings.SEAFILE_VERSION,
}
features = ['seafile-basic']
if any(['seahub_extra' in app for app in settings.INSTALLED_APPS]):
features.append('seafile-pro')
if HAS_OFFICE_CONVERTER:
features.append('office-preview')
if HAS_FILE_SEARCH:
features.append('file-search')
info['features'] = features
return info

View File

@@ -1,6 +1,7 @@
import unittest import unittest
import requests
from tests.api.apitestbase import ApiTestBase from tests.api.apitestbase import ApiTestBase
from tests.api.urls import LIST_GROUP_AND_CONTACTS_URL from tests.api.urls import LIST_GROUP_AND_CONTACTS_URL, SERVER_INFO_URL
class MiscApiTest(ApiTestBase): class MiscApiTest(ApiTestBase):
def test_list_group_and_contacts(self): def test_list_group_and_contacts(self):
@@ -12,3 +13,10 @@ class MiscApiTest(ApiTestBase):
self.assertIsInstance(res['groups'], list) self.assertIsInstance(res['groups'], list)
self.assertIsNotNone(res['gmsgnum']) self.assertIsNotNone(res['gmsgnum'])
self.assertIsNotNone(res['newreplies']) self.assertIsNotNone(res['newreplies'])
def test_server_info(self):
r = requests.get(SERVER_INFO_URL)
r.raise_for_status()
info = r.json()
self.assertTrue('version' in info)
self.assertTrue('seafile-basic' in info['features'])

View File

@@ -30,3 +30,4 @@ S_F_URL = apiurl('/api2/s/f/')
LIST_GROUP_AND_CONTACTS_URL = apiurl('/api2/groupandcontacts/') LIST_GROUP_AND_CONTACTS_URL = apiurl('/api2/groupandcontacts/')
SERVER_INFO_URL = apiurl('/api2/server-info/')