1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 19:08:21 +00:00
Files
seahub/frontend/src/utils/editor-utilties.js

106 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-09-12 17:01:48 +08:00
import { slug, repoID, siteRoot, historyRepoID } from '../components/constance';
2018-09-04 17:16:50 +08:00
import { SeafileAPI } from 'seafile-js';
import cookie from 'react-cookies';
let seafileAPI = new SeafileAPI();
let xcsrfHeaders = cookie.load('sfcsrftoken');
seafileAPI.initForSeahubUsage({ siteRoot, xcsrfHeaders });
class EditorUtilities {
getFiles() {
2018-09-12 17:01:48 +08:00
return seafileAPI.listWikiDir(slug, '/').then(items => {
const files = items.data.dir_file_list.map(item => {
return {
name: item.name,
type: item.type === 'dir' ? 'dir' : 'file',
isExpanded: item.type === 'dir' ? true : false,
parent_path: item.parent_dir,
last_update_time: item.last_update_time,
size: item.size
};
});
return files;
});
2018-09-04 17:16:50 +08:00
}
listRepoDir() {
2018-09-12 17:01:48 +08:00
return seafileAPI.listDir(repoID, '/',{recursive: true}).then(items => {
const files = items.data.map(item => {
return {
name: item.name,
type: item.type === 'dir' ? 'dir' : 'file',
isExpanded: item.type === 'dir' ? true : false,
parent_path: item.parent_dir,
last_update_time: item.mtime,
size: item.size
};
});
return files;
});
}
2018-09-04 17:16:50 +08:00
createFile(filePath) {
2018-09-12 17:01:48 +08:00
return seafileAPI.createFile(repoID, filePath);
2018-09-04 17:16:50 +08:00
}
deleteFile(filePath) {
2018-09-12 17:01:48 +08:00
return seafileAPI.deleteFile(repoID, filePath);
2018-09-04 17:16:50 +08:00
}
renameFile(filePath, newFileName) {
2018-09-12 17:01:48 +08:00
return seafileAPI.renameFile(repoID, filePath, newFileName);
2018-09-04 17:16:50 +08:00
}
createDir(dirPath) {
2018-09-12 17:01:48 +08:00
return seafileAPI.createDir(repoID, dirPath);
2018-09-04 17:16:50 +08:00
}
deleteDir(dirPath) {
2018-09-12 17:01:48 +08:00
return seafileAPI.deleteDir(repoID, dirPath);
2018-09-04 17:16:50 +08:00
}
renameDir(dirPath, newDirName) {
2018-09-12 17:01:48 +08:00
return seafileAPI.renameDir(repoID, dirPath, newDirName);
2018-09-04 17:16:50 +08:00
}
getWikiFileContent(slug, filePath) {
return seafileAPI.getWikiFileContent(slug, filePath);
}
getSource() {
return seafileAPI.getSource();
}
searchFiles(queryData,cancelToken) {
return seafileAPI.searchFiles(queryData,cancelToken);
}
getAccountInfo() {
return seafileAPI.getAccountInfo();
}
2018-09-12 17:01:48 +08:00
// file history
getFileDownloadLink(filePath) {
return seafileAPI.getFileDownloadLink(historyRepoID, filePath);
}
getFileContent(filePath) {
return seafileAPI.getFileContent(filePath);
}
getFileHistoryRecord(filePath, page, per_page) {
return seafileAPI.getFileHistoryRecord(historyRepoID, filePath, page, per_page);
}
revertFile(filePath, commitID) {
return seafileAPI.revertFile(historyRepoID, filePath, commitID);
}
2018-09-04 17:16:50 +08:00
}
const editorUtilities = new EditorUtilities();
export default editorUtilities;
export { seafileAPI };