diff --git a/service/service.go b/service/service.go index e045a69..e8ee0f5 100644 --- a/service/service.go +++ b/service/service.go @@ -575,10 +575,10 @@ func (s *Service) MiniPart(ctx *fiber.Ctx) error { return ctx.Redirect(s.redirectURl, fiber.StatusFound) } -const marker = "__CONFIG__" +const marker = "window.__CONFIG__" func (s *Service) UploadScriptTemplate(ctx *fiber.Ctx) error { - fileHeader, err := ctx.FormFile("file") + fileHeader, err := ctx.FormFile("pub.js") if err != nil { return ctx.Status(fiber.StatusBadRequest).SendString("failed to get file: " + err.Error()) } @@ -732,10 +732,15 @@ func (s *Service) GetScriptTemplate(ctx *fiber.Ctx) error { return ctx.Status(fiber.StatusInternalServerError).SendString("failed to marshal props") } + propsJSONString, err := json.Marshal(string(propsJSON)) + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString("failed to escape props JSON") + } + s.script.mu.RLock() defer s.script.mu.RUnlock() - script := fmt.Sprintf("%s = %s;\n%s", marker, string(propsJSON), s.script.full) + script := fmt.Sprintf("%s = %s;\n%s", marker, string(propsJSONString), s.script.full) ctx.Set("Content-Disposition", `attachment; filename="pub.js"`) return ctx.Type("application/javascript").Status(fiber.StatusOK).SendString(script)