mirror of
https://github.com/usememos/memos.git
synced 2025-01-31 17:48:12 +08:00
feat: const session secret key in dev
This commit is contained in:
parent
8f76120e4e
commit
1cebf1dbd0
5 changed files with 9 additions and 17 deletions
|
@ -37,7 +37,7 @@ func (m *Main) Run() error {
|
|||
|
||||
m.db = db
|
||||
|
||||
s := server.NewServer(m.profile.port)
|
||||
s := server.NewServer(m.profile.port, m.profile.mode)
|
||||
|
||||
s.ShortcutService = store.NewShortcutService(db)
|
||||
s.MemoService = store.NewMemoService(db)
|
||||
|
|
|
@ -23,7 +23,7 @@ type Server struct {
|
|||
port int
|
||||
}
|
||||
|
||||
func NewServer(port int) *Server {
|
||||
func NewServer(port int, mode string) *Server {
|
||||
e := echo.New()
|
||||
e.Debug = true
|
||||
e.HideBanner = true
|
||||
|
@ -46,7 +46,11 @@ func NewServer(port int) *Server {
|
|||
HTML5: true,
|
||||
}))
|
||||
|
||||
e.Use(session.Middleware(sessions.NewCookieStore([]byte(securecookie.GenerateRandomKey(16)))))
|
||||
secret := []byte("justmemos")
|
||||
if mode != "dev" {
|
||||
secret = securecookie.GenerateRandomKey(16)
|
||||
}
|
||||
e.Use(session.Middleware(sessions.NewCookieStore(secret)))
|
||||
|
||||
s := &Server{
|
||||
e: e,
|
||||
|
|
|
@ -11,8 +11,8 @@ import (
|
|||
)
|
||||
|
||||
func (s *Server) registerUserRoutes(g *echo.Group) {
|
||||
// GET /api/user/me is used to check if the user is logged in.
|
||||
g.GET("/user/me", func(c echo.Context) error {
|
||||
// /api/user/me is used to check if the user is logged in,
|
||||
userSessionId := c.Get(getUserIdContextKey())
|
||||
if userSessionId == nil {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing session")
|
||||
|
|
|
@ -103,9 +103,8 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
|
|||
}
|
||||
|
||||
c.Response().Writer.WriteHeader(http.StatusOK)
|
||||
c.Response().Writer.Header().Set("Content-Type", "application/octet-stream")
|
||||
c.Response().Writer.Header().Set("Content-Type", resource.Type)
|
||||
c.Response().Writer.Write(resource.Blob)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { useContext } from "react";
|
||||
import appContext from "../stores/appContext";
|
||||
import { globalStateService, memoService } from "../services";
|
||||
import { parseHtmlToRawText } from "../helpers/marked";
|
||||
import { formatMemoContent } from "./Memo";
|
||||
import "../less/preferences-section.less";
|
||||
|
||||
|
@ -49,13 +48,6 @@ const PreferencesSection: React.FC<Props> = () => {
|
|||
document.body.removeChild(element);
|
||||
};
|
||||
|
||||
const handleFormatMemosBtnClick = async () => {
|
||||
const memos = memoService.getState().memos;
|
||||
for (const m of memos) {
|
||||
memoService.updateMemo(m.id, parseHtmlToRawText(m.content));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="section-container preferences-section-container">
|
||||
|
@ -83,9 +75,6 @@ const PreferencesSection: React.FC<Props> = () => {
|
|||
<button className="px-2 py-1 border rounded text-base hover:opacity-80" onClick={handleExportBtnClick}>
|
||||
Export data as JSON
|
||||
</button>
|
||||
<button className="btn format-btn hidden" onClick={handleFormatMemosBtnClick}>
|
||||
Format Data
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
|
Loading…
Reference in a new issue