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) diff --git a/frontend/src/components/AccountDashboard.vue b/frontend/src/components/AccountDashboard.vue index 5687bf6..132fe28 100644 --- a/frontend/src/components/AccountDashboard.vue +++ b/frontend/src/components/AccountDashboard.vue @@ -105,13 +105,25 @@ const onDelete = async (event: FormSubmitEvent) => { return; } console.log("Starting deletion procedure..."); - // TODO: Implement file deletion and remove the if statement below + // TODO: Remove this when file-transfer starts working if (1 == 1) { console.log("Not yet implemented"); toast.add({severity: 'error', summary: 'Operation not yet implemented', life: 3000}); return; } - // TODO: Delete user files first + // Delete user files first + let filesToDelete = user._value.ownedFiles; + for (const file of filesToDelete) { + console.log("Deleting "+file); + let response = await fetch ("http://localhost:8080/"+file, { + method: "DELETE" + }); + if (!response.ok) { + this.toast.add({severity: 'error', summary: 'Could not delete files.', life: 3000}); + return; + } + } + let response = fetch(`http://localhost:2024/accounts/`+user._value.id, {method: 'DELETE'}) if ((await response).status === 200) { await store.clearUser(); diff --git a/frontend/src/components/AddFile.vue b/frontend/src/components/AddFile.vue new file mode 100644 index 0000000..f80f42a --- /dev/null +++ b/frontend/src/components/AddFile.vue @@ -0,0 +1,251 @@ + + + + +