Skip to content

Commit 23b5181

Browse files
committed
2 parents f0fee12 + 2d689f9 commit 23b5181

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

server/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"fmt"
55
"io/fs"
66
"net/http"
7-
"os"
87
"strings"
98

9+
// Importing web package
10+
"github.com/EnjoyBacon7/cbFiles/web"
1011
// Importing handlers package
1112
"github.com/EnjoyBacon7/cbFiles/server/handlers"
1213
)
@@ -84,8 +85,9 @@ func serveFileContents(file string, files http.FileSystem) http.HandlerFunc {
8485
// ------------------------------------------------------------
8586
// Main Go Routing Logic
8687
// ------------------------------------------------------------
88+
8789
func main() {
88-
var frontend fs.FS = os.DirFS("./web/build")
90+
var frontend fs.FS = web.GetUiFs()
8991
httpFS := http.FS(frontend)
9092
fileServer := http.FileServer(httpFS)
9193
serveIndex := serveFileContents("index.html", httpFS)

web/embed.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package web
2+
3+
import (
4+
"embed"
5+
"io/fs"
6+
"os"
7+
)
8+
9+
//go:embed build
10+
var Embedded_reactApp embed.FS
11+
12+
func GetUiFs() fs.FS {
13+
//embedRoot, err := fs.Sub(EMBED_UI, "ui")
14+
embedRoot, err := fs.Sub(Embedded_reactApp, "build")
15+
if err != nil {
16+
os.Exit(1)
17+
}
18+
return embedRoot
19+
// return http.FileServer(http.FS(embedRoot))
20+
}

web/src/components/CbFiles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function handleIconPath(fileName) {
141141

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

155155
function handleDownload(shareId, fileName) {
156156
var request = new XMLHttpRequest();
157-
request.open('GET', `/api/download?shareId=${shareId}&fileName=${fileName}`, true);
157+
request.open('GET', `/api/download?shareId=${encodeURIComponent(shareId)}&fileName=${encodeURIComponent(fileName)}`, true);
158158
request.responseType = 'blob';
159159
request.onload = function () {
160160
if (request.status >= 200 && request.status < 400) {

0 commit comments

Comments
 (0)