Skip to content

Commit

Permalink
feat: add explorer multi-select
Browse files Browse the repository at this point in the history
feat: add text file editor
  • Loading branch information
XZB-1248 committed Jun 12, 2022
1 parent 5cfac98 commit 88dafef
Show file tree
Hide file tree
Showing 34 changed files with 1,309 additions and 245 deletions.
6 changes: 4 additions & 2 deletions API.ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@ Authorization: Basic WFpCOjEyNDg=

### 读取设备上的文件:`/device/file/get`

参数:`file`(文件路径) 以及 `device`(设备ID)
参数:`files`(文件数组) 以及 `device`(设备ID)

如果文件存在且可访问,则文件会直接输出。
<br />
否则,会给出错误原因。
<br />
如果`files`为文件数组或者目录,则会输出一个zip文件。

```
{
Expand All @@ -169,7 +171,7 @@ Authorization: Basic WFpCOjEyNDg=

### 删除设备上的文件:`/device/file/remove`

参数:`file`(文件路径) 以及 `device`(设备ID)
参数:`files`(文件数组) 以及 `device`(设备ID)

如果文件存在且被成功删除,则`code``0`

Expand Down
20 changes: 13 additions & 7 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ For example, when you call `/device/restart`, your device will restart.

Parameters: `device` (device ID)

If screenshot is captured successfully, it gives you the image directly. If failed, then the following response are given.
If screenshot is captured successfully, it gives you the image directly.
<br />
If failed, then the following response are given.

```
{
Expand All @@ -145,11 +147,15 @@ If screenshot is captured successfully, it gives you the image directly. If fail

---

### Get a file: `/device/file/get`
### Get files: `/device/file/get`

Parameters: `file` (path to file) and `device` (device ID)
Parameters: `files` (array of files) and `device` (device ID)

If file exists and is accessible, then the file is given directly. If failed, then the following response are given.
If files exist and are accessible, then the archive file or file itself is given directly.
<br />
If unable to read files, then the following response are given.
<br />
A zip file is given if multiple files (including directory) are given.

```
{
Expand All @@ -160,11 +166,11 @@ If file exists and is accessible, then the file is given directly. If failed, th

---

### Delete a file: `/device/file/remove`
### Delete files: `/device/file/remove`

Parameters: `file` (path to file) and `device` (device ID)
Parameters: `files` (array of files) and `device` (device ID)

If file exists and is deleted successfully, then `code` will be `0`.
If files exist and are deleted successfully, then `code` will be `0`.

```
{
Expand Down
26 changes: 22 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
## v0.1.1

* Add: text file editor.
* Add: explorer multi-select.
* Add: explorer search.
* Fix: some potential bugs.
* BREAKING-CHANGE: API `/device/file/get` parameter `file` changed to `files`.
* BREAKING-CHANGE: API `/device/file/remove` parameter `file` changed to `files`.

* 新增: 文本文件编辑器。
* 新增: 文件管理器多选。
* 新增: 文件管理器过滤。
* 修复: 一些潜在的bug。
* 破坏性变动:API `/device/file/get` 参数 `file` 变为 `files`
* 破坏性变动:API `/device/file/remove` 参数 `file` 变为 `files`



## v0.1.0

* fix: don't refresh after file upload
* fix: don't display error when screenshot fails
* fix: don't refresh after file upload.
* fix: don't display error when screenshot fails.

* 修复:文件上传成功后文件管理器不会自动刷新
* 修复:截图失败时不会显示错误提示
* 修复:文件上传成功后文件管理器不会自动刷新
* 修复:截图失败时不会显示错误提示



Expand Down
10 changes: 9 additions & 1 deletion README.ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

### **免责声明**

**本项目及其源代码和发行版,旨在用于学习和交流。使用本项目所带来的风险由使用者本人承担。作者和开发者不会对你的错误使用而造成的损害承担任何责任。**
**本项目及其源代码和发行版,旨在用于学习和交流。**
<br />
**使用本项目所带来的风险由使用者本人承担。**
<br />
**作者和开发者不会对你的错误使用而造成的损害承担任何责任。**

**数据无价,在点击任何按钮、输入任何命令之前,请三思。**

Expand Down Expand Up @@ -62,6 +66,8 @@
| 网络状态 ||||
| 文件浏览 ||||
| 文件传输 ||||
| 文件编辑 ||||
| 代码高亮 ||||
| 删除文件 ||||
| 系统信息 ||||
| 远程终端 ||||
Expand Down Expand Up @@ -90,6 +96,8 @@

![overview.cpu](./screenshots/overview.cpu.ZH.png)

![explorer.editor](./screenshots/explorer.editor.ZH.png)

---

## **开发**
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ server forever.

## **Disclaimer**

**THIS PROJECT, ITS SOURCE CODE, AND ITS RELEASES SHOULD ONLY BE USED FOR EDUCATIONAL PURPOSES.YOU SHALL USE THIS
PROJECT AT YOUR OWN RISK.THE AUTHORS AND DEVELOPERS ARE NOT RESPONSIBLE FOR ANY DAMAGE CAUSED BY YOUR MISUSE OF THIS
PROJECT.**
**THIS PROJECT, ITS SOURCE CODE, AND ITS RELEASES SHOULD ONLY BE USED FOR EDUCATIONAL PURPOSES.**
<br />
**YOU SHALL USE THIS PROJECT AT YOUR OWN RISK.**
<br />
**THE AUTHORS AND DEVELOPERS ARE NOT RESPONSIBLE FOR ANY DAMAGE CAUSED BY YOUR MISUSE OF THIS PROJECT.**

**YOUR DATA IS PRICELESS. THINK TWICE BEFORE YOU CLICK ANY BUTTON OR ENTER ANY COMMAND.**

Expand Down Expand Up @@ -65,6 +67,8 @@ Only local installation are available yet.
| Network traffic ||||
| File explorer ||||
| File transfer ||||
| File editor ||||
| Code highlight ||||
| Delete file ||||
| OS info ||||
| Terminal ||||
Expand Down Expand Up @@ -93,6 +97,8 @@ Only local installation are available yet.

![overview.cpu](./screenshots/overview.cpu.png)

![explorer.editor](./screenshots/explorer.editor.png)

---

## **Development**
Expand Down
7 changes: 4 additions & 3 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ var handlers = map[string]func(pack modules.Packet, wsConn *common.Conn){
`killTerminal`: killTerminal,
`listFiles`: listFiles,
`fetchFile`: fetchFile,
`removeFile`: removeFile,
`uploadFile`: uploadFile,
`removeFiles`: removeFiles,
`uploadFiles`: uploadFiles,
`uploadTextFile`: uploadTextFile,
`listProcesses`: listProcesses,
`killProcess`: killProcess,
}
Expand Down Expand Up @@ -206,7 +207,7 @@ func handleWS(wsConn *common.Conn) error {

func handleAct(pack modules.Packet, wsConn *common.Conn) {
if act, ok := handlers[pack.Act]; !ok {
common.SendCb(modules.Packet{Code: 0}, pack, wsConn)
common.SendCb(modules.Packet{Code: 1, Msg: `${i18n|actionNotImplemented}`}, pack, wsConn)
} else {
act(pack, wsConn)
}
Expand Down
64 changes: 54 additions & 10 deletions client/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,51 @@ func fetchFile(pack modules.Packet, wsConn *common.Conn) {
}
}

func removeFile(pack modules.Packet, wsConn *common.Conn) {
var path string
if val, ok := pack.GetData(`file`, reflect.String); !ok {
func removeFiles(pack modules.Packet, wsConn *common.Conn) {
var files []string
if val, ok := pack.Data[`files`]; !ok {
common.SendCb(modules.Packet{Code: 1, Msg: `${i18n|fileOrDirNotExist}`}, pack, wsConn)
return
} else {
path = val.(string)
slice := val.([]interface{})
for i := 0; i < len(slice); i++ {
file, ok := slice[i].(string)
if ok {
files = append(files, file)
}
}
if len(files) == 0 {
common.SendCb(modules.Packet{Code: 1, Msg: `${i18n|fileOrDirNotExist}`}, pack, wsConn)
return
}
}
err := file.RemoveFile(path)
err := file.RemoveFiles(files)
if err != nil {
common.SendCb(modules.Packet{Code: 1, Msg: err.Error()}, pack, wsConn)
} else {
common.SendCb(modules.Packet{Code: 0}, pack, wsConn)
}
}

func uploadFile(pack modules.Packet, wsConn *common.Conn) {
func uploadFiles(pack modules.Packet, wsConn *common.Conn) {
var start, end int64
var path, bridge string
if val, ok := pack.GetData(`file`, reflect.String); !ok {
var files []string
var bridge string
if val, ok := pack.Data[`files`]; !ok {
common.SendCb(modules.Packet{Code: 1, Msg: `${i18n|fileOrDirNotExist}`}, pack, wsConn)
return
} else {
path = val.(string)
slice := val.([]interface{})
for i := 0; i < len(slice); i++ {
file, ok := slice[i].(string)
if ok {
files = append(files, file)
}
}
if len(files) == 0 {
common.SendCb(modules.Packet{Code: 1, Msg: `${i18n|fileOrDirNotExist}`}, pack, wsConn)
return
}
}
if val, ok := pack.GetData(`bridge`, reflect.String); !ok {
common.SendCb(modules.Packet{Code: 1, Msg: `${i18n|invalidParameter}`}, pack, wsConn)
Expand All @@ -203,8 +224,31 @@ func uploadFile(pack modules.Packet, wsConn *common.Conn) {
return
}
}
err := file.UploadFile(path, bridge, start, end)
err := file.UploadFiles(files, bridge, start, end)
if err != nil {
golog.Error(err)
common.SendCb(modules.Packet{Code: 1, Msg: err.Error()}, pack, wsConn)
}
}

func uploadTextFile(pack modules.Packet, wsConn *common.Conn) {
var path string
var bridge string
if val, ok := pack.Data[`file`]; !ok {
common.SendCb(modules.Packet{Code: 1, Msg: `${i18n|fileOrDirNotExist}`}, pack, wsConn)
return
} else {
path = val.(string)
}
if val, ok := pack.GetData(`bridge`, reflect.String); !ok {
common.SendCb(modules.Packet{Code: 1, Msg: `${i18n|invalidParameter}`}, pack, wsConn)
return
} else {
bridge = val.(string)
}
err := file.UploadTextFile(path, bridge)
if err != nil {
golog.Error(err)
common.SendCb(modules.Packet{Code: 1, Msg: err.Error()}, pack, wsConn)
}
}
Expand Down
Loading

0 comments on commit 88dafef

Please sign in to comment.