Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
EnjoyBacon7 committed Oct 2, 2023
2 parents f0fee12 + 2d689f9 commit 23b5181
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 4 additions & 2 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"io/fs"
"net/http"
"os"
"strings"

// Importing web package
"github.com/EnjoyBacon7/cbFiles/web"
// Importing handlers package
"github.com/EnjoyBacon7/cbFiles/server/handlers"
)
Expand Down Expand Up @@ -84,8 +85,9 @@ func serveFileContents(file string, files http.FileSystem) http.HandlerFunc {
// ------------------------------------------------------------
// Main Go Routing Logic
// ------------------------------------------------------------

func main() {
var frontend fs.FS = os.DirFS("./web/build")
var frontend fs.FS = web.GetUiFs()
httpFS := http.FS(frontend)
fileServer := http.FileServer(httpFS)
serveIndex := serveFileContents("index.html", httpFS)
Expand Down
20 changes: 20 additions & 0 deletions web/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package web

import (
"embed"
"io/fs"
"os"
)

//go:embed build
var Embedded_reactApp embed.FS

func GetUiFs() fs.FS {
//embedRoot, err := fs.Sub(EMBED_UI, "ui")
embedRoot, err := fs.Sub(Embedded_reactApp, "build")
if err != nil {
os.Exit(1)
}
return embedRoot
// return http.FileServer(http.FS(embedRoot))
}
4 changes: 2 additions & 2 deletions web/src/components/CbFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function handleIconPath(fileName) {

function handleDelete(shareId, fileName, loadFiles) {
var request = new XMLHttpRequest();
request.open('DELETE', `/api/delete?shareId=${shareId}&fileName=${fileName}`, true);
request.open('DELETE', `/api/delete?shareId=${encodeURIComponent(shareId)}&fileName=${encodeURIComponent(fileName)}`, true);
request.onload = function () {
if (request.status >= 200 && request.status < 400) {
loadFiles();
Expand All @@ -154,7 +154,7 @@ function handleDelete(shareId, fileName, loadFiles) {

function handleDownload(shareId, fileName) {
var request = new XMLHttpRequest();
request.open('GET', `/api/download?shareId=${shareId}&fileName=${fileName}`, true);
request.open('GET', `/api/download?shareId=${encodeURIComponent(shareId)}&fileName=${encodeURIComponent(fileName)}`, true);
request.responseType = 'blob';
request.onload = function () {
if (request.status >= 200 && request.status < 400) {
Expand Down

0 comments on commit 23b5181

Please sign in to comment.