mirror of
https://github.com/usememos/memos.git
synced 2025-09-12 16:54:39 +08:00
refactor: clean packages
This commit is contained in:
parent
2bde296217
commit
f1b365f928
23 changed files with 38 additions and 31 deletions
|
@ -12,9 +12,9 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/internal/profile"
|
||||||
|
"github.com/usememos/memos/internal/version"
|
||||||
"github.com/usememos/memos/server"
|
"github.com/usememos/memos/server"
|
||||||
"github.com/usememos/memos/server/profile"
|
|
||||||
"github.com/usememos/memos/server/version"
|
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
"github.com/usememos/memos/store/db"
|
"github.com/usememos/memos/store/db"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package util
|
package base
|
||||||
|
|
||||||
import "regexp"
|
import "regexp"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package util
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"google.golang.org/protobuf/types/known/emptypb"
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/internal/base"
|
||||||
"github.com/usememos/memos/internal/util"
|
"github.com/usememos/memos/internal/util"
|
||||||
"github.com/usememos/memos/plugin/idp"
|
"github.com/usememos/memos/plugin/idp"
|
||||||
"github.com/usememos/memos/plugin/idp/oauth2"
|
"github.com/usememos/memos/plugin/idp/oauth2"
|
||||||
|
@ -207,7 +208,7 @@ func (s *APIV1Service) SignUp(ctx context.Context, request *v1pb.SignUpRequest)
|
||||||
Nickname: request.Username,
|
Nickname: request.Username,
|
||||||
PasswordHash: string(passwordHash),
|
PasswordHash: string(passwordHash),
|
||||||
}
|
}
|
||||||
if !util.UIDMatcher.MatchString(strings.ToLower(create.Username)) {
|
if !base.UIDMatcher.MatchString(strings.ToLower(create.Username)) {
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "invalid username: %s", create.Username)
|
return nil, status.Errorf(codes.InvalidArgument, "invalid username: %s", create.Username)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ import (
|
||||||
"google.golang.org/protobuf/types/known/emptypb"
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/internal/profile"
|
||||||
"github.com/usememos/memos/internal/util"
|
"github.com/usememos/memos/internal/util"
|
||||||
"github.com/usememos/memos/plugin/storage/s3"
|
"github.com/usememos/memos/plugin/storage/s3"
|
||||||
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
"github.com/usememos/memos/server/profile"
|
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"google.golang.org/protobuf/types/known/emptypb"
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
"github.com/usememos/memos/internal/util"
|
"github.com/usememos/memos/internal/base"
|
||||||
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
|
@ -122,7 +122,7 @@ func (s *APIV1Service) CreateUser(ctx context.Context, request *v1pb.CreateUserR
|
||||||
if currentUser.Role != store.RoleHost {
|
if currentUser.Role != store.RoleHost {
|
||||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||||
}
|
}
|
||||||
if !util.UIDMatcher.MatchString(strings.ToLower(request.User.Username)) {
|
if !base.UIDMatcher.MatchString(strings.ToLower(request.User.Username)) {
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "invalid username: %s", request.User.Username)
|
return nil, status.Errorf(codes.InvalidArgument, "invalid username: %s", request.User.Username)
|
||||||
}
|
}
|
||||||
passwordHash, err := bcrypt.GenerateFromPassword([]byte(request.User.Password), bcrypt.DefaultCost)
|
passwordHash, err := bcrypt.GenerateFromPassword([]byte(request.User.Password), bcrypt.DefaultCost)
|
||||||
|
@ -184,7 +184,7 @@ func (s *APIV1Service) UpdateUser(ctx context.Context, request *v1pb.UpdateUserR
|
||||||
if workspaceGeneralSetting.DisallowChangeUsername {
|
if workspaceGeneralSetting.DisallowChangeUsername {
|
||||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied: disallow change username")
|
return nil, status.Errorf(codes.PermissionDenied, "permission denied: disallow change username")
|
||||||
}
|
}
|
||||||
if !util.UIDMatcher.MatchString(strings.ToLower(request.User.Username)) {
|
if !base.UIDMatcher.MatchString(strings.ToLower(request.User.Username)) {
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "invalid username: %s", request.User.Username)
|
return nil, status.Errorf(codes.InvalidArgument, "invalid username: %s", request.User.Username)
|
||||||
}
|
}
|
||||||
update.Username = &request.User.Username
|
update.Username = &request.User.Username
|
||||||
|
|
|
@ -14,8 +14,8 @@ import (
|
||||||
"google.golang.org/grpc/health/grpc_health_v1"
|
"google.golang.org/grpc/health/grpc_health_v1"
|
||||||
"google.golang.org/grpc/reflection"
|
"google.golang.org/grpc/reflection"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/internal/profile"
|
||||||
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
||||||
"github.com/usememos/memos/server/profile"
|
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/internal/profile"
|
||||||
"github.com/usememos/memos/internal/util"
|
"github.com/usememos/memos/internal/util"
|
||||||
"github.com/usememos/memos/server/profile"
|
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,12 +30,17 @@ func NewFrontendService(profile *profile.Profile, store *store.Store) *FrontendS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*FrontendService) Serve(_ context.Context, e *echo.Echo) {
|
func (*FrontendService) Serve(_ context.Context, e *echo.Echo) {
|
||||||
apiSkipper := func(c echo.Context) bool {
|
skipper := func(c echo.Context) bool {
|
||||||
|
// Skip API routes.
|
||||||
if util.HasPrefixes(c.Path(), "/api", "/memos.api.v1") {
|
if util.HasPrefixes(c.Path(), "/api", "/memos.api.v1") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// Set Cache-Control header to allow public caching with a max-age of 30 days (in seconds).
|
// Skip setting cache headers for index.html
|
||||||
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=2592000")
|
if c.Path() == "/" || c.Path() == "/index.html" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// Set Cache-Control header to allow public caching with a max-age of 7 days.
|
||||||
|
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=604800") // 7 days
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +48,7 @@ func (*FrontendService) Serve(_ context.Context, e *echo.Echo) {
|
||||||
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
Filesystem: getFileSystem("dist"),
|
Filesystem: getFileSystem("dist"),
|
||||||
HTML5: true, // Enable fallback to index.html
|
HTML5: true, // Enable fallback to index.html
|
||||||
Skipper: apiSkipper,
|
Skipper: skipper,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
"github.com/usememos/gomark"
|
"github.com/usememos/gomark"
|
||||||
"github.com/usememos/gomark/renderer"
|
"github.com/usememos/gomark/renderer"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/internal/profile"
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
"github.com/usememos/memos/server/profile"
|
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ import (
|
||||||
"github.com/soheilhy/cmux"
|
"github.com/soheilhy/cmux"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/internal/profile"
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
"github.com/usememos/memos/server/profile"
|
|
||||||
"github.com/usememos/memos/server/profiler"
|
"github.com/usememos/memos/server/profiler"
|
||||||
apiv1 "github.com/usememos/memos/server/router/api/v1"
|
apiv1 "github.com/usememos/memos/server/router/api/v1"
|
||||||
"github.com/usememos/memos/server/router/frontend"
|
"github.com/usememos/memos/server/router/frontend"
|
||||||
|
|
|
@ -3,7 +3,7 @@ package db
|
||||||
import (
|
import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usememos/memos/server/profile"
|
"github.com/usememos/memos/internal/profile"
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
"github.com/usememos/memos/store/db/mysql"
|
"github.com/usememos/memos/store/db/mysql"
|
||||||
"github.com/usememos/memos/store/db/postgres"
|
"github.com/usememos/memos/store/db/postgres"
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/go-sql-driver/mysql"
|
"github.com/go-sql-driver/mysql"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usememos/memos/server/profile"
|
"github.com/usememos/memos/internal/profile"
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usememos/memos/server/profile"
|
"github.com/usememos/memos/internal/profile"
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
// Import the SQLite driver.
|
// Import the SQLite driver.
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
|
|
||||||
"github.com/usememos/memos/server/profile"
|
"github.com/usememos/memos/internal/profile"
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/usememos/memos/internal/util"
|
"github.com/usememos/memos/internal/base"
|
||||||
|
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
)
|
)
|
||||||
|
@ -112,7 +112,7 @@ type DeleteMemo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) CreateMemo(ctx context.Context, create *Memo) (*Memo, error) {
|
func (s *Store) CreateMemo(ctx context.Context, create *Memo) (*Memo, error) {
|
||||||
if !util.UIDMatcher.MatchString(create.UID) {
|
if !base.UIDMatcher.MatchString(create.UID) {
|
||||||
return nil, errors.New("invalid uid")
|
return nil, errors.New("invalid uid")
|
||||||
}
|
}
|
||||||
return s.driver.CreateMemo(ctx, create)
|
return s.driver.CreateMemo(ctx, create)
|
||||||
|
@ -136,7 +136,7 @@ func (s *Store) GetMemo(ctx context.Context, find *FindMemo) (*Memo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) UpdateMemo(ctx context.Context, update *UpdateMemo) error {
|
func (s *Store) UpdateMemo(ctx context.Context, update *UpdateMemo) error {
|
||||||
if update.UID != nil && !util.UIDMatcher.MatchString(*update.UID) {
|
if update.UID != nil && !base.UIDMatcher.MatchString(*update.UID) {
|
||||||
return errors.New("invalid uid")
|
return errors.New("invalid uid")
|
||||||
}
|
}
|
||||||
return s.driver.UpdateMemo(ctx, update)
|
return s.driver.UpdateMemo(ctx, update)
|
||||||
|
|
|
@ -14,8 +14,8 @@ import (
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/internal/version"
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
"github.com/usememos/memos/server/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed migration
|
//go:embed migration
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usememos/memos/internal/util"
|
"github.com/usememos/memos/internal/base"
|
||||||
"github.com/usememos/memos/plugin/storage/s3"
|
"github.com/usememos/memos/plugin/storage/s3"
|
||||||
storepb "github.com/usememos/memos/proto/gen/store"
|
storepb "github.com/usememos/memos/proto/gen/store"
|
||||||
)
|
)
|
||||||
|
@ -67,7 +67,7 @@ type DeleteResource struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) CreateResource(ctx context.Context, create *Resource) (*Resource, error) {
|
func (s *Store) CreateResource(ctx context.Context, create *Resource) (*Resource, error) {
|
||||||
if !util.UIDMatcher.MatchString(create.UID) {
|
if !base.UIDMatcher.MatchString(create.UID) {
|
||||||
return nil, errors.New("invalid uid")
|
return nil, errors.New("invalid uid")
|
||||||
}
|
}
|
||||||
return s.driver.CreateResource(ctx, create)
|
return s.driver.CreateResource(ctx, create)
|
||||||
|
@ -102,7 +102,7 @@ func (s *Store) GetResource(ctx context.Context, find *FindResource) (*Resource,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) UpdateResource(ctx context.Context, update *UpdateResource) error {
|
func (s *Store) UpdateResource(ctx context.Context, update *UpdateResource) error {
|
||||||
if update.UID != nil && !util.UIDMatcher.MatchString(*update.UID) {
|
if update.UID != nil && !base.UIDMatcher.MatchString(*update.UID) {
|
||||||
return errors.New("invalid uid")
|
return errors.New("invalid uid")
|
||||||
}
|
}
|
||||||
return s.driver.UpdateResource(ctx, update)
|
return s.driver.UpdateResource(ctx, update)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package store
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/usememos/memos/server/profile"
|
"github.com/usememos/memos/internal/profile"
|
||||||
"github.com/usememos/memos/store/cache"
|
"github.com/usememos/memos/store/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ import (
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
|
||||||
"github.com/usememos/memos/server/profile"
|
"github.com/usememos/memos/internal/profile"
|
||||||
"github.com/usememos/memos/server/version"
|
"github.com/usememos/memos/internal/version"
|
||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
"github.com/usememos/memos/store/db"
|
"github.com/usememos/memos/store/db"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "memos",
|
"name": "memos",
|
||||||
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
|
Loading…
Add table
Reference in a new issue