diff --git a/cmd/handlers.go b/cmd/handlers.go
index 5acd1f7..7a6e8f0 100644
--- a/cmd/handlers.go
+++ b/cmd/handlers.go
@@ -3,6 +3,7 @@ package main
import (
"mime"
"net/http"
+ "path"
"path/filepath"
"github.com/abhinavxd/artemis/internal/envelope"
@@ -132,7 +133,7 @@ func initHandlers(g *fastglue.Fastglue, hub *ws.Hub) {
g.DELETE("/api/templates/{id}", authPerm(handleDeleteTemplate, "templates", "delete"))
// WebSocket.
- g.GET("/api/ws", auth(func(r *fastglue.Request) error {
+ g.GET("/ws", auth(func(r *fastglue.Request) error {
return handleWS(r, hub)
}))
@@ -157,14 +158,14 @@ func serveIndexPage(r *fastglue.Request) error {
r.RequestCtx.Response.Header.Add("Expires", "-1")
// Serve the index.html file from the embedded filesystem.
- file, err := app.fs.Get("/frontend/dist/index.html")
+ file, err := app.fs.Get(path.Join(frontendDir, "index.html"))
if err != nil {
- return r.SendErrorEnvelope(http.StatusNotFound, "Page not found", nil, "InputException")
+ return r.SendErrorEnvelope(http.StatusNotFound, "Page not found", nil, envelope.NotFoundError)
}
r.RequestCtx.Response.Header.Set("Content-Type", "text/html")
r.RequestCtx.SetBody(file.ReadBytes())
- // Set csrf cookie if not already set.
+ // Set CSRF cookie if not already set.
if err := app.auth.SetCSRFCookie(r); err != nil {
app.lo.Error("error setting csrf cookie", "error", err)
return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.T("user.errorAcquiringSession"), nil))
@@ -180,10 +181,10 @@ func serveStaticFiles(r *fastglue.Request) error {
filePath := string(r.RequestCtx.Path())
// Fetch and serve the file from the embedded filesystem.
- finalPath := filepath.Join("frontend/dist", filePath)
+ finalPath := filepath.Join(frontendDir, filePath)
file, err := app.fs.Get(finalPath)
if err != nil {
- return r.SendErrorEnvelope(http.StatusNotFound, "File not found", nil, "InputException")
+ return r.SendErrorEnvelope(http.StatusNotFound, "File not found", nil, envelope.NotFoundError)
}
// Set the appropriate Content-Type based on the file extension.
diff --git a/cmd/inboxes.go b/cmd/inboxes.go
index 08e824e..1fec301 100644
--- a/cmd/inboxes.go
+++ b/cmd/inboxes.go
@@ -12,9 +12,8 @@ import (
func handleGetInboxes(r *fastglue.Request) error {
var app = r.Context.(*App)
inboxes, err := app.inbox.GetAll()
- // TODO: Clear out passwords.
if err != nil {
- return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, "Could not fetch inboxes", nil, envelope.GeneralError)
+ return sendErrorEnvelope(r, err)
}
return r.SendEnvelope(inboxes)
}
@@ -25,9 +24,12 @@ func handleGetInbox(r *fastglue.Request) error {
id, _ = strconv.Atoi(r.RequestCtx.UserValue("id").(string))
)
inbox, err := app.inbox.GetByID(id)
- // TODO: Clear out passwords.
if err != nil {
- return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, "Could not fetch inboxes", nil, envelope.GeneralError)
+ return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, "Error fetching inbox", nil, envelope.GeneralError)
+ }
+ if err := inbox.ClearPasswords(); err != nil {
+ app.lo.Error("error clearing out passwords", "error", err)
+ return envelope.NewError(envelope.GeneralError, "Error fetching inbox", nil)
}
return r.SendEnvelope(inbox)
}
diff --git a/cmd/login.go b/cmd/login.go
index cbcdc65..22c6235 100644
--- a/cmd/login.go
+++ b/cmd/login.go
@@ -22,6 +22,11 @@ func handleLogin(r *fastglue.Request) error {
app.lo.Error("error saving session", "error", err)
return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.T("user.errorAcquiringSession"), nil))
}
+ // Set CSRF cookie if not already set.
+ if err := app.auth.SetCSRFCookie(r); err != nil {
+ app.lo.Error("error setting csrf cookie", "error", err)
+ return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.T("user.errorAcquiringSession"), nil))
+ }
return r.SendEnvelope(user)
}
diff --git a/cmd/main.go b/cmd/main.go
index fa91b27..4b97ffa 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -33,7 +33,10 @@ import (
"github.com/zerodha/logf"
)
-var ko = koanf.New(".")
+var (
+ ko = koanf.New(".")
+ frontendDir = "frontend/dist"
+)
// App is the global app context which is passed and injected in the http handlers.
type App struct {
@@ -176,7 +179,7 @@ func main() {
initHandlers(g, wsHub)
s := &fasthttp.Server{
- Name: ko.MustString("app.server.name"),
+ Name: "server",
ReadTimeout: ko.MustDuration("app.server.read_timeout"),
WriteTimeout: ko.MustDuration("app.server.write_timeout"),
MaxRequestBodySize: ko.MustInt("app.server.max_body_size"),
diff --git a/cmd/media.go b/cmd/media.go
index aa05366..cad5356 100644
--- a/cmd/media.go
+++ b/cmd/media.go
@@ -87,7 +87,8 @@ func handleMediaUpload(r *fastglue.Request) error {
}
}()
- // Generate and upload thumbnail if it's an image.
+ // Generate and upload thumbnail and save it's dimensions if it's an image.
+ var meta = []byte("{}")
if slices.Contains(image.Exts, srcExt) {
file.Seek(0, 0)
thumbFile, err := image.CreateThumb(thumbnailSize, file)
@@ -100,20 +101,21 @@ func handleMediaUpload(r *fastglue.Request) error {
app.lo.Error("error uploading thumbnail", "error", err)
return sendErrorEnvelope(r, err)
}
- }
- // Store image dimensions in the media meta.
- file.Seek(0, 0)
- width, height, err := image.GetDimensions(file)
- if err != nil {
- cleanUp = true
- app.lo.Error("error getting image dimensions", "error", err)
- return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, "Error uploading file", nil, envelope.GeneralError)
+ // Store image dimensions in the media meta.
+ file.Seek(0, 0)
+ width, height, err := image.GetDimensions(file)
+ if err != nil {
+ cleanUp = true
+ app.lo.Error("error getting image dimensions", "error", err)
+ return r.SendErrorEnvelope(fasthttp.StatusInternalServerError, "Error uploading file", nil, envelope.GeneralError)
+ }
+ meta, _ = json.Marshal(map[string]interface{}{
+ "width": width,
+ "height": height,
+ })
+
}
- meta, _ := json.Marshal(map[string]interface{}{
- "width": width,
- "height": height,
- })
file.Seek(0, 0)
_, err = app.media.Upload(uuid.String(), srcContentType, file)
diff --git a/cmd/settings.go b/cmd/settings.go
index 9cb8e44..28b3b90 100644
--- a/cmd/settings.go
+++ b/cmd/settings.go
@@ -1,7 +1,12 @@
package main
import (
+ "encoding/json"
+ "strings"
+
+ "github.com/abhinavxd/artemis/internal/envelope"
"github.com/abhinavxd/artemis/internal/setting/models"
+ "github.com/abhinavxd/artemis/internal/stringutil"
"github.com/valyala/fasthttp"
"github.com/zerodha/fastglue"
)
@@ -35,30 +40,48 @@ func handleUpdateGeneralSettings(r *fastglue.Request) error {
func handleGetEmailNotificationSettings(r *fastglue.Request) error {
var (
- app = r.Context.(*App)
- req = models.EmailNotification{}
+ app = r.Context.(*App)
+ notif = models.EmailNotification{}
)
- if err := r.Decode(&req, "json"); err != nil {
- return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Bad request", nil, "")
- }
out, err := app.setting.GetByPrefix("notification.email")
if err != nil {
return sendErrorEnvelope(r, err)
}
- return r.SendEnvelope(out)
+
+ // Unmarshal and filter out password.
+ if err := json.Unmarshal(out, ¬if); err != nil {
+ return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, "Error fetching settings", nil))
+ }
+ if notif.Password != "" {
+ notif.Password = strings.Repeat(stringutil.PasswordDummy, 10)
+ }
+ return r.SendEnvelope(notif)
}
func handleUpdateEmailNotificationSettings(r *fastglue.Request) error {
var (
app = r.Context.(*App)
req = models.EmailNotification{}
+ cur = models.EmailNotification{}
)
if err := r.Decode(&req, "json"); err != nil {
- return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Bad request", nil, "")
+ return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Bad request", nil, envelope.InputError)
}
+ out, err := app.setting.GetByPrefix("notification.email")
+ if err != nil {
+ return sendErrorEnvelope(r, err)
+ }
+
+ if err := json.Unmarshal(out, &cur); err != nil {
+ return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, "Error updating settings", nil))
+ }
+
+ if req.Password == "" {
+ req.Password = cur.Password
+ }
if err := app.setting.Update(req); err != nil {
return sendErrorEnvelope(r, err)
diff --git a/config.sample.toml b/config.sample.toml
index 8ec4cc3..cea1aa2 100644
--- a/config.sample.toml
+++ b/config.sample.toml
@@ -5,7 +5,6 @@ env = "dev"
# HTTP server.
[app.server]
-name = ""
address = "0.0.0.0:9009"
socket = ""
read_timeout = "5s"
diff --git a/frontend/package.json b/frontend/package.json
index 4c82050..280d475 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -73,7 +73,7 @@
"sass": "^1.70.0",
"start-server-and-test": "^2.0.3",
"tailwindcss": "latest",
- "vite": "^5.0.11"
+ "vite": "^5.4.9"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
diff --git a/frontend/src/components/admin/automation/CreateOrEditRule.vue b/frontend/src/components/admin/automation/CreateOrEditRule.vue
index 8021d7b..833a85d 100644
--- a/frontend/src/components/admin/automation/CreateOrEditRule.vue
+++ b/frontend/src/components/admin/automation/CreateOrEditRule.vue
@@ -10,7 +10,7 @@
-
+
Name
@@ -21,7 +21,7 @@
-
+
Description
@@ -32,7 +32,7 @@
-
+
Type