Skip to content

Commit

Permalink
add:添加文件管理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiFengJia authored and jiazhifeng committed Dec 21, 2021
1 parent 12b6b15 commit b185ac1
Show file tree
Hide file tree
Showing 5 changed files with 432 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.jzf.remote.web.controller;

import com.jzf.remote.core.util.Constants;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
* @author jiazhifeng
* @date 2021/12/21 11:36
*/
@RestController
@RequestMapping("/file")
public class FileController {
private static final Logger LOG = LoggerFactory.getLogger(FileController.class);

@PostMapping("/create")
public boolean create(String path, String fileName, boolean isDirectory) {
LOG.info("create:{} {} {}", path, fileName, isDirectory ? "创建文件夹" : "创建文件");
File filePath = new File(Constants.SOURCE_DIR, path);
if (filePath.isDirectory()) {
File file = new File(filePath, fileName);
if (isDirectory) {
return file.mkdir();
} else {
try {
return file.createNewFile();
} catch (IOException e) {
LOG.info(e.getMessage());
return false;
}
}
}
return true;
}

@PostMapping("/rename")
public boolean rename(String path, String oldFileName, String newFileName) {
LOG.info("rename:{} {} {}", path, oldFileName, newFileName);
File filePath = new File(Constants.SOURCE_DIR, path);
if (filePath.isDirectory()) {
File file = new File(filePath, oldFileName);
if (file.isDirectory()) {
try {
FileUtils.moveDirectory(file, new File(filePath, newFileName));
} catch (IOException e) {
LOG.info(e.getMessage());
return false;
}
} else {
try {
FileUtils.moveFile(file, new File(filePath, newFileName));
} catch (IOException e) {
LOG.info(e.getMessage());
return false;
}
}
}
return true;
}

@PostMapping("/delete")
public boolean delete(String path, String fileName) {
LOG.info("delete:{} {}", path, fileName);
File filePath = new File(Constants.SOURCE_DIR, path);
if (filePath.isDirectory()) {
File file = new File(filePath, fileName);
if (file.isDirectory()) {
try {
FileUtils.deleteDirectory(file);
} catch (IOException e) {
LOG.info(e.getMessage());
return false;
}
} else {
try {
FileUtils.delete(file);
} catch (IOException e) {
LOG.info(e.getMessage());
return false;
}
}
}
return true;
}

@PostMapping("/move")
public boolean move(String oldPath, String newPath, String fileName) {
LOG.info("move:{} {} {}", oldPath, newPath, fileName);
File fileOldPath = new File(Constants.SOURCE_DIR, oldPath);
if (fileOldPath.isDirectory()) {
File file = new File(fileOldPath, fileName);
if (file.isDirectory()) {
try {
FileUtils.moveDirectoryToDirectory(file, new File(Constants.SOURCE_DIR, newPath), false);
} catch (Exception e) {
LOG.info(e.getMessage());
return false;
}
} else {
try {
FileUtils.moveFileToDirectory(file, new File(Constants.SOURCE_DIR, newPath), false);
} catch (Exception e) {
LOG.info(e.getMessage());
return false;
}
}
}
return true;
}

@PostMapping("/save")
public boolean save(String filePath, String content) {
LOG.info("save:{} {}", filePath, content);
try {
FileUtils.write(new File(Constants.SOURCE_DIR, filePath), content, StandardCharsets.UTF_8);
} catch (IOException e) {
LOG.info(e.getMessage());
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.jzf.remote.core.util.Constants;
import com.jzf.remote.core.util.DecompiledUtils;
import com.jzf.remote.core.util.HexUtils;
import com.jzf.remote.core.util.MavenUtils;
import com.jzf.remote.web.model.dto.TreeDTO;
import com.jzf.remote.web.util.TreeUtils;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -41,7 +40,7 @@ public String getFile(String filePath) throws IOException {
return FileUtils.readFileToString(file, StandardCharsets.UTF_8);
}
} else {
return "";
return null;
}
}

Expand All @@ -52,7 +51,7 @@ public String getHexStrByFilePath(String filePath) throws IOException {
byte[] bytes = FileUtils.readFileToByteArray(file);
return HexUtils.bytesToBeautiful(bytes);
} else {
return "";
return null;
}
}

Expand All @@ -65,23 +64,4 @@ public String getBytecode(String classFullName) {
}
return bytecode.substring(index + 2);
}

@PostMapping("/mvn")
public String mvn(String projectName, List<String> goals) {
MavenUtils.goals(projectName, goals,
consumer -> {
try {
do {
String line = consumer.readLine();
if (line == null) {
break;
}
System.out.println(line);
} while (true);
} catch (IOException e) {
e.printStackTrace();
}
});
return "";
}
}
100 changes: 72 additions & 28 deletions remote-web/src/main/resources/static/WebIDE.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css"
integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/themes/default/style.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/themes/default/style.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/theme/darcula.min.css"
integrity="sha512-kqCOYFDdyQF4JM8RddA6rMBi9oaLdR0aEACdB95Xl1EgaBhaXMIe8T4uxmPitfq4qRmHqo+nBU2d1l+M4zUx1g=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/codemirror.min.css"
integrity="sha512-CCnciBUnVXwa6IQT9q8EmGcarNit9GdKI5nJnj56B1iu0LuD13Qn/GZ+IUkrZROZaBdutN718NK6mIXdUjZGqg=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/xterm/2.9.2/xterm.min.css"
integrity="sha512-yqkIsVYKEsENpXQX0zLrKj6n50rmX5X1j0cclmCnETFoWG2PKMZjvDEp6do28gGLxIvMnihpERBGRa8Ck0Ls8g=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
crossorigin="anonymous" referrerpolicy="no-referrer" />

<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
Expand All @@ -32,9 +32,6 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/codemirror.min.js"
integrity="sha512-4DlmQ+aBOfYTZ3uzRKCDXdyL7y8IlopnVChhXG0pRFgyvhwONVQW3JX8e5DYoXUNr3evQpLZz7S3O1XxMH4WKA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/clike/clike.min.js"
integrity="sha512-GAled7oA9WlRkBaUQlUEgxm37hf43V2KEMaEiWlvBO/ueP2BLvBLKN5tIJu4VZOTwo6Z4XvrojYngoN9dJw2ug=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type='text/javascript' src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xterm/2.9.2/xterm.min.js"
integrity="sha512-S1ITNcRgtLq/tVnMcX7Qcss09kJ5Lu7dZbtXw/dBDjxYJSdyucbYKOYI1nSbb9EtrjEK3h7Kxekkbg4gVLr8gg=="
Expand All @@ -43,7 +40,39 @@
integrity="sha512-PyTGariw9ceX9zejvpqCikObn0A3cwR3LoDQY1/L+NET1LZBMYi/IPIn6pvfRt02etYhRw4zJ2iU3yGyEH5+8A=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<link rel="stylesheet" href="/css/darkly.css"/>
<!-- 语法高亮 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/clike/clike.min.js"
integrity="sha512-GAled7oA9WlRkBaUQlUEgxm37hf43V2KEMaEiWlvBO/ueP2BLvBLKN5tIJu4VZOTwo6Z4XvrojYngoN9dJw2ug=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/xml/xml.min.js"
integrity="sha512-UWfBe6aiZInvbBlm91IURVHHTwigTPtM3M4B73a8AykmxhDWq4EC/V2rgUNiLgmd/i0y0KWHolqmVQyJ35JsNA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/javascript/javascript.min.js"
integrity="sha512-DJ/Flq7rxJDDhgkO49H/rmidX44jmxWot/ku3c+XXEF9XFal78KIpu7w6jEaQhK4jli1U3/yOH+Rp3cIIEYFPQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/yaml/yaml.min.js"
integrity="sha512-+aXDZ93WyextRiAZpsRuJyiAZ38ztttUyO/H3FZx4gOAOv4/k9C6Um1CvHVtaowHZ2h7kH0d+orWvdBLPVwb4g=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/css/css.min.js"
integrity="sha512-5jz5G7Fn6Xbc3YA/5KYXYwxSkyKEh7oEFNwc7cCnMs48diTBh24gKxcbt7r8Do+xFK6pJgr+BFfcKnUne+XUvA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/htmlmixed/htmlmixed.min.js"
integrity="sha512-IC+qg9ITjo2CLFOTQcO6fBbvisTeJmiT5D5FnXsCptqY8t7/UxWhOorn2X+GHkoD1FNkyfnMJujt5PcB7qutyA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/htmlembedded/htmlembedded.min.js"
integrity="sha512-nZlYJlXg6ZqhEdMELUCY9QpeUZHLZh9JUUe2wnHmEvFSWer2gxmDO4xeQ4QlRM1zMzeZsTdm5oFw2IGhsmmLlA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/sql/sql.min.js"
integrity="sha512-kBoE9Dbn6VAppk/B1tqI04cc/3hvR/tDEjoEntUMt8YU3INy/+xDyUpi7aNmjLIqgHHAMYOvDLR+/v1pOaA5ZA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/markdown/markdown.min.js"
integrity="sha512-M1xCxP7Cdf+uWhKzPWcI1rMEXDiEyxTyVqRfzGVGoim93W+IWPaJL3gni6aGuE9HJcIMUFqLtLY5ypeNtguQPg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/shell/shell.min.js"
integrity="sha512-hPxGlSDYCFC8zXHIbOSD/Qo5DDCxyrfWnMvwVi1TutjhPOsf9Sgo6bu5SRDXIbuWfi22YRr+RpKwJ4XOzj7mnw=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<link rel="stylesheet" href="/css/darkly.css" />

<title>Web IDE</title>
</head>
Expand All @@ -64,7 +93,7 @@
<a class="dropdown-item" href="#">Import Project From Zip</a>
<a class="dropdown-item" href="#">Export Project To Zip</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Save File</a>
<a class="dropdown-item" href="#" onclick="saveFile()">Save File</a>
<a class="dropdown-item" href="#">Save All</a>
</div>
</li>
Expand All @@ -79,19 +108,22 @@
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Tools</a>
<a class="nav-link" data-toggle="dropdown" href="#" role="button"
aria-expanded="false">Tools</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" onClick="getBytecode()">Show Bytecode</a>
<a class="dropdown-item" href="#" onClick="getHexStrByFilePath()">View in HEX</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Build</a>
<a class="nav-link" data-toggle="dropdown" href="#" role="button"
aria-expanded="false">Build</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" onclick="projectClean()">Clean Project</a>
<a class="dropdown-item" href="#" onclick="projectCompile()">Compile Project</a>
<a class="dropdown-item" href="#" onclick="projectBuild()">Build Project</a>
<a class="dropdown-item" href="#" onclick="projectCleanAndBuild()">Clean and Build Project</a>
<a class="dropdown-item" href="#" onclick="projectCleanAndBuild()">Clean and Build
Project</a>
</div>
</li>
<li class="nav-item dropdown">
Expand Down Expand Up @@ -140,26 +172,38 @@
<ul class="nav nav-tabs card-header-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">
<span id="fileName">HelloWorld.java</span>
<span id="fileName">项目简介</span>
<span id="dot" class="dot" style="display: none"></span>
</a>
</li>
</ul>
</div>
<div class="card-body" style="padding:0px;">
<div class="editor_control">
<textarea class="form-control" id="code" name="code">
/**
* 简单示例
*
* @author jiazhifeng
* @date 2021/12/07 10:14
*/
public class HelloWorld {
public static void main(String[] args) {
System.out.println("HelloWorld");
}
}
<textarea class="form-control" id="code" name="code">
项目目标
1. 项目的目标是建立一种基于云的集成开发环境 (IDE),您只需要一个浏览器,即可编写、运行和调试代码。它包括一个代码编辑器、控制台和终端。
您无需安装文件或配置开发计算机,即可开始新的项目。项目基于云,因此您可以从办公室、家中或任何地方使用已连接互联网的计算机完成项目。

优势
1. 只需一个浏览器即可进行代码编码、运行。

一分钟短视频介绍
1. 【YouTube】https://youtu.be/Z6aumPttg6o
2. 【哔哩哔哩】https://b23.tv/zZve2g2

目前已实现功能:
1. 文件树生成
2. 代码编辑
3. 代码云端编译,运行
4. 控制台输出
5. 支持暗黑模式
6. 增加反编译工具
7. 增加项目构建功能
8. 增加web终端(借鉴https://github.com/NoCortY/WebSSH)
9. 增加十六进制转换工具

## 项目开发中,敬请期待。
</textarea>
</div>
</div>
Expand Down Expand Up @@ -238,8 +282,7 @@ <h5 class="modal-title" id="cloneFromGithubLabel">Clone Project From GitHub</h5>
</div>

<!-- Modal -->
<div class="modal fade" id="sshInfo" tabindex="-1" aria-labelledby="sshInfoLabel"
aria-hidden="true">
<div class="modal fade" id="sshInfo" tabindex="-1" aria-labelledby="sshInfoLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
Expand Down Expand Up @@ -275,7 +318,8 @@ <h5 class="modal-title" id="sshInfoLabel">配置ssh连接信息</h5>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="connectSSH()">Connect
<button type="button" class="btn btn-primary" data-dismiss="modal"
onclick="connectSSH()">Connect
</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cannel</button>
</div>
Expand Down
Loading

0 comments on commit b185ac1

Please sign in to comment.