From 1cb5aef77787797a0b36ae995215b54e24d2d17d Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Mon, 25 Jul 2022 21:56:48 +0800 Subject: [PATCH] Fix bugs --- controllers/store.go | 5 +++++ web/src/FileTree.js | 45 ++++++++++++++++------------------------ web/src/StoreListPage.js | 7 ------- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/controllers/store.go b/controllers/store.go index 8d04a07..e594a76 100644 --- a/controllers/store.go +++ b/controllers/store.go @@ -22,6 +22,11 @@ func (c *ApiController) GetStore() { id := c.Input().Get("id") store := object.GetStore(id) + if store == nil { + c.ResponseError("store is empty") + return + } + store.Populate() c.Data["json"] = store diff --git a/web/src/FileTree.js b/web/src/FileTree.js index 7930956..db874c6 100644 --- a/web/src/FileTree.js +++ b/web/src/FileTree.js @@ -1,14 +1,6 @@ import React from "react"; import {Button, Col, Empty, Input, Popconfirm, Row, Spin, Tooltip, Tree, Upload} from 'antd'; -import { - CloudUploadOutlined, - createFromIconfontCN, - DeleteOutlined, - DownloadOutlined, - EditOutlined, - FolderAddOutlined, - RadiusSettingOutlined -} from "@ant-design/icons"; +import {CloudUploadOutlined, createFromIconfontCN, DeleteOutlined, DownloadOutlined, FolderAddOutlined} from "@ant-design/icons"; import * as Setting from "./Setting"; import * as FileBackend from "./backend/FileBackend"; import DocViewer, { DocViewerRenderers } from "react-doc-viewer"; @@ -17,7 +9,6 @@ import i18next from "i18next"; import {Controlled as CodeMirror} from "react-codemirror2"; import "codemirror/lib/codemirror.css"; -import {downloadFile, openLink} from "./Setting"; // require("codemirror/theme/material-darker.css"); // require("codemirror/mode/javascript/javascript"); @@ -440,9 +431,23 @@ class FileTree extends React.Component { }} /> ); - } - - if (["txt", "htm", "html", "js", "css", "md"].includes(ext)) { + } else if (["png", "jpeg", "gif", "bmp", "pdf", "csv", "xlsx", "docx", "mp4", "webm", "mp3"].includes(ext)) { + // https://github.com/plangrid/react-file-viewer + return ( + + error} + onError={(error) => { + Setting.showMessage("error", error); + }} + /> + + ); + } else { + // https://github.com/scniro/react-codemirror2 if (this.state.loading) { return (
@@ -461,20 +466,6 @@ class FileTree extends React.Component {
); } - - return ( - - error} - onError={(error) => { - Setting.showMessage("error", error); - }} - /> - - ); } render() { diff --git a/web/src/StoreListPage.js b/web/src/StoreListPage.js index bfd25e5..8981dfc 100644 --- a/web/src/StoreListPage.js +++ b/web/src/StoreListPage.js @@ -36,13 +36,6 @@ class StoreListPage extends React.Component { displayName: `Store ${this.state.stores.length}`, bucket: "casbase", domain: "https://github.com/casbin/casbase", - fileTree: { - key: "/", - title: "", - modifiedTime: moment().format(), - isLeaf: false, - children: [], - }, } }