Skip to content

Commit

Permalink
Merge pull request #4 from pldubouilh/rm
Browse files Browse the repository at this point in the history
add rm/rename commands
  • Loading branch information
pldubouilh authored Nov 24, 2018
2 parents 83e610b + 64c6971 commit 52188c1
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ debug
test
gossa.go
gossa
gossa-linux
gossa-linux64
gossa-linux-arm
gossa-linux-arm64
gossa-mac
Expand Down
37 changes: 25 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ gossa

[![Build Status](https://travis-ci.org/pldubouilh/gossa.svg?branch=master)](https://travis-ci.org/pldubouilh/gossa)

🎢 A fast and simple webserver for your files. It's dependency-free and with under 250 lines for the server code, easily code-reviewable.
🎢 A fast and simple webserver for your files, that's dependency-free and with under 240 lines for the server code, easily code-reviewable.

### features
* browse through files/directories
* upload with drag-and-drop
* create new folders
* move files with drag-and-drop and keyboard
* move/rename/delete files
* browse through pictures with a full-screen carousel
* simple keyboard navigation/shortcuts
* fast ; fills my 80MB/s AC wifi link

### built blobs
built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases).

### run
```sh
# build
Expand All @@ -26,15 +28,26 @@ make
```

### keyboard shortcuts
* Arrows/Enter browse throughout the files/directories and pictures
* Ctrl/Meta + C copy URL to clipboard
* Ctrl/Meta + D create a new directory
* Ctrl/Meta + X cut selected path
* Ctrl/Meta + V paste previously selected paths to directory
* \<any letter\> search

### built blobs
built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases).
|shortcut | action|
|-------------|-------------|
|Arrows/Enter | browse through files/directories and pictures|
|Ctrl/Meta + C | copy URL to clipboard|
|Ctrl/Meta + E | rename file/folder|
|Ctrl/Meta + Del | delete file/folder|
|Ctrl/Meta + D | create a new directory|
|Ctrl/Meta + X | cut selected path|
|Ctrl/Meta + V | paste previously selected paths to directory|
|\<any letter\> | search|

### ui shortcuts
|shortcut | action|
| ------------- |-------------|
|click new folder icon | create new folder|
|click images icon | toggle image carousel|
|click file icon | rename item|
|double click file icon | delete item|
|drag-and-drop item on UI | move item|
|drag-and-drop external item | upload file/folders|

### using with docker
a pretty short docker file is provided
Expand Down
4 changes: 3 additions & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func row(name string, href string, size float64, ext string) string {
}

return `<tr>
<td><i class="btn icon icon-` + strings.ToLower(ext) + ` icon-blank"></i></td>
<td><i ondblclick="return rm(event)" onclick="return rename(event)" class="btn icon icon-` + strings.ToLower(ext) + ` icon-blank"></i></td>
<td class="file-size"><code>` + sizeToString(size) + `</code></td>
<td class="arrow"><i class="arrow-icon"></i></td>
<td class="display-name"><a class="list-links" onclick="return onClickLink(event)" href="` + url.PathEscape(href) + `">` + name + `</a></td>
Expand Down Expand Up @@ -185,6 +185,8 @@ func rpc(w http.ResponseWriter, r *http.Request) {
err = os.MkdirAll(payload.Args[0], os.ModePerm)
} else if payload.Call == "mv" {
err = os.Rename(payload.Args[0], payload.Args[1])
} else if payload.Call == "rm" {
err = os.Remove(payload.Args[0])
}

logVerb("RPC", err, payload)
Expand Down
25 changes: 21 additions & 4 deletions src/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func testDefaults(t *testing.T, url string) string {
t.Fatal("error δΈ­ζ–‡ folder")
}

if !strings.Contains(bodyStr, `<tr> <td><i class="btn icon icon-types icon-blank"></i></td> <td class="file-size"><code>0.2k</code></td> <td class="arrow"><i class="arrow-icon"></i></td> <td class="display-name"><a class="list-links" onclick="return onClickLink(event)" href="custom_mime_type.types">custom_mime_type.types</a></td> </tr>`) {
if !strings.Contains(bodyStr, `<tr> <td><i ondblclick="return rm(event)" onclick="return rename(event)" class="btn icon icon-types icon-blank"></i></td> <td class="file-size"><code>0.2k</code></td> <td class="arrow"><i class="arrow-icon"></i></td> <td class="display-name"><a class="list-links" onclick="return onClickLink(event)" href="custom_mime_type.types">custom_mime_type.types</a></td> </tr>`) {
t.Fatal("error row custom_mime_type")
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func TestGetFolder(t *testing.T) {
}

bodyStr = testDefaults(t, "http://127.0.0.1:8001/")
if !strings.Contains(bodyStr, `<tr> <td><i class="btn icon icon-folder icon-blank"></i></td> <td class="file-size"><code>0</code></td> <td class="arrow"><i class="arrow-icon"></i></td> <td class="display-name"><a class="list-links" onclick="return onClickLink(event)" href="AAA">AAA/</a></td> </tr>`) {
if !strings.Contains(bodyStr, `<tr> <td><i ondblclick="return rm(event)" onclick="return rename(event)" class="btn icon icon-folder icon-blank"></i></td> <td class="file-size"><code>0</code></td> <td class="arrow"><i class="arrow-icon"></i></td> <td class="display-name"><a class="list-links" onclick="return onClickLink(event)" href="AAA">AAA/</a></td> </tr>`) {
t.Fatal("error new folder created")
}

Expand All @@ -140,7 +140,7 @@ func TestGetFolder(t *testing.T) {
}

bodyStr = testDefaults(t, "http://127.0.0.1:8001/")
if strings.Contains(bodyStr, `<tr> <td><i class="btn icon icon-folder icon-blank"></i></td> <td class="file-size"><code>0</code></td> <td class="arrow"><i class="arrow-icon"></i></td> <td class="display-name"><a class="list-links" onclick="return onClickLink(event)" href="AAA">AAA/</a></td> </tr>`) {
if strings.Contains(bodyStr, `<tr> <td><i ondblclick="return rm(event)" onclick="return rename(event)" class="btn icon icon-folder icon-blank"></i></td> <td class="file-size"><code>0</code></td> <td class="arrow"><i class="arrow-icon"></i></td> <td class="display-name"><a class="list-links" onclick="return onClickLink(event)" href="AAA">AAA/</a></td> </tr>`) {
t.Fatal("error folder moved")
}

Expand All @@ -157,7 +157,7 @@ func TestGetFolder(t *testing.T) {
}

bodyStr = testDefaults(t, "http://127.0.0.1:8001/")
if !strings.Contains(bodyStr, `<tr> <td><i class="btn icon icon-α„’α…‘ α„’α…‘ icon-blank"></i></td> <td class="file-size"><code>0.0k</code></td> <td class="arrow"><i class="arrow-icon"></i></td> <td class="display-name"><a class="list-links" onclick="return onClickLink(event)" href="%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1">α„’α…‘ α„’α…‘</a></td> </tr>`) {
if !strings.Contains(bodyStr, `<tr> <td><i ondblclick="return rm(event)" onclick="return rename(event)" class="btn icon icon-α„’α…‘ α„’α…‘ icon-blank"></i></td> <td class="file-size"><code>0.0k</code></td> <td class="arrow"><i class="arrow-icon"></i></td> <td class="display-name"><a class="list-links" onclick="return onClickLink(event)" href="%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1">α„’α…‘ α„’α…‘</a></td> </tr>`) {
t.Fatal("error checking new file row")
}

Expand All @@ -167,4 +167,21 @@ func TestGetFolder(t *testing.T) {
if !strings.Contains(bodyStr, `err`) {
t.Fatal("error not returned")
}

// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test rm rpc & cleanup")
bodyStr = postJSON(t, "http://127.0.0.1:8001/rpc", `{"call":"rm","args":["/hols/AAA"]}`)
if !strings.Contains(bodyStr, `ok`) {
t.Fatal("error returned value")
}

bodyStr = get(t, "http://127.0.0.1:8001/hols/AAA")
if !strings.Contains(bodyStr, `error`) {
t.Fatal("error not returned")
}

bodyStr = postJSON(t, "http://127.0.0.1:8001/rpc", `{"call":"rm","args":["/α„’α…‘ α„’α…‘"]}`)
if !strings.Contains(bodyStr, `ok`) {
t.Fatal("error returned value")
}
}
Loading

0 comments on commit 52188c1

Please sign in to comment.