mirror of
https://github.com/usememos/memos.git
synced 2025-02-12 01:10:38 +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"`
|
||||
RowStatus *string `json:"rowStatus"`
|
||||
CreatedTs *int64 `json:"createdTs"`
|
||||
}
|
||||
|
||||
type MemoFind struct {
|
||||
|
@ -22,29 +22,6 @@ const (
|
||||
DbConnectionFailure Code = 101
|
||||
DbStatementSyntaxError Code = 102
|
||||
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
|
||||
|
@ -23,10 +23,10 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
|
||||
}
|
||||
user, err := s.UserService.FindUser(userFind)
|
||||
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 {
|
||||
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.
|
||||
@ -35,8 +35,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Incorrect password").SetInternal(err)
|
||||
}
|
||||
|
||||
err = setUserSession(c, user)
|
||||
if err != nil {
|
||||
if err = setUserSession(c, user); err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
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.")
|
||||
}
|
||||
if len(signup.Password) <= 5 {
|
||||
if len(signup.Password) < 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)
|
||||
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 {
|
||||
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)
|
||||
|
@ -65,17 +65,11 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
||||
memoFind := &api.MemoFind{
|
||||
CreatorId: &userId,
|
||||
}
|
||||
showHiddenMemo, err := strconv.ParseBool(c.QueryParam("hidden"))
|
||||
if err != nil {
|
||||
showHiddenMemo = false
|
||||
rowStatus := c.QueryParam("rowStatus")
|
||||
if rowStatus != "" {
|
||||
memoFind.RowStatus = &rowStatus
|
||||
}
|
||||
|
||||
rowStatus := "NORMAL"
|
||||
if showHiddenMemo {
|
||||
rowStatus = "HIDDEN"
|
||||
}
|
||||
memoFind.RowStatus = &rowStatus
|
||||
|
||||
list, err := s.MemoService.FindMemoList(memoFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch memo list").SetInternal(err)
|
||||
|
@ -66,17 +66,11 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
|
||||
memoFind := &api.MemoFind{
|
||||
CreatorId: &user.Id,
|
||||
}
|
||||
showHiddenMemo, err := strconv.ParseBool(c.QueryParam("hidden"))
|
||||
if err != nil {
|
||||
showHiddenMemo = false
|
||||
rowStatus := c.QueryParam("rowStatus")
|
||||
if rowStatus != "" {
|
||||
memoFind.RowStatus = &rowStatus
|
||||
}
|
||||
|
||||
rowStatus := "NORMAL"
|
||||
if showHiddenMemo {
|
||||
rowStatus = "HIDDEN"
|
||||
}
|
||||
memoFind.RowStatus = &rowStatus
|
||||
|
||||
list, err := s.MemoService.FindMemoList(memoFind)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch memo list").SetInternal(err)
|
||||
|
@ -109,6 +109,9 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
|
||||
if v := patch.RowStatus; v != nil {
|
||||
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)
|
||||
|
||||
|
@ -113,14 +113,14 @@ namespace api {
|
||||
export function getMyMemos() {
|
||||
return request<Model.Memo[]>({
|
||||
method: "GET",
|
||||
url: "/api/memo",
|
||||
url: "/api/memo?rowStatus=NORMAL",
|
||||
});
|
||||
}
|
||||
|
||||
export function getMyDeletedMemos() {
|
||||
return request<Model.Memo[]>({
|
||||
method: "GET",
|
||||
url: "/api/memo?hidden=true",
|
||||
url: "/api/memo?rowStatus=HIDDEN",
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user