1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-17 07:41:26 +00:00

optimize code and structure

This commit is contained in:
Junxiang Huang
2024-06-12 09:56:53 +08:00
parent f68a6cc098
commit 0e3886e254
4 changed files with 20 additions and 20 deletions

View File

@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { Utils } from '../../utils/utils'; import { Utils } from '../../utils/utils';
import { gettext } from '../../utils/constants'; import { gettext } from '../../utils/constants';
import toaster from '../../components/toast'; import toaster from '../../components/toast';
import seahubManageAPI from './seahub-manage-api'; import seahubMetadataAPI from './seahub-metadata-api';
const propTypes = { const propTypes = {
repoID: PropTypes.string.isRequired, repoID: PropTypes.string.isRequired,
@@ -48,11 +48,11 @@ class MetadataManageView extends React.Component {
}; };
onClick = () => { onClick = () => {
seahubManageAPI.getMetadataManagementEnabledStatus(this.props.repoID).then((res) => { seahubMetadataAPI.getMetadataManagementEnabledStatus(this.props.repoID).then((res) => {
if (res.data.enabled){ if (res.data.enabled){
this.viewMetadata(); this.viewMetadata();
} else if (confirm(gettext('Enable-Metadata-Manage?'))){ } else if (confirm(gettext('Enable-Metadata-Manage?'))){
seahubManageAPI.enableMetadataManagement(this.props.repoID).then((res) => { seahubMetadataAPI.enableMetadataManagement(this.props.repoID).then((res) => {
this.viewMetadata(); this.viewMetadata();
}).catch((error) => { }).catch((error) => {
let errMessage = Utils.getErrorMsg(error); let errMessage = Utils.getErrorMsg(error);

View File

@@ -2,7 +2,7 @@ import axios from 'axios';
import cookie from 'react-cookies'; import cookie from 'react-cookies';
import { siteRoot } from '../../utils/constants'; import { siteRoot } from '../../utils/constants';
class SeahubManageAPI { class SeahubMetadataAPI {
init({ server, username, password, token }) { init({ server, username, password, token }) {
this.server = server; this.server = server;
this.username = username; this.username = username;
@@ -50,7 +50,7 @@ class SeahubManageAPI {
enableMetadataManagement(repoID) { enableMetadataManagement(repoID) {
const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/'; const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/';
return this.req.post(url); return this.req.put(url);
} }
disableMetadataManagement(repoID) { disableMetadataManagement(repoID) {
@@ -91,8 +91,8 @@ class SeahubManageAPI {
} }
} }
const seahubManageAPI = new SeahubManageAPI(); const seahubMetadataAPI = new SeahubMetadataAPI();
const xcsrfHeaders = cookie.load('sfcsrftoken'); const xcsrfHeaders = cookie.load('sfcsrftoken');
seahubManageAPI.initForSeahubUsage({ siteRoot, xcsrfHeaders }); seahubMetadataAPI.initForSeahubUsage({ siteRoot, xcsrfHeaders });
export default seahubManageAPI; export default seahubMetadataAPI;

View File

@@ -218,7 +218,7 @@ class MetadataManage(APIView):
error_msg = 'Internal Server Error' error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
def post(self, request, repo_id): def put(self, request, repo_id):
''' '''
enable a new repo's metadata manage enable a new repo's metadata manage
''' '''
@@ -309,7 +309,7 @@ class MetadataManage(APIView):
error_msg = 'Internal Server Error' error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
class MetadataManageRecords(APIView): class MetadataRecords(APIView):
authentication_classes = (TokenAuthentication, SessionAuthentication) authentication_classes = (TokenAuthentication, SessionAuthentication)
permission_classes = (IsAuthenticated, ) permission_classes = (IsAuthenticated, )
throttle_classes = (UserRateThrottle, ) throttle_classes = (UserRateThrottle, )
@@ -321,7 +321,7 @@ class MetadataManageRecords(APIView):
parent_dir: optional, if not specify, search from all dirs parent_dir: optional, if not specify, search from all dirs
name: optional, if not specify, search from all objects name: optional, if not specify, search from all objects
page: optional, the current page page: optional, the current page
perpage: optional, if use page, default is 25 per_page: optional, if use page, default is 25
is_dir: optional, True or False is_dir: optional, True or False
''' '''
if not ENABLE_METADATA_MANAGEMENT or not MATEDATA_SERVER_URL: if not ENABLE_METADATA_MANAGEMENT or not MATEDATA_SERVER_URL:
@@ -333,7 +333,7 @@ class MetadataManageRecords(APIView):
parent_dir = request.GET.get('parent_dir') parent_dir = request.GET.get('parent_dir')
name = request.GET.get('name') name = request.GET.get('name')
page = request.GET.get('page') page = request.GET.get('page')
perpage = request.GET.get('perpage') per_page = request.GET.get('per_page')
is_dir = request.GET.get('is_dir') is_dir = request.GET.get('is_dir')
if page: if page:
@@ -343,15 +343,15 @@ class MetadataManageRecords(APIView):
error_msg = 'Page is not vaild.' error_msg = 'Page is not vaild.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg) return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if perpage: if per_page:
try: try:
perpage = int(perpage) per_page = int(per_page)
except ValueError: except ValueError:
error_msg = 'Perpage is not vaild.' error_msg = 'Perpage is not vaild.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg) return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
else: else:
perpage = 25 per_page = 25
if is_dir: if is_dir:
try: try:
@@ -405,7 +405,7 @@ class MetadataManageRecords(APIView):
sql += f' ORDER BY `{COLUMN_CURRENT_DIR.name}` ASC, `{COLUMN_IS_DIR.name}` DESC, `{COLUMN_NAME.name}` ASC' sql += f' ORDER BY `{COLUMN_CURRENT_DIR.name}` ASC, `{COLUMN_IS_DIR.name}` DESC, `{COLUMN_NAME.name}` ASC'
if page: if page:
sql += f' LIMIT {(page - 1) * perpage}, {page * perpage}' sql += f' LIMIT {(page - 1) * per_page}, {page * per_page}'
sql += ';' sql += ';'
@@ -537,7 +537,7 @@ class MetadataManageRecords(APIView):
else: else:
return api_error(status.HTTP_503_SERVICE_UNAVAILABLE, f'error from metadata server with code {response.status_code}: {response.reason}') return api_error(status.HTTP_503_SERVICE_UNAVAILABLE, f'error from metadata server with code {response.status_code}: {response.reason}')
class MetadataManageRecord(APIView): class MetadataRecord(APIView):
#authentication_classes = (TokenAuthentication, SessionAuthentication) #authentication_classes = (TokenAuthentication, SessionAuthentication)
#permission_classes = (IsAuthenticated, ) #permission_classes = (IsAuthenticated, )
throttle_classes = (UserRateThrottle, ) throttle_classes = (UserRateThrottle, )

View File

@@ -206,7 +206,7 @@ from seahub.ai.apis import LibrarySdocIndexes, Search, LibrarySdocIndex, TaskSta
from seahub.wiki2.views import wiki_view from seahub.wiki2.views import wiki_view
from seahub.api2.endpoints.wiki2 import Wikis2View, Wiki2View, Wiki2ConfigView, Wiki2PagesView, Wiki2PageView from seahub.api2.endpoints.wiki2 import Wikis2View, Wiki2View, Wiki2ConfigView, Wiki2PagesView, Wiki2PageView
from seahub.api2.endpoints.subscription import SubscriptionView, SubscriptionPlansView, SubscriptionLogsView from seahub.api2.endpoints.subscription import SubscriptionView, SubscriptionPlansView, SubscriptionLogsView
from seahub.api2.endpoints.metadata_manager import MetadataManageRecords, MetadataManage, MetadataManageRecord from seahub.api2.endpoints.metadata_manager import MetadataRecords, MetadataManage, MetadataRecord
urlpatterns = [ urlpatterns = [
@@ -437,8 +437,8 @@ urlpatterns = [
re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/file/participant/$', FileParticipantView.as_view(), name='api-v2.1-file-participant'), re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/file/participant/$', FileParticipantView.as_view(), name='api-v2.1-file-participant'),
re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/related-users/$', RepoRelatedUsersView.as_view(), name='api-v2.1-related-user'), re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/related-users/$', RepoRelatedUsersView.as_view(), name='api-v2.1-related-user'),
re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/metadata/$', MetadataManage.as_view(), name='api-v2.1-metadata'), re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/metadata/$', MetadataManage.as_view(), name='api-v2.1-metadata'),
re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/metadata/records/$', MetadataManageRecords.as_view(), name='api-v2.1-metadata-records'), re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/metadata/records/$', MetadataRecords.as_view(), name='api-v2.1-metadata-records'),
re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/metadata/records/(?P<record_id>[A-Za-z0-9_]+)/$', MetadataManageRecord.as_view(), name='api-v2.1-metadata-record'), re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/metadata/records/(?P<record_id>[A-Za-z0-9_]+)/$', MetadataRecord.as_view(), name='api-v2.1-metadata-record'),
## user:file:extended-props ## user:file:extended-props
re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/extended-properties/$', ExtendedPropertiesView.as_view(), name='api-v2.1-extended-properties'), re_path(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/extended-properties/$', ExtendedPropertiesView.as_view(), name='api-v2.1-extended-properties'),