Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
7c5296cf
Unverified
Commit
7c5296cf
authored
Aug 04, 2023
by
boojack
Committed by
GitHub
Aug 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update id type to int32 (#2076)
parent
cbe27923
Changes
36
Show whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
208 additions
and
198 deletions
+208
-198
activity.go
api/v1/activity.go
+5
-5
auth.go
api/v1/auth.go
+1
-1
idp.go
api/v1/idp.go
+11
-11
jwt.go
api/v1/jwt.go
+4
-5
memo.go
api/v1/memo.go
+23
-22
memo_organizer.go
api/v1/memo_organizer.go
+6
-6
memo_relation.go
api/v1/memo_relation.go
+8
-8
memo_resource.go
api/v1/memo_resource.go
+14
-14
resource.go
api/v1/resource.go
+15
-15
rss.go
api/v1/rss.go
+4
-4
storage.go
api/v1/storage.go
+10
-10
system.go
api/v1/system.go
+3
-3
system_setting.go
api/v1/system_setting.go
+2
-2
tag.go
api/v1/tag.go
+5
-5
user.go
api/v1/user.go
+8
-9
user_setting.go
api/v1/user_setting.go
+3
-3
jwt.go
api/v2/jwt.go
+3
-2
tag_service.go
api/v2/tag_service.go
+1
-1
user_service.go
api/v2/user_service.go
+1
-2
util.go
common/util/util.go
+10
-0
telegram.go
server/telegram.go
+3
-3
activity.go
store/activity.go
+2
-2
cache.go
store/cache.go
+1
-1
idp.go
store/idp.go
+4
-4
memo.go
store/memo.go
+13
-12
memo_organizer.go
store/memo_organizer.go
+6
-6
memo_relation.go
store/memo_relation.go
+6
-6
memo_resource.go
store/memo_resource.go
+8
-8
resource.go
store/resource.go
+7
-7
storage.go
store/storage.go
+4
-4
tag.go
store/tag.go
+3
-3
user.go
store/user.go
+4
-4
user_setting.go
store/user_setting.go
+2
-2
memo_relation_test.go
test/server/memo_relation_test.go
+2
-2
memo_test.go
test/server/memo_test.go
+3
-3
resource_test.go
test/store/resource_test.go
+3
-3
No files found.
api/v1/activity.go
View file @
7c5296cf
...
@@ -71,13 +71,13 @@ func (l ActivityLevel) String() string {
...
@@ -71,13 +71,13 @@ func (l ActivityLevel) String() string {
}
}
type
ActivityUserCreatePayload
struct
{
type
ActivityUserCreatePayload
struct
{
UserID
int
`json:"userId"`
UserID
int
32
`json:"userId"`
Username
string
`json:"username"`
Username
string
`json:"username"`
Role
Role
`json:"role"`
Role
Role
`json:"role"`
}
}
type
ActivityUserAuthSignInPayload
struct
{
type
ActivityUserAuthSignInPayload
struct
{
UserID
int
`json:"userId"`
UserID
int
32
`json:"userId"`
IP
string
`json:"ip"`
IP
string
`json:"ip"`
}
}
...
@@ -107,10 +107,10 @@ type ActivityServerStartPayload struct {
...
@@ -107,10 +107,10 @@ type ActivityServerStartPayload struct {
}
}
type
Activity
struct
{
type
Activity
struct
{
ID
int
`json:"id"`
ID
int
32
`json:"id"`
// Standard fields
// Standard fields
CreatorID
int
`json:"creatorId"`
CreatorID
int
32
`json:"creatorId"`
CreatedTs
int64
`json:"createdTs"`
CreatedTs
int64
`json:"createdTs"`
// Domain specific fields
// Domain specific fields
...
@@ -122,7 +122,7 @@ type Activity struct {
...
@@ -122,7 +122,7 @@ type Activity struct {
// ActivityCreate is the API message for creating an activity.
// ActivityCreate is the API message for creating an activity.
type
ActivityCreate
struct
{
type
ActivityCreate
struct
{
// Standard fields
// Standard fields
CreatorID
int
CreatorID
int
32
// Domain specific fields
// Domain specific fields
Type
ActivityType
`json:"type"`
Type
ActivityType
`json:"type"`
...
...
api/v1/auth.go
View file @
7c5296cf
...
@@ -21,7 +21,7 @@ type SignIn struct {
...
@@ -21,7 +21,7 @@ type SignIn struct {
}
}
type
SSOSignIn
struct
{
type
SSOSignIn
struct
{
IdentityProviderID
int
`json:"identityProviderId"`
IdentityProviderID
int
32
`json:"identityProviderId"`
Code
string
`json:"code"`
Code
string
`json:"code"`
RedirectURI
string
`json:"redirectUri"`
RedirectURI
string
`json:"redirectUri"`
}
}
...
...
api/v1/idp.go
View file @
7c5296cf
...
@@ -4,10 +4,10 @@ import (
...
@@ -4,10 +4,10 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"strconv"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
...
@@ -42,7 +42,7 @@ type FieldMapping struct {
...
@@ -42,7 +42,7 @@ type FieldMapping struct {
}
}
type
IdentityProvider
struct
{
type
IdentityProvider
struct
{
ID
int
`json:"id"`
ID
int
32
`json:"id"`
Name
string
`json:"name"`
Name
string
`json:"name"`
Type
IdentityProviderType
`json:"type"`
Type
IdentityProviderType
`json:"type"`
IdentifierFilter
string
`json:"identifierFilter"`
IdentifierFilter
string
`json:"identifierFilter"`
...
@@ -57,7 +57,7 @@ type CreateIdentityProviderRequest struct {
...
@@ -57,7 +57,7 @@ type CreateIdentityProviderRequest struct {
}
}
type
UpdateIdentityProviderRequest
struct
{
type
UpdateIdentityProviderRequest
struct
{
ID
int
`json:"-"`
ID
int
32
`json:"-"`
Type
IdentityProviderType
`json:"type"`
Type
IdentityProviderType
`json:"type"`
Name
*
string
`json:"name"`
Name
*
string
`json:"name"`
IdentifierFilter
*
string
`json:"identifierFilter"`
IdentifierFilter
*
string
`json:"identifierFilter"`
...
@@ -67,7 +67,7 @@ type UpdateIdentityProviderRequest struct {
...
@@ -67,7 +67,7 @@ type UpdateIdentityProviderRequest struct {
func
(
s
*
APIV1Service
)
registerIdentityProviderRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerIdentityProviderRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/idp"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/idp"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -101,7 +101,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
...
@@ -101,7 +101,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
g
.
PATCH
(
"/idp/:idpId"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"/idp/:idpId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -116,7 +116,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
...
@@ -116,7 +116,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
}
}
identityProviderID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"idpId"
))
identityProviderID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"idpId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"idpId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"idpId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -148,7 +148,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
...
@@ -148,7 +148,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find identity provider list"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find identity provider list"
)
.
SetInternal
(
err
)
}
}
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
isHostUser
:=
false
isHostUser
:=
false
if
ok
{
if
ok
{
user
,
err
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
user
,
err
:=
s
.
Store
.
GetUser
(
ctx
,
&
store
.
FindUser
{
...
@@ -176,7 +176,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
...
@@ -176,7 +176,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
g
.
GET
(
"/idp/:idpId"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/idp/:idpId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -191,7 +191,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
...
@@ -191,7 +191,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
}
}
identityProviderID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"idpId"
))
identityProviderID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"idpId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"idpId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"idpId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -210,7 +210,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
...
@@ -210,7 +210,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
g
.
DELETE
(
"/idp/:idpId"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/idp/:idpId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -225,7 +225,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
...
@@ -225,7 +225,7 @@ func (s *APIV1Service) registerIdentityProviderRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
}
}
identityProviderID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"idpId"
))
identityProviderID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"idpId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"idpId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"idpId"
)))
.
SetInternal
(
err
)
}
}
...
...
api/v1/jwt.go
View file @
7c5296cf
...
@@ -3,7 +3,6 @@ package v1
...
@@ -3,7 +3,6 @@ package v1
import
(
import
(
"fmt"
"fmt"
"net/http"
"net/http"
"strconv"
"strings"
"strings"
"time"
"time"
...
@@ -21,7 +20,7 @@ type claimsMessage struct {
...
@@ -21,7 +20,7 @@ type claimsMessage struct {
}
}
// GenerateAccessToken generates an access token for web.
// GenerateAccessToken generates an access token for web.
func
GenerateAccessToken
(
username
string
,
userID
int
,
secret
string
)
(
string
,
error
)
{
func
GenerateAccessToken
(
username
string
,
userID
int
32
,
secret
string
)
(
string
,
error
)
{
expirationTime
:=
time
.
Now
()
.
Add
(
auth
.
AccessTokenDuration
)
expirationTime
:=
time
.
Now
()
.
Add
(
auth
.
AccessTokenDuration
)
return
generateToken
(
username
,
userID
,
auth
.
AccessTokenAudienceName
,
expirationTime
,
[]
byte
(
secret
))
return
generateToken
(
username
,
userID
,
auth
.
AccessTokenAudienceName
,
expirationTime
,
[]
byte
(
secret
))
}
}
...
@@ -58,7 +57,7 @@ func setTokenCookie(c echo.Context, name, token string, expiration time.Time) {
...
@@ -58,7 +57,7 @@ func setTokenCookie(c echo.Context, name, token string, expiration time.Time) {
}
}
// generateToken generates a jwt token.
// generateToken generates a jwt token.
func
generateToken
(
username
string
,
userID
int
,
aud
string
,
expirationTime
time
.
Time
,
secret
[]
byte
)
(
string
,
error
)
{
func
generateToken
(
username
string
,
userID
int
32
,
aud
string
,
expirationTime
time
.
Time
,
secret
[]
byte
)
(
string
,
error
)
{
// Create the JWT claims, which includes the username and expiry time.
// Create the JWT claims, which includes the username and expiry time.
claims
:=
&
claimsMessage
{
claims
:=
&
claimsMessage
{
Name
:
username
,
Name
:
username
,
...
@@ -68,7 +67,7 @@ func generateToken(username string, userID int, aud string, expirationTime time.
...
@@ -68,7 +67,7 @@ func generateToken(username string, userID int, aud string, expirationTime time.
ExpiresAt
:
jwt
.
NewNumericDate
(
expirationTime
),
ExpiresAt
:
jwt
.
NewNumericDate
(
expirationTime
),
IssuedAt
:
jwt
.
NewNumericDate
(
time
.
Now
()),
IssuedAt
:
jwt
.
NewNumericDate
(
time
.
Now
()),
Issuer
:
auth
.
Issuer
,
Issuer
:
auth
.
Issuer
,
Subject
:
strconv
.
Itoa
(
userID
),
Subject
:
fmt
.
Sprintf
(
"%d"
,
userID
),
},
},
}
}
...
@@ -174,7 +173,7 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
...
@@ -174,7 +173,7 @@ func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) e
}
}
// We either have a valid access token or we will attempt to generate new access token and refresh token
// We either have a valid access token or we will attempt to generate new access token and refresh token
userID
,
err
:=
strconv
.
Atoi
(
claims
.
Subject
)
userID
,
err
:=
util
.
ConvertStringToInt32
(
claims
.
Subject
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Malformed ID in the token."
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Malformed ID in the token."
)
}
}
...
...
api/v1/memo.go
View file @
7c5296cf
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"github.com/pkg/errors"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
...
@@ -39,11 +40,11 @@ func (v Visibility) String() string {
...
@@ -39,11 +40,11 @@ func (v Visibility) String() string {
}
}
type
Memo
struct
{
type
Memo
struct
{
ID
int
`json:"id"`
ID
int
32
`json:"id"`
// Standard fields
// Standard fields
RowStatus
RowStatus
`json:"rowStatus"`
RowStatus
RowStatus
`json:"rowStatus"`
CreatorID
int
`json:"creatorId"`
CreatorID
int
32
`json:"creatorId"`
CreatedTs
int64
`json:"createdTs"`
CreatedTs
int64
`json:"createdTs"`
UpdatedTs
int64
`json:"updatedTs"`
UpdatedTs
int64
`json:"updatedTs"`
...
@@ -62,7 +63,7 @@ type Memo struct {
...
@@ -62,7 +63,7 @@ type Memo struct {
type
CreateMemoRequest
struct
{
type
CreateMemoRequest
struct
{
// Standard fields
// Standard fields
CreatorID
int
`json:"-"`
CreatorID
int
32
`json:"-"`
CreatedTs
*
int64
`json:"createdTs"`
CreatedTs
*
int64
`json:"createdTs"`
// Domain specific fields
// Domain specific fields
...
@@ -70,12 +71,12 @@ type CreateMemoRequest struct {
...
@@ -70,12 +71,12 @@ type CreateMemoRequest struct {
Content
string
`json:"content"`
Content
string
`json:"content"`
// Related fields
// Related fields
ResourceIDList
[]
int
`json:"resourceIdList"`
ResourceIDList
[]
int
32
`json:"resourceIdList"`
RelationList
[]
*
UpsertMemoRelationRequest
`json:"relationList"`
RelationList
[]
*
UpsertMemoRelationRequest
`json:"relationList"`
}
}
type
PatchMemoRequest
struct
{
type
PatchMemoRequest
struct
{
ID
int
`json:"-"`
ID
int
32
`json:"-"`
// Standard fields
// Standard fields
CreatedTs
*
int64
`json:"createdTs"`
CreatedTs
*
int64
`json:"createdTs"`
...
@@ -87,16 +88,16 @@ type PatchMemoRequest struct {
...
@@ -87,16 +88,16 @@ type PatchMemoRequest struct {
Visibility
*
Visibility
`json:"visibility"`
Visibility
*
Visibility
`json:"visibility"`
// Related fields
// Related fields
ResourceIDList
[]
int
`json:"resourceIdList"`
ResourceIDList
[]
int
32
`json:"resourceIdList"`
RelationList
[]
*
UpsertMemoRelationRequest
`json:"relationList"`
RelationList
[]
*
UpsertMemoRelationRequest
`json:"relationList"`
}
}
type
FindMemoRequest
struct
{
type
FindMemoRequest
struct
{
ID
*
int
ID
*
int
32
// Standard fields
// Standard fields
RowStatus
*
RowStatus
RowStatus
*
RowStatus
CreatorID
*
int
CreatorID
*
int
32
// Domain specific fields
// Domain specific fields
Pinned
*
bool
Pinned
*
bool
...
@@ -114,7 +115,7 @@ const maxContentLength = 1 << 30
...
@@ -114,7 +115,7 @@ const maxContentLength = 1 << 30
func
(
s
*
APIV1Service
)
registerMemoRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerMemoRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/memo"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/memo"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -225,12 +226,12 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
...
@@ -225,12 +226,12 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
g
.
PATCH
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -352,7 +353,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
...
@@ -352,7 +353,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
g
.
GET
(
"/memo"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/memo"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
findMemoMessage
:=
&
store
.
FindMemo
{}
findMemoMessage
:=
&
store
.
FindMemo
{}
if
userID
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
if
userID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
findMemoMessage
.
CreatorID
=
&
userID
findMemoMessage
.
CreatorID
=
&
userID
}
}
...
@@ -363,7 +364,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
...
@@ -363,7 +364,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
}
}
}
}
currentUserID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
currentUserID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
// Anonymous use should only fetch PUBLIC memos with specified user
// Anonymous use should only fetch PUBLIC memos with specified user
if
findMemoMessage
.
CreatorID
==
nil
{
if
findMemoMessage
.
CreatorID
==
nil
{
...
@@ -435,7 +436,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
...
@@ -435,7 +436,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
g
.
GET
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -450,7 +451,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
...
@@ -450,7 +451,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo not found: %d"
,
memoID
))
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo not found: %d"
,
memoID
))
}
}
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
memo
.
Visibility
==
store
.
Private
{
if
memo
.
Visibility
==
store
.
Private
{
if
!
ok
||
memo
.
CreatorID
!=
userID
{
if
!
ok
||
memo
.
CreatorID
!=
userID
{
return
echo
.
NewHTTPError
(
http
.
StatusForbidden
,
"this memo is private only"
)
return
echo
.
NewHTTPError
(
http
.
StatusForbidden
,
"this memo is private only"
)
...
@@ -473,7 +474,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
...
@@ -473,7 +474,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
findMemoMessage
:=
&
store
.
FindMemo
{
findMemoMessage
:=
&
store
.
FindMemo
{
RowStatus
:
&
normalStatus
,
RowStatus
:
&
normalStatus
,
}
}
if
creatorID
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
if
creatorID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
findMemoMessage
.
CreatorID
=
&
creatorID
findMemoMessage
.
CreatorID
=
&
creatorID
}
}
...
@@ -488,7 +489,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
...
@@ -488,7 +489,7 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user id to find memo"
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user id to find memo"
)
}
}
currentUserID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
currentUserID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
findMemoMessage
.
VisibilityList
=
[]
store
.
Visibility
{
store
.
Public
}
findMemoMessage
.
VisibilityList
=
[]
store
.
Visibility
{
store
.
Public
}
}
else
{
}
else
{
...
@@ -590,11 +591,11 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
...
@@ -590,11 +591,11 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
g
.
DELETE
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/memo/:memoId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -757,12 +758,12 @@ func getMemoRelationListDiff(oldList, newList []*store.MemoRelation) (addedList,
...
@@ -757,12 +758,12 @@ func getMemoRelationListDiff(oldList, newList []*store.MemoRelation) (addedList,
return
addedList
,
removedList
return
addedList
,
removedList
}
}
func
getIDListDiff
(
oldList
,
newList
[]
int
)
(
addedList
,
removedList
[]
int
)
{
func
getIDListDiff
(
oldList
,
newList
[]
int
32
)
(
addedList
,
removedList
[]
int32
)
{
oldMap
:=
map
[
int
]
bool
{}
oldMap
:=
map
[
int
32
]
bool
{}
for
_
,
id
:=
range
oldList
{
for
_
,
id
:=
range
oldList
{
oldMap
[
id
]
=
true
oldMap
[
id
]
=
true
}
}
newMap
:=
map
[
int
]
bool
{}
newMap
:=
map
[
int
32
]
bool
{}
for
_
,
id
:=
range
newList
{
for
_
,
id
:=
range
newList
{
newMap
[
id
]
=
true
newMap
[
id
]
=
true
}
}
...
...
api/v1/memo_organizer.go
View file @
7c5296cf
...
@@ -4,16 +4,16 @@ import (
...
@@ -4,16 +4,16 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"strconv"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
type
MemoOrganizer
struct
{
type
MemoOrganizer
struct
{
MemoID
int
`json:"memoId"`
MemoID
int
32
`json:"memoId"`
UserID
int
`json:"userId"`
UserID
int
32
`json:"userId"`
Pinned
bool
`json:"pinned"`
Pinned
bool
`json:"pinned"`
}
}
...
@@ -24,12 +24,12 @@ type UpsertMemoOrganizerRequest struct {
...
@@ -24,12 +24,12 @@ type UpsertMemoOrganizerRequest struct {
func
(
s
*
APIV1Service
)
registerMemoOrganizerRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerMemoOrganizerRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/memo/:memoId/organizer"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/memo/:memoId/organizer"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
...
api/v1/memo_relation.go
View file @
7c5296cf
...
@@ -4,9 +4,9 @@ import (
...
@@ -4,9 +4,9 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"strconv"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
...
@@ -18,20 +18,20 @@ const (
...
@@ -18,20 +18,20 @@ const (
)
)
type
MemoRelation
struct
{
type
MemoRelation
struct
{
MemoID
int
`json:"memoId"`
MemoID
int
32
`json:"memoId"`
RelatedMemoID
int
`json:"relatedMemoId"`
RelatedMemoID
int
32
`json:"relatedMemoId"`
Type
MemoRelationType
`json:"type"`
Type
MemoRelationType
`json:"type"`
}
}
type
UpsertMemoRelationRequest
struct
{
type
UpsertMemoRelationRequest
struct
{
RelatedMemoID
int
`json:"relatedMemoId"`
RelatedMemoID
int
32
`json:"relatedMemoId"`
Type
MemoRelationType
`json:"type"`
Type
MemoRelationType
`json:"type"`
}
}
func
(
s
*
APIV1Service
)
registerMemoRelationRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerMemoRelationRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/memo/:memoId/relation"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/memo/:memoId/relation"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -54,7 +54,7 @@ func (s *APIV1Service) registerMemoRelationRoutes(g *echo.Group) {
...
@@ -54,7 +54,7 @@ func (s *APIV1Service) registerMemoRelationRoutes(g *echo.Group) {
g
.
GET
(
"/memo/:memoId/relation"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/memo/:memoId/relation"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -70,11 +70,11 @@ func (s *APIV1Service) registerMemoRelationRoutes(g *echo.Group) {
...
@@ -70,11 +70,11 @@ func (s *APIV1Service) registerMemoRelationRoutes(g *echo.Group) {
g
.
DELETE
(
"/memo/:memoId/relation/:relatedMemoId/type/:relationType"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/memo/:memoId/relation/:relatedMemoId/type/:relationType"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Memo ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Memo ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
relatedMemoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"relatedMemoId"
))
relatedMemoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"relatedMemoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Related memo ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Related memo ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
}
}
...
...
api/v1/memo_resource.go
View file @
7c5296cf
...
@@ -4,45 +4,45 @@ import (
...
@@ -4,45 +4,45 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"strconv"
"time"
"time"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
type
MemoResource
struct
{
type
MemoResource
struct
{
MemoID
int
`json:"memoId"`
MemoID
int
32
`json:"memoId"`
ResourceID
int
`json:"resourceId"`
ResourceID
int
32
`json:"resourceId"`
CreatedTs
int64
`json:"createdTs"`
CreatedTs
int64
`json:"createdTs"`
UpdatedTs
int64
`json:"updatedTs"`
UpdatedTs
int64
`json:"updatedTs"`
}
}
type
UpsertMemoResourceRequest
struct
{
type
UpsertMemoResourceRequest
struct
{
ResourceID
int
`json:"resourceId"`
ResourceID
int
32
`json:"resourceId"`
UpdatedTs
*
int64
`json:"updatedTs"`
UpdatedTs
*
int64
`json:"updatedTs"`
}
}
type
MemoResourceFind
struct
{
type
MemoResourceFind
struct
{
MemoID
*
int
MemoID
*
int
32
ResourceID
*
int
ResourceID
*
int
32
}
}
type
MemoResourceDelete
struct
{
type
MemoResourceDelete
struct
{
MemoID
*
int
MemoID
*
int
32
ResourceID
*
int
ResourceID
*
int
32
}
}
func
(
s
*
APIV1Service
)
registerMemoResourceRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerMemoResourceRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/memo/:memoId/resource"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/memo/:memoId/resource"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -78,7 +78,7 @@ func (s *APIV1Service) registerMemoResourceRoutes(g *echo.Group) {
...
@@ -78,7 +78,7 @@ func (s *APIV1Service) registerMemoResourceRoutes(g *echo.Group) {
g
.
GET
(
"/memo/:memoId/resource"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/memo/:memoId/resource"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -98,15 +98,15 @@ func (s *APIV1Service) registerMemoResourceRoutes(g *echo.Group) {
...
@@ -98,15 +98,15 @@ func (s *APIV1Service) registerMemoResourceRoutes(g *echo.Group) {
g
.
DELETE
(
"/memo/:memoId/resource/:resourceId"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/memo/:memoId/resource/:resourceId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Memo ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Memo ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
resourceID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
resourceID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"resourceId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Resource ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Resource ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
}
}
...
...
api/v1/resource.go
View file @
7c5296cf
...
@@ -30,10 +30,10 @@ import (
...
@@ -30,10 +30,10 @@ import (
)
)
type
Resource
struct
{
type
Resource
struct
{
ID
int
`json:"id"`
ID
int
32
`json:"id"`
// Standard fields
// Standard fields
CreatorID
int
`json:"creatorId"`
CreatorID
int
32
`json:"creatorId"`
CreatedTs
int64
`json:"createdTs"`
CreatedTs
int64
`json:"createdTs"`
UpdatedTs
int64
`json:"updatedTs"`
UpdatedTs
int64
`json:"updatedTs"`
...
@@ -58,8 +58,8 @@ type CreateResourceRequest struct {
...
@@ -58,8 +58,8 @@ type CreateResourceRequest struct {
}
}
type
FindResourceRequest
struct
{
type
FindResourceRequest
struct
{
ID
*
int
`json:"id"`
ID
*
int
32
`json:"id"`
CreatorID
*
int
`json:"creatorId"`
CreatorID
*
int
32
`json:"creatorId"`
Filename
*
string
`json:"filename"`
Filename
*
string
`json:"filename"`
}
}
...
@@ -83,7 +83,7 @@ var fileKeyPattern = regexp.MustCompile(`\{[a-z]{1,9}\}`)
...
@@ -83,7 +83,7 @@ var fileKeyPattern = regexp.MustCompile(`\{[a-z]{1,9}\}`)
func
(
s
*
APIV1Service
)
registerResourceRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerResourceRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/resource"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/resource"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -157,7 +157,7 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
...
@@ -157,7 +157,7 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
g
.
POST
(
"/resource/blob"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/resource/blob"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -217,7 +217,7 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
...
@@ -217,7 +217,7 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
g
.
GET
(
"/resource"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/resource"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -244,12 +244,12 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
...
@@ -244,12 +244,12 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
g
.
PATCH
(
"/resource/:resourceId"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"/resource/:resourceId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
resourceID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
resourceID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"resourceId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -290,12 +290,12 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
...
@@ -290,12 +290,12 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
g
.
DELETE
(
"/resource/:resourceId"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/resource/:resourceId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
resourceID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
resourceID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"resourceId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -335,7 +335,7 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
...
@@ -335,7 +335,7 @@ func (s *APIV1Service) registerResourceRoutes(g *echo.Group) {
func
(
s
*
APIV1Service
)
registerResourcePublicRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerResourcePublicRoutes
(
g
*
echo
.
Group
)
{
f
:=
func
(
c
echo
.
Context
)
error
{
f
:=
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
resourceID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"resourceId"
))
resourceID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"resourceId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -346,7 +346,7 @@ func (s *APIV1Service) registerResourcePublicRoutes(g *echo.Group) {
...
@@ -346,7 +346,7 @@ func (s *APIV1Service) registerResourcePublicRoutes(g *echo.Group) {
}
}
// Protected resource require a logined user
// Protected resource require a logined user
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
resourceVisibility
==
store
.
Protected
&&
(
!
ok
||
userID
<=
0
)
{
if
resourceVisibility
==
store
.
Protected
&&
(
!
ok
||
userID
<=
0
)
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Resource visibility not match"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Resource visibility not match"
)
.
SetInternal
(
err
)
}
}
...
@@ -501,7 +501,7 @@ func getOrGenerateThumbnailImage(srcBlob []byte, dstPath string) ([]byte, error)
...
@@ -501,7 +501,7 @@ func getOrGenerateThumbnailImage(srcBlob []byte, dstPath string) ([]byte, error)
return
dstBlob
,
nil
return
dstBlob
,
nil
}
}
func
checkResourceVisibility
(
ctx
context
.
Context
,
s
*
store
.
Store
,
resourceID
int
)
(
store
.
Visibility
,
error
)
{
func
checkResourceVisibility
(
ctx
context
.
Context
,
s
*
store
.
Store
,
resourceID
int
32
)
(
store
.
Visibility
,
error
)
{
memoResources
,
err
:=
s
.
ListMemoResources
(
ctx
,
&
store
.
FindMemoResource
{
memoResources
,
err
:=
s
.
ListMemoResources
(
ctx
,
&
store
.
FindMemoResource
{
ResourceID
:
&
resourceID
,
ResourceID
:
&
resourceID
,
})
})
...
@@ -514,7 +514,7 @@ func checkResourceVisibility(ctx context.Context, s *store.Store, resourceID int
...
@@ -514,7 +514,7 @@ func checkResourceVisibility(ctx context.Context, s *store.Store, resourceID int
return
store
.
Private
,
nil
return
store
.
Private
,
nil
}
}
memoIDs
:=
make
([]
int
,
0
,
len
(
memoResources
))
memoIDs
:=
make
([]
int
32
,
0
,
len
(
memoResources
))
for
_
,
memoResource
:=
range
memoResources
{
for
_
,
memoResource
:=
range
memoResources
{
memoIDs
=
append
(
memoIDs
,
memoResource
.
MemoID
)
memoIDs
=
append
(
memoIDs
,
memoResource
.
MemoID
)
}
}
...
...
api/v1/rss.go
View file @
7c5296cf
...
@@ -49,7 +49,7 @@ func (s *APIV1Service) registerRSSRoutes(g *echo.Group) {
...
@@ -49,7 +49,7 @@ func (s *APIV1Service) registerRSSRoutes(g *echo.Group) {
g
.
GET
(
"/u/:id/rss.xml"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/u/:id/rss.xml"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"User id is not a number"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"User id is not a number"
)
.
SetInternal
(
err
)
}
}
...
@@ -94,10 +94,10 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
...
@@ -94,10 +94,10 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
memo
:=
memoList
[
i
]
memo
:=
memoList
[
i
]
feed
.
Items
[
i
]
=
&
feeds
.
Item
{
feed
.
Items
[
i
]
=
&
feeds
.
Item
{
Title
:
getRSSItemTitle
(
memo
.
Content
),
Title
:
getRSSItemTitle
(
memo
.
Content
),
Link
:
&
feeds
.
Link
{
Href
:
baseURL
+
"/m/"
+
strconv
.
Itoa
(
memo
.
ID
)},
Link
:
&
feeds
.
Link
{
Href
:
baseURL
+
"/m/"
+
fmt
.
Sprintf
(
"%d"
,
memo
.
ID
)},
Description
:
getRSSItemDescription
(
memo
.
Content
),
Description
:
getRSSItemDescription
(
memo
.
Content
),
Created
:
time
.
Unix
(
memo
.
CreatedTs
,
0
),
Created
:
time
.
Unix
(
memo
.
CreatedTs
,
0
),
Enclosure
:
&
feeds
.
Enclosure
{
Url
:
baseURL
+
"/m/"
+
strconv
.
Itoa
(
memo
.
ID
)
+
"/image"
},
Enclosure
:
&
feeds
.
Enclosure
{
Url
:
baseURL
+
"/m/"
+
fmt
.
Sprintf
(
"%d"
,
memo
.
ID
)
+
"/image"
},
}
}
if
len
(
memo
.
ResourceIDList
)
>
0
{
if
len
(
memo
.
ResourceIDList
)
>
0
{
resourceID
:=
memo
.
ResourceIDList
[
0
]
resourceID
:=
memo
.
ResourceIDList
[
0
]
...
@@ -114,7 +114,7 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
...
@@ -114,7 +114,7 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
if
resource
.
ExternalLink
!=
""
{
if
resource
.
ExternalLink
!=
""
{
enclosure
.
Url
=
resource
.
ExternalLink
enclosure
.
Url
=
resource
.
ExternalLink
}
else
{
}
else
{
enclosure
.
Url
=
baseURL
+
"/o/r/"
+
strconv
.
Itoa
(
resource
.
ID
)
enclosure
.
Url
=
baseURL
+
"/o/r/"
+
fmt
.
Sprintf
(
"%d"
,
resource
.
ID
)
}
}
enclosure
.
Length
=
strconv
.
Itoa
(
int
(
resource
.
Size
))
enclosure
.
Length
=
strconv
.
Itoa
(
int
(
resource
.
Size
))
enclosure
.
Type
=
resource
.
Type
enclosure
.
Type
=
resource
.
Type
...
...
api/v1/storage.go
View file @
7c5296cf
...
@@ -4,18 +4,18 @@ import (
...
@@ -4,18 +4,18 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"strconv"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
const
(
const
(
// LocalStorage means the storage service is local file system.
// LocalStorage means the storage service is local file system.
LocalStorage
=
-
1
LocalStorage
int32
=
-
1
// DatabaseStorage means the storage service is database.
// DatabaseStorage means the storage service is database.
DatabaseStorage
=
0
DatabaseStorage
int32
=
0
)
)
type
StorageType
string
type
StorageType
string
...
@@ -44,7 +44,7 @@ type StorageS3Config struct {
...
@@ -44,7 +44,7 @@ type StorageS3Config struct {
}
}
type
Storage
struct
{
type
Storage
struct
{
ID
int
`json:"id"`
ID
int
32
`json:"id"`
Name
string
`json:"name"`
Name
string
`json:"name"`
Type
StorageType
`json:"type"`
Type
StorageType
`json:"type"`
Config
*
StorageConfig
`json:"config"`
Config
*
StorageConfig
`json:"config"`
...
@@ -65,7 +65,7 @@ type UpdateStorageRequest struct {
...
@@ -65,7 +65,7 @@ type UpdateStorageRequest struct {
func
(
s
*
APIV1Service
)
registerStorageRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerStorageRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/storage"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/storage"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -111,7 +111,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
...
@@ -111,7 +111,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
g
.
PATCH
(
"/storage/:storageId"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"/storage/:storageId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -126,7 +126,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
...
@@ -126,7 +126,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
}
}
storageID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"storageId"
))
storageID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"storageId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"storageId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"storageId"
)))
.
SetInternal
(
err
)
}
}
...
@@ -165,7 +165,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
...
@@ -165,7 +165,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
g
.
GET
(
"/storage"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/storage"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -199,7 +199,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
...
@@ -199,7 +199,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
g
.
DELETE
(
"/storage/:storageId"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/storage/:storageId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -214,7 +214,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
...
@@ -214,7 +214,7 @@ func (s *APIV1Service) registerStorageRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
}
}
storageID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"storageId"
))
storageID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"storageId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"storageId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"storageId"
)))
.
SetInternal
(
err
)
}
}
...
...
api/v1/system.go
View file @
7c5296cf
...
@@ -35,7 +35,7 @@ type SystemStatus struct {
...
@@ -35,7 +35,7 @@ type SystemStatus struct {
// Customized server profile, including server name and external url.
// Customized server profile, including server name and external url.
CustomizedProfile
CustomizedProfile
`json:"customizedProfile"`
CustomizedProfile
CustomizedProfile
`json:"customizedProfile"`
// Storage service ID.
// Storage service ID.
StorageServiceID
int
`json:"storageServiceId"`
StorageServiceID
int
32
`json:"storageServiceId"`
// Local storage path.
// Local storage path.
LocalStoragePath
string
`json:"localStoragePath"`
LocalStoragePath
string
`json:"localStoragePath"`
// Memo display with updated timestamp.
// Memo display with updated timestamp.
...
@@ -126,7 +126,7 @@ func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
...
@@ -126,7 +126,7 @@ func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
}
}
systemStatus
.
CustomizedProfile
=
customizedProfile
systemStatus
.
CustomizedProfile
=
customizedProfile
case
SystemSettingStorageServiceIDName
.
String
()
:
case
SystemSettingStorageServiceIDName
.
String
()
:
systemStatus
.
StorageServiceID
=
int
(
baseValue
.
(
float64
))
systemStatus
.
StorageServiceID
=
int
32
(
baseValue
.
(
float64
))
case
SystemSettingLocalStoragePathName
.
String
()
:
case
SystemSettingLocalStoragePathName
.
String
()
:
systemStatus
.
LocalStoragePath
=
baseValue
.
(
string
)
systemStatus
.
LocalStoragePath
=
baseValue
.
(
string
)
case
SystemSettingMemoDisplayWithUpdatedTsName
.
String
()
:
case
SystemSettingMemoDisplayWithUpdatedTsName
.
String
()
:
...
@@ -141,7 +141,7 @@ func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
...
@@ -141,7 +141,7 @@ func (s *APIV1Service) registerSystemRoutes(g *echo.Group) {
g
.
POST
(
"/system/vacuum"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/system/vacuum"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
...
api/v1/system_setting.go
View file @
7c5296cf
...
@@ -187,7 +187,7 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
...
@@ -187,7 +187,7 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
func
(
s
*
APIV1Service
)
registerSystemSettingRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerSystemSettingRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/system/setting"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/system/setting"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -237,7 +237,7 @@ func (s *APIV1Service) registerSystemSettingRoutes(g *echo.Group) {
...
@@ -237,7 +237,7 @@ func (s *APIV1Service) registerSystemSettingRoutes(g *echo.Group) {
g
.
GET
(
"/system/setting"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/system/setting"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
...
api/v1/tag.go
View file @
7c5296cf
...
@@ -16,7 +16,7 @@ import (
...
@@ -16,7 +16,7 @@ import (
type
Tag
struct
{
type
Tag
struct
{
Name
string
Name
string
CreatorID
int
CreatorID
int
32
}
}
type
UpsertTagRequest
struct
{
type
UpsertTagRequest
struct
{
...
@@ -30,7 +30,7 @@ type DeleteTagRequest struct {
...
@@ -30,7 +30,7 @@ type DeleteTagRequest struct {
func
(
s
*
APIV1Service
)
registerTagRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerTagRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/tag"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/tag"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -59,7 +59,7 @@ func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
...
@@ -59,7 +59,7 @@ func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
g
.
GET
(
"/tag"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/tag"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user id to find tag"
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user id to find tag"
)
}
}
...
@@ -80,7 +80,7 @@ func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
...
@@ -80,7 +80,7 @@ func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
g
.
GET
(
"/tag/suggestion"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/tag/suggestion"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user session"
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user session"
)
}
}
...
@@ -125,7 +125,7 @@ func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
...
@@ -125,7 +125,7 @@ func (s *APIV1Service) registerTagRoutes(g *echo.Group) {
g
.
POST
(
"/tag/delete"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/tag/delete"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
...
api/v1/user.go
View file @
7c5296cf
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"strconv"
"time"
"time"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
...
@@ -32,7 +31,7 @@ func (role Role) String() string {
...
@@ -32,7 +31,7 @@ func (role Role) String() string {
}
}
type
User
struct
{
type
User
struct
{
ID
int
`json:"id"`
ID
int
32
`json:"id"`
// Standard fields
// Standard fields
RowStatus
RowStatus
`json:"rowStatus"`
RowStatus
RowStatus
`json:"rowStatus"`
...
@@ -133,7 +132,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
...
@@ -133,7 +132,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
// POST /user - Create a new user.
// POST /user - Create a new user.
g
.
POST
(
"/user"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/user"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing auth session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing auth session"
)
}
}
...
@@ -208,7 +207,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
...
@@ -208,7 +207,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
// GET /user/me - Get current user.
// GET /user/me - Get current user.
g
.
GET
(
"/user/me"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/user/me"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing auth session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing auth session"
)
}
}
...
@@ -239,7 +238,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
...
@@ -239,7 +238,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
// GET /user/:id - Get user by id.
// GET /user/:id - Get user by id.
g
.
GET
(
"/user/:id"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/user/:id"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted user id"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted user id"
)
.
SetInternal
(
err
)
}
}
...
@@ -282,12 +281,12 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
...
@@ -282,12 +281,12 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
// PUT /user/:id - Update user by id.
// PUT /user/:id - Update user by id.
g
.
PATCH
(
"/user/:id"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"/user/:id"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
userID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"id"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"id"
)))
.
SetInternal
(
err
)
}
}
currentUserID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
currentUserID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -367,7 +366,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
...
@@ -367,7 +366,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
// DELETE /user/:id - Delete user by id.
// DELETE /user/:id - Delete user by id.
g
.
DELETE
(
"/user/:id"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/user/:id"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
currentUserID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
currentUserID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
...
@@ -383,7 +382,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
...
@@ -383,7 +382,7 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusForbidden
,
"Unauthorized to delete user"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusForbidden
,
"Unauthorized to delete user"
)
.
SetInternal
(
err
)
}
}
userID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
userID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"id"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"id"
)))
.
SetInternal
(
err
)
}
}
...
...
api/v1/user_setting.go
View file @
7c5296cf
...
@@ -67,13 +67,13 @@ var (
...
@@ -67,13 +67,13 @@ var (
)
)
type
UserSetting
struct
{
type
UserSetting
struct
{
UserID
int
`json:"userId"`
UserID
int
32
`json:"userId"`
Key
UserSettingKey
`json:"key"`
Key
UserSettingKey
`json:"key"`
Value
string
`json:"value"`
Value
string
`json:"value"`
}
}
type
UpsertUserSettingRequest
struct
{
type
UpsertUserSettingRequest
struct
{
UserID
int
`json:"-"`
UserID
int
32
`json:"-"`
Key
UserSettingKey
`json:"key"`
Key
UserSettingKey
`json:"key"`
Value
string
`json:"value"`
Value
string
`json:"value"`
}
}
...
@@ -122,7 +122,7 @@ func (upsert UpsertUserSettingRequest) Validate() error {
...
@@ -122,7 +122,7 @@ func (upsert UpsertUserSettingRequest) Validate() error {
func
(
s
*
APIV1Service
)
registerUserSettingRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
APIV1Service
)
registerUserSettingRoutes
(
g
*
echo
.
Group
)
{
g
.
POST
(
"/user/setting"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/user/setting"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
)
userID
,
ok
:=
c
.
Get
(
auth
.
UserIDContextKey
)
.
(
int
32
)
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing auth session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing auth session"
)
}
}
...
...
api/v2/jwt.go
View file @
7c5296cf
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v4"
"github.com/pkg/errors"
"github.com/pkg/errors"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/api/auth"
"github.com/usememos/memos/common/util"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
"google.golang.org/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/codes"
...
@@ -76,7 +77,7 @@ func (in *GRPCAuthInterceptor) AuthenticationInterceptor(ctx context.Context, re
...
@@ -76,7 +77,7 @@ func (in *GRPCAuthInterceptor) AuthenticationInterceptor(ctx context.Context, re
return
handler
(
childCtx
,
request
)
return
handler
(
childCtx
,
request
)
}
}
func
(
in
*
GRPCAuthInterceptor
)
authenticate
(
ctx
context
.
Context
,
accessTokenStr
string
)
(
int
,
error
)
{
func
(
in
*
GRPCAuthInterceptor
)
authenticate
(
ctx
context
.
Context
,
accessTokenStr
string
)
(
int
32
,
error
)
{
if
accessTokenStr
==
""
{
if
accessTokenStr
==
""
{
return
0
,
status
.
Errorf
(
codes
.
Unauthenticated
,
"access token not found"
)
return
0
,
status
.
Errorf
(
codes
.
Unauthenticated
,
"access token not found"
)
}
}
...
@@ -103,7 +104,7 @@ func (in *GRPCAuthInterceptor) authenticate(ctx context.Context, accessTokenStr
...
@@ -103,7 +104,7 @@ func (in *GRPCAuthInterceptor) authenticate(ctx context.Context, accessTokenStr
)
)
}
}
userID
,
err
:=
strconv
.
Atoi
(
claims
.
Subject
)
userID
,
err
:=
util
.
ConvertStringToInt32
(
claims
.
Subject
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
status
.
Errorf
(
codes
.
Unauthenticated
,
"malformed ID %q in the access token"
,
claims
.
Subject
)
return
0
,
status
.
Errorf
(
codes
.
Unauthenticated
,
"malformed ID %q in the access token"
,
claims
.
Subject
)
}
}
...
...
api/v2/tag_service.go
View file @
7c5296cf
...
@@ -24,7 +24,7 @@ func NewTagService(store *store.Store) *TagService {
...
@@ -24,7 +24,7 @@ func NewTagService(store *store.Store) *TagService {
func
(
s
*
TagService
)
ListTags
(
ctx
context
.
Context
,
request
*
apiv2pb
.
ListTagsRequest
)
(
*
apiv2pb
.
ListTagsResponse
,
error
)
{
func
(
s
*
TagService
)
ListTags
(
ctx
context
.
Context
,
request
*
apiv2pb
.
ListTagsRequest
)
(
*
apiv2pb
.
ListTagsResponse
,
error
)
{
tags
,
err
:=
s
.
Store
.
ListTags
(
ctx
,
&
store
.
FindTag
{
tags
,
err
:=
s
.
Store
.
ListTags
(
ctx
,
&
store
.
FindTag
{
CreatorID
:
int
(
request
.
CreatorId
)
,
CreatorID
:
request
.
CreatorId
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to list tags: %v"
,
err
)
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to list tags: %v"
,
err
)
...
...
api/v2/user_service.go
View file @
7c5296cf
...
@@ -37,9 +37,8 @@ func (s *UserService) GetUser(ctx context.Context, request *apiv2pb.GetUserReque
...
@@ -37,9 +37,8 @@ func (s *UserService) GetUser(ctx context.Context, request *apiv2pb.GetUserReque
// Data desensitization.
// Data desensitization.
userMessage
.
OpenId
=
""
userMessage
.
OpenId
=
""
userUID
:=
int
(
userMessage
.
Id
)
userSettings
,
err
:=
s
.
Store
.
ListUserSettings
(
ctx
,
&
store
.
FindUserSetting
{
userSettings
,
err
:=
s
.
Store
.
ListUserSettings
(
ctx
,
&
store
.
FindUserSetting
{
UserID
:
&
user
UID
,
UserID
:
&
user
Message
.
Id
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to list user settings: %v"
,
err
)
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to list user settings: %v"
,
err
)
...
...
common/util/util.go
View file @
7c5296cf
...
@@ -4,11 +4,21 @@ import (
...
@@ -4,11 +4,21 @@ import (
"crypto/rand"
"crypto/rand"
"math/big"
"math/big"
"net/mail"
"net/mail"
"strconv"
"strings"
"strings"
"github.com/google/uuid"
"github.com/google/uuid"
)
)
// ConvertStringToInt32 converts a string to int32.
func
ConvertStringToInt32
(
src
string
)
(
int32
,
error
)
{
i
,
err
:=
strconv
.
Atoi
(
src
)
if
err
!=
nil
{
return
0
,
err
}
return
int32
(
i
),
nil
}
// HasPrefixes returns true if the string s has any of the given prefixes.
// HasPrefixes returns true if the string s has any of the given prefixes.
func
HasPrefixes
(
src
string
,
prefixes
...
string
)
bool
{
func
HasPrefixes
(
src
string
,
prefixes
...
string
)
bool
{
for
_
,
prefix
:=
range
prefixes
{
for
_
,
prefix
:=
range
prefixes
{
...
...
server/telegram.go
View file @
7c5296cf
...
@@ -37,7 +37,7 @@ func (t *telegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
...
@@ -37,7 +37,7 @@ func (t *telegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
return
fmt
.
Errorf
(
"fail to SendReplyMessage: %s"
,
err
)
return
fmt
.
Errorf
(
"fail to SendReplyMessage: %s"
,
err
)
}
}
var
creatorID
int
var
creatorID
int
32
userSettingList
,
err
:=
t
.
store
.
ListUserSettings
(
ctx
,
&
store
.
FindUserSetting
{
userSettingList
,
err
:=
t
.
store
.
ListUserSettings
(
ctx
,
&
store
.
FindUserSetting
{
Key
:
apiv1
.
UserSettingTelegramUserIDKey
.
String
(),
Key
:
apiv1
.
UserSettingTelegramUserIDKey
.
String
(),
})
})
...
@@ -121,7 +121,7 @@ func (t *telegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
...
@@ -121,7 +121,7 @@ func (t *telegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
}
}
func
(
t
*
telegramHandler
)
CallbackQueryHandle
(
ctx
context
.
Context
,
bot
*
telegram
.
Bot
,
callbackQuery
telegram
.
CallbackQuery
)
error
{
func
(
t
*
telegramHandler
)
CallbackQueryHandle
(
ctx
context
.
Context
,
bot
*
telegram
.
Bot
,
callbackQuery
telegram
.
CallbackQuery
)
error
{
var
memoID
int
var
memoID
int
32
var
visibility
store
.
Visibility
var
visibility
store
.
Visibility
n
,
err
:=
fmt
.
Sscanf
(
callbackQuery
.
Data
,
"%s %d"
,
&
visibility
,
&
memoID
)
n
,
err
:=
fmt
.
Sscanf
(
callbackQuery
.
Data
,
"%s %d"
,
&
visibility
,
&
memoID
)
if
err
!=
nil
||
n
!=
2
{
if
err
!=
nil
||
n
!=
2
{
...
@@ -146,7 +146,7 @@ func (t *telegramHandler) CallbackQueryHandle(ctx context.Context, bot *telegram
...
@@ -146,7 +146,7 @@ func (t *telegramHandler) CallbackQueryHandle(ctx context.Context, bot *telegram
return
bot
.
AnswerCallbackQuery
(
ctx
,
callbackQuery
.
ID
,
fmt
.
Sprintf
(
"Success change Memo %d to %s"
,
memoID
,
visibility
))
return
bot
.
AnswerCallbackQuery
(
ctx
,
callbackQuery
.
ID
,
fmt
.
Sprintf
(
"Success change Memo %d to %s"
,
memoID
,
visibility
))
}
}
func
generateKeyboardForMemoID
(
id
int
)
[][]
telegram
.
InlineKeyboardButton
{
func
generateKeyboardForMemoID
(
id
int
32
)
[][]
telegram
.
InlineKeyboardButton
{
allVisibility
:=
[]
store
.
Visibility
{
allVisibility
:=
[]
store
.
Visibility
{
store
.
Public
,
store
.
Public
,
store
.
Protected
,
store
.
Protected
,
...
...
store/activity.go
View file @
7c5296cf
...
@@ -5,10 +5,10 @@ import (
...
@@ -5,10 +5,10 @@ import (
)
)
type
Activity
struct
{
type
Activity
struct
{
ID
int
ID
int
32
// Standard fields
// Standard fields
CreatorID
int
CreatorID
int
32
CreatedTs
int64
CreatedTs
int64
// Domain specific fields
// Domain specific fields
...
...
store/cache.go
View file @
7c5296cf
...
@@ -4,6 +4,6 @@ import (
...
@@ -4,6 +4,6 @@ import (
"fmt"
"fmt"
)
)
func
getUserSettingCacheKey
(
userID
int
,
key
string
)
string
{
func
getUserSettingCacheKey
(
userID
int
32
,
key
string
)
string
{
return
fmt
.
Sprintf
(
"%d-%s"
,
userID
,
key
)
return
fmt
.
Sprintf
(
"%d-%s"
,
userID
,
key
)
}
}
store/idp.go
View file @
7c5296cf
...
@@ -38,7 +38,7 @@ type FieldMapping struct {
...
@@ -38,7 +38,7 @@ type FieldMapping struct {
}
}
type
IdentityProvider
struct
{
type
IdentityProvider
struct
{
ID
int
ID
int
32
Name
string
Name
string
Type
IdentityProviderType
Type
IdentityProviderType
IdentifierFilter
string
IdentifierFilter
string
...
@@ -46,11 +46,11 @@ type IdentityProvider struct {
...
@@ -46,11 +46,11 @@ type IdentityProvider struct {
}
}
type
FindIdentityProvider
struct
{
type
FindIdentityProvider
struct
{
ID
*
int
ID
*
int
32
}
}
type
UpdateIdentityProvider
struct
{
type
UpdateIdentityProvider
struct
{
ID
int
ID
int
32
Type
IdentityProviderType
Type
IdentityProviderType
Name
*
string
Name
*
string
IdentifierFilter
*
string
IdentifierFilter
*
string
...
@@ -58,7 +58,7 @@ type UpdateIdentityProvider struct {
...
@@ -58,7 +58,7 @@ type UpdateIdentityProvider struct {
}
}
type
DeleteIdentityProvider
struct
{
type
DeleteIdentityProvider
struct
{
ID
int
ID
int
32
}
}
func
(
s
*
Store
)
CreateIdentityProvider
(
ctx
context
.
Context
,
create
*
IdentityProvider
)
(
*
IdentityProvider
,
error
)
{
func
(
s
*
Store
)
CreateIdentityProvider
(
ctx
context
.
Context
,
create
*
IdentityProvider
)
(
*
IdentityProvider
,
error
)
{
...
...
store/memo.go
View file @
7c5296cf
...
@@ -4,9 +4,10 @@ import (
...
@@ -4,9 +4,10 @@ import (
"context"
"context"
"database/sql"
"database/sql"
"fmt"
"fmt"
"strconv"
"strings"
"strings"
"time"
"time"
"github.com/usememos/memos/common/util"
)
)
// Visibility is the type of a visibility.
// Visibility is the type of a visibility.
...
@@ -34,11 +35,11 @@ func (v Visibility) String() string {
...
@@ -34,11 +35,11 @@ func (v Visibility) String() string {
}
}
type
Memo
struct
{
type
Memo
struct
{
ID
int
ID
int
32
// Standard fields
// Standard fields
RowStatus
RowStatus
RowStatus
RowStatus
CreatorID
int
CreatorID
int
32
CreatedTs
int64
CreatedTs
int64
UpdatedTs
int64
UpdatedTs
int64
...
@@ -48,16 +49,16 @@ type Memo struct {
...
@@ -48,16 +49,16 @@ type Memo struct {
// Composed fields
// Composed fields
Pinned
bool
Pinned
bool
ResourceIDList
[]
int
ResourceIDList
[]
int
32
RelationList
[]
*
MemoRelation
RelationList
[]
*
MemoRelation
}
}
type
FindMemo
struct
{
type
FindMemo
struct
{
ID
*
int
ID
*
int
32
// Standard fields
// Standard fields
RowStatus
*
RowStatus
RowStatus
*
RowStatus
CreatorID
*
int
CreatorID
*
int
32
// Domain specific fields
// Domain specific fields
Pinned
*
bool
Pinned
*
bool
...
@@ -71,7 +72,7 @@ type FindMemo struct {
...
@@ -71,7 +72,7 @@ type FindMemo struct {
}
}
type
UpdateMemo
struct
{
type
UpdateMemo
struct
{
ID
int
ID
int
32
CreatedTs
*
int64
CreatedTs
*
int64
UpdatedTs
*
int64
UpdatedTs
*
int64
RowStatus
*
RowStatus
RowStatus
*
RowStatus
...
@@ -80,7 +81,7 @@ type UpdateMemo struct {
...
@@ -80,7 +81,7 @@ type UpdateMemo struct {
}
}
type
DeleteMemo
struct
{
type
DeleteMemo
struct
{
ID
int
ID
int
32
}
}
func
(
s
*
Store
)
CreateMemo
(
ctx
context
.
Context
,
create
*
Memo
)
(
*
Memo
,
error
)
{
func
(
s
*
Store
)
CreateMemo
(
ctx
context
.
Context
,
create
*
Memo
)
(
*
Memo
,
error
)
{
...
@@ -220,9 +221,9 @@ func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
...
@@ -220,9 +221,9 @@ func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
if
memoResourceIDList
.
Valid
{
if
memoResourceIDList
.
Valid
{
idStringList
:=
strings
.
Split
(
memoResourceIDList
.
String
,
","
)
idStringList
:=
strings
.
Split
(
memoResourceIDList
.
String
,
","
)
memo
.
ResourceIDList
=
make
([]
int
,
0
,
len
(
idStringList
))
memo
.
ResourceIDList
=
make
([]
int
32
,
0
,
len
(
idStringList
))
for
_
,
idString
:=
range
idStringList
{
for
_
,
idString
:=
range
idStringList
{
id
,
err
:=
strconv
.
Atoi
(
idString
)
id
,
err
:=
util
.
ConvertStringToInt32
(
idString
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -237,7 +238,7 @@ func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
...
@@ -237,7 +238,7 @@ func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
if
len
(
relatedMemoTypeList
)
!=
2
{
if
len
(
relatedMemoTypeList
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"invalid relation format"
)
return
nil
,
fmt
.
Errorf
(
"invalid relation format"
)
}
}
relatedMemoID
,
err
:=
strconv
.
Atoi
(
relatedMemoTypeList
[
0
])
relatedMemoID
,
err
:=
util
.
ConvertStringToInt32
(
relatedMemoTypeList
[
0
])
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -318,7 +319,7 @@ func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error {
...
@@ -318,7 +319,7 @@ func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error {
return
nil
return
nil
}
}
func
(
s
*
Store
)
FindMemosVisibilityList
(
ctx
context
.
Context
,
memoIDs
[]
int
)
([]
Visibility
,
error
)
{
func
(
s
*
Store
)
FindMemosVisibilityList
(
ctx
context
.
Context
,
memoIDs
[]
int
32
)
([]
Visibility
,
error
)
{
args
:=
make
([]
any
,
0
,
len
(
memoIDs
))
args
:=
make
([]
any
,
0
,
len
(
memoIDs
))
list
:=
make
([]
string
,
0
,
len
(
memoIDs
))
list
:=
make
([]
string
,
0
,
len
(
memoIDs
))
for
_
,
memoID
:=
range
memoIDs
{
for
_
,
memoID
:=
range
memoIDs
{
...
...
store/memo_organizer.go
View file @
7c5296cf
...
@@ -8,19 +8,19 @@ import (
...
@@ -8,19 +8,19 @@ import (
)
)
type
MemoOrganizer
struct
{
type
MemoOrganizer
struct
{
MemoID
int
MemoID
int
32
UserID
int
UserID
int
32
Pinned
bool
Pinned
bool
}
}
type
FindMemoOrganizer
struct
{
type
FindMemoOrganizer
struct
{
MemoID
int
MemoID
int
32
UserID
int
UserID
int
32
}
}
type
DeleteMemoOrganizer
struct
{
type
DeleteMemoOrganizer
struct
{
MemoID
*
int
MemoID
*
int
32
UserID
*
int
UserID
*
int
32
}
}
func
(
s
*
Store
)
UpsertMemoOrganizer
(
ctx
context
.
Context
,
upsert
*
MemoOrganizer
)
(
*
MemoOrganizer
,
error
)
{
func
(
s
*
Store
)
UpsertMemoOrganizer
(
ctx
context
.
Context
,
upsert
*
MemoOrganizer
)
(
*
MemoOrganizer
,
error
)
{
...
...
store/memo_relation.go
View file @
7c5296cf
...
@@ -14,20 +14,20 @@ const (
...
@@ -14,20 +14,20 @@ const (
)
)
type
MemoRelation
struct
{
type
MemoRelation
struct
{
MemoID
int
MemoID
int
32
RelatedMemoID
int
RelatedMemoID
int
32
Type
MemoRelationType
Type
MemoRelationType
}
}
type
FindMemoRelation
struct
{
type
FindMemoRelation
struct
{
MemoID
*
int
MemoID
*
int
32
RelatedMemoID
*
int
RelatedMemoID
*
int
32
Type
*
MemoRelationType
Type
*
MemoRelationType
}
}
type
DeleteMemoRelation
struct
{
type
DeleteMemoRelation
struct
{
MemoID
*
int
MemoID
*
int
32
RelatedMemoID
*
int
RelatedMemoID
*
int
32
Type
*
MemoRelationType
Type
*
MemoRelationType
}
}
...
...
store/memo_resource.go
View file @
7c5296cf
...
@@ -7,27 +7,27 @@ import (
...
@@ -7,27 +7,27 @@ import (
)
)
type
MemoResource
struct
{
type
MemoResource
struct
{
MemoID
int
MemoID
int
32
ResourceID
int
ResourceID
int
32
CreatedTs
int64
CreatedTs
int64
UpdatedTs
int64
UpdatedTs
int64
}
}
type
UpsertMemoResource
struct
{
type
UpsertMemoResource
struct
{
MemoID
int
MemoID
int
32
ResourceID
int
ResourceID
int
32
CreatedTs
int64
CreatedTs
int64
UpdatedTs
*
int64
UpdatedTs
*
int64
}
}
type
FindMemoResource
struct
{
type
FindMemoResource
struct
{
MemoID
*
int
MemoID
*
int
32
ResourceID
*
int
ResourceID
*
int
32
}
}
type
DeleteMemoResource
struct
{
type
DeleteMemoResource
struct
{
MemoID
*
int
MemoID
*
int
32
ResourceID
*
int
ResourceID
*
int
32
}
}
func
(
s
*
Store
)
UpsertMemoResource
(
ctx
context
.
Context
,
upsert
*
UpsertMemoResource
)
(
*
MemoResource
,
error
)
{
func
(
s
*
Store
)
UpsertMemoResource
(
ctx
context
.
Context
,
upsert
*
UpsertMemoResource
)
(
*
MemoResource
,
error
)
{
...
...
store/resource.go
View file @
7c5296cf
...
@@ -8,10 +8,10 @@ import (
...
@@ -8,10 +8,10 @@ import (
)
)
type
Resource
struct
{
type
Resource
struct
{
ID
int
ID
int
32
// Standard fields
// Standard fields
CreatorID
int
CreatorID
int
32
CreatedTs
int64
CreatedTs
int64
UpdatedTs
int64
UpdatedTs
int64
...
@@ -27,16 +27,16 @@ type Resource struct {
...
@@ -27,16 +27,16 @@ type Resource struct {
type
FindResource
struct
{
type
FindResource
struct
{
GetBlob
bool
GetBlob
bool
ID
*
int
ID
*
int
32
CreatorID
*
int
CreatorID
*
int
32
Filename
*
string
Filename
*
string
MemoID
*
int
MemoID
*
int
32
Limit
*
int
Limit
*
int
Offset
*
int
Offset
*
int
}
}
type
UpdateResource
struct
{
type
UpdateResource
struct
{
ID
int
ID
int
32
UpdatedTs
*
int64
UpdatedTs
*
int64
Filename
*
string
Filename
*
string
InternalPath
*
string
InternalPath
*
string
...
@@ -44,7 +44,7 @@ type UpdateResource struct {
...
@@ -44,7 +44,7 @@ type UpdateResource struct {
}
}
type
DeleteResource
struct
{
type
DeleteResource
struct
{
ID
int
ID
int
32
}
}
func
(
s
*
Store
)
CreateResource
(
ctx
context
.
Context
,
create
*
Resource
)
(
*
Resource
,
error
)
{
func
(
s
*
Store
)
CreateResource
(
ctx
context
.
Context
,
create
*
Resource
)
(
*
Resource
,
error
)
{
...
...
store/storage.go
View file @
7c5296cf
...
@@ -6,24 +6,24 @@ import (
...
@@ -6,24 +6,24 @@ import (
)
)
type
Storage
struct
{
type
Storage
struct
{
ID
int
ID
int
32
Name
string
Name
string
Type
string
Type
string
Config
string
Config
string
}
}
type
FindStorage
struct
{
type
FindStorage
struct
{
ID
*
int
ID
*
int
32
}
}
type
UpdateStorage
struct
{
type
UpdateStorage
struct
{
ID
int
ID
int
32
Name
*
string
Name
*
string
Config
*
string
Config
*
string
}
}
type
DeleteStorage
struct
{
type
DeleteStorage
struct
{
ID
int
ID
int
32
}
}
func
(
s
*
Store
)
CreateStorage
(
ctx
context
.
Context
,
create
*
Storage
)
(
*
Storage
,
error
)
{
func
(
s
*
Store
)
CreateStorage
(
ctx
context
.
Context
,
create
*
Storage
)
(
*
Storage
,
error
)
{
...
...
store/tag.go
View file @
7c5296cf
...
@@ -8,16 +8,16 @@ import (
...
@@ -8,16 +8,16 @@ import (
type
Tag
struct
{
type
Tag
struct
{
Name
string
Name
string
CreatorID
int
CreatorID
int
32
}
}
type
FindTag
struct
{
type
FindTag
struct
{
CreatorID
int
CreatorID
int
32
}
}
type
DeleteTag
struct
{
type
DeleteTag
struct
{
Name
string
Name
string
CreatorID
int
CreatorID
int
32
}
}
func
(
s
*
Store
)
UpsertTag
(
ctx
context
.
Context
,
upsert
*
Tag
)
(
*
Tag
,
error
)
{
func
(
s
*
Store
)
UpsertTag
(
ctx
context
.
Context
,
upsert
*
Tag
)
(
*
Tag
,
error
)
{
...
...
store/user.go
View file @
7c5296cf
...
@@ -30,7 +30,7 @@ func (e Role) String() string {
...
@@ -30,7 +30,7 @@ func (e Role) String() string {
}
}
type
User
struct
{
type
User
struct
{
ID
int
ID
int
32
// Standard fields
// Standard fields
RowStatus
RowStatus
RowStatus
RowStatus
...
@@ -48,7 +48,7 @@ type User struct {
...
@@ -48,7 +48,7 @@ type User struct {
}
}
type
UpdateUser
struct
{
type
UpdateUser
struct
{
ID
int
ID
int
32
UpdatedTs
*
int64
UpdatedTs
*
int64
RowStatus
*
RowStatus
RowStatus
*
RowStatus
...
@@ -63,7 +63,7 @@ type UpdateUser struct {
...
@@ -63,7 +63,7 @@ type UpdateUser struct {
}
}
type
FindUser
struct
{
type
FindUser
struct
{
ID
*
int
ID
*
int
32
RowStatus
*
RowStatus
RowStatus
*
RowStatus
Username
*
string
Username
*
string
Role
*
Role
Role
*
Role
...
@@ -73,7 +73,7 @@ type FindUser struct {
...
@@ -73,7 +73,7 @@ type FindUser struct {
}
}
type
DeleteUser
struct
{
type
DeleteUser
struct
{
ID
int
ID
int
32
}
}
func
(
s
*
Store
)
CreateUser
(
ctx
context
.
Context
,
create
*
User
)
(
*
User
,
error
)
{
func
(
s
*
Store
)
CreateUser
(
ctx
context
.
Context
,
create
*
User
)
(
*
User
,
error
)
{
...
...
store/user_setting.go
View file @
7c5296cf
...
@@ -7,13 +7,13 @@ import (
...
@@ -7,13 +7,13 @@ import (
)
)
type
UserSetting
struct
{
type
UserSetting
struct
{
UserID
int
UserID
int
32
Key
string
Key
string
Value
string
Value
string
}
}
type
FindUserSetting
struct
{
type
FindUserSetting
struct
{
UserID
*
int
UserID
*
int
32
Key
string
Key
string
}
}
...
...
test/server/memo_relation_test.go
View file @
7c5296cf
...
@@ -61,7 +61,7 @@ func TestMemoRelationServer(t *testing.T) {
...
@@ -61,7 +61,7 @@ func TestMemoRelationServer(t *testing.T) {
require
.
Len
(
t
,
memo2
.
RelationList
,
1
)
require
.
Len
(
t
,
memo2
.
RelationList
,
1
)
}
}
func
(
s
*
TestingServer
)
postMemoRelationUpsert
(
memoID
int
,
memoRelationUpsert
*
apiv1
.
UpsertMemoRelationRequest
)
(
*
apiv1
.
MemoRelation
,
error
)
{
func
(
s
*
TestingServer
)
postMemoRelationUpsert
(
memoID
int
32
,
memoRelationUpsert
*
apiv1
.
UpsertMemoRelationRequest
)
(
*
apiv1
.
MemoRelation
,
error
)
{
rawData
,
err
:=
json
.
Marshal
(
&
memoRelationUpsert
)
rawData
,
err
:=
json
.
Marshal
(
&
memoRelationUpsert
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to marshal memo relation upsert"
)
return
nil
,
errors
.
Wrap
(
err
,
"failed to marshal memo relation upsert"
)
...
@@ -85,7 +85,7 @@ func (s *TestingServer) postMemoRelationUpsert(memoID int, memoRelationUpsert *a
...
@@ -85,7 +85,7 @@ func (s *TestingServer) postMemoRelationUpsert(memoID int, memoRelationUpsert *a
return
memoRelation
,
nil
return
memoRelation
,
nil
}
}
func
(
s
*
TestingServer
)
deleteMemoRelation
(
memoID
int
,
relatedMemoID
int
,
relationType
apiv1
.
MemoRelationType
)
error
{
func
(
s
*
TestingServer
)
deleteMemoRelation
(
memoID
int
32
,
relatedMemoID
int32
,
relationType
apiv1
.
MemoRelationType
)
error
{
_
,
err
:=
s
.
delete
(
fmt
.
Sprintf
(
"/api/v1/memo/%d/relation/%d/type/%s"
,
memoID
,
relatedMemoID
,
relationType
),
nil
)
_
,
err
:=
s
.
delete
(
fmt
.
Sprintf
(
"/api/v1/memo/%d/relation/%d/type/%s"
,
memoID
,
relatedMemoID
,
relationType
),
nil
)
return
err
return
err
}
}
test/server/memo_test.go
View file @
7c5296cf
...
@@ -59,7 +59,7 @@ func TestMemoServer(t *testing.T) {
...
@@ -59,7 +59,7 @@ func TestMemoServer(t *testing.T) {
require
.
Len
(
t
,
memoList
,
0
)
require
.
Len
(
t
,
memoList
,
0
)
}
}
func
(
s
*
TestingServer
)
getMemo
(
memoID
int
)
(
*
apiv1
.
Memo
,
error
)
{
func
(
s
*
TestingServer
)
getMemo
(
memoID
int
32
)
(
*
apiv1
.
Memo
,
error
)
{
body
,
err
:=
s
.
get
(
fmt
.
Sprintf
(
"/api/v1/memo/%d"
,
memoID
),
nil
)
body
,
err
:=
s
.
get
(
fmt
.
Sprintf
(
"/api/v1/memo/%d"
,
memoID
),
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -145,12 +145,12 @@ func (s *TestingServer) patchMemo(memoPatch *apiv1.PatchMemoRequest) (*apiv1.Mem
...
@@ -145,12 +145,12 @@ func (s *TestingServer) patchMemo(memoPatch *apiv1.PatchMemoRequest) (*apiv1.Mem
return
memo
,
nil
return
memo
,
nil
}
}
func
(
s
*
TestingServer
)
deleteMemo
(
memoID
int
)
error
{
func
(
s
*
TestingServer
)
deleteMemo
(
memoID
int
32
)
error
{
_
,
err
:=
s
.
delete
(
fmt
.
Sprintf
(
"/api/v1/memo/%d"
,
memoID
),
nil
)
_
,
err
:=
s
.
delete
(
fmt
.
Sprintf
(
"/api/v1/memo/%d"
,
memoID
),
nil
)
return
err
return
err
}
}
func
(
s
*
TestingServer
)
postMemoOrganizer
(
memoID
int
,
memosOrganizer
*
apiv1
.
UpsertMemoOrganizerRequest
)
(
*
apiv1
.
Memo
,
error
)
{
func
(
s
*
TestingServer
)
postMemoOrganizer
(
memoID
int
32
,
memosOrganizer
*
apiv1
.
UpsertMemoOrganizerRequest
)
(
*
apiv1
.
Memo
,
error
)
{
rawData
,
err
:=
json
.
Marshal
(
&
memosOrganizer
)
rawData
,
err
:=
json
.
Marshal
(
&
memosOrganizer
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to marshal memos organizer"
)
return
nil
,
errors
.
Wrap
(
err
,
"failed to marshal memos organizer"
)
...
...
test/store/resource_test.go
View file @
7c5296cf
...
@@ -29,15 +29,15 @@ func TestResourceStore(t *testing.T) {
...
@@ -29,15 +29,15 @@ func TestResourceStore(t *testing.T) {
})
})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
correctFilename
,
res
.
Filename
)
require
.
Equal
(
t
,
correctFilename
,
res
.
Filename
)
require
.
Equal
(
t
,
1
,
res
.
ID
)
require
.
Equal
(
t
,
int32
(
1
)
,
res
.
ID
)
notFoundResource
,
err
:=
ts
.
GetResource
(
ctx
,
&
store
.
FindResource
{
notFoundResource
,
err
:=
ts
.
GetResource
(
ctx
,
&
store
.
FindResource
{
Filename
:
&
incorrectFilename
,
Filename
:
&
incorrectFilename
,
})
})
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Nil
(
t
,
notFoundResource
)
require
.
Nil
(
t
,
notFoundResource
)
correctCreatorID
:
=
101
var
correctCreatorID
int32
=
101
incorrectCreatorID
:
=
102
var
incorrectCreatorID
int32
=
102
_
,
err
=
ts
.
GetResource
(
ctx
,
&
store
.
FindResource
{
_
,
err
=
ts
.
GetResource
(
ctx
,
&
store
.
FindResource
{
CreatorID
:
&
correctCreatorID
,
CreatorID
:
&
correctCreatorID
,
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment