From 4b9a687b9f62f0344804b01d64055eec53cb7be1 Mon Sep 17 00:00:00 2001 From: Duszke333 Date: Fri, 24 Jan 2025 11:39:03 +0100 Subject: [PATCH 1/5] Add cors --- file-encryption/go.mod | 1 + file-encryption/go.sum | 2 ++ file-encryption/main.go | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/file-encryption/go.mod b/file-encryption/go.mod index 5472283..e912744 100644 --- a/file-encryption/go.mod +++ b/file-encryption/go.mod @@ -10,6 +10,7 @@ require ( require ( github.com/KyleBanks/depth v1.2.1 // indirect + github.com/go-chi/cors v1.2.1 // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/jsonreference v0.21.0 // indirect github.com/go-openapi/spec v0.21.0 // indirect diff --git a/file-encryption/go.sum b/file-encryption/go.sum index 09b000f..0d05738 100644 --- a/file-encryption/go.sum +++ b/file-encryption/go.sum @@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0= github.com/go-chi/chi/v5 v5.2.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4= +github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58= github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= diff --git a/file-encryption/main.go b/file-encryption/main.go index 1874e63..3219c6c 100644 --- a/file-encryption/main.go +++ b/file-encryption/main.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" + "github.com/go-chi/cors" httpSwagger "github.com/swaggo/http-swagger" "log" "net/http" @@ -34,6 +35,14 @@ func main() { r.Use(middleware.Heartbeat("/ping")) r.Use(middleware.Recoverer) r.Use(middleware.Logger) + r.Use(cors.Handler(cors.Options{ + AllowedOrigins: []string{"http://localhost*", "https://localhost*"}, + AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, + AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"}, + ExposedHeaders: []string{"Link"}, + AllowCredentials: false, + MaxAge: 300, // Maximum value not ignored by any of major browsers + })) r.Post("/encrypt", handler.Encrypt) r.Post("/decrypt", handler.Decrypt) From 2d8fbbcdfc5c13a604e76c26a5f9a41173a07ecd Mon Sep 17 00:00:00 2001 From: Duszke333 Date: Fri, 24 Jan 2025 12:27:40 +0100 Subject: [PATCH 2/5] Added "add file" button --- frontend/src/components/AddFile.vue | 216 ++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 frontend/src/components/AddFile.vue diff --git a/frontend/src/components/AddFile.vue b/frontend/src/components/AddFile.vue new file mode 100644 index 0000000..2eeea23 --- /dev/null +++ b/frontend/src/components/AddFile.vue @@ -0,0 +1,216 @@ + + + + + From c82c06793e71627180161f1b209a41c8004f0b9f Mon Sep 17 00:00:00 2001 From: Duszke333 Date: Fri, 24 Jan 2025 12:30:26 +0100 Subject: [PATCH 3/5] Added "add file" button --- frontend/src/components/AddFile.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/components/AddFile.vue b/frontend/src/components/AddFile.vue index 2eeea23..cd8a907 100644 --- a/frontend/src/components/AddFile.vue +++ b/frontend/src/components/AddFile.vue @@ -87,6 +87,7 @@ export default { try { let fileData = this.selectedFile; + let fileName = this.selectedFile.name; let passwordSalt = null; let passwordHash = null; // Encrypt the file if password is provided @@ -107,6 +108,7 @@ export default { }, body: JSON.stringify({ "data": fileData, + "file_name": fileName, "has_access": [], "id": Array.prototype.map.call(crypto.getRandomValues(new Uint8Array(16)), x=>(('00'+x.toString(16)).slice(-2))).join(''), "tags": this.tags, From 44f9e834c2a536adfd084ea868b281cde37805f6 Mon Sep 17 00:00:00 2001 From: Duszke333 Date: Fri, 24 Jan 2025 13:27:22 +0100 Subject: [PATCH 4/5] Fixes --- frontend/src/components/AddFile.vue | 41 ++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/AddFile.vue b/frontend/src/components/AddFile.vue index cd8a907..f80f42a 100644 --- a/frontend/src/components/AddFile.vue +++ b/frontend/src/components/AddFile.vue @@ -1,4 +1,11 @@