2018-09-18 10:11:37 +08:00
|
|
|
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,
|
2018-09-29 15:47:53 +08:00
|
|
|
permission: item.permission,
|
2018-09-12 17:01:48 +08:00
|
|
|
size: item.size
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return files;
|
|
|
|
});
|
2018-09-04 17:16:50 +08:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:32:31 +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,
|
2018-09-29 15:47:53 +08:00
|
|
|
permission: item.permission,
|
2018-09-12 17:01:48 +08:00
|
|
|
size: item.size
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return files;
|
|
|
|
});
|
2018-09-12 10:32:31 +08:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-09-25 15:10:23 +08:00
|
|
|
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-29 15:47:53 +08:00
|
|
|
|
|
|
|
zipDownload(parent_dir, dirents) {
|
|
|
|
return seafileAPI.zipDownload(repoID, parent_dir, dirents);
|
|
|
|
}
|
|
|
|
|
|
|
|
queryZipProgress(zip_token) {
|
|
|
|
return seafileAPI.queryZipProgress(zip_token);
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelZipTask(zip_token) {
|
|
|
|
return seafileAPI.cancelZipTask(zip_token)
|
|
|
|
}
|
|
|
|
|
2018-09-04 17:16:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const editorUtilities = new EditorUtilities();
|
|
|
|
|
|
|
|
export default editorUtilities;
|