mirror of
https://github.com/usememos/memos.git
synced 2025-02-16 03:12:13 +01:00
chore: clean server
This commit is contained in:
parent
3c06c68691
commit
8f76120e4e
@ -21,6 +21,7 @@ type MemoPatch struct {
|
|||||||
|
|
||||||
Content *string `json:"content"`
|
Content *string `json:"content"`
|
||||||
RowStatus *string `json:"rowStatus"`
|
RowStatus *string `json:"rowStatus"`
|
||||||
|
CreatedTs *int64 `json:"createdTs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemoFind struct {
|
type MemoFind struct {
|
||||||
|
@ -22,29 +22,6 @@ const (
|
|||||||
DbConnectionFailure Code = 101
|
DbConnectionFailure Code = 101
|
||||||
DbStatementSyntaxError Code = 102
|
DbStatementSyntaxError Code = 102
|
||||||
DbExecutionError Code = 103
|
DbExecutionError Code = 103
|
||||||
|
|
||||||
// 201 db migration error
|
|
||||||
// Db migration is a core feature, so we separate it from the db error
|
|
||||||
MigrationSchemaMissing Code = 201
|
|
||||||
MigrationAlreadyApplied Code = 202
|
|
||||||
MigrationOutOfOrder Code = 203
|
|
||||||
MigrationBaselineMissing Code = 204
|
|
||||||
|
|
||||||
// 301 task error
|
|
||||||
TaskTimingNotAllowed Code = 301
|
|
||||||
|
|
||||||
// 10001 advisor error code
|
|
||||||
CompatibilityDropDatabase Code = 10001
|
|
||||||
CompatibilityRenameTable Code = 10002
|
|
||||||
CompatibilityDropTable Code = 10003
|
|
||||||
CompatibilityRenameColumn Code = 10004
|
|
||||||
CompatibilityDropColumn Code = 10005
|
|
||||||
CompatibilityAddPrimaryKey Code = 10006
|
|
||||||
CompatibilityAddUniqueKey Code = 10007
|
|
||||||
CompatibilityAddForeignKey Code = 10008
|
|
||||||
CompatibilityAddCheck Code = 10009
|
|
||||||
CompatibilityAlterCheck Code = 10010
|
|
||||||
CompatibilityAlterColumn Code = 10011
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error represents an application-specific error. Application errors can be
|
// Error represents an application-specific error. Application errors can be
|
||||||
|
@ -23,10 +23,10 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
|
|||||||
}
|
}
|
||||||
user, err := s.UserService.FindUser(userFind)
|
user, err := s.UserService.FindUser(userFind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to authenticate user").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user by name %s", login.Name)).SetInternal(err)
|
||||||
}
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("User not found: %s", login.Name))
|
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("User not found with name %s", login.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare the stored hashed password, with the hashed version of the password that was received.
|
// Compare the stored hashed password, with the hashed version of the password that was received.
|
||||||
@ -35,8 +35,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
|
|||||||
return echo.NewHTTPError(http.StatusUnauthorized, "Incorrect password").SetInternal(err)
|
return echo.NewHTTPError(http.StatusUnauthorized, "Incorrect password").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = setUserSession(c, user)
|
if err = setUserSession(c, user); err != nil {
|
||||||
if err != nil {
|
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to set login session").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to set login session").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,10 +63,12 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
|
|||||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted signup request").SetInternal(err)
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted signup request").SetInternal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(signup.Name) <= 5 {
|
// Validate signup form.
|
||||||
|
// We can do stricter checks later.
|
||||||
|
if len(signup.Name) < 6 {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Username is too short, minimum length is 6.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Username is too short, minimum length is 6.")
|
||||||
}
|
}
|
||||||
if len(signup.Password) <= 5 {
|
if len(signup.Password) < 6 {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Password is too short, minimum length is 6.")
|
return echo.NewHTTPError(http.StatusBadRequest, "Password is too short, minimum length is 6.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,10 +77,10 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
|
|||||||
}
|
}
|
||||||
user, err := s.UserService.FindUser(userFind)
|
user, err := s.UserService.FindUser(userFind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to authenticate user").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user by name %s", signup.Name)).SetInternal(err)
|
||||||
}
|
}
|
||||||
if user != nil {
|
if user != nil {
|
||||||
return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Existed user found: %s", signup.Name))
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Existed user found: %s", signup.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordHash, err := bcrypt.GenerateFromPassword([]byte(signup.Password), bcrypt.DefaultCost)
|
passwordHash, err := bcrypt.GenerateFromPassword([]byte(signup.Password), bcrypt.DefaultCost)
|
||||||
|
@ -65,16 +65,10 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
memoFind := &api.MemoFind{
|
memoFind := &api.MemoFind{
|
||||||
CreatorId: &userId,
|
CreatorId: &userId,
|
||||||
}
|
}
|
||||||
showHiddenMemo, err := strconv.ParseBool(c.QueryParam("hidden"))
|
rowStatus := c.QueryParam("rowStatus")
|
||||||
if err != nil {
|
if rowStatus != "" {
|
||||||
showHiddenMemo = false
|
|
||||||
}
|
|
||||||
|
|
||||||
rowStatus := "NORMAL"
|
|
||||||
if showHiddenMemo {
|
|
||||||
rowStatus = "HIDDEN"
|
|
||||||
}
|
|
||||||
memoFind.RowStatus = &rowStatus
|
memoFind.RowStatus = &rowStatus
|
||||||
|
}
|
||||||
|
|
||||||
list, err := s.MemoService.FindMemoList(memoFind)
|
list, err := s.MemoService.FindMemoList(memoFind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -66,16 +66,10 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
|
|||||||
memoFind := &api.MemoFind{
|
memoFind := &api.MemoFind{
|
||||||
CreatorId: &user.Id,
|
CreatorId: &user.Id,
|
||||||
}
|
}
|
||||||
showHiddenMemo, err := strconv.ParseBool(c.QueryParam("hidden"))
|
rowStatus := c.QueryParam("rowStatus")
|
||||||
if err != nil {
|
if rowStatus != "" {
|
||||||
showHiddenMemo = false
|
|
||||||
}
|
|
||||||
|
|
||||||
rowStatus := "NORMAL"
|
|
||||||
if showHiddenMemo {
|
|
||||||
rowStatus = "HIDDEN"
|
|
||||||
}
|
|
||||||
memoFind.RowStatus = &rowStatus
|
memoFind.RowStatus = &rowStatus
|
||||||
|
}
|
||||||
|
|
||||||
list, err := s.MemoService.FindMemoList(memoFind)
|
list, err := s.MemoService.FindMemoList(memoFind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,6 +109,9 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
|
|||||||
if v := patch.RowStatus; v != nil {
|
if v := patch.RowStatus; v != nil {
|
||||||
set, args = append(set, "row_status = ?"), append(args, *v)
|
set, args = append(set, "row_status = ?"), append(args, *v)
|
||||||
}
|
}
|
||||||
|
if v := patch.CreatedTs; v != nil {
|
||||||
|
set, args = append(set, "created_ts = ?"), append(args, *v)
|
||||||
|
}
|
||||||
|
|
||||||
args = append(args, patch.Id)
|
args = append(args, patch.Id)
|
||||||
|
|
||||||
|
@ -113,14 +113,14 @@ namespace api {
|
|||||||
export function getMyMemos() {
|
export function getMyMemos() {
|
||||||
return request<Model.Memo[]>({
|
return request<Model.Memo[]>({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: "/api/memo",
|
url: "/api/memo?rowStatus=NORMAL",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMyDeletedMemos() {
|
export function getMyDeletedMemos() {
|
||||||
return request<Model.Memo[]>({
|
return request<Model.Memo[]>({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: "/api/memo?hidden=true",
|
url: "/api/memo?rowStatus=HIDDEN",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user