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
7cc8b951
Commit
7cc8b951
authored
Mar 20, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: update resource id naming
parent
a3a4e37c
Changes
48
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
48 changed files
with
700 additions
and
689 deletions
+700
-689
resource_name.go
internal/util/resource_name.go
+1
-1
memo_service.proto
proto/api/v2/memo_service.proto
+17
-15
reaction_service.proto
proto/api/v2/reaction_service.proto
+1
-1
tag_service.proto
proto/api/v2/tag_service.proto
+4
-4
user_service.proto
proto/api/v2/user_service.proto
+8
-8
README.md
proto/gen/api/v2/README.md
+28
-28
memo_service.pb.go
proto/gen/api/v2/memo_service.pb.go
+368
-367
reaction_service.pb.go
proto/gen/api/v2/reaction_service.pb.go
+1
-1
tag_service.pb.go
proto/gen/api/v2/tag_service.pb.go
+4
-4
user_service.pb.go
proto/gen/api/v2/user_service.pb.go
+8
-8
telegram.go
server/integration/telegram.go
+9
-9
auth.go
server/route/api/v1/auth.go
+1
-1
memo.go
server/route/api/v1/memo.go
+6
-6
resource.go
server/route/api/v1/resource.go
+7
-7
user.go
server/route/api/v1/user.go
+2
-2
apidocs.swagger.md
server/route/api/v2/apidocs.swagger.md
+30
-30
apidocs.swagger.yaml
server/route/api/v2/apidocs.swagger.yaml
+40
-36
auth_service.go
server/route/api/v2/auth_service.go
+1
-1
memo_service.go
server/route/api/v2/memo_service.go
+15
-15
resource_service.go
server/route/api/v2/resource_service.go
+3
-3
user_service.go
server/route/api/v2/user_service.go
+2
-2
frontend.go
server/route/frontend/frontend.go
+4
-4
resource.go
server/route/resource/resource.go
+7
-7
rss.go
server/route/rss/rss.go
+2
-2
memo.go
store/db/mysql/memo.go
+8
-8
LATEST__SCHEMA.sql
store/db/mysql/migration/dev/LATEST__SCHEMA.sql
+2
-2
resource.go
store/db/mysql/resource.go
+8
-8
memo.go
store/db/postgres/memo.go
+8
-8
LATEST__SCHEMA.sql
store/db/postgres/migration/dev/LATEST__SCHEMA.sql
+2
-2
resource.go
store/db/postgres/resource.go
+10
-10
memo.go
store/db/sqlite/memo.go
+8
-8
LATEST__SCHEMA.sql
store/db/sqlite/migration/dev/LATEST__SCHEMA.sql
+2
-2
resource.go
store/db/sqlite/resource.go
+10
-10
10002__memo.sql
store/db/sqlite/seed/10002__memo.sql
+5
-5
10006__resource.sql
store/db/sqlite/seed/10006__resource.sql
+1
-1
memo.go
store/memo.go
+17
-15
resource.go
store/resource.go
+10
-8
memo_organizer_test.go
test/store/memo_organizer_test.go
+4
-4
memo_relation_test.go
test/store/memo_relation_test.go
+12
-12
memo_test.go
test/store/memo_test.go
+8
-8
resource_test.go
test/store/resource_test.go
+1
-1
EmbeddedMemo.tsx
...c/components/MemoContent/EmbeddedContent/EmbeddedMemo.tsx
+2
-2
ReferencedMemo.tsx
...mponents/MemoContent/ReferencedContent/ReferencedMemo.tsx
+2
-2
MemoView.tsx
web/src/components/MemoView.tsx
+2
-2
MemoDetail.tsx
web/src/pages/MemoDetail.tsx
+5
-5
Resources.tsx
web/src/pages/Resources.tsx
+1
-1
index.tsx
web/src/router/index.tsx
+1
-1
memo.ts
web/src/store/v1/memo.ts
+2
-2
No files found.
internal/util/resource_name.go
View file @
7cc8b951
...
...
@@ -3,5 +3,5 @@ package util
import
"regexp"
var
(
ResourceName
Matcher
=
regexp
.
MustCompile
(
"^[a-zA-Z0-9]([a-zA-Z0-9-]{1,30}[a-zA-Z0-9])$"
)
UID
Matcher
=
regexp
.
MustCompile
(
"^[a-zA-Z0-9]([a-zA-Z0-9-]{1,30}[a-zA-Z0-9])$"
)
)
proto/api/v2/memo_service.proto
View file @
7cc8b951
...
...
@@ -122,15 +122,17 @@ enum Visibility {
message
Memo
{
// The name of the memo.
// Format: memos/{uid}
// Format: memos/{id}
// id is the system generated id.
string
name
=
1
;
string
resource_id
=
2
;
// The user defined id of the memo.
string
uid
=
2
;
RowStatus
row_status
=
3
;
// The name of the creator.
// Format: users/{
u
id}
// Format: users/{id}
string
creator
=
4
;
google.protobuf.Timestamp
create_time
=
5
;
...
...
@@ -197,7 +199,7 @@ message SearchMemosResponse {
message
GetMemoRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
}
...
...
@@ -217,7 +219,7 @@ message UpdateMemoResponse {
message
DeleteMemoRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
}
...
...
@@ -234,7 +236,7 @@ message ExportMemosResponse {
message
SetMemoResourcesRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
repeated
Resource
resources
=
2
;
...
...
@@ -244,7 +246,7 @@ message SetMemoResourcesResponse {}
message
ListMemoResourcesRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
}
...
...
@@ -254,7 +256,7 @@ message ListMemoResourcesResponse {
message
SetMemoRelationsRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
repeated
MemoRelation
relations
=
2
;
...
...
@@ -264,7 +266,7 @@ message SetMemoRelationsResponse {}
message
ListMemoRelationsRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
}
...
...
@@ -274,7 +276,7 @@ message ListMemoRelationsResponse {
message
CreateMemoCommentRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
CreateMemoRequest
comment
=
2
;
...
...
@@ -286,7 +288,7 @@ message CreateMemoCommentResponse {
message
ListMemoCommentsRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
}
...
...
@@ -296,7 +298,7 @@ message ListMemoCommentsResponse {
message
GetUserMemosStatsRequest
{
// name is the name of the user to get stats for.
// Format: users/{
u
id}
// Format: users/{id}
string
name
=
1
;
// timezone location
...
...
@@ -316,7 +318,7 @@ message GetUserMemosStatsResponse {
message
ListMemoReactionsRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
}
...
...
@@ -326,7 +328,7 @@ message ListMemoReactionsResponse {
message
UpsertMemoReactionRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
Reaction
reaction
=
2
;
...
...
@@ -338,7 +340,7 @@ message UpsertMemoReactionResponse {
message
DeleteMemoReactionRequest
{
// The name of the memo.
// Format: memos/{
u
id}
// Format: memos/{id}
string
name
=
1
;
int32
reaction_id
=
2
;
...
...
proto/api/v2/reaction_service.proto
View file @
7cc8b951
...
...
@@ -8,7 +8,7 @@ message Reaction {
int32
id
=
1
;
// The name of the creator.
// Format: users/{
u
id}
// Format: users/{id}
string
creator
=
2
;
string
content_id
=
3
;
...
...
proto/api/v2/tag_service.proto
View file @
7cc8b951
...
...
@@ -37,7 +37,7 @@ service TagService {
message
Tag
{
string
name
=
1
;
// The creator of tags.
// Format: users/{
u
id}
// Format: users/{id}
string
creator
=
2
;
}
...
...
@@ -57,7 +57,7 @@ message BatchUpsertTagResponse {}
message
ListTagsRequest
{
// The creator of tags.
// Format: users/{
u
id}
// Format: users/{id}
string
user
=
1
;
}
...
...
@@ -67,7 +67,7 @@ message ListTagsResponse {
message
RenameTagRequest
{
// The creator of tags.
// Format: users/{
u
id}
// Format: users/{id}
string
user
=
1
;
string
old_name
=
2
;
string
new_name
=
3
;
...
...
@@ -85,7 +85,7 @@ message DeleteTagResponse {}
message
GetTagSuggestionsRequest
{
// The creator of tags.
// Format: users/{
u
id}
// Format: users/{id}
string
user
=
1
;
}
...
...
proto/api/v2/user_service.proto
View file @
7cc8b951
...
...
@@ -91,7 +91,7 @@ service UserService {
message
User
{
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
string
name
=
1
;
// The system generated uid of the user.
...
...
@@ -140,7 +140,7 @@ message SearchUsersResponse {
message
GetUserRequest
{
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
string
name
=
1
;
}
...
...
@@ -168,7 +168,7 @@ message UpdateUserResponse {
message
DeleteUserRequest
{
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
string
name
=
1
;
}
...
...
@@ -176,7 +176,7 @@ message DeleteUserResponse {}
message
UserSetting
{
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
string
name
=
1
;
// The preferred locale of the user.
string
locale
=
2
;
...
...
@@ -190,7 +190,7 @@ message UserSetting {
message
GetUserSettingRequest
{
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
string
name
=
1
;
}
...
...
@@ -217,7 +217,7 @@ message UserAccessToken {
message
ListUserAccessTokensRequest
{
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
string
name
=
1
;
}
...
...
@@ -227,7 +227,7 @@ message ListUserAccessTokensResponse {
message
CreateUserAccessTokenRequest
{
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
string
name
=
1
;
string
description
=
2
;
...
...
@@ -241,7 +241,7 @@ message CreateUserAccessTokenResponse {
message
DeleteUserAccessTokenRequest
{
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
string
name
=
1
;
// access_token is the access token to delete.
string
access_token
=
2
;
...
...
proto/gen/api/v2/README.md
View file @
7cc8b951
...
...
@@ -389,7 +389,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{id} |
| description |
[
string
](
#string
)
| | |
| expires_at |
[
google.protobuf.Timestamp
](
#google-protobuf-Timestamp
)
| optional | |
...
...
@@ -451,7 +451,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{id} |
| access_token |
[
string
](
#string
)
| | access_token is the access token to delete. |
...
...
@@ -477,7 +477,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{id} |
...
...
@@ -502,7 +502,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{id} |
...
...
@@ -532,7 +532,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{id} |
...
...
@@ -562,7 +562,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{id} |
...
...
@@ -709,7 +709,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{id} |
| id |
[
int32
](
#int32
)
| | The system generated uid of the user. |
| role |
[
User.Role
](
#memos-api-v2-User-Role
)
| | |
| username |
[
string
](
#string
)
| | |
...
...
@@ -753,7 +753,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the user. Format: users/{id} |
| locale |
[
string
](
#string
)
| | The preferred locale of the user. |
| appearance |
[
string
](
#string
)
| | The preferred appearance of the user. |
| memo_visibility |
[
string
](
#string
)
| | The default visibility of the memo. |
...
...
@@ -1273,7 +1273,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| id |
[
int32
](
#int32
)
| | |
| creator |
[
string
](
#string
)
| | The name of the creator. Format: users/{
u
id} |
| creator |
[
string
](
#string
)
| | The name of the creator. Format: users/{id} |
| content_id |
[
string
](
#string
)
| | |
| reaction_type |
[
Reaction.Type
](
#memos-api-v2-Reaction-Type
)
| | |
...
...
@@ -1556,7 +1556,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
| comment |
[
CreateMemoRequest
](
#memos-api-v2-CreateMemoRequest
)
| | |
...
...
@@ -1618,7 +1618,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
| reaction_id |
[
int32
](
#int32
)
| | |
...
...
@@ -1644,7 +1644,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
...
...
@@ -1699,7 +1699,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
...
...
@@ -1729,7 +1729,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | name is the name of the user to get stats for. Format: users/{
u
id} |
| name |
[
string
](
#string
)
| | name is the name of the user to get stats for. Format: users/{id} |
| timezone |
[
string
](
#string
)
| | timezone location Format: uses tz identifier https://en.wikipedia.org/wiki/List_of_tz_database_time_zones |
| filter |
[
string
](
#string
)
| | Same as ListMemosRequest.filter |
...
...
@@ -1777,7 +1777,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
...
...
@@ -1807,7 +1807,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
...
...
@@ -1837,7 +1837,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
...
...
@@ -1867,7 +1867,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
...
...
@@ -1930,10 +1930,10 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
uid}
|
|
resource_id |
[
string
](
#string
)
| |
|
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
id} id is the system generated id.
|
|
uid |
[
string
](
#string
)
| | The user defined id of the memo.
|
| row_status |
[
RowStatus
](
#memos-api-v2-RowStatus
)
| | |
| creator |
[
string
](
#string
)
| | The name of the creator. Format: users/{
u
id} |
| creator |
[
string
](
#string
)
| | The name of the creator. Format: users/{id} |
| create_time |
[
google.protobuf.Timestamp
](
#google-protobuf-Timestamp
)
| | |
| update_time |
[
google.protobuf.Timestamp
](
#google-protobuf-Timestamp
)
| | |
| display_time |
[
google.protobuf.Timestamp
](
#google-protobuf-Timestamp
)
| | |
...
...
@@ -1988,7 +1988,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
| relations |
[
MemoRelation
](
#memos-api-v2-MemoRelation
)
| repeated | |
...
...
@@ -2014,7 +2014,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
| resources |
[
Resource
](
#memos-api-v2-Resource
)
| repeated | |
...
...
@@ -2071,7 +2071,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{
u
id} |
| name |
[
string
](
#string
)
| | The name of the memo. Format: memos/{id} |
| reaction |
[
Reaction
](
#memos-api-v2-Reaction
)
| | |
...
...
@@ -2208,7 +2208,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user |
[
string
](
#string
)
| | The creator of tags. Format: users/{
u
id} |
| user |
[
string
](
#string
)
| | The creator of tags. Format: users/{id} |
...
...
@@ -2238,7 +2238,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user |
[
string
](
#string
)
| | The creator of tags. Format: users/{
u
id} |
| user |
[
string
](
#string
)
| | The creator of tags. Format: users/{id} |
...
...
@@ -2268,7 +2268,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user |
[
string
](
#string
)
| | The creator of tags. Format: users/{
u
id} |
| user |
[
string
](
#string
)
| | The creator of tags. Format: users/{id} |
| old_name |
[
string
](
#string
)
| | |
| new_name |
[
string
](
#string
)
| | |
...
...
@@ -2301,7 +2301,7 @@ Used internally for obfuscating the page token.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name |
[
string
](
#string
)
| | |
| creator |
[
string
](
#string
)
| | The creator of tags. Format: users/{
u
id} |
| creator |
[
string
](
#string
)
| | The creator of tags. Format: users/{id} |
...
...
proto/gen/api/v2/memo_service.pb.go
View file @
7cc8b951
This diff is collapsed.
Click to expand it.
proto/gen/api/v2/reaction_service.pb.go
View file @
7cc8b951
...
...
@@ -106,7 +106,7 @@ type Reaction struct {
Id
int32
`protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
// The name of the creator.
// Format: users/{
u
id}
// Format: users/{id}
Creator
string
`protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"`
ContentId
string
`protobuf:"bytes,3,opt,name=content_id,json=contentId,proto3" json:"content_id,omitempty"`
ReactionType
Reaction_Type
`protobuf:"varint,4,opt,name=reaction_type,json=reactionType,proto3,enum=memos.api.v2.Reaction_Type" json:"reaction_type,omitempty"`
...
...
proto/gen/api/v2/tag_service.pb.go
View file @
7cc8b951
...
...
@@ -28,7 +28,7 @@ type Tag struct {
Name
string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// The creator of tags.
// Format: users/{
u
id}
// Format: users/{id}
Creator
string
`protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"`
}
...
...
@@ -263,7 +263,7 @@ type ListTagsRequest struct {
unknownFields
protoimpl
.
UnknownFields
// The creator of tags.
// Format: users/{
u
id}
// Format: users/{id}
User
string
`protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
}
...
...
@@ -359,7 +359,7 @@ type RenameTagRequest struct {
unknownFields
protoimpl
.
UnknownFields
// The creator of tags.
// Format: users/{
u
id}
// Format: users/{id}
User
string
`protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
OldName
string
`protobuf:"bytes,2,opt,name=old_name,json=oldName,proto3" json:"old_name,omitempty"`
NewName
string
`protobuf:"bytes,3,opt,name=new_name,json=newName,proto3" json:"new_name,omitempty"`
...
...
@@ -556,7 +556,7 @@ type GetTagSuggestionsRequest struct {
unknownFields
protoimpl
.
UnknownFields
// The creator of tags.
// Format: users/{
u
id}
// Format: users/{id}
User
string
`protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
}
...
...
proto/gen/api/v2/user_service.pb.go
View file @
7cc8b951
...
...
@@ -81,7 +81,7 @@ type User struct {
unknownFields
protoimpl
.
UnknownFields
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
Name
string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// The system generated uid of the user.
Id
int32
`protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"`
...
...
@@ -398,7 +398,7 @@ type GetUserRequest struct {
unknownFields
protoimpl
.
UnknownFields
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
Name
string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
...
...
@@ -690,7 +690,7 @@ type DeleteUserRequest struct {
unknownFields
protoimpl
.
UnknownFields
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
Name
string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
...
...
@@ -777,7 +777,7 @@ type UserSetting struct {
unknownFields
protoimpl
.
UnknownFields
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
Name
string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// The preferred locale of the user.
Locale
string
`protobuf:"bytes,2,opt,name=locale,proto3" json:"locale,omitempty"`
...
...
@@ -862,7 +862,7 @@ type GetUserSettingRequest struct {
unknownFields
protoimpl
.
UnknownFields
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
Name
string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
...
...
@@ -1131,7 +1131,7 @@ type ListUserAccessTokensRequest struct {
unknownFields
protoimpl
.
UnknownFields
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
Name
string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
...
...
@@ -1227,7 +1227,7 @@ type CreateUserAccessTokenRequest struct {
unknownFields
protoimpl
.
UnknownFields
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
Name
string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
Description
string
`protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
ExpiresAt
*
timestamppb
.
Timestamp
`protobuf:"bytes,3,opt,name=expires_at,json=expiresAt,proto3,oneof" json:"expires_at,omitempty"`
...
...
@@ -1339,7 +1339,7 @@ type DeleteUserAccessTokenRequest struct {
unknownFields
protoimpl
.
UnknownFields
// The name of the user.
// Format: users/{
u
id}
// Format: users/{id}
Name
string
`protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// access_token is the access token to delete.
AccessToken
string
`protobuf:"bytes,2,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
...
...
server/integration/telegram.go
View file @
7cc8b951
...
...
@@ -74,9 +74,9 @@ func (t *TelegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
}
create
:=
&
store
.
Memo
{
ResourceName
:
shortuuid
.
New
(),
CreatorID
:
creatorID
,
Visibility
:
store
.
Private
,
UID
:
shortuuid
.
New
(),
CreatorID
:
creatorID
,
Visibility
:
store
.
Private
,
}
if
message
.
Text
!=
nil
{
create
.
Content
=
convertToMarkdown
(
*
message
.
Text
,
message
.
Entities
)
...
...
@@ -121,12 +121,12 @@ func (t *TelegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
for
_
,
attachment
:=
range
attachments
{
// Fill the common field of create
create
:=
store
.
Resource
{
ResourceName
:
shortuuid
.
New
(),
CreatorID
:
creatorID
,
Filename
:
filepath
.
Base
(
attachment
.
FileName
),
Type
:
attachment
.
GetMimeType
(),
Size
:
attachment
.
FileSize
,
MemoID
:
&
memoMessage
.
ID
,
UID
:
shortuuid
.
New
(),
CreatorID
:
creatorID
,
Filename
:
filepath
.
Base
(
attachment
.
FileName
),
Type
:
attachment
.
GetMimeType
(),
Size
:
attachment
.
FileSize
,
MemoID
:
&
memoMessage
.
ID
,
}
err
:=
apiv1
.
SaveResourceBlob
(
ctx
,
t
.
store
,
&
create
,
bytes
.
NewReader
(
attachment
.
Data
))
...
...
server/route/api/v1/auth.go
View file @
7cc8b951
...
...
@@ -269,7 +269,7 @@ func (s *APIV1Service) SignUp(c echo.Context) error {
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Failed to find users"
)
.
SetInternal
(
err
)
}
if
!
util
.
ResourceName
Matcher
.
MatchString
(
strings
.
ToLower
(
signup
.
Username
))
{
if
!
util
.
UID
Matcher
.
MatchString
(
strings
.
ToLower
(
signup
.
Username
))
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Invalid username %s"
,
signup
.
Username
))
.
SetInternal
(
err
)
}
...
...
server/route/api/v1/memo.go
View file @
7cc8b951
...
...
@@ -827,7 +827,7 @@ func (s *APIV1Service) UpdateMemo(c echo.Context) error {
func
(
s
*
APIV1Service
)
convertMemoFromStore
(
ctx
context
.
Context
,
memo
*
store
.
Memo
)
(
*
Memo
,
error
)
{
memoMessage
:=
&
Memo
{
ID
:
memo
.
ID
,
Name
:
memo
.
ResourceName
,
Name
:
memo
.
UID
,
RowStatus
:
RowStatus
(
memo
.
RowStatus
.
String
()),
CreatorID
:
memo
.
CreatorID
,
CreatedTs
:
memo
.
CreatedTs
,
...
...
@@ -921,11 +921,11 @@ func convertCreateMemoRequestToMemoMessage(memoCreate *CreateMemoRequest) *store
createdTs
=
*
memoCreate
.
CreatedTs
}
return
&
store
.
Memo
{
ResourceName
:
shortuuid
.
New
(),
CreatorID
:
memoCreate
.
CreatorID
,
CreatedTs
:
createdTs
,
Content
:
memoCreate
.
Content
,
Visibility
:
store
.
Visibility
(
memoCreate
.
Visibility
),
UID
:
shortuuid
.
New
(),
CreatorID
:
memoCreate
.
CreatorID
,
CreatedTs
:
createdTs
,
Content
:
memoCreate
.
Content
,
Visibility
:
store
.
Visibility
(
memoCreate
.
Visibility
),
}
}
...
...
server/route/api/v1/resource.go
View file @
7cc8b951
...
...
@@ -138,7 +138,7 @@ func (s *APIV1Service) CreateResource(c echo.Context) error {
}
create
:=
&
store
.
Resource
{
ResourceName
:
shortuuid
.
New
(),
UID
:
shortuuid
.
New
(),
CreatorID
:
userID
,
Filename
:
request
.
Filename
,
ExternalLink
:
request
.
ExternalLink
,
...
...
@@ -220,11 +220,11 @@ func (s *APIV1Service) UploadResource(c echo.Context) error {
defer
sourceFile
.
Close
()
create
:=
&
store
.
Resource
{
ResourceName
:
shortuuid
.
New
(),
CreatorID
:
userID
,
Filename
:
file
.
Filename
,
Type
:
file
.
Header
.
Get
(
"Content-Type"
),
Size
:
file
.
Size
,
UID
:
shortuuid
.
New
(),
CreatorID
:
userID
,
Filename
:
file
.
Filename
,
Type
:
file
.
Header
.
Get
(
"Content-Type"
),
Size
:
file
.
Size
,
}
err
=
SaveResourceBlob
(
ctx
,
s
.
Store
,
create
,
sourceFile
)
if
err
!=
nil
{
...
...
@@ -371,7 +371,7 @@ func replacePathTemplate(path, filename string) string {
func
convertResourceFromStore
(
resource
*
store
.
Resource
)
*
Resource
{
return
&
Resource
{
ID
:
resource
.
ID
,
Name
:
resource
.
ResourceName
,
Name
:
resource
.
UID
,
CreatorID
:
resource
.
CreatorID
,
CreatedTs
:
resource
.
CreatedTs
,
UpdatedTs
:
resource
.
UpdatedTs
,
...
...
server/route/api/v1/user.go
View file @
7cc8b951
...
...
@@ -157,7 +157,7 @@ func (s *APIV1Service) CreateUser(c echo.Context) error {
if
err
:=
userCreate
.
Validate
();
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Invalid user create format"
)
.
SetInternal
(
err
)
}
if
!
util
.
ResourceName
Matcher
.
MatchString
(
strings
.
ToLower
(
userCreate
.
Username
))
{
if
!
util
.
UID
Matcher
.
MatchString
(
strings
.
ToLower
(
userCreate
.
Username
))
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Invalid username %s"
,
userCreate
.
Username
))
.
SetInternal
(
err
)
}
// Disallow host user to be created.
...
...
@@ -377,7 +377,7 @@ func (s *APIV1Service) UpdateUser(c echo.Context) error {
}
}
if
request
.
Username
!=
nil
{
if
!
util
.
ResourceName
Matcher
.
MatchString
(
strings
.
ToLower
(
*
request
.
Username
))
{
if
!
util
.
UID
Matcher
.
MatchString
(
strings
.
ToLower
(
*
request
.
Username
))
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Invalid username %s"
,
*
request
.
Username
))
.
SetInternal
(
err
)
}
userUpdate
.
Username
=
request
.
Username
...
...
server/route/api/v2/apidocs.swagger.md
View file @
7cc8b951
This diff is collapsed.
Click to expand it.
server/route/api/v2/apidocs.swagger.yaml
View file @
7cc8b951
...
...
@@ -243,7 +243,7 @@ paths:
-
name
:
name
description
:
|-
name is the name of the user to get stats for.
Format: users/{
u
id}
Format: users/{id}
in: query
required: false
type: string
...
...
@@ -477,7 +477,7 @@ paths:
-
name
:
user
description
:
|-
The creator of tags.
Format: users/{
u
id}
Format: users/{id}
in: query
required: false
type: string
...
...
@@ -503,7 +503,7 @@ paths:
-
name
:
tag.creator
description
:
|-
The creator of tags.
Format: users/{
u
id}
Format: users/{id}
in: query
required: false
type: string
...
...
@@ -545,7 +545,7 @@ paths:
-
name
:
user
description
:
|-
The creator of tags.
Format: users/{
u
id}
Format: users/{id}
in: query
required: false
type: string
...
...
@@ -585,7 +585,7 @@ paths:
- name: user
description: |-
The creator of tags.
Format: users/{
u
id}
Format: users/{id}
in: query
required: false
type: string
...
...
@@ -915,7 +915,8 @@ paths:
-
name
:
memo.name
description
:
|-
The name of the memo.
Format: memos/{uid}
Format: memos/{id}
id is the system generated id.
in: path
required: true
type: string
...
...
@@ -926,15 +927,16 @@ paths:
schema
:
type
:
object
properties
:
resourceI
d
:
ui
d
:
type
:
string
description
:
The user defined id of the memo.
rowStatus
:
$ref
:
'
#/definitions/apiv2RowStatus'
creator
:
type
:
string
title
:
|-
The name of the creator.
Format: users/{
u
id}
Format: users/{id}
createTime
:
type
:
string
format
:
date-time
...
...
@@ -991,7 +993,7 @@ paths:
-
name
:
name_1
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1038,7 +1040,7 @@ paths:
-
name
:
name_2
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1062,7 +1064,7 @@ paths:
-
name
:
name
description
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
in: path
required: true
type: string
...
...
@@ -1085,7 +1087,7 @@ paths:
-
name
:
name
description
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
in: path
required: true
type: string
...
...
@@ -1109,7 +1111,7 @@ paths:
-
name
:
name
description
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
in: path
required: true
type: string
...
...
@@ -1132,7 +1134,7 @@ paths:
-
name
:
name
description
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
in: path
required: true
type: string
...
...
@@ -1161,7 +1163,7 @@ paths:
-
name
:
name
description
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
in: path
required: true
type: string
...
...
@@ -1190,7 +1192,7 @@ paths:
-
name
:
name
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1213,7 +1215,7 @@ paths:
-
name
:
name
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1251,7 +1253,7 @@ paths:
-
name
:
name
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1274,7 +1276,7 @@ paths:
-
name
:
name
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1287,7 +1289,7 @@ paths:
-
name
:
reaction.creator
description
:
|-
The name of the creator.
Format: users/{
u
id}
Format: users/{id}
in: query
required: false
type: string
...
...
@@ -1333,7 +1335,7 @@ paths:
-
name
:
name
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1362,7 +1364,7 @@ paths:
-
name
:
name
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1385,7 +1387,7 @@ paths:
-
name
:
name
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1414,7 +1416,7 @@ paths:
-
name
:
name
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1437,7 +1439,7 @@ paths:
-
name
:
name
description
:
|-
The name of the memo.
Format: memos/{
u
id}
Format: memos/{id}
in: path
required: true
type: string
...
...
@@ -1466,7 +1468,7 @@ paths:
-
name
:
name
description
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
in: path
required: true
type: string
...
...
@@ -1490,7 +1492,7 @@ paths:
-
name
:
setting.name
description
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
in: path
required: true
type: string
...
...
@@ -1532,7 +1534,7 @@ paths:
-
name
:
user.name
description
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
in: path
required: true
type: string
...
...
@@ -1656,7 +1658,7 @@ definitions:
type
:
string
title
:
|-
The name of the creator.
Format: users/{
u
id}
Format: users/{id}
contentId
:
type
:
string
reactionType
:
...
...
@@ -1692,7 +1694,7 @@ definitions:
type
:
string
title
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
locale
:
type
:
string
description
:
The preferred locale of the user.
...
...
@@ -2078,18 +2080,20 @@ definitions:
properties
:
name
:
type
:
string
title
:
|-
description
:
|-
The name of the memo.
Format: memos/{uid}
resourceId
:
Format: memos/{id}
id is the system generated id.
uid
:
type
:
string
description
:
The user defined id of the memo.
rowStatus
:
$ref
:
'
#/definitions/apiv2RowStatus'
creator
:
type
:
string
title
:
|-
The name of the creator.
Format: users/{
u
id}
Format: users/{id}
createTime
:
type
:
string
format
:
date-time
...
...
@@ -2230,7 +2234,7 @@ definitions:
type
:
string
title
:
|-
The creator of tags.
Format: users/{
u
id}
Format: users/{id}
v2UpdateInboxResponse
:
type
:
object
properties
:
...
...
@@ -2283,7 +2287,7 @@ definitions:
type
:
string
title
:
|-
The name of the user.
Format: users/{
u
id}
Format: users/{id}
id
:
type
:
integer
format
:
int32
...
...
server/route/api/v2/auth_service.go
View file @
7cc8b951
...
...
@@ -189,7 +189,7 @@ func (s *APIV2Service) SignUp(ctx context.Context, request *apiv2pb.SignUpReques
Nickname
:
request
.
Username
,
PasswordHash
:
string
(
passwordHash
),
}
if
!
util
.
ResourceName
Matcher
.
MatchString
(
strings
.
ToLower
(
create
.
Username
))
{
if
!
util
.
UID
Matcher
.
MatchString
(
strings
.
ToLower
(
create
.
Username
))
{
return
nil
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"invalid username: %s"
,
create
.
Username
)
}
...
...
server/route/api/v2/memo_service.go
View file @
7cc8b951
...
...
@@ -44,10 +44,10 @@ func (s *APIV2Service) CreateMemo(ctx context.Context, request *apiv2pb.CreateMe
}
create
:=
&
store
.
Memo
{
ResourceName
:
shortuuid
.
New
(),
CreatorID
:
user
.
ID
,
Content
:
request
.
Content
,
Visibility
:
convertVisibilityToStore
(
request
.
Visibility
),
UID
:
shortuuid
.
New
(),
CreatorID
:
user
.
ID
,
Content
:
request
.
Content
,
Visibility
:
convertVisibilityToStore
(
request
.
Visibility
),
}
// Find disable public memos system setting.
disablePublicMemosSystem
,
err
:=
s
.
getDisablePublicMemosSystemSettingValue
(
ctx
)
...
...
@@ -231,9 +231,9 @@ func (s *APIV2Service) UpdateMemo(ctx context.Context, request *apiv2pb.UpdateMe
for
_
,
path
:=
range
request
.
UpdateMask
.
Paths
{
if
path
==
"content"
{
update
.
Content
=
&
request
.
Memo
.
Content
}
else
if
path
==
"
resource_name
"
{
update
.
ResourceName
=
&
request
.
Memo
.
Name
if
!
util
.
ResourceNameMatcher
.
MatchString
(
*
update
.
ResourceName
)
{
}
else
if
path
==
"
uid
"
{
update
.
UID
=
&
request
.
Memo
.
Name
if
!
util
.
UIDMatcher
.
MatchString
(
*
update
.
UID
)
{
return
nil
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"invalid resource name"
)
}
}
else
if
path
==
"visibility"
{
...
...
@@ -555,7 +555,7 @@ func (s *APIV2Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
return
&
apiv2pb
.
Memo
{
Name
:
name
,
ResourceId
:
memo
.
ResourceName
,
Uid
:
memo
.
UID
,
RowStatus
:
convertRowStatusFromStore
(
memo
.
RowStatus
),
Creator
:
fmt
.
Sprintf
(
"%s%d"
,
UserNamePrefix
,
creator
.
ID
),
CreateTime
:
timestamppb
.
New
(
time
.
Unix
(
memo
.
CreatedTs
,
0
)),
...
...
@@ -690,8 +690,8 @@ func (s *APIV2Service) buildMemoFindWithFilter(ctx context.Context, find *store.
}
find
.
CreatorID
=
&
user
.
ID
}
if
filter
.
ResourceName
!=
nil
{
find
.
ResourceName
=
filter
.
ResourceName
if
filter
.
UID
!=
nil
{
find
.
UID
=
filter
.
UID
}
if
filter
.
RowStatus
!=
nil
{
find
.
RowStatus
=
filter
.
RowStatus
...
...
@@ -728,7 +728,7 @@ var SearchMemosFilterCELAttributes = []cel.EnvOption{
cel
.
Variable
(
"display_time_before"
,
cel
.
IntType
),
cel
.
Variable
(
"display_time_after"
,
cel
.
IntType
),
cel
.
Variable
(
"creator"
,
cel
.
StringType
),
cel
.
Variable
(
"
resource_name
"
,
cel
.
StringType
),
cel
.
Variable
(
"
uid
"
,
cel
.
StringType
),
cel
.
Variable
(
"row_status"
,
cel
.
StringType
),
}
...
...
@@ -739,7 +739,7 @@ type SearchMemosFilter struct {
DisplayTimeBefore
*
int64
DisplayTimeAfter
*
int64
Creator
*
string
ResourceName
*
string
UID
*
string
RowStatus
*
store
.
RowStatus
}
...
...
@@ -792,9 +792,9 @@ func findSearchMemosField(callExpr *expr.Expr_Call, filter *SearchMemosFilter) {
}
else
if
idExpr
.
Name
==
"creator"
{
creator
:=
callExpr
.
Args
[
1
]
.
GetConstExpr
()
.
GetStringValue
()
filter
.
Creator
=
&
creator
}
else
if
idExpr
.
Name
==
"
resource_name
"
{
resourceName
:=
callExpr
.
Args
[
1
]
.
GetConstExpr
()
.
GetStringValue
()
filter
.
ResourceName
=
&
resourceName
}
else
if
idExpr
.
Name
==
"
uid
"
{
uid
:=
callExpr
.
Args
[
1
]
.
GetConstExpr
()
.
GetStringValue
()
filter
.
UID
=
&
uid
}
else
if
idExpr
.
Name
==
"row_status"
{
rowStatus
:=
store
.
RowStatus
(
callExpr
.
Args
[
1
]
.
GetConstExpr
()
.
GetStringValue
())
filter
.
RowStatus
=
&
rowStatus
...
...
server/route/api/v2/resource_service.go
View file @
7cc8b951
...
...
@@ -31,7 +31,7 @@ func (s *APIV2Service) CreateResource(ctx context.Context, request *apiv2pb.Crea
}
create
:=
&
store
.
Resource
{
ResourceName
:
shortuuid
.
New
(),
UID
:
shortuuid
.
New
(),
CreatorID
:
user
.
ID
,
Filename
:
request
.
Filename
,
ExternalLink
:
request
.
ExternalLink
,
...
...
@@ -87,7 +87,7 @@ func (s *APIV2Service) GetResource(ctx context.Context, request *apiv2pb.GetReso
func
(
s
*
APIV2Service
)
GetResourceByName
(
ctx
context
.
Context
,
request
*
apiv2pb
.
GetResourceByNameRequest
)
(
*
apiv2pb
.
GetResourceByNameResponse
,
error
)
{
resource
,
err
:=
s
.
Store
.
GetResource
(
ctx
,
&
store
.
FindResource
{
ResourceName
:
&
request
.
Name
,
UID
:
&
request
.
Name
,
})
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to get resource: %v"
,
err
)
...
...
@@ -165,7 +165,7 @@ func (s *APIV2Service) convertResourceFromStore(ctx context.Context, resource *s
return
&
apiv2pb
.
Resource
{
Id
:
resource
.
ID
,
Name
:
resource
.
ResourceName
,
Name
:
resource
.
UID
,
CreateTime
:
timestamppb
.
New
(
time
.
Unix
(
resource
.
CreatedTs
,
0
)),
Filename
:
resource
.
Filename
,
ExternalLink
:
resource
.
ExternalLink
,
...
...
server/route/api/v2/user_service.go
View file @
7cc8b951
...
...
@@ -105,7 +105,7 @@ func (s *APIV2Service) CreateUser(ctx context.Context, request *apiv2pb.CreateUs
if
currentUser
.
Role
!=
store
.
RoleHost
{
return
nil
,
status
.
Errorf
(
codes
.
PermissionDenied
,
"permission denied"
)
}
if
!
util
.
ResourceName
Matcher
.
MatchString
(
strings
.
ToLower
(
request
.
User
.
Username
))
{
if
!
util
.
UID
Matcher
.
MatchString
(
strings
.
ToLower
(
request
.
User
.
Username
))
{
return
nil
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"invalid username: %s"
,
request
.
User
.
Username
)
}
passwordHash
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
request
.
User
.
Password
),
bcrypt
.
DefaultCost
)
...
...
@@ -161,7 +161,7 @@ func (s *APIV2Service) UpdateUser(ctx context.Context, request *apiv2pb.UpdateUs
}
for
_
,
field
:=
range
request
.
UpdateMask
.
Paths
{
if
field
==
"username"
{
if
!
util
.
ResourceName
Matcher
.
MatchString
(
strings
.
ToLower
(
request
.
User
.
Username
))
{
if
!
util
.
UID
Matcher
.
MatchString
(
strings
.
ToLower
(
request
.
User
.
Username
))
{
return
nil
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"invalid username: %s"
,
request
.
User
.
Username
)
}
update
.
Username
=
&
request
.
User
.
Username
...
...
server/route/frontend/frontend.go
View file @
7cc8b951
...
...
@@ -53,11 +53,11 @@ func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
func
(
s
*
FrontendService
)
registerRoutes
(
e
*
echo
.
Echo
)
{
rawIndexHTML
:=
getRawIndexHTML
()
e
.
GET
(
"/m/:
name
"
,
func
(
c
echo
.
Context
)
error
{
e
.
GET
(
"/m/:
uid
"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
resourceName
:=
c
.
Param
(
"name
"
)
uid
:=
c
.
Param
(
"uid
"
)
memo
,
err
:=
s
.
Store
.
GetMemo
(
ctx
,
&
store
.
FindMemo
{
ResourceName
:
&
resourceName
,
UID
:
&
uid
,
})
if
err
!=
nil
{
return
c
.
HTML
(
http
.
StatusOK
,
rawIndexHTML
)
...
...
@@ -108,7 +108,7 @@ Sitemap: %s/sitemap.xml`, instanceURL, instanceURL)
return
err
}
for
_
,
memo
:=
range
memoList
{
urlsets
=
append
(
urlsets
,
fmt
.
Sprintf
(
`<url><loc>%s</loc></url>`
,
fmt
.
Sprintf
(
"%s/m/%s"
,
instanceURL
,
memo
.
ResourceName
)))
urlsets
=
append
(
urlsets
,
fmt
.
Sprintf
(
`<url><loc>%s</loc></url>`
,
fmt
.
Sprintf
(
"%s/m/%s"
,
instanceURL
,
memo
.
UID
)))
}
sitemap
:=
fmt
.
Sprintf
(
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">%s</urlset>`
,
strings
.
Join
(
urlsets
,
"
\n
"
))
return
c
.
XMLBlob
(
http
.
StatusOK
,
[]
byte
(
sitemap
))
...
...
server/route/resource/resource.go
View file @
7cc8b951
...
...
@@ -42,22 +42,22 @@ func NewResourceService(profile *profile.Profile, store *store.Store) *ResourceS
}
func
(
s
*
ResourceService
)
RegisterRoutes
(
g
*
echo
.
Group
)
{
g
.
GET
(
"/r/:
resourceName
"
,
s
.
streamResource
)
g
.
GET
(
"/r/:
resourceName
/*"
,
s
.
streamResource
)
g
.
GET
(
"/r/:
uid
"
,
s
.
streamResource
)
g
.
GET
(
"/r/:
uid
/*"
,
s
.
streamResource
)
}
func
(
s
*
ResourceService
)
streamResource
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
resourceName
:=
c
.
Param
(
"resourceName
"
)
uid
:=
c
.
Param
(
"uid
"
)
resource
,
err
:=
s
.
Store
.
GetResource
(
ctx
,
&
store
.
FindResource
{
ResourceName
:
&
resourceName
,
GetBlob
:
true
,
UID
:
&
uid
,
GetBlob
:
true
,
})
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find resource by
id: %s"
,
resourceName
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find resource by
uid: %s"
,
uid
))
.
SetInternal
(
err
)
}
if
resource
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Resource not found: %s"
,
resourceName
))
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Resource not found: %s"
,
uid
))
}
// Check the related memo visibility.
if
resource
.
MemoID
!=
nil
{
...
...
server/route/rss/rss.go
View file @
7cc8b951
...
...
@@ -112,7 +112,7 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st
}
feed
.
Items
[
i
]
=
&
feeds
.
Item
{
Title
:
getRSSItemTitle
(
memo
.
Content
),
Link
:
&
feeds
.
Link
{
Href
:
baseURL
+
"/m/"
+
memo
.
ResourceName
},
Link
:
&
feeds
.
Link
{
Href
:
baseURL
+
"/m/"
+
memo
.
UID
},
Description
:
description
,
Created
:
time
.
Unix
(
memo
.
CreatedTs
,
0
),
}
...
...
@@ -128,7 +128,7 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st
if
resource
.
ExternalLink
!=
""
{
enclosure
.
Url
=
resource
.
ExternalLink
}
else
{
enclosure
.
Url
=
baseURL
+
"/o/r/"
+
resource
.
ResourceName
enclosure
.
Url
=
baseURL
+
"/o/r/"
+
resource
.
UID
}
enclosure
.
Length
=
strconv
.
Itoa
(
int
(
resource
.
Size
))
enclosure
.
Type
=
resource
.
Type
...
...
store/db/mysql/memo.go
View file @
7cc8b951
...
...
@@ -12,9 +12,9 @@ import (
)
func
(
d
*
DB
)
CreateMemo
(
ctx
context
.
Context
,
create
*
store
.
Memo
)
(
*
store
.
Memo
,
error
)
{
fields
:=
[]
string
{
"`
resource_name
`"
,
"`creator_id`"
,
"`content`"
,
"`visibility`"
}
fields
:=
[]
string
{
"`
uid
`"
,
"`creator_id`"
,
"`content`"
,
"`visibility`"
}
placeholder
:=
[]
string
{
"?"
,
"?"
,
"?"
,
"?"
}
args
:=
[]
any
{
create
.
ResourceName
,
create
.
CreatorID
,
create
.
Content
,
create
.
Visibility
}
args
:=
[]
any
{
create
.
UID
,
create
.
CreatorID
,
create
.
Content
,
create
.
Visibility
}
stmt
:=
"INSERT INTO `memo` ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
")"
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
...
...
@@ -43,8 +43,8 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
if
v
:=
find
.
ID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`memo`.`id` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
ResourceName
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`memo`.`
resource_name
` = ?"
),
append
(
args
,
*
v
)
if
v
:=
find
.
UID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`memo`.`
uid
` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`memo`.`creator_id` = ?"
),
append
(
args
,
*
v
)
...
...
@@ -94,7 +94,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
fields
:=
[]
string
{
"`memo`.`id` AS `id`"
,
"`memo`.`
resource_name` AS `resource_name
`"
,
"`memo`.`
uid` AS `uid
`"
,
"`memo`.`creator_id` AS `creator_id`"
,
"UNIX_TIMESTAMP(`memo`.`created_ts`) AS `created_ts`"
,
"UNIX_TIMESTAMP(`memo`.`updated_ts`) AS `updated_ts`"
,
...
...
@@ -126,7 +126,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
var
memo
store
.
Memo
dests
:=
[]
any
{
&
memo
.
ID
,
&
memo
.
ResourceName
,
&
memo
.
UID
,
&
memo
.
CreatorID
,
&
memo
.
CreatedTs
,
&
memo
.
UpdatedTs
,
...
...
@@ -166,8 +166,8 @@ func (d *DB) GetMemo(ctx context.Context, find *store.FindMemo) (*store.Memo, er
func
(
d
*
DB
)
UpdateMemo
(
ctx
context
.
Context
,
update
*
store
.
UpdateMemo
)
error
{
set
,
args
:=
[]
string
{},
[]
any
{}
if
v
:=
update
.
ResourceName
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`
resource_name
` = ?"
),
append
(
args
,
*
v
)
if
v
:=
update
.
UID
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`
uid
` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
update
.
CreatedTs
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`created_ts` = FROM_UNIXTIME(?)"
),
append
(
args
,
*
v
)
...
...
store/db/mysql/migration/dev/LATEST__SCHEMA.sql
View file @
7cc8b951
...
...
@@ -37,7 +37,7 @@ CREATE TABLE `user_setting` (
-- memo
CREATE
TABLE
`memo`
(
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`
resource_name
`
VARCHAR
(
256
)
NOT
NULL
UNIQUE
,
`
uid
`
VARCHAR
(
256
)
NOT
NULL
UNIQUE
,
`creator_id`
INT
NOT
NULL
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
...
...
@@ -65,7 +65,7 @@ CREATE TABLE `memo_relation` (
-- resource
CREATE
TABLE
`resource`
(
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`
resource_name
`
VARCHAR
(
256
)
NOT
NULL
UNIQUE
,
`
uid
`
VARCHAR
(
256
)
NOT
NULL
UNIQUE
,
`creator_id`
INT
NOT
NULL
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
...
...
store/db/mysql/resource.go
View file @
7cc8b951
...
...
@@ -10,9 +10,9 @@ import (
)
func
(
d
*
DB
)
CreateResource
(
ctx
context
.
Context
,
create
*
store
.
Resource
)
(
*
store
.
Resource
,
error
)
{
fields
:=
[]
string
{
"`
resource_name
`"
,
"`filename`"
,
"`blob`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"`internal_path`"
,
"`memo_id`"
}
fields
:=
[]
string
{
"`
uid
`"
,
"`filename`"
,
"`blob`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"`internal_path`"
,
"`memo_id`"
}
placeholder
:=
[]
string
{
"?"
,
"?"
,
"?"
,
"?"
,
"?"
,
"?"
,
"?"
,
"?"
,
"?"
}
args
:=
[]
any
{
create
.
ResourceName
,
create
.
Filename
,
create
.
Blob
,
create
.
ExternalLink
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
InternalPath
,
create
.
MemoID
}
args
:=
[]
any
{
create
.
UID
,
create
.
Filename
,
create
.
Blob
,
create
.
ExternalLink
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
InternalPath
,
create
.
MemoID
}
stmt
:=
"INSERT INTO `resource` ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
")"
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
...
...
@@ -35,8 +35,8 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
if
v
:=
find
.
ID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`id` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
ResourceName
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource_name
` = ?"
),
append
(
args
,
*
v
)
if
v
:=
find
.
UID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
uid
` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`creator_id` = ?"
),
append
(
args
,
*
v
)
...
...
@@ -51,7 +51,7 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
where
=
append
(
where
,
"`memo_id` IS NOT NULL"
)
}
fields
:=
[]
string
{
"`id`"
,
"`
resource_name
`"
,
"`filename`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"UNIX_TIMESTAMP(`created_ts`)"
,
"UNIX_TIMESTAMP(`updated_ts`)"
,
"`internal_path`"
,
"`memo_id`"
}
fields
:=
[]
string
{
"`id`"
,
"`
uid
`"
,
"`filename`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"UNIX_TIMESTAMP(`created_ts`)"
,
"UNIX_TIMESTAMP(`updated_ts`)"
,
"`internal_path`"
,
"`memo_id`"
}
if
find
.
GetBlob
{
fields
=
append
(
fields
,
"`blob`"
)
}
...
...
@@ -76,7 +76,7 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
var
memoID
sql
.
NullInt32
dests
:=
[]
any
{
&
resource
.
ID
,
&
resource
.
ResourceName
,
&
resource
.
UID
,
&
resource
.
Filename
,
&
resource
.
ExternalLink
,
&
resource
.
Type
,
...
...
@@ -121,8 +121,8 @@ func (d *DB) GetResource(ctx context.Context, find *store.FindResource) (*store.
func
(
d
*
DB
)
UpdateResource
(
ctx
context
.
Context
,
update
*
store
.
UpdateResource
)
(
*
store
.
Resource
,
error
)
{
set
,
args
:=
[]
string
{},
[]
any
{}
if
v
:=
update
.
ResourceName
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`
resource_name
` = ?"
),
append
(
args
,
*
v
)
if
v
:=
update
.
UID
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`
uid
` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
update
.
UpdatedTs
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`updated_ts` = FROM_UNIXTIME(?)"
),
append
(
args
,
*
v
)
...
...
store/db/postgres/memo.go
View file @
7cc8b951
...
...
@@ -12,8 +12,8 @@ import (
)
func
(
d
*
DB
)
CreateMemo
(
ctx
context
.
Context
,
create
*
store
.
Memo
)
(
*
store
.
Memo
,
error
)
{
fields
:=
[]
string
{
"
resource_name
"
,
"creator_id"
,
"content"
,
"visibility"
}
args
:=
[]
any
{
create
.
ResourceName
,
create
.
CreatorID
,
create
.
Content
,
create
.
Visibility
}
fields
:=
[]
string
{
"
uid
"
,
"creator_id"
,
"content"
,
"visibility"
}
args
:=
[]
any
{
create
.
UID
,
create
.
CreatorID
,
create
.
Content
,
create
.
Visibility
}
stmt
:=
"INSERT INTO memo ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
placeholders
(
len
(
args
))
+
") RETURNING id, created_ts, updated_ts, row_status"
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
args
...
)
.
Scan
(
...
...
@@ -34,8 +34,8 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
if
v
:=
find
.
ID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"memo.id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
if
v
:=
find
.
ResourceName
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"memo.
resource_name
= "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
if
v
:=
find
.
UID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"memo.
uid
= "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"memo.creator_id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
...
...
@@ -85,7 +85,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
fields
:=
[]
string
{
`memo.id AS id`
,
`memo.
resource_name AS resource_name
`
,
`memo.
uid AS uid
`
,
`memo.creator_id AS creator_id`
,
`memo.created_ts AS created_ts`
,
`memo.updated_ts AS updated_ts`
,
...
...
@@ -122,7 +122,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
var
memo
store
.
Memo
dests
:=
[]
any
{
&
memo
.
ID
,
&
memo
.
ResourceName
,
&
memo
.
UID
,
&
memo
.
CreatorID
,
&
memo
.
CreatedTs
,
&
memo
.
UpdatedTs
,
...
...
@@ -162,8 +162,8 @@ func (d *DB) GetMemo(ctx context.Context, find *store.FindMemo) (*store.Memo, er
func
(
d
*
DB
)
UpdateMemo
(
ctx
context
.
Context
,
update
*
store
.
UpdateMemo
)
error
{
set
,
args
:=
[]
string
{},
[]
any
{}
if
v
:=
update
.
ResourceName
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"
resource_name
= "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
if
v
:=
update
.
UID
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"
uid
= "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
if
v
:=
update
.
CreatedTs
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"created_ts = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
...
...
store/db/postgres/migration/dev/LATEST__SCHEMA.sql
View file @
7cc8b951
...
...
@@ -37,7 +37,7 @@ CREATE TABLE user_setting (
-- memo
CREATE
TABLE
memo
(
id
SERIAL
PRIMARY
KEY
,
resource_name
TEXT
NOT
NULL
UNIQUE
,
uid
TEXT
NOT
NULL
UNIQUE
,
creator_id
INTEGER
NOT
NULL
,
created_ts
BIGINT
NOT
NULL
DEFAULT
EXTRACT
(
EPOCH
FROM
NOW
()),
updated_ts
BIGINT
NOT
NULL
DEFAULT
EXTRACT
(
EPOCH
FROM
NOW
()),
...
...
@@ -65,7 +65,7 @@ CREATE TABLE memo_relation (
-- resource
CREATE
TABLE
resource
(
id
SERIAL
PRIMARY
KEY
,
resource_name
TEXT
NOT
NULL
UNIQUE
,
uid
TEXT
NOT
NULL
UNIQUE
,
creator_id
INTEGER
NOT
NULL
,
created_ts
BIGINT
NOT
NULL
DEFAULT
EXTRACT
(
EPOCH
FROM
NOW
()),
updated_ts
BIGINT
NOT
NULL
DEFAULT
EXTRACT
(
EPOCH
FROM
NOW
()),
...
...
store/db/postgres/resource.go
View file @
7cc8b951
...
...
@@ -10,8 +10,8 @@ import (
)
func
(
d
*
DB
)
CreateResource
(
ctx
context
.
Context
,
create
*
store
.
Resource
)
(
*
store
.
Resource
,
error
)
{
fields
:=
[]
string
{
"
resource_name
"
,
"filename"
,
"blob"
,
"external_link"
,
"type"
,
"size"
,
"creator_id"
,
"internal_path"
,
"memo_id"
}
args
:=
[]
any
{
create
.
ResourceName
,
create
.
Filename
,
create
.
Blob
,
create
.
ExternalLink
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
InternalPath
,
create
.
MemoID
}
fields
:=
[]
string
{
"
uid
"
,
"filename"
,
"blob"
,
"external_link"
,
"type"
,
"size"
,
"creator_id"
,
"internal_path"
,
"memo_id"
}
args
:=
[]
any
{
create
.
UID
,
create
.
Filename
,
create
.
Blob
,
create
.
ExternalLink
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
InternalPath
,
create
.
MemoID
}
stmt
:=
"INSERT INTO resource ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
placeholders
(
len
(
args
))
+
") RETURNING id, created_ts, updated_ts"
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
args
...
)
.
Scan
(
&
create
.
ID
,
&
create
.
CreatedTs
,
&
create
.
UpdatedTs
);
err
!=
nil
{
...
...
@@ -26,8 +26,8 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
if
v
:=
find
.
ID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
if
v
:=
find
.
ResourceName
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"
resource_name
= "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
if
v
:=
find
.
UID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"
uid
= "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"creator_id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
...
...
@@ -42,7 +42,7 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
where
=
append
(
where
,
"memo_id IS NOT NULL"
)
}
fields
:=
[]
string
{
"id"
,
"
resource_name
"
,
"filename"
,
"external_link"
,
"type"
,
"size"
,
"creator_id"
,
"created_ts"
,
"updated_ts"
,
"internal_path"
,
"memo_id"
}
fields
:=
[]
string
{
"id"
,
"
uid
"
,
"filename"
,
"external_link"
,
"type"
,
"size"
,
"creator_id"
,
"created_ts"
,
"updated_ts"
,
"internal_path"
,
"memo_id"
}
if
find
.
GetBlob
{
fields
=
append
(
fields
,
"blob"
)
}
...
...
@@ -73,7 +73,7 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
var
memoID
sql
.
NullInt32
dests
:=
[]
any
{
&
resource
.
ID
,
&
resource
.
ResourceName
,
&
resource
.
UID
,
&
resource
.
Filename
,
&
resource
.
ExternalLink
,
&
resource
.
Type
,
...
...
@@ -106,8 +106,8 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
func
(
d
*
DB
)
UpdateResource
(
ctx
context
.
Context
,
update
*
store
.
UpdateResource
)
(
*
store
.
Resource
,
error
)
{
set
,
args
:=
[]
string
{},
[]
any
{}
if
v
:=
update
.
ResourceName
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"
resource_name
= "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
if
v
:=
update
.
UID
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"
uid
= "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
if
v
:=
update
.
UpdatedTs
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"updated_ts = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
...
...
@@ -128,13 +128,13 @@ func (d *DB) UpdateResource(ctx context.Context, update *store.UpdateResource) (
set
,
args
=
append
(
set
,
"blob = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
v
)
}
fields
:=
[]
string
{
"id"
,
"
resource_name
"
,
"filename"
,
"external_link"
,
"type"
,
"size"
,
"creator_id"
,
"created_ts"
,
"updated_ts"
,
"internal_path"
}
fields
:=
[]
string
{
"id"
,
"
uid
"
,
"filename"
,
"external_link"
,
"type"
,
"size"
,
"creator_id"
,
"created_ts"
,
"updated_ts"
,
"internal_path"
}
stmt
:=
`UPDATE resource SET `
+
strings
.
Join
(
set
,
", "
)
+
` WHERE id = `
+
placeholder
(
len
(
args
)
+
1
)
+
` RETURNING `
+
strings
.
Join
(
fields
,
", "
)
args
=
append
(
args
,
update
.
ID
)
resource
:=
store
.
Resource
{}
dests
:=
[]
any
{
&
resource
.
ID
,
&
resource
.
ResourceName
,
&
resource
.
UID
,
&
resource
.
Filename
,
&
resource
.
ExternalLink
,
&
resource
.
Type
,
...
...
store/db/sqlite/memo.go
View file @
7cc8b951
...
...
@@ -10,9 +10,9 @@ import (
)
func
(
d
*
DB
)
CreateMemo
(
ctx
context
.
Context
,
create
*
store
.
Memo
)
(
*
store
.
Memo
,
error
)
{
fields
:=
[]
string
{
"`
resource_name
`"
,
"`creator_id`"
,
"`content`"
,
"`visibility`"
}
fields
:=
[]
string
{
"`
uid
`"
,
"`creator_id`"
,
"`content`"
,
"`visibility`"
}
placeholder
:=
[]
string
{
"?"
,
"?"
,
"?"
,
"?"
}
args
:=
[]
any
{
create
.
ResourceName
,
create
.
CreatorID
,
create
.
Content
,
create
.
Visibility
}
args
:=
[]
any
{
create
.
UID
,
create
.
CreatorID
,
create
.
Content
,
create
.
Visibility
}
stmt
:=
"INSERT INTO `memo` ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
") RETURNING `id`, `created_ts`, `updated_ts`, `row_status`"
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
args
...
)
.
Scan
(
...
...
@@ -33,8 +33,8 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
if
v
:=
find
.
ID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`memo`.`id` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
ResourceName
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`memo`.`
resource_name
` = ?"
),
append
(
args
,
*
v
)
if
v
:=
find
.
UID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`memo`.`
uid
` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`memo`.`creator_id` = ?"
),
append
(
args
,
*
v
)
...
...
@@ -84,7 +84,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
fields
:=
[]
string
{
"`memo`.`id` AS `id`"
,
"`memo`.`
resource_name` AS `resource_name
`"
,
"`memo`.`
uid` AS `uid
`"
,
"`memo`.`creator_id` AS `creator_id`"
,
"`memo`.`created_ts` AS `created_ts`"
,
"`memo`.`updated_ts` AS `updated_ts`"
,
...
...
@@ -120,7 +120,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
var
memo
store
.
Memo
dests
:=
[]
any
{
&
memo
.
ID
,
&
memo
.
ResourceName
,
&
memo
.
UID
,
&
memo
.
CreatorID
,
&
memo
.
CreatedTs
,
&
memo
.
UpdatedTs
,
...
...
@@ -147,8 +147,8 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
func
(
d
*
DB
)
UpdateMemo
(
ctx
context
.
Context
,
update
*
store
.
UpdateMemo
)
error
{
set
,
args
:=
[]
string
{},
[]
any
{}
if
v
:=
update
.
ResourceName
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`
resource_name
` = ?"
),
append
(
args
,
*
v
)
if
v
:=
update
.
UID
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`
uid
` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
update
.
CreatedTs
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`created_ts` = ?"
),
append
(
args
,
*
v
)
...
...
store/db/sqlite/migration/dev/LATEST__SCHEMA.sql
View file @
7cc8b951
...
...
@@ -40,7 +40,7 @@ CREATE TABLE user_setting (
-- memo
CREATE
TABLE
memo
(
id
INTEGER
PRIMARY
KEY
AUTOINCREMENT
,
resource_name
TEXT
NOT
NULL
UNIQUE
,
uid
TEXT
NOT
NULL
UNIQUE
,
creator_id
INTEGER
NOT
NULL
,
created_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
updated_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
...
...
@@ -72,7 +72,7 @@ CREATE TABLE memo_relation (
-- resource
CREATE
TABLE
resource
(
id
INTEGER
PRIMARY
KEY
AUTOINCREMENT
,
resource_name
TEXT
NOT
NULL
UNIQUE
,
uid
TEXT
NOT
NULL
UNIQUE
,
creator_id
INTEGER
NOT
NULL
,
created_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
updated_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
...
...
store/db/sqlite/resource.go
View file @
7cc8b951
...
...
@@ -10,9 +10,9 @@ import (
)
func
(
d
*
DB
)
CreateResource
(
ctx
context
.
Context
,
create
*
store
.
Resource
)
(
*
store
.
Resource
,
error
)
{
fields
:=
[]
string
{
"`
resource_name
`"
,
"`filename`"
,
"`blob`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"`internal_path`"
,
"`memo_id`"
}
fields
:=
[]
string
{
"`
uid
`"
,
"`filename`"
,
"`blob`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"`internal_path`"
,
"`memo_id`"
}
placeholder
:=
[]
string
{
"?"
,
"?"
,
"?"
,
"?"
,
"?"
,
"?"
,
"?"
,
"?"
,
"?"
}
args
:=
[]
any
{
create
.
ResourceName
,
create
.
Filename
,
create
.
Blob
,
create
.
ExternalLink
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
InternalPath
,
create
.
MemoID
}
args
:=
[]
any
{
create
.
UID
,
create
.
Filename
,
create
.
Blob
,
create
.
ExternalLink
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
InternalPath
,
create
.
MemoID
}
stmt
:=
"INSERT INTO `resource` ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
") RETURNING `id`, `created_ts`, `updated_ts`"
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
args
...
)
.
Scan
(
&
create
.
ID
,
&
create
.
CreatedTs
,
&
create
.
UpdatedTs
);
err
!=
nil
{
...
...
@@ -28,8 +28,8 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
if
v
:=
find
.
ID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`id` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
ResourceName
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource_name
` = ?"
),
append
(
args
,
*
v
)
if
v
:=
find
.
UID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
uid
` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`creator_id` = ?"
),
append
(
args
,
*
v
)
...
...
@@ -44,7 +44,7 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
where
=
append
(
where
,
"`memo_id` IS NOT NULL"
)
}
fields
:=
[]
string
{
"`id`"
,
"`
resource_name
`"
,
"`filename`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"`created_ts`"
,
"`updated_ts`"
,
"`internal_path`"
,
"`memo_id`"
}
fields
:=
[]
string
{
"`id`"
,
"`
uid
`"
,
"`filename`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"`created_ts`"
,
"`updated_ts`"
,
"`internal_path`"
,
"`memo_id`"
}
if
find
.
GetBlob
{
fields
=
append
(
fields
,
"`blob`"
)
}
...
...
@@ -69,7 +69,7 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
var
memoID
sql
.
NullInt32
dests
:=
[]
any
{
&
resource
.
ID
,
&
resource
.
ResourceName
,
&
resource
.
UID
,
&
resource
.
Filename
,
&
resource
.
ExternalLink
,
&
resource
.
Type
,
...
...
@@ -102,8 +102,8 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
func
(
d
*
DB
)
UpdateResource
(
ctx
context
.
Context
,
update
*
store
.
UpdateResource
)
(
*
store
.
Resource
,
error
)
{
set
,
args
:=
[]
string
{},
[]
any
{}
if
v
:=
update
.
ResourceName
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`
resource_name
` = ?"
),
append
(
args
,
*
v
)
if
v
:=
update
.
UID
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`
uid
` = ?"
),
append
(
args
,
*
v
)
}
if
v
:=
update
.
UpdatedTs
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"`updated_ts` = ?"
),
append
(
args
,
*
v
)
...
...
@@ -125,12 +125,12 @@ func (d *DB) UpdateResource(ctx context.Context, update *store.UpdateResource) (
}
args
=
append
(
args
,
update
.
ID
)
fields
:=
[]
string
{
"`id`"
,
"`
resource_name
`"
,
"`filename`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"`created_ts`"
,
"`updated_ts`"
,
"`internal_path`"
}
fields
:=
[]
string
{
"`id`"
,
"`
uid
`"
,
"`filename`"
,
"`external_link`"
,
"`type`"
,
"`size`"
,
"`creator_id`"
,
"`created_ts`"
,
"`updated_ts`"
,
"`internal_path`"
}
stmt
:=
"UPDATE `resource` SET "
+
strings
.
Join
(
set
,
", "
)
+
" WHERE `id` = ? RETURNING "
+
strings
.
Join
(
fields
,
", "
)
resource
:=
store
.
Resource
{}
dests
:=
[]
any
{
&
resource
.
ID
,
&
resource
.
ResourceName
,
&
resource
.
UID
,
&
resource
.
Filename
,
&
resource
.
ExternalLink
,
&
resource
.
Type
,
...
...
store/db/sqlite/seed/10002__memo.sql
View file @
7cc8b951
INSERT
INTO
memo
(
`id`
,
`
resource_name
`
,
`
uid
`
,
`content`
,
`creator_id`
)
...
...
@@ -16,7 +16,7 @@ VALUES
INSERT
INTO
memo
(
`id`
,
`
resource_name
`
,
`
uid
`
,
`content`
,
`creator_id`
,
`visibility`
...
...
@@ -36,7 +36,7 @@ VALUES
INSERT
INTO
memo
(
`id`
,
`
resource_name
`
,
`
uid
`
,
`content`
,
`creator_id`
,
`visibility`
...
...
@@ -54,7 +54,7 @@ VALUES
INSERT
INTO
memo
(
`id`
,
`
resource_name
`
,
`
uid
`
,
`content`
,
`creator_id`
,
`visibility`
...
...
@@ -74,7 +74,7 @@ VALUES
INSERT
INTO
memo
(
`id`
,
`
resource_name
`
,
`
uid
`
,
`content`
,
`creator_id`
,
`visibility`
...
...
store/db/sqlite/seed/10006__resource.sql
View file @
7cc8b951
INSERT
INTO
resource
(
`
resource_name
`
,
`creator_id`
,
`filename`
,
`external_link`
,
`type`
,
`memo_id`
)
resource
(
`
uid
`
,
`creator_id`
,
`filename`
,
`external_link`
,
`type`
,
`memo_id`
)
VALUES
(
"Pw2awZvxxLK4sPRtHmYuS7"
,
101
,
'slash-demo.png'
,
'https://github.com/yourselfhosted/slash/blob/main/docs/assets/demo.png?raw=true'
,
'image/png'
,
3
);
store/memo.go
View file @
7cc8b951
...
...
@@ -32,8 +32,10 @@ func (v Visibility) String() string {
}
type
Memo
struct
{
ID
int32
ResourceName
string
// ID is the system generated unique identifier for the memo.
ID
int32
// UID is the user defined unique identifier for the memo.
UID
string
// Standard fields
RowStatus
RowStatus
...
...
@@ -51,8 +53,8 @@ type Memo struct {
}
type
FindMemo
struct
{
ID
*
int32
ResourceName
*
string
ID
*
int32
UID
*
string
// Standard fields
RowStatus
*
RowStatus
...
...
@@ -76,13 +78,13 @@ type FindMemo struct {
}
type
UpdateMemo
struct
{
ID
int32
ResourceName
*
string
CreatedTs
*
int64
UpdatedTs
*
int64
RowStatus
*
RowStatus
Content
*
string
Visibility
*
Visibility
ID
int32
UID
*
string
CreatedTs
*
int64
UpdatedTs
*
int64
RowStatus
*
RowStatus
Content
*
string
Visibility
*
Visibility
}
type
DeleteMemo
struct
{
...
...
@@ -90,8 +92,8 @@ type DeleteMemo struct {
}
func
(
s
*
Store
)
CreateMemo
(
ctx
context
.
Context
,
create
*
Memo
)
(
*
Memo
,
error
)
{
if
!
util
.
ResourceNameMatcher
.
MatchString
(
create
.
ResourceName
)
{
return
nil
,
errors
.
New
(
"
resource name is inval
id"
)
if
!
util
.
UIDMatcher
.
MatchString
(
create
.
UID
)
{
return
nil
,
errors
.
New
(
"
invalid u
id"
)
}
return
s
.
driver
.
CreateMemo
(
ctx
,
create
)
}
...
...
@@ -114,8 +116,8 @@ func (s *Store) GetMemo(ctx context.Context, find *FindMemo) (*Memo, error) {
}
func
(
s
*
Store
)
UpdateMemo
(
ctx
context
.
Context
,
update
*
UpdateMemo
)
error
{
if
update
.
ResourceName
!=
nil
&&
!
util
.
ResourceNameMatcher
.
MatchString
(
*
update
.
ResourceName
)
{
return
errors
.
New
(
"
resource name is inval
id"
)
if
update
.
UID
!=
nil
&&
!
util
.
UIDMatcher
.
MatchString
(
*
update
.
UID
)
{
return
errors
.
New
(
"
invalid u
id"
)
}
return
s
.
driver
.
UpdateMemo
(
ctx
,
update
)
}
...
...
store/resource.go
View file @
7cc8b951
...
...
@@ -17,8 +17,10 @@ const (
)
type
Resource
struct
{
ID
int32
ResourceName
string
// ID is the system generated unique identifier for the resource.
ID
int32
// UID is the user defined unique identifier for the resource.
UID
string
// Standard fields
CreatorID
int32
...
...
@@ -38,7 +40,7 @@ type Resource struct {
type
FindResource
struct
{
GetBlob
bool
ID
*
int32
ResourceName
*
string
UID
*
string
CreatorID
*
int32
Filename
*
string
MemoID
*
int32
...
...
@@ -49,7 +51,7 @@ type FindResource struct {
type
UpdateResource
struct
{
ID
int32
ResourceName
*
string
UID
*
string
UpdatedTs
*
int64
Filename
*
string
InternalPath
*
string
...
...
@@ -64,8 +66,8 @@ type DeleteResource struct {
}
func
(
s
*
Store
)
CreateResource
(
ctx
context
.
Context
,
create
*
Resource
)
(
*
Resource
,
error
)
{
if
!
util
.
ResourceNameMatcher
.
MatchString
(
create
.
ResourceName
)
{
return
nil
,
errors
.
New
(
"invalid
resource name
"
)
if
!
util
.
UIDMatcher
.
MatchString
(
create
.
UID
)
{
return
nil
,
errors
.
New
(
"invalid
uid
"
)
}
return
s
.
driver
.
CreateResource
(
ctx
,
create
)
}
...
...
@@ -88,8 +90,8 @@ func (s *Store) GetResource(ctx context.Context, find *FindResource) (*Resource,
}
func
(
s
*
Store
)
UpdateResource
(
ctx
context
.
Context
,
update
*
UpdateResource
)
(
*
Resource
,
error
)
{
if
update
.
ResourceName
!=
nil
&&
!
util
.
ResourceNameMatcher
.
MatchString
(
*
update
.
ResourceName
)
{
return
nil
,
errors
.
New
(
"invalid
resource name
"
)
if
update
.
UID
!=
nil
&&
!
util
.
UIDMatcher
.
MatchString
(
*
update
.
UID
)
{
return
nil
,
errors
.
New
(
"invalid
uid
"
)
}
return
s
.
driver
.
UpdateResource
(
ctx
,
update
)
}
...
...
test/store/memo_organizer_test.go
View file @
7cc8b951
...
...
@@ -15,10 +15,10 @@ func TestMemoOrganizerStore(t *testing.T) {
user
,
err
:=
createTestingHostUser
(
ctx
,
ts
)
require
.
NoError
(
t
,
err
)
memoCreate
:=
&
store
.
Memo
{
ResourceName
:
"main-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"main memo content"
,
Visibility
:
store
.
Public
,
UID
:
"main-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"main memo content"
,
Visibility
:
store
.
Public
,
}
memo
,
err
:=
ts
.
CreateMemo
(
ctx
,
memoCreate
)
require
.
NoError
(
t
,
err
)
...
...
test/store/memo_relation_test.go
View file @
7cc8b951
...
...
@@ -15,28 +15,28 @@ func TestMemoRelationStore(t *testing.T) {
user
,
err
:=
createTestingHostUser
(
ctx
,
ts
)
require
.
NoError
(
t
,
err
)
memoCreate
:=
&
store
.
Memo
{
ResourceName
:
"main-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"main memo content"
,
Visibility
:
store
.
Public
,
UID
:
"main-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"main memo content"
,
Visibility
:
store
.
Public
,
}
memo
,
err
:=
ts
.
CreateMemo
(
ctx
,
memoCreate
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
memoCreate
.
Content
,
memo
.
Content
)
relatedMemoCreate
:=
&
store
.
Memo
{
ResourceName
:
"related-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"related memo content"
,
Visibility
:
store
.
Public
,
UID
:
"related-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"related memo content"
,
Visibility
:
store
.
Public
,
}
relatedMemo
,
err
:=
ts
.
CreateMemo
(
ctx
,
relatedMemoCreate
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
relatedMemoCreate
.
Content
,
relatedMemo
.
Content
)
commentMemoCreate
:=
&
store
.
Memo
{
ResourceName
:
"comment-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"comment memo content"
,
Visibility
:
store
.
Public
,
UID
:
"comment-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"comment memo content"
,
Visibility
:
store
.
Public
,
}
commentMemo
,
err
:=
ts
.
CreateMemo
(
ctx
,
commentMemoCreate
)
require
.
NoError
(
t
,
err
)
...
...
test/store/memo_test.go
View file @
7cc8b951
...
...
@@ -15,10 +15,10 @@ func TestMemoStore(t *testing.T) {
user
,
err
:=
createTestingHostUser
(
ctx
,
ts
)
require
.
NoError
(
t
,
err
)
memoCreate
:=
&
store
.
Memo
{
ResourceName
:
"test-resource-name"
,
CreatorID
:
user
.
ID
,
Content
:
"test_content"
,
Visibility
:
store
.
Public
,
UID
:
"test-resource-name"
,
CreatorID
:
user
.
ID
,
Content
:
"test_content"
,
Visibility
:
store
.
Public
,
}
memo
,
err
:=
ts
.
CreateMemo
(
ctx
,
memoCreate
)
require
.
NoError
(
t
,
err
)
...
...
@@ -68,10 +68,10 @@ func TestDeleteMemoStore(t *testing.T) {
user
,
err
:=
createTestingHostUser
(
ctx
,
ts
)
require
.
NoError
(
t
,
err
)
memoCreate
:=
&
store
.
Memo
{
ResourceName
:
"test-resource-name"
,
CreatorID
:
user
.
ID
,
Content
:
"test_content"
,
Visibility
:
store
.
Public
,
UID
:
"test-resource-name"
,
CreatorID
:
user
.
ID
,
Content
:
"test_content"
,
Visibility
:
store
.
Public
,
}
memo
,
err
:=
ts
.
CreateMemo
(
ctx
,
memoCreate
)
require
.
NoError
(
t
,
err
)
...
...
test/store/resource_test.go
View file @
7cc8b951
...
...
@@ -14,7 +14,7 @@ func TestResourceStore(t *testing.T) {
ctx
:=
context
.
Background
()
ts
:=
NewTestingStore
(
ctx
,
t
)
_
,
err
:=
ts
.
CreateResource
(
ctx
,
&
store
.
Resource
{
ResourceName
:
shortuuid
.
New
(),
UID
:
shortuuid
.
New
(),
CreatorID
:
101
,
Filename
:
"test.epub"
,
Blob
:
[]
byte
(
"test"
),
...
...
web/src/components/MemoContent/EmbeddedContent/EmbeddedMemo.tsx
View file @
7cc8b951
...
...
@@ -17,11 +17,11 @@ const EmbeddedMemo = ({ resourceId, params: paramsStr }: Props) => {
const
context
=
useContext
(
RendererContext
);
const
loadingState
=
useLoading
();
const
memoStore
=
useMemoStore
();
const
memo
=
memoStore
.
getMemoBy
ResourceI
d
(
resourceId
);
const
memo
=
memoStore
.
getMemoBy
Ui
d
(
resourceId
);
const
resourceName
=
`memos/
${
resourceId
}
`
;
useEffect
(()
=>
{
memoStore
.
searchMemos
(
`
resource_name
== "
${
resourceId
}
"`
).
finally
(()
=>
loadingState
.
setFinish
());
memoStore
.
searchMemos
(
`
uid
== "
${
resourceId
}
"`
).
finally
(()
=>
loadingState
.
setFinish
());
},
[
resourceId
]);
if
(
loadingState
.
isLoading
)
{
...
...
web/src/components/MemoContent/ReferencedContent/ReferencedMemo.tsx
View file @
7cc8b951
...
...
@@ -13,11 +13,11 @@ const ReferencedMemo = ({ resourceId, params: paramsStr }: Props) => {
const
navigateTo
=
useNavigateTo
();
const
loadingState
=
useLoading
();
const
memoStore
=
useMemoStore
();
const
memo
=
memoStore
.
getMemoBy
ResourceI
d
(
resourceId
);
const
memo
=
memoStore
.
getMemoBy
Ui
d
(
resourceId
);
const
params
=
new
URLSearchParams
(
paramsStr
);
useEffect
(()
=>
{
memoStore
.
searchMemos
(
`
resource_name
== "
${
resourceId
}
"`
).
finally
(()
=>
loadingState
.
setFinish
());
memoStore
.
searchMemos
(
`
uid
== "
${
resourceId
}
"`
).
finally
(()
=>
loadingState
.
setFinish
());
},
[
resourceId
]);
if
(
loadingState
.
isLoading
)
{
...
...
web/src/components/MemoView.tsx
View file @
7cc8b951
...
...
@@ -58,7 +58,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
if
(
event
.
altKey
)
{
showChangeMemoCreatedTsDialog
(
extractMemoIdFromName
(
memo
.
name
));
}
else
{
navigateTo
(
`/m/
${
memo
.
resourceI
d
}
`
);
navigateTo
(
`/m/
${
memo
.
ui
d
}
`
);
}
};
...
...
@@ -119,7 +119,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
"flex flex-row justify-start items-center hover:opacity-70"
,
commentAmount
===
0
&&
"invisible group-hover:visible"
,
)
}
to=
{
`/m/${memo.
resourceI
d}#comments`
}
to=
{
`/m/${memo.
ui
d}#comments`
}
unstable_viewTransition
>
<
Icon
.
MessageCircleMore
className=
"w-4 h-4 mx-auto text-gray-500 dark:text-gray-400"
/>
...
...
web/src/pages/MemoDetail.tsx
View file @
7cc8b951
...
...
@@ -19,8 +19,8 @@ const MemoDetail = () => {
const
navigateTo
=
useNavigateTo
();
const
currentUser
=
useCurrentUser
();
const
memoStore
=
useMemoStore
();
const
resourceId
=
params
.
resourceI
d
;
const
memo
=
memoStore
.
getMemoBy
ResourceId
(
resourceI
d
||
""
);
const
uid
=
params
.
ui
d
;
const
memo
=
memoStore
.
getMemoBy
Uid
(
ui
d
||
""
);
const
[
parentMemo
,
setParentMemo
]
=
useState
<
Memo
|
undefined
>
(
undefined
);
const
commentRelations
=
memo
?.
relations
.
filter
((
relation
)
=>
relation
.
relatedMemo
===
memo
.
name
&&
relation
.
type
===
MemoRelation_Type
.
COMMENT
)
||
[];
...
...
@@ -28,15 +28,15 @@ const MemoDetail = () => {
// Prepare memo.
useEffect
(()
=>
{
if
(
resourceI
d
)
{
memoStore
.
searchMemos
(
`
resource_name == "
${
resourceI
d
}
"`
).
catch
((
error
:
ClientError
)
=>
{
if
(
ui
d
)
{
memoStore
.
searchMemos
(
`
uid == "
${
ui
d
}
"`
).
catch
((
error
:
ClientError
)
=>
{
toast
.
error
(
error
.
details
);
navigateTo
(
"/403"
);
});
}
else
{
navigateTo
(
"/404"
);
}
},
[
resourceI
d
]);
},
[
ui
d
]);
// Prepare memo comments.
useEffect
(()
=>
{
...
...
web/src/pages/Resources.tsx
View file @
7cc8b951
...
...
@@ -132,7 +132,7 @@ const Resources = () => {
{
relatedMemo
&&
(
<
Link
className=
"shrink-0 text-xs ml-1 text-gray-400 hover:underline hover:text-blue-600"
to=
{
`/m/${relatedMemo.
resourceI
d}`
}
to=
{
`/m/${relatedMemo.
ui
d}`
}
>
#
{
extractMemoIdFromName
(
relatedMemo
.
name
)
}
</
Link
>
...
...
web/src/router/index.tsx
View file @
7cc8b951
...
...
@@ -88,7 +88,7 @@ const router = createBrowserRouter([
element
:
<
Explore
/>,
},
{
path
:
"m/:
resourceI
d"
,
path
:
"m/:
ui
d"
,
element
:
<
MemoDetail
/>,
},
{
...
...
web/src/store/v1/memo.ts
View file @
7cc8b951
...
...
@@ -58,9 +58,9 @@ export const useMemoStore = create(
set
({
memoMapByName
:
memoMap
});
return
memos
;
},
getMemoBy
ResourceId
:
(
resourceI
d
:
string
)
=>
{
getMemoBy
Uid
:
(
ui
d
:
string
)
=>
{
const
memoMap
=
get
().
memoMapByName
;
return
Object
.
values
(
memoMap
).
find
((
memo
)
=>
memo
.
resourceId
===
resourceI
d
);
return
Object
.
values
(
memoMap
).
find
((
memo
)
=>
memo
.
uid
===
ui
d
);
},
createMemo
:
async
(
request
:
CreateMemoRequest
)
=>
{
const
{
memo
}
=
await
memoServiceClient
.
createMemo
(
request
);
...
...
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