Skip to content

Commit

Permalink
Improve upon serving
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel2392 committed May 4, 2024
1 parent ff0d82c commit 6e36269
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 107 deletions.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ func main() {

qg.ProjectConfig.Name = flagger.Import

if err = qg.ProjectConfig.Validate(); err != nil {
logger.Fatal(1, fmt.Errorf("failed to validate project config: %w", err))
}

err = qg.WriteProjectConfig(qg.ProjectConfig)
if err != nil {
logger.Fatal(1, fmt.Errorf("failed to write project config: %w", err))
Expand Down
18 changes: 18 additions & 0 deletions quickgo/_templates/dir.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{template "base" .}}

{{define "content"}}
<div class="box-content">
{{ template "parent_url" . }}
{{ if gt (len .ObjectList) 0 }}
{{ range $obj := .ObjectList }}
<div class="quickgo-dir-link-container">
<a class="quickgo-dir-link quickgo-dir" href="{{ ObjectURL $obj }}">{{$obj.GetName}}</a>
</div>
{{ end }}
{{ else }}
<div style="display: flex;align-items: center;justify-content: center;height:50%;">
<h1 style="color:#ff5555;">Directory is empty</h1>
</div>
{{ end }}
</div>
{{end}}
8 changes: 8 additions & 0 deletions quickgo/_templates/file.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{template "base" .}}

{{define "content"}}
<div class="box-content">
{{ template "parent_url" . }}
<pre class="quickgo-file-content">{{.Content}}</pre>
</div>
{{end}}
2 changes: 1 addition & 1 deletion quickgo/_templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{define "content"}}
<div class="box-content">
<h2>{{.Dir.GetName}}</h2>
<h2>Index: {{.Dir.GetName}}</h2>
<pre class="quickgo-file-content">{{.Content}}</pre>
</div>
{{end}}
7 changes: 7 additions & 0 deletions quickgo/_templates/parent_url.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ define "parent_url" }}
{{ if .Parent }}
<h2><a href="{{ ObjectURL .Parent }}">../{{.Parent.GetName}}</a></h2>
{{ else }}
<h2><a href="/">Back to Index</a></h2>
{{ end }}
{{ end }}
12 changes: 0 additions & 12 deletions quickgo/_templates/readme.tmpl

This file was deleted.

46 changes: 37 additions & 9 deletions quickgo/_templates/static/template.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,36 +122,64 @@ body{
padding-top: 0 !important;
padding-bottom: 0 !important;
}
.box-content{
.box-content {
margin-top:10px;
background-color: #f5f5f5;
padding-top: 20px;
height:85vh !important;
overflow-y: scroll;
overflow-y: auto;
/* border-radius: 0px 0px 5px 5px; */
border-radius: 10px;
box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.75);
}
.box-content h1,
.box-content h2,
.box-content h3,
.box-content h4,
.box-content h5,
.box-content h6 {
margin: 0;
padding: 10px 20px;
border-bottom: 1px solid #bbb;
}
.box-content h1 {
font-size: 40px;
}
.box-content h2 {
font-size: 35px;
}
.box-content h3 {
font-size: 28px;
}
.box-content h4 {
font-size: 24px;
}
.box-content h5 {
font-size: 20px;
}
.box-content h6 {
font-size: 18px;
}
.quickgo-dir-link-container{
border-bottom: 1px solid #bbb;
border-radius: 5px;
background-color: #f5f5f5;
width: 100% !important;
height: 45px
}
.box-content a {
transition: all 0.3s ease;
text-decoration: none;
color: #555;
}
.quickgo-dir-link {
display:block;
color: #555;
font-size: 25px;
text-decoration: none;
width:50%;
transition: all 0.3s ease;
margin-left: 20px;
float:left;
}
.quickgo-dir-link:hover {
.box-content a:hover {
color: #9200ff;
text-decoration: none;
}
.quickgo-datasize{
color: #6c757d !important;
Expand Down Expand Up @@ -678,7 +706,7 @@ code{
}

.row {
--bs-gutter-x: 1.5rem;
--bs-gutter-x: 0;
--bs-gutter-y: 0;
display: flex;
flex-wrap: wrap;
Expand Down
48 changes: 28 additions & 20 deletions quickgo/quickfs/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ func (d *FSDirectory) AddDirectory(dirPath string) {
}

for _, part := range parts {
//if _d, ok = dir.Directories[part]; !ok {
// _d = NewFSDirectory(
// part, filepath.Join(dir.Path, part), root,
// )
// dir.Directories[part] = _d
//}
if _d, ok = dir.Directories.Get(part); !ok {
_d = NewFSDirectory(
part, filepath.Join(dir.Path, part), root,
Expand All @@ -230,12 +224,6 @@ func (d *FSDirectory) AddFile(filePath string, reader io.ReadCloser) *FSFile {
)
for i := 0; i < len(parts)-1; i++ {
var part = parts[i]
//if _, ok := dir.Directories[parts[i]]; !ok {
// dir.Directories[part] = NewFSDirectory(
// part, filepath.Join(dir.Path, part), d.root,
// )
//}
//dir = dir.Directories[part]
if d, ok = dir.Directories.Get(part); !ok {
d = NewFSDirectory(
part, filepath.Join(dir.Path, part), dir.root,
Expand All @@ -256,24 +244,44 @@ func (d *FSDirectory) AddFile(filePath string, reader io.ReadCloser) *FSFile {
return f
}

func (d *FSDirectory) ForEach(fn func(FileLike) (cancel bool, err error)) (cancel bool, err error) {
cancel, err = fn(d)
if cancel || err != nil {
// Traverse traverses the directory tree.
// It will traverse into subdirectories.
func (d *FSDirectory) Traverse(fn func(FileLike) (cancel bool, err error)) (cancel bool, err error) {
if cancel, err = fn(d); cancel || err != nil {
return
}

for el := d.Directories.Front(); el != nil; el = el.Next() {
cancel, err = el.Value.ForEach(fn)
if cancel || err != nil {
if cancel, err = el.Value.Traverse(fn); cancel || err != nil {
return
}
}
for el := d.Files.Front(); el != nil; el = el.Next() {
cancel, err = fn(el.Value)
if cancel || err != nil {
if cancel, err = fn(el.Value); cancel || err != nil {
return
}
}
return
}

// ForEach loops over all directories and files in this directory.
// This will not traverse into subdirectories and is not recursive.
func (d *FSDirectory) ForEach(execRoot bool, fn func(FileLike) (cancel bool, err error)) (cancel bool, err error) {
if execRoot {
if cancel, err = fn(d); err != nil || cancel {
return
}
}

for el := d.Directories.Front(); el != nil; el = el.Next() {
if cancel, err = fn(el.Value); err != nil || cancel {
return
}
}

for el := d.Files.Front(); el != nil; el = el.Next() {
if cancel, err = fn(el.Value); err != nil || cancel {
return
}
}
return
}
11 changes: 10 additions & 1 deletion quickgo/quickfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ type (
Directory interface {
FileLike

// Find a directory by path.
Find(path []string) (FileLike, error)

ForEach(func(FileLike) (cancel bool, err error)) (cancel bool, err error)
// Traverse traverses the directory tree.
// It will traverse into subdirectories.
Traverse(fn func(FileLike) (cancel bool, err error)) (cancel bool, err error)

// ForEach loops over all directories and files in this directory.
// This will not traverse into subdirectories and is not recursive.
// execRoot will let execute the function on the directory itself if true (as well as its direct children)
ForEach(execRoot bool, fn func(FileLike) (cancel bool, err error)) (cancel bool, err error)

// Load loads the directory content.
Load() error
}

Expand Down
6 changes: 3 additions & 3 deletions quickgo/quickfs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var FileTree = &quickfs.FSDirectory{

func TestForEach(t *testing.T) {
var count int
FileTree.ForEach(func(fl quickfs.FileLike) (cancel bool, err error) {
FileTree.Traverse(func(fl quickfs.FileLike) (cancel bool, err error) {
t.Logf("file: %s", fl.GetPath())
count++
return
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestAddDirectories(t *testing.T) {
}

var count int
newRoot.ForEach(func(fl quickfs.FileLike) (cancel bool, err error) {
newRoot.Traverse(func(fl quickfs.FileLike) (cancel bool, err error) {
t.Logf("dir: %s", fl.GetPath())
count++
return
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestAddFiles(t *testing.T) {
}

var count int
newRoot.ForEach(func(fl quickfs.FileLike) (cancel bool, err error) {
newRoot.Traverse(func(fl quickfs.FileLike) (cancel bool, err error) {
t.Logf("file: %s", fl.GetPath())
count++
return
Expand Down
Loading

0 comments on commit 6e36269

Please sign in to comment.