1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-18 16:36:15 +00:00

Merge pull request #7088 from haiwen/fix-tags-api

fix: tags api
This commit is contained in:
杨国璇
2024-11-22 18:28:03 +08:00
committed by GitHub
3 changed files with 50 additions and 6 deletions

View File

@@ -73,7 +73,7 @@ const MetadataTagsStatusDialog = ({ value: oldValue, repoID, toggleDialog: toggl
placeholder={gettext('Tags')}
/>
<p className="tip m-0">
{gettext('Enable tags to describe, categorize and mark files.')}
{gettext('Enable tags to add tags to files and search files by tags.')}
</p>
</ModalBody>
<ModalFooter>

View File

@@ -1,4 +1,5 @@
import metadataAPI from './api';
import tagsAPI from '../tag/api';
import {
PRIVATE_COLUMN_KEYS, EDITABLE_DATA_PRIVATE_COLUMN_KEYS, EDITABLE_PRIVATE_COLUMN_KEYS, DELETABLE_PRIVATE_COLUMN_KEY,
FACE_RECOGNITION_VIEW_ID,
@@ -13,6 +14,7 @@ class Context {
constructor() {
this.settings = { lang };
this.metadataAPI = null;
this.tagsAPI = null;
this.localStorage = null;
this.eventBus = null;
this.hasInit = false;
@@ -26,9 +28,10 @@ class Context {
// init settings
this.settings = { ...this.settings, ...settings };
// init metadataAPI
// init API
const { repoInfo } = this.settings;
this.metadataAPI = metadataAPI;
this.tagsAPI = tagsAPI;
// init localStorage
const { repoID, viewID } = this.settings;
@@ -46,6 +49,7 @@ class Context {
destroy = () => {
this.settings = {};
this.metadataAPI = null;
this.tagsAPI = null;
this.localStorage = null;
this.eventBus = null;
this.hasInit = false;
@@ -257,12 +261,12 @@ class Context {
// file tag
addFileTags = (recordId, tagIds) => {
const repoID = this.settings['repoID'];
return this.metadataAPI.addFileTags(repoID, recordId, tagIds);
return this.tagsAPI.addFileTags(repoID, recordId, tagIds);
};
updateFileTags = (recordId, tagIds) => {
const repoID = this.settings['repoID'];
return this.metadataAPI.updateFileTags(repoID, recordId, tagIds);
return this.tagsAPI.updateFileTags(repoID, recordId, tagIds);
};
}

View File

@@ -1,8 +1,48 @@
import axios from 'axios';
import cookie from 'react-cookies';
import { siteRoot } from '../utils/constants';
import { MetadataManagerAPI } from '../metadata';
class TagsManagerAPI extends MetadataManagerAPI {
class TagsManagerAPI {
init({ server, username, password, token }) {
this.server = server;
this.username = username;
this.password = password;
this.token = token; // none
if (this.token && this.server) {
this.req = axios.create({
baseURL: this.server,
headers: { 'Authorization': 'Token ' + this.token },
});
}
return this;
}
initForSeahubUsage({ siteRoot, xcsrfHeaders }) {
if (siteRoot && siteRoot.charAt(siteRoot.length - 1) === '/') {
var server = siteRoot.substring(0, siteRoot.length - 1);
this.server = server;
} else {
this.server = siteRoot;
}
this.req = axios.create({
headers: {
'X-CSRFToken': xcsrfHeaders,
}
});
return this;
}
_sendPostRequest(url, form) {
if (form.getHeaders) {
return this.req.post(url, form, {
headers: form.getHeaders()
});
} else {
return this.req.post(url, form);
}
}
getTagsStatus = (repoID) => {
const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/tags-status/';