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
4d48f508
Commit
4d48f508
authored
Jan 21, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: use resource name in frontend
parent
582cc660
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
168 additions
and
147 deletions
+168
-147
resource.go
api/resource/resource.go
+7
-11
resource.go
api/v1/resource.go
+3
-1
rss.go
api/v1/rss.go
+1
-1
resource_service.go
api/v2/resource_service.go
+1
-0
memo_service.proto
proto/api/v2/memo_service.proto
+2
-2
resource_service.proto
proto/api/v2/resource_service.proto
+16
-6
README.md
proto/gen/api/v2/README.md
+4
-3
memo_service.pb.go
proto/gen/api/v2/memo_service.pb.go
+2
-2
resource_service.pb.go
proto/gen/api/v2/resource_service.pb.go
+131
-120
resource.ts
web/src/utils/resource.ts
+1
-1
No files found.
api/resource/resource.go
View file @
4d48f508
...
@@ -43,26 +43,22 @@ func NewService(profile *profile.Profile, store *store.Store) *Service {
...
@@ -43,26 +43,22 @@ func NewService(profile *profile.Profile, store *store.Store) *Service {
}
}
func
(
s
*
Service
)
RegisterResourcePublicRoutes
(
g
*
echo
.
Group
)
{
func
(
s
*
Service
)
RegisterResourcePublicRoutes
(
g
*
echo
.
Group
)
{
g
.
GET
(
"/r/:resource
Id
"
,
s
.
streamResource
)
g
.
GET
(
"/r/:resource
Name
"
,
s
.
streamResource
)
g
.
GET
(
"/r/:resource
Id
/*"
,
s
.
streamResource
)
g
.
GET
(
"/r/:resource
Name
/*"
,
s
.
streamResource
)
}
}
func
(
s
*
Service
)
streamResource
(
c
echo
.
Context
)
error
{
func
(
s
*
Service
)
streamResource
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
resourceID
,
err
:=
util
.
ConvertStringToInt32
(
c
.
Param
(
"resourceId"
))
resourceName
:=
c
.
Param
(
"resourceName"
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"resourceId"
)))
.
SetInternal
(
err
)
}
resource
,
err
:=
s
.
Store
.
GetResource
(
ctx
,
&
store
.
FindResource
{
resource
,
err
:=
s
.
Store
.
GetResource
(
ctx
,
&
store
.
FindResource
{
ID
:
&
resourceID
,
ResourceName
:
&
resourceName
,
GetBlob
:
true
,
GetBlob
:
true
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find resource by
ID: %v"
,
resourceID
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find resource by
id: %s"
,
resourceName
))
.
SetInternal
(
err
)
}
}
if
resource
==
nil
{
if
resource
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Resource not found: %
d"
,
resourceID
))
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Resource not found: %
s"
,
resourceName
))
}
}
// Check the related memo visibility.
// Check the related memo visibility.
if
resource
.
MemoID
!=
nil
{
if
resource
.
MemoID
!=
nil
{
...
...
api/v1/resource.go
View file @
4d48f508
...
@@ -27,7 +27,8 @@ import (
...
@@ -27,7 +27,8 @@ import (
)
)
type
Resource
struct
{
type
Resource
struct
{
ID
int32
`json:"id"`
ID
int32
`json:"id"`
Name
string
`json:"name"`
// Standard fields
// Standard fields
CreatorID
int32
`json:"creatorId"`
CreatorID
int32
`json:"creatorId"`
...
@@ -368,6 +369,7 @@ func replacePathTemplate(path, filename string) string {
...
@@ -368,6 +369,7 @@ func replacePathTemplate(path, filename string) string {
func
convertResourceFromStore
(
resource
*
store
.
Resource
)
*
Resource
{
func
convertResourceFromStore
(
resource
*
store
.
Resource
)
*
Resource
{
return
&
Resource
{
return
&
Resource
{
ID
:
resource
.
ID
,
ID
:
resource
.
ID
,
Name
:
resource
.
ResourceName
,
CreatorID
:
resource
.
CreatorID
,
CreatorID
:
resource
.
CreatorID
,
CreatedTs
:
resource
.
CreatedTs
,
CreatedTs
:
resource
.
CreatedTs
,
UpdatedTs
:
resource
.
UpdatedTs
,
UpdatedTs
:
resource
.
UpdatedTs
,
...
...
api/v1/rss.go
View file @
4d48f508
...
@@ -138,7 +138,7 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
...
@@ -138,7 +138,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/"
+
fmt
.
Sprintf
(
"%d"
,
resource
.
ID
)
enclosure
.
Url
=
baseURL
+
"/o/r/"
+
resource
.
Name
}
}
enclosure
.
Length
=
strconv
.
Itoa
(
int
(
resource
.
Size
))
enclosure
.
Length
=
strconv
.
Itoa
(
int
(
resource
.
Size
))
enclosure
.
Type
=
resource
.
Type
enclosure
.
Type
=
resource
.
Type
...
...
api/v2/resource_service.go
View file @
4d48f508
...
@@ -148,6 +148,7 @@ func (s *APIV2Service) convertResourceFromStore(ctx context.Context, resource *s
...
@@ -148,6 +148,7 @@ func (s *APIV2Service) convertResourceFromStore(ctx context.Context, resource *s
return
&
apiv2pb
.
Resource
{
return
&
apiv2pb
.
Resource
{
Id
:
resource
.
ID
,
Id
:
resource
.
ID
,
Name
:
resource
.
ResourceName
,
CreateTime
:
timestamppb
.
New
(
time
.
Unix
(
resource
.
CreatedTs
,
0
)),
CreateTime
:
timestamppb
.
New
(
time
.
Unix
(
resource
.
CreatedTs
,
0
)),
Filename
:
resource
.
Filename
,
Filename
:
resource
.
Filename
,
ExternalLink
:
resource
.
ExternalLink
,
ExternalLink
:
resource
.
ExternalLink
,
...
...
proto/api/v2/memo_service.proto
View file @
4d48f508
...
@@ -103,10 +103,10 @@ enum Visibility {
...
@@ -103,10 +103,10 @@ enum Visibility {
}
}
message
Memo
{
message
Memo
{
// id is the
unique auto-incremented id
.
// id is the
system generated unique identifier
.
int32
id
=
1
;
int32
id
=
1
;
// name is the user
-defin
ed name.
// name is the user
provid
ed name.
string
name
=
2
;
string
name
=
2
;
RowStatus
row_status
=
3
;
RowStatus
row_status
=
3
;
...
...
proto/api/v2/resource_service.proto
View file @
4d48f508
...
@@ -34,13 +34,23 @@ service ResourceService {
...
@@ -34,13 +34,23 @@ service ResourceService {
}
}
message
Resource
{
message
Resource
{
// id is the system generated unique identifier.
int32
id
=
1
;
int32
id
=
1
;
google.protobuf.Timestamp
create_time
=
2
;
string
filename
=
3
;
// name is the user provided name.
string
external_link
=
4
;
string
name
=
2
;
string
type
=
5
;
int64
size
=
6
;
google.protobuf.Timestamp
create_time
=
3
;
optional
int32
memo_id
=
7
;
string
filename
=
4
;
string
external_link
=
5
;
string
type
=
6
;
int64
size
=
7
;
optional
int32
memo_id
=
8
;
}
}
message
CreateResourceRequest
{
message
CreateResourceRequest
{
...
...
proto/gen/api/v2/README.md
View file @
4d48f508
...
@@ -1705,7 +1705,8 @@
...
@@ -1705,7 +1705,8 @@
| Field | Type | Label | Description |
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| ----- | ---- | ----- | ----------- |
| id |
[
int32
](
#int32
)
| | |
| id |
[
int32
](
#int32
)
| | id is the system generated unique identifier. |
| name |
[
string
](
#string
)
| | name is the user provided name. |
| create_time |
[
google.protobuf.Timestamp
](
#google-protobuf-Timestamp
)
| | |
| create_time |
[
google.protobuf.Timestamp
](
#google-protobuf-Timestamp
)
| | |
| filename |
[
string
](
#string
)
| | |
| filename |
[
string
](
#string
)
| | |
| external_link |
[
string
](
#string
)
| | |
| external_link |
[
string
](
#string
)
| | |
...
@@ -2104,8 +2105,8 @@
...
@@ -2104,8 +2105,8 @@
| Field | Type | Label | Description |
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| ----- | ---- | ----- | ----------- |
| id |
[
int32
](
#int32
)
| | id is the
unique auto-incremented id
. |
| id |
[
int32
](
#int32
)
| | id is the
system generated unique identifier
. |
| name |
[
string
](
#string
)
| | name is the user
-defin
ed name. |
| name |
[
string
](
#string
)
| | name is the user
provid
ed name. |
| row_status |
[
RowStatus
](
#memos-api-v2-RowStatus
)
| | |
| row_status |
[
RowStatus
](
#memos-api-v2-RowStatus
)
| | |
| creator |
[
string
](
#string
)
| | The name of the creator. Format: users/{username} |
| creator |
[
string
](
#string
)
| | The name of the creator. Format: users/{username} |
| creator_id |
[
int32
](
#int32
)
| | |
| creator_id |
[
int32
](
#int32
)
| | |
...
...
proto/gen/api/v2/memo_service.pb.go
View file @
4d48f508
...
@@ -80,9 +80,9 @@ type Memo struct {
...
@@ -80,9 +80,9 @@ type Memo struct {
sizeCache
protoimpl
.
SizeCache
sizeCache
protoimpl
.
SizeCache
unknownFields
protoimpl
.
UnknownFields
unknownFields
protoimpl
.
UnknownFields
// id is the
unique auto-incremented id
.
// id is the
system generated unique identifier
.
Id
int32
`protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Id
int32
`protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
// name is the user
-defin
ed name.
// name is the user
provid
ed name.
Name
string
`protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Name
string
`protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
RowStatus
RowStatus
`protobuf:"varint,3,opt,name=row_status,json=rowStatus,proto3,enum=memos.api.v2.RowStatus" json:"row_status,omitempty"`
RowStatus
RowStatus
`protobuf:"varint,3,opt,name=row_status,json=rowStatus,proto3,enum=memos.api.v2.RowStatus" json:"row_status,omitempty"`
// The name of the creator.
// The name of the creator.
...
...
proto/gen/api/v2/resource_service.pb.go
View file @
4d48f508
This diff is collapsed.
Click to expand it.
web/src/utils/resource.ts
View file @
4d48f508
...
@@ -5,7 +5,7 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => {
...
@@ -5,7 +5,7 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => {
return
resource
.
externalLink
;
return
resource
.
externalLink
;
}
}
return
`
${
withOrigin
?
window
.
location
.
origin
:
""
}
/o/r/
${
resource
.
id
}
`
;
return
`
${
withOrigin
?
window
.
location
.
origin
:
""
}
/o/r/
${
resource
.
name
}
`
;
};
};
export
const
getResourceType
=
(
resource
:
Resource
)
=>
{
export
const
getResourceType
=
(
resource
:
Resource
)
=>
{
...
...
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