Skip to content

Commit b185ac1

Browse files
ZhiFengJiajiazhifeng
authored and
jiazhifeng
committed
add:添加文件管理代码
1 parent 12b6b15 commit b185ac1

File tree

5 files changed

+432
-94
lines changed

5 files changed

+432
-94
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.jzf.remote.web.controller;
2+
3+
import com.jzf.remote.core.util.Constants;
4+
import org.apache.commons.io.FileUtils;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.web.bind.annotation.PostMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
import java.io.File;
12+
import java.io.IOException;
13+
import java.nio.charset.StandardCharsets;
14+
15+
/**
16+
* @author jiazhifeng
17+
* @date 2021/12/21 11:36
18+
*/
19+
@RestController
20+
@RequestMapping("/file")
21+
public class FileController {
22+
private static final Logger LOG = LoggerFactory.getLogger(FileController.class);
23+
24+
@PostMapping("/create")
25+
public boolean create(String path, String fileName, boolean isDirectory) {
26+
LOG.info("create:{} {} {}", path, fileName, isDirectory ? "创建文件夹" : "创建文件");
27+
File filePath = new File(Constants.SOURCE_DIR, path);
28+
if (filePath.isDirectory()) {
29+
File file = new File(filePath, fileName);
30+
if (isDirectory) {
31+
return file.mkdir();
32+
} else {
33+
try {
34+
return file.createNewFile();
35+
} catch (IOException e) {
36+
LOG.info(e.getMessage());
37+
return false;
38+
}
39+
}
40+
}
41+
return true;
42+
}
43+
44+
@PostMapping("/rename")
45+
public boolean rename(String path, String oldFileName, String newFileName) {
46+
LOG.info("rename:{} {} {}", path, oldFileName, newFileName);
47+
File filePath = new File(Constants.SOURCE_DIR, path);
48+
if (filePath.isDirectory()) {
49+
File file = new File(filePath, oldFileName);
50+
if (file.isDirectory()) {
51+
try {
52+
FileUtils.moveDirectory(file, new File(filePath, newFileName));
53+
} catch (IOException e) {
54+
LOG.info(e.getMessage());
55+
return false;
56+
}
57+
} else {
58+
try {
59+
FileUtils.moveFile(file, new File(filePath, newFileName));
60+
} catch (IOException e) {
61+
LOG.info(e.getMessage());
62+
return false;
63+
}
64+
}
65+
}
66+
return true;
67+
}
68+
69+
@PostMapping("/delete")
70+
public boolean delete(String path, String fileName) {
71+
LOG.info("delete:{} {}", path, fileName);
72+
File filePath = new File(Constants.SOURCE_DIR, path);
73+
if (filePath.isDirectory()) {
74+
File file = new File(filePath, fileName);
75+
if (file.isDirectory()) {
76+
try {
77+
FileUtils.deleteDirectory(file);
78+
} catch (IOException e) {
79+
LOG.info(e.getMessage());
80+
return false;
81+
}
82+
} else {
83+
try {
84+
FileUtils.delete(file);
85+
} catch (IOException e) {
86+
LOG.info(e.getMessage());
87+
return false;
88+
}
89+
}
90+
}
91+
return true;
92+
}
93+
94+
@PostMapping("/move")
95+
public boolean move(String oldPath, String newPath, String fileName) {
96+
LOG.info("move:{} {} {}", oldPath, newPath, fileName);
97+
File fileOldPath = new File(Constants.SOURCE_DIR, oldPath);
98+
if (fileOldPath.isDirectory()) {
99+
File file = new File(fileOldPath, fileName);
100+
if (file.isDirectory()) {
101+
try {
102+
FileUtils.moveDirectoryToDirectory(file, new File(Constants.SOURCE_DIR, newPath), false);
103+
} catch (Exception e) {
104+
LOG.info(e.getMessage());
105+
return false;
106+
}
107+
} else {
108+
try {
109+
FileUtils.moveFileToDirectory(file, new File(Constants.SOURCE_DIR, newPath), false);
110+
} catch (Exception e) {
111+
LOG.info(e.getMessage());
112+
return false;
113+
}
114+
}
115+
}
116+
return true;
117+
}
118+
119+
@PostMapping("/save")
120+
public boolean save(String filePath, String content) {
121+
LOG.info("save:{} {}", filePath, content);
122+
try {
123+
FileUtils.write(new File(Constants.SOURCE_DIR, filePath), content, StandardCharsets.UTF_8);
124+
} catch (IOException e) {
125+
LOG.info(e.getMessage());
126+
return false;
127+
}
128+
return true;
129+
}
130+
}

remote-web/src/main/java/com/jzf/remote/web/controller/projectController.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.jzf.remote.core.util.Constants;
44
import com.jzf.remote.core.util.DecompiledUtils;
55
import com.jzf.remote.core.util.HexUtils;
6-
import com.jzf.remote.core.util.MavenUtils;
76
import com.jzf.remote.web.model.dto.TreeDTO;
87
import com.jzf.remote.web.util.TreeUtils;
98
import org.apache.commons.io.FileUtils;
@@ -41,7 +40,7 @@ public String getFile(String filePath) throws IOException {
4140
return FileUtils.readFileToString(file, StandardCharsets.UTF_8);
4241
}
4342
} else {
44-
return "";
43+
return null;
4544
}
4645
}
4746

@@ -52,7 +51,7 @@ public String getHexStrByFilePath(String filePath) throws IOException {
5251
byte[] bytes = FileUtils.readFileToByteArray(file);
5352
return HexUtils.bytesToBeautiful(bytes);
5453
} else {
55-
return "";
54+
return null;
5655
}
5756
}
5857

@@ -65,23 +64,4 @@ public String getBytecode(String classFullName) {
6564
}
6665
return bytecode.substring(index + 2);
6766
}
68-
69-
@PostMapping("/mvn")
70-
public String mvn(String projectName, List<String> goals) {
71-
MavenUtils.goals(projectName, goals,
72-
consumer -> {
73-
try {
74-
do {
75-
String line = consumer.readLine();
76-
if (line == null) {
77-
break;
78-
}
79-
System.out.println(line);
80-
} while (true);
81-
} catch (IOException e) {
82-
e.printStackTrace();
83-
}
84-
});
85-
return "";
86-
}
8767
}

remote-web/src/main/resources/static/WebIDE.html

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

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

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

46-
<link rel="stylesheet" href="/css/darkly.css"/>
43+
<!-- 语法高亮 -->
44+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/clike/clike.min.js"
45+
integrity="sha512-GAled7oA9WlRkBaUQlUEgxm37hf43V2KEMaEiWlvBO/ueP2BLvBLKN5tIJu4VZOTwo6Z4XvrojYngoN9dJw2ug=="
46+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
47+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/xml/xml.min.js"
48+
integrity="sha512-UWfBe6aiZInvbBlm91IURVHHTwigTPtM3M4B73a8AykmxhDWq4EC/V2rgUNiLgmd/i0y0KWHolqmVQyJ35JsNA=="
49+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
50+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/javascript/javascript.min.js"
51+
integrity="sha512-DJ/Flq7rxJDDhgkO49H/rmidX44jmxWot/ku3c+XXEF9XFal78KIpu7w6jEaQhK4jli1U3/yOH+Rp3cIIEYFPQ=="
52+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
53+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/yaml/yaml.min.js"
54+
integrity="sha512-+aXDZ93WyextRiAZpsRuJyiAZ38ztttUyO/H3FZx4gOAOv4/k9C6Um1CvHVtaowHZ2h7kH0d+orWvdBLPVwb4g=="
55+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
56+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/css/css.min.js"
57+
integrity="sha512-5jz5G7Fn6Xbc3YA/5KYXYwxSkyKEh7oEFNwc7cCnMs48diTBh24gKxcbt7r8Do+xFK6pJgr+BFfcKnUne+XUvA=="
58+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
59+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/htmlmixed/htmlmixed.min.js"
60+
integrity="sha512-IC+qg9ITjo2CLFOTQcO6fBbvisTeJmiT5D5FnXsCptqY8t7/UxWhOorn2X+GHkoD1FNkyfnMJujt5PcB7qutyA=="
61+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
62+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/htmlembedded/htmlembedded.min.js"
63+
integrity="sha512-nZlYJlXg6ZqhEdMELUCY9QpeUZHLZh9JUUe2wnHmEvFSWer2gxmDO4xeQ4QlRM1zMzeZsTdm5oFw2IGhsmmLlA=="
64+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
65+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/sql/sql.min.js"
66+
integrity="sha512-kBoE9Dbn6VAppk/B1tqI04cc/3hvR/tDEjoEntUMt8YU3INy/+xDyUpi7aNmjLIqgHHAMYOvDLR+/v1pOaA5ZA=="
67+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
68+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/markdown/markdown.min.js"
69+
integrity="sha512-M1xCxP7Cdf+uWhKzPWcI1rMEXDiEyxTyVqRfzGVGoim93W+IWPaJL3gni6aGuE9HJcIMUFqLtLY5ypeNtguQPg=="
70+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
71+
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.64.0/mode/shell/shell.min.js"
72+
integrity="sha512-hPxGlSDYCFC8zXHIbOSD/Qo5DDCxyrfWnMvwVi1TutjhPOsf9Sgo6bu5SRDXIbuWfi22YRr+RpKwJ4XOzj7mnw=="
73+
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
74+
75+
<link rel="stylesheet" href="/css/darkly.css" />
4776

4877
<title>Web IDE</title>
4978
</head>
@@ -64,7 +93,7 @@
6493
<a class="dropdown-item" href="#">Import Project From Zip</a>
6594
<a class="dropdown-item" href="#">Export Project To Zip</a>
6695
<div class="dropdown-divider"></div>
67-
<a class="dropdown-item" href="#">Save File</a>
96+
<a class="dropdown-item" href="#" onclick="saveFile()">Save File</a>
6897
<a class="dropdown-item" href="#">Save All</a>
6998
</div>
7099
</li>
@@ -79,19 +108,22 @@
79108
</div>
80109
</li>
81110
<li class="nav-item dropdown">
82-
<a class="nav-link" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Tools</a>
111+
<a class="nav-link" data-toggle="dropdown" href="#" role="button"
112+
aria-expanded="false">Tools</a>
83113
<div class="dropdown-menu">
84114
<a class="dropdown-item" href="#" onClick="getBytecode()">Show Bytecode</a>
85115
<a class="dropdown-item" href="#" onClick="getHexStrByFilePath()">View in HEX</a>
86116
</div>
87117
</li>
88118
<li class="nav-item dropdown">
89-
<a class="nav-link" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Build</a>
119+
<a class="nav-link" data-toggle="dropdown" href="#" role="button"
120+
aria-expanded="false">Build</a>
90121
<div class="dropdown-menu">
91122
<a class="dropdown-item" href="#" onclick="projectClean()">Clean Project</a>
92123
<a class="dropdown-item" href="#" onclick="projectCompile()">Compile Project</a>
93124
<a class="dropdown-item" href="#" onclick="projectBuild()">Build Project</a>
94-
<a class="dropdown-item" href="#" onclick="projectCleanAndBuild()">Clean and Build Project</a>
125+
<a class="dropdown-item" href="#" onclick="projectCleanAndBuild()">Clean and Build
126+
Project</a>
95127
</div>
96128
</li>
97129
<li class="nav-item dropdown">
@@ -140,26 +172,38 @@
140172
<ul class="nav nav-tabs card-header-tabs">
141173
<li class="nav-item">
142174
<a class="nav-link active" href="#">
143-
<span id="fileName">HelloWorld.java</span>
175+
<span id="fileName">项目简介</span>
144176
<span id="dot" class="dot" style="display: none"></span>
145177
</a>
146178
</li>
147179
</ul>
148180
</div>
149181
<div class="card-body" style="padding:0px;">
150182
<div class="editor_control">
151-
<textarea class="form-control" id="code" name="code">
152-
/**
153-
* 简单示例
154-
*
155-
* @author jiazhifeng
156-
* @date 2021/12/07 10:14
157-
*/
158-
public class HelloWorld {
159-
public static void main(String[] args) {
160-
System.out.println("HelloWorld");
161-
}
162-
}
183+
<textarea class="form-control" id="code" name="code">
184+
项目目标
185+
1. 项目的目标是建立一种基于云的集成开发环境 (IDE),您只需要一个浏览器,即可编写、运行和调试代码。它包括一个代码编辑器、控制台和终端。
186+
您无需安装文件或配置开发计算机,即可开始新的项目。项目基于云,因此您可以从办公室、家中或任何地方使用已连接互联网的计算机完成项目。
187+
188+
优势
189+
1. 只需一个浏览器即可进行代码编码、运行。
190+
191+
一分钟短视频介绍
192+
1. 【YouTube】https://youtu.be/Z6aumPttg6o
193+
2. 【哔哩哔哩】https://b23.tv/zZve2g2
194+
195+
目前已实现功能:
196+
1. 文件树生成
197+
2. 代码编辑
198+
3. 代码云端编译,运行
199+
4. 控制台输出
200+
5. 支持暗黑模式
201+
6. 增加反编译工具
202+
7. 增加项目构建功能
203+
8. 增加web终端(借鉴https://github.com/NoCortY/WebSSH)
204+
9. 增加十六进制转换工具
205+
206+
## 项目开发中,敬请期待。
163207
</textarea>
164208
</div>
165209
</div>
@@ -238,8 +282,7 @@ <h5 class="modal-title" id="cloneFromGithubLabel">Clone Project From GitHub</h5>
238282
</div>
239283

240284
<!-- Modal -->
241-
<div class="modal fade" id="sshInfo" tabindex="-1" aria-labelledby="sshInfoLabel"
242-
aria-hidden="true">
285+
<div class="modal fade" id="sshInfo" tabindex="-1" aria-labelledby="sshInfoLabel" aria-hidden="true">
243286
<div class="modal-dialog modal-dialog-centered">
244287
<div class="modal-content">
245288
<div class="modal-header">
@@ -275,7 +318,8 @@ <h5 class="modal-title" id="sshInfoLabel">配置ssh连接信息</h5>
275318
</div>
276319
</div>
277320
<div class="modal-footer">
278-
<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="connectSSH()">Connect
321+
<button type="button" class="btn btn-primary" data-dismiss="modal"
322+
onclick="connectSSH()">Connect
279323
</button>
280324
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cannel</button>
281325
</div>

0 commit comments

Comments
 (0)