Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help message + bugfix #106

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions gossa.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"html/template"
"io"
"io/fs"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand All @@ -25,7 +24,7 @@ import (

type rowTemplate struct {
Name string
Href template.HTML
Href template.URL
Size string
Ext string
}
Expand Down Expand Up @@ -83,9 +82,9 @@ func humanize(bytes int64) string {
}

func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path string) {
_files, err := ioutil.ReadDir(fullPath)
files, err := os.ReadDir(fullPath)
check(err)
sort.Slice(_files, func(i, j int) bool { return strings.ToLower(_files[i].Name()) < strings.ToLower(_files[j].Name()) })
sort.Slice(files, func(i, j int) bool { return strings.ToLower(files[i].Name()) < strings.ToLower(files[j].Name()) })

if !strings.HasSuffix(path, "/") {
path += "/"
Expand All @@ -100,20 +99,20 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
p.Ro = *ro
p.Title = template.HTML(html.EscapeString(title))

for _, el := range _files {
if *skipHidden && strings.HasPrefix(el.Name(), ".") {
continue // dont print hidden files if we're not allowed
}
if !*symlinks && el.Mode()&os.ModeSymlink != 0 {
continue // dont print symlinks if were not allowed
}

el, err := os.Stat(fullPath + "/" + el.Name())
for _, el := range files {
info, err := el.Info()
if err != nil {
log.Println("error - cant stat a file", err)
continue
}

if *skipHidden && strings.HasPrefix(el.Name(), ".") {
continue // dont print hidden files if we're not allowed
}
if *symlinks && info.Mode()&os.ModeSymlink != 0 {
continue // dont follow symlinks if we're not allowed
}

href := url.PathEscape(el.Name())
name := el.Name()

Expand All @@ -122,11 +121,13 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
}

if el.IsDir() {
p.RowsFolders = append(p.RowsFolders, rowTemplate{name + "/", template.HTML(href), "", "folder"})
row := rowTemplate{name + "/", template.URL(href), "", "folder"}
p.RowsFolders = append(p.RowsFolders, row)
} else {
sl := strings.Split(name, ".")
ext := strings.ToLower(sl[len(sl)-1])
p.RowsFiles = append(p.RowsFiles, rowTemplate{name, template.HTML(href), humanize(el.Size()), ext})
row := rowTemplate{name, template.URL(href), humanize(info.Size()), ext}
p.RowsFiles = append(p.RowsFiles, row)
}
}

Expand Down Expand Up @@ -226,7 +227,7 @@ func rpc(w http.ResponseWriter, r *http.Request) {
var err error
var rpc rpcCall
defer exitPath(w, "rpc", rpc)
bodyBytes, err := ioutil.ReadAll(r.Body)
bodyBytes, err := io.ReadAll(r.Body)
check(err)
json.Unmarshal(bodyBytes, &rpc)

Expand Down
11 changes: 11 additions & 0 deletions gossa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
t.Fatal("post file incorrect path didnt errored")
}

// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test post file")
path = "2024-01-02-10:36:58.png"
payload = "123123123123123123123123"
body0 = postDummyFile(t, url, path, payload)
body1 = get(t, url+path)
body2 = fetchAndTestDefault(t, url)
if body0 != `ok` || body1 != payload || !strings.Contains(body2, `href="2024-01-02-10:36:58.png"`) {
t.Fatal("post file errored")
}

// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test mv rpc")
body0 = postJSON(t, url+"rpc", `{"call":"mv","args":["/AAA", "/hols/AAA"]}`)
Expand Down
10 changes: 10 additions & 0 deletions ui/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const rmMsg = () => !confirm('Remove file?\n')
const ensureMove = () => !confirm('move items?')
const isRo = () => window.ro

// DOM elements
const upBarName = document.getElementById('upBarName')
const upBarPc = document.getElementById('upBarPc')
const upGrid = document.getElementById('drop-grid')
Expand All @@ -29,6 +30,8 @@ const editor = document.getElementById('text-editor')
const crossIcon = document.getElementById('quitAll')
const toast = document.getElementById('toast')
const table = document.getElementById('linkTable')
const helpMsg = document.getElementById('help_message')

const transparentPixel = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='

// helpers
Expand Down Expand Up @@ -847,5 +850,12 @@ function init () {
const matchingA = allA.find(a => a.href === cleanURL)
padOn(matchingA)
}

// check if we're at root path
if (location.pathname === window.extraPath + '/') {
helpMsg.style.display = 'block'
} else {
helpMsg.style.display = 'none'
}
}
init()
16 changes: 15 additions & 1 deletion ui/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/ui.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
</tr>
{{end}}
</table>
<p id="help_message">Help: Ctrl/Cmd + h<p>
</body>
<div id="upBar" class="bar">
<span style="display: none;" class="barName" id="upBarName"></span>
Expand Down
Loading