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

112 lines
2.6 KiB
JavaScript
Raw Normal View History

import { slug, repoID, siteRoot, historyRepoID } from '../components/constants';
import { seafileAPI } from './seafile-api';
2018-09-04 17:16:50 +08:00
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);
}
listFileHistoryRecords(filePath, page, per_page) {
return seafileAPI.listFileHistoryRecords(historyRepoID, filePath, page, per_page);
2018-09-12 17:01:48 +08:00
}
revertFile(filePath, commitID) {
return seafileAPI.revertFile(historyRepoID, filePath, commitID);
}
2018-09-15 16:14:17 +08:00
listDrafts() {
return seafileAPI.listDrafts();
}
deleteDraft(id) {
return seafileAPI.deleteDraft(id);
}
publishDraft(id) {
return seafileAPI.publishDraft(id);
}
2018-09-04 17:16:50 +08:00
}
const editorUtilities = new EditorUtilities();
export default editorUtilities;