refactor: remove unused constants

This commit is contained in:
Johnny 2025-10-16 20:40:46 +08:00
parent b685ffacdf
commit bc7decf642
37 changed files with 38 additions and 62 deletions

5
.gitignore vendored
View File

@ -4,8 +4,9 @@ tmp
# Frontend asset # Frontend asset
web/dist web/dist
# build folder # Build artifacts
build build/
bin/
.DS_Store .DS_Store

View File

@ -6,7 +6,7 @@ before:
- go mod tidy - go mod tidy
builds: builds:
- main: ./bin/memos - main: ./cmd/memos
binary: memos binary: memos
goos: goos:
- linux - linux

View File

@ -1,11 +1,11 @@
# Repository Guidelines # Repository Guidelines
## Project Structure & Module Organization ## Project Structure & Module Organization
Memos pairs a Go backend with a Vite React client. The CLI entry in `bin/memos` boots the HTTP server under `server`, backed by shared domain logic in `internal` and persistence adapters in `store`. Frontend code lives in `web/src` with static assets in `web/public`; `pnpm release` publishes bundles into `server/router/frontend/dist`. API schemas sit in `proto/` (Buf-managed), extensions in `plugin/`, deployment helpers in `scripts/`, and sample SQLite databases in `build/`. Memos pairs a Go backend with a Vite React client. The CLI entry in `cmd/memos` boots the HTTP server under `server`, backed by shared domain logic in `internal` and persistence adapters in `store`. Frontend code lives in `web/src` with static assets in `web/public`; `pnpm release` publishes bundles into `server/router/frontend/dist`. API schemas sit in `proto/` (Buf-managed), extensions in `plugin/`, deployment helpers in `scripts/`, and sample SQLite databases in `build/`.
## Build, Test, and Development Commands ## Build, Test, and Development Commands
- `go run ./bin/memos --mode dev --port 8081` start the backend with the default SQLite store. - `go run ./cmd/memos --mode dev --port 8081` start the backend with the default SQLite store.
- `go build ./bin/memos` compile the backend binary. - `go build ./cmd/memos` compile the backend binary.
- `go test ./...` run Go unit and store tests. - `go test ./...` run Go unit and store tests.
- `cd web && pnpm install` install frontend dependencies. - `cd web && pnpm install` install frontend dependencies.
- `cd web && pnpm dev` start the Vite dev server with hot reload. - `cd web && pnpm dev` start the Vite dev server with hot reload.

View File

@ -278,6 +278,8 @@ func buildValueExpr(expr *exprv1.Expr, schema Schema) (ValueExpr, error) {
if ok { if ok {
return &LiteralValue{Value: value}, nil return &LiteralValue{Value: value}, nil
} }
default:
// Fall through to error return below
} }
} }
@ -402,10 +404,12 @@ func evaluateNumeric(expr *exprv1.Expr) (int64, bool, error) {
return left - right, true, nil return left - right, true, nil
case "_*_": case "_*_":
return left * right, true, nil return left * right, true, nil
default:
return 0, false, errors.Errorf("unsupported arithmetic operator %q", call.Function)
} }
default:
return 0, false, nil
} }
return 0, false, nil
} }
func timeNowUnix() int64 { func timeNowUnix() int64 {

View File

@ -7,7 +7,7 @@ COPY . .
# Refer to `pnpm release` in package.json for the build command. # Refer to `pnpm release` in package.json for the build command.
RUN --mount=type=cache,target=/go/pkg/mod \ RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/root/.cache/go-build \
go build -ldflags="-s -w" -o memos ./bin/memos/main.go go build -ldflags="-s -w" -o memos ./cmd/memos
# Make workspace with above generated files. # Make workspace with above generated files.
FROM alpine:latest AS monolithic FROM alpine:latest AS monolithic

View File

@ -25,7 +25,7 @@ export GOCACHE="$(pwd)/build/.gocache"
export GOMODCACHE="$(pwd)/build/.gomodcache" export GOMODCACHE="$(pwd)/build/.gomodcache"
# Build the executable # Build the executable
go build -o "$OUTPUT" ./bin/memos go build -o "$OUTPUT" ./cmd/memos
echo "Build successful!" echo "Build successful!"
echo "To run the application, execute the following command:" echo "To run the application, execute the following command:"

View File

@ -359,14 +359,12 @@ func (*APIV1Service) parseUserAgent(userAgent string, clientInfo *storepb.Sessio
userAgent = strings.ToLower(userAgent) userAgent = strings.ToLower(userAgent)
// Detect device type // Detect device type
if strings.Contains(userAgent, "ipad") { if strings.Contains(userAgent, "ipad") || strings.Contains(userAgent, "tablet") {
clientInfo.DeviceType = "tablet" clientInfo.DeviceType = "tablet"
} else if strings.Contains(userAgent, "mobile") || strings.Contains(userAgent, "android") || } else if strings.Contains(userAgent, "mobile") || strings.Contains(userAgent, "android") ||
strings.Contains(userAgent, "iphone") || strings.Contains(userAgent, "ipod") || strings.Contains(userAgent, "iphone") || strings.Contains(userAgent, "ipod") ||
strings.Contains(userAgent, "windows phone") || strings.Contains(userAgent, "blackberry") { strings.Contains(userAgent, "windows phone") || strings.Contains(userAgent, "blackberry") {
clientInfo.DeviceType = "mobile" clientInfo.DeviceType = "mobile"
} else if strings.Contains(userAgent, "tablet") {
clientInfo.DeviceType = "tablet"
} else { } else {
clientInfo.DeviceType = "desktop" clientInfo.DeviceType = "desktop"
} }

View File

@ -30,8 +30,6 @@ func convertStateFromStore(rowStatus store.RowStatus) v1pb.State {
func convertStateToStore(state v1pb.State) store.RowStatus { func convertStateToStore(state v1pb.State) store.RowStatus {
switch state { switch state {
case v1pb.State_NORMAL:
return store.Normal
case v1pb.State_ARCHIVED: case v1pb.State_ARCHIVED:
return store.Archived return store.Archived
default: default:

View File

@ -216,8 +216,6 @@ func convertInboxStatusFromStore(status store.InboxStatus) v1pb.Inbox_Status {
func convertInboxStatusToStore(status v1pb.Inbox_Status) store.InboxStatus { func convertInboxStatusToStore(status v1pb.Inbox_Status) store.InboxStatus {
switch status { switch status {
case v1pb.Inbox_UNREAD:
return store.UNREAD
case v1pb.Inbox_ARCHIVED: case v1pb.Inbox_ARCHIVED:
return store.ARCHIVED return store.ARCHIVED
default: default:

View File

@ -299,8 +299,6 @@ func convertListKindToASTNode(kind v1pb.ListNode_Kind) ast.ListKind {
return ast.OrderedList return ast.OrderedList
case v1pb.ListNode_UNORDERED: case v1pb.ListNode_UNORDERED:
return ast.UnorderedList return ast.UnorderedList
case v1pb.ListNode_DESCRIPTION:
return ast.DescriptionList
default: default:
// Default to description list. // Default to description list.
return ast.DescriptionList return ast.DescriptionList

View File

@ -160,8 +160,6 @@ func convertMemoRelationTypeFromStore(relationType store.MemoRelationType) v1pb.
func convertMemoRelationTypeToStore(relationType v1pb.MemoRelation_Type) store.MemoRelationType { func convertMemoRelationTypeToStore(relationType v1pb.MemoRelation_Type) store.MemoRelationType {
switch relationType { switch relationType {
case v1pb.MemoRelation_REFERENCE:
return store.MemoRelationReference
case v1pb.MemoRelation_COMMENT: case v1pb.MemoRelation_COMMENT:
return store.MemoRelationComment return store.MemoRelationComment
default: default:

View File

@ -892,16 +892,11 @@ func (*APIV1Service) parseMemoOrderBy(orderBy string, memoFind *store.FindMemo)
} }
switch field { switch field {
case "display_time": case "display_time", "create_time", "name":
memoFind.OrderByTimeAsc = direction == "asc"
case "create_time":
memoFind.OrderByTimeAsc = direction == "asc" memoFind.OrderByTimeAsc = direction == "asc"
case "update_time": case "update_time":
memoFind.OrderByUpdatedTs = true memoFind.OrderByUpdatedTs = true
memoFind.OrderByTimeAsc = direction == "asc" memoFind.OrderByTimeAsc = direction == "asc"
case "name":
// For ordering by memo name/id - not commonly used but supported
memoFind.OrderByTimeAsc = direction == "asc"
default: default:
return errors.Errorf("unsupported order field: %s, supported fields are: display_time, create_time, update_time, name", field) return errors.Errorf("unsupported order field: %s, supported fields are: display_time, create_time, update_time, name", field)
} }

View File

@ -134,8 +134,6 @@ func convertVisibilityFromStore(visibility store.Visibility) v1pb.Visibility {
func convertVisibilityToStore(visibility v1pb.Visibility) store.Visibility { func convertVisibilityToStore(visibility v1pb.Visibility) store.Visibility {
switch visibility { switch visibility {
case v1pb.Visibility_PRIVATE:
return store.Private
case v1pb.Visibility_PROTECTED: case v1pb.Visibility_PROTECTED:
return store.Protected return store.Protected
case v1pb.Visibility_PUBLIC: case v1pb.Visibility_PUBLIC:

View File

@ -331,8 +331,6 @@ func (s *APIV1Service) validateFilter(ctx context.Context, filterStr string) err
var dialect filter.DialectName var dialect filter.DialectName
switch s.Profile.Driver { switch s.Profile.Driver {
case "sqlite":
dialect = filter.DialectSQLite
case "mysql": case "mysql":
dialect = filter.DialectMySQL dialect = filter.DialectMySQL
case "postgres": case "postgres":

View File

@ -1,4 +1,4 @@
package v1 package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package v1 package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package v1 package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package v1 package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package v1 package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package v1 package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package v1 package test
import ( import (
"context" "context"

View File

@ -45,7 +45,7 @@ func (s *APIV1Service) ListUsers(ctx context.Context, request *v1pb.ListUsersReq
userFind := &store.FindUser{} userFind := &store.FindUser{}
if request.Filter != "" { if request.Filter != "" {
if err := s.validateUserFilter(ctx, request.Filter); err != nil { if err := validateUserFilter(ctx, request.Filter); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid filter: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid filter: %v", err)
} }
} }
@ -1065,8 +1065,6 @@ func convertUserRoleToStore(role v1pb.User_Role) store.Role {
return store.RoleHost return store.RoleHost
case v1pb.User_ADMIN: case v1pb.User_ADMIN:
return store.RoleAdmin return store.RoleAdmin
case v1pb.User_USER:
return store.RoleUser
default: default:
return store.RoleUser return store.RoleUser
} }
@ -1147,10 +1145,6 @@ func convertUserSettingFromStore(storeSetting *storepb.UserSetting, userID int32
} }
switch key { switch key {
case storepb.UserSetting_GENERAL:
setting.Value = &v1pb.UserSetting_GeneralSetting_{
GeneralSetting: getDefaultUserGeneralSetting(),
}
case storepb.UserSetting_SESSIONS: case storepb.UserSetting_SESSIONS:
setting.Value = &v1pb.UserSetting_SessionsSetting_{ setting.Value = &v1pb.UserSetting_SessionsSetting_{
SessionsSetting: &v1pb.UserSetting_SessionsSetting{ SessionsSetting: &v1pb.UserSetting_SessionsSetting{
@ -1365,7 +1359,7 @@ func extractWebhookIDFromName(name string) string {
} }
// validateUserFilter validates the user filter string. // validateUserFilter validates the user filter string.
func (s *APIV1Service) validateUserFilter(_ context.Context, filterStr string) error { func validateUserFilter(_ context.Context, filterStr string) error {
if strings.TrimSpace(filterStr) != "" { if strings.TrimSpace(filterStr) != "" {
return errors.New("user filters are not supported") return errors.New("user filters are not supported")
} }

View File

@ -27,8 +27,6 @@ func (v Visibility) String() string {
return "PUBLIC" return "PUBLIC"
case Protected: case Protected:
return "PROTECTED" return "PROTECTED"
case Private:
return "PRIVATE"
default: default:
return "PRIVATE" return "PRIVATE"
} }

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package teststore package test
import ( import (
"context" "context"

View File

@ -22,8 +22,6 @@ func (e Role) String() string {
return "HOST" return "HOST"
case RoleAdmin: case RoleAdmin:
return "ADMIN" return "ADMIN"
case RoleUser:
return "USER"
default: default:
return "USER" return "USER"
} }