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
16d3de63
Commit
16d3de63
authored
May 21, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update resource binary endpoint
parent
2c50d346
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
152 additions
and
112 deletions
+152
-112
apidocs.swagger.yaml
docs/apidocs.swagger.yaml
+30
-25
resource_service.proto
proto/api/v1/resource_service.proto
+5
-2
resource_service.pb.go
proto/gen/api/v1/resource_service.pb.go
+92
-80
resource_service.pb.gw.go
proto/gen/api/v1/resource_service.pb.gw.go
+23
-3
rss.go
server/router/rss/rss.go
+1
-1
resource.ts
web/src/utils/resource.ts
+1
-1
No files found.
docs/apidocs.swagger.yaml
View file @
16d3de63
...
...
@@ -1736,31 +1736,6 @@ paths:
format
:
date-time
tags
:
-
UserService
/file/{name}
:
get
:
summary
:
GetResourceBinary returns a resource binary by name.
operationId
:
ResourceService_GetResourceBinary
responses
:
"
200"
:
description
:
A successful response.
schema
:
$ref
:
'
#/definitions/apiHttpBody'
default
:
description
:
An unexpected error response.
schema
:
$ref
:
'
#/definitions/googlerpcStatus'
parameters
:
-
name
:
name
description
:
|-
The name of the resource.
Format: resources/{id}
id is the system generated unique identifier.
in: path
required: true
type: string
pattern: resources/[^/]+
tags
:
-
ResourceService
/file/{name}/avatar
:
get
:
summary
:
GetUserAvatarBinary gets the avatar of a user.
...
...
@@ -1796,6 +1771,36 @@ paths:
format
:
byte
tags
:
-
UserService
/file/{name}/{filename}
:
get
:
summary
:
GetResourceBinary returns a resource binary by name.
operationId
:
ResourceService_GetResourceBinary
responses
:
"
200"
:
description
:
A successful response.
schema
:
$ref
:
'
#/definitions/apiHttpBody'
default
:
description
:
An unexpected error response.
schema
:
$ref
:
'
#/definitions/googlerpcStatus'
parameters
:
-
name
:
name
description
:
|-
The name of the resource.
Format: resources/{id}
id is the system generated unique identifier.
in: path
required: true
type: string
pattern: resources/[^/]+
-
name
:
filename
description
:
The filename of the resource. Mainly used for downloading.
in
:
path
required
:
true
type
:
string
tags
:
-
ResourceService
definitions
:
MemoServiceRebuildMemoPropertyBody
:
type
:
object
...
...
proto/api/v1/resource_service.proto
View file @
16d3de63
...
...
@@ -35,8 +35,8 @@ service ResourceService {
}
// GetResourceBinary returns a resource binary by name.
rpc
GetResourceBinary
(
GetResourceBinaryRequest
)
returns
(
google.api.HttpBody
)
{
option
(
google.api.http
)
=
{
get
:
"/file/{name=resources/*}"
};
option
(
google.api.method_signature
)
=
"name"
;
option
(
google.api.http
)
=
{
get
:
"/file/{name=resources/*}
/{filename}
"
};
option
(
google.api.method_signature
)
=
"name
,filename
"
;
}
// UpdateResource updates a resource.
rpc
UpdateResource
(
UpdateResourceRequest
)
returns
(
Resource
)
{
...
...
@@ -109,6 +109,9 @@ message GetResourceBinaryRequest {
// Format: resources/{id}
// id is the system generated unique identifier.
string
name
=
1
;
// The filename of the resource. Mainly used for downloading.
string
filename
=
2
;
}
message
UpdateResourceRequest
{
...
...
proto/gen/api/v1/resource_service.pb.go
View file @
16d3de63
This diff is collapsed.
Click to expand it.
proto/gen/api/v1/resource_service.pb.gw.go
View file @
16d3de63
...
...
@@ -184,6 +184,16 @@ func request_ResourceService_GetResourceBinary_0(ctx context.Context, marshaler
return
nil
,
metadata
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"type mismatch, parameter: %s, error: %v"
,
"name"
,
err
)
}
val
,
ok
=
pathParams
[
"filename"
]
if
!
ok
{
return
nil
,
metadata
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"missing parameter %s"
,
"filename"
)
}
protoReq
.
Filename
,
err
=
runtime
.
String
(
val
)
if
err
!=
nil
{
return
nil
,
metadata
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"type mismatch, parameter: %s, error: %v"
,
"filename"
,
err
)
}
msg
,
err
:=
client
.
GetResourceBinary
(
ctx
,
&
protoReq
,
grpc
.
Header
(
&
metadata
.
HeaderMD
),
grpc
.
Trailer
(
&
metadata
.
TrailerMD
))
return
msg
,
metadata
,
err
...
...
@@ -210,6 +220,16 @@ func local_request_ResourceService_GetResourceBinary_0(ctx context.Context, mars
return
nil
,
metadata
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"type mismatch, parameter: %s, error: %v"
,
"name"
,
err
)
}
val
,
ok
=
pathParams
[
"filename"
]
if
!
ok
{
return
nil
,
metadata
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"missing parameter %s"
,
"filename"
)
}
protoReq
.
Filename
,
err
=
runtime
.
String
(
val
)
if
err
!=
nil
{
return
nil
,
metadata
,
status
.
Errorf
(
codes
.
InvalidArgument
,
"type mismatch, parameter: %s, error: %v"
,
"filename"
,
err
)
}
msg
,
err
:=
server
.
GetResourceBinary
(
ctx
,
&
protoReq
)
return
msg
,
metadata
,
err
...
...
@@ -481,7 +501,7 @@ func RegisterResourceServiceHandlerServer(ctx context.Context, mux *runtime.Serv
inboundMarshaler
,
outboundMarshaler
:=
runtime
.
MarshalerForRequest
(
mux
,
req
)
var
err
error
var
annotatedContext
context
.
Context
annotatedContext
,
err
=
runtime
.
AnnotateIncomingContext
(
ctx
,
mux
,
req
,
"/memos.api.v1.ResourceService/GetResourceBinary"
,
runtime
.
WithHTTPPathPattern
(
"/file/{name=resources/*}"
))
annotatedContext
,
err
=
runtime
.
AnnotateIncomingContext
(
ctx
,
mux
,
req
,
"/memos.api.v1.ResourceService/GetResourceBinary"
,
runtime
.
WithHTTPPathPattern
(
"/file/{name=resources/*}
/{filename}
"
))
if
err
!=
nil
{
runtime
.
HTTPError
(
ctx
,
mux
,
outboundMarshaler
,
w
,
req
,
err
)
return
...
...
@@ -683,7 +703,7 @@ func RegisterResourceServiceHandlerClient(ctx context.Context, mux *runtime.Serv
inboundMarshaler
,
outboundMarshaler
:=
runtime
.
MarshalerForRequest
(
mux
,
req
)
var
err
error
var
annotatedContext
context
.
Context
annotatedContext
,
err
=
runtime
.
AnnotateContext
(
ctx
,
mux
,
req
,
"/memos.api.v1.ResourceService/GetResourceBinary"
,
runtime
.
WithHTTPPathPattern
(
"/file/{name=resources/*}"
))
annotatedContext
,
err
=
runtime
.
AnnotateContext
(
ctx
,
mux
,
req
,
"/memos.api.v1.ResourceService/GetResourceBinary"
,
runtime
.
WithHTTPPathPattern
(
"/file/{name=resources/*}
/{filename}
"
))
if
err
!=
nil
{
runtime
.
HTTPError
(
ctx
,
mux
,
outboundMarshaler
,
w
,
req
,
err
)
return
...
...
@@ -755,7 +775,7 @@ var (
pattern_ResourceService_GetResource_0
=
runtime
.
MustPattern
(
runtime
.
NewPattern
(
1
,
[]
int
{
2
,
0
,
2
,
1
,
2
,
2
,
1
,
0
,
4
,
2
,
5
,
3
},
[]
string
{
"api"
,
"v1"
,
"resources"
,
"name"
},
""
))
pattern_ResourceService_GetResourceBinary_0
=
runtime
.
MustPattern
(
runtime
.
NewPattern
(
1
,
[]
int
{
2
,
0
,
2
,
1
,
1
,
0
,
4
,
2
,
5
,
2
},
[]
string
{
"file"
,
"resources"
,
"
name"
},
""
))
pattern_ResourceService_GetResourceBinary_0
=
runtime
.
MustPattern
(
runtime
.
NewPattern
(
1
,
[]
int
{
2
,
0
,
2
,
1
,
1
,
0
,
4
,
2
,
5
,
2
,
1
,
0
,
4
,
1
,
5
,
3
},
[]
string
{
"file"
,
"resources"
,
"name"
,
"file
name"
},
""
))
pattern_ResourceService_UpdateResource_0
=
runtime
.
MustPattern
(
runtime
.
NewPattern
(
1
,
[]
int
{
2
,
0
,
2
,
1
,
2
,
2
,
1
,
0
,
4
,
2
,
5
,
3
},
[]
string
{
"api"
,
"v1"
,
"resources"
,
"resource.name"
},
""
))
...
...
server/router/rss/rss.go
View file @
16d3de63
...
...
@@ -129,7 +129,7 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st
if
resource
.
StorageType
==
storepb
.
ResourceStorageType_EXTERNAL
||
resource
.
StorageType
==
storepb
.
ResourceStorageType_S3
{
enclosure
.
Url
=
resource
.
Reference
}
else
{
enclosure
.
Url
=
fmt
.
Sprintf
(
"%s/file/resources/%d
"
,
baseURL
,
resource
.
ID
)
enclosure
.
Url
=
fmt
.
Sprintf
(
"%s/file/resources/%d
/%s"
,
baseURL
,
resource
.
ID
,
resource
.
Filename
)
}
enclosure
.
Length
=
strconv
.
Itoa
(
int
(
resource
.
Size
))
enclosure
.
Type
=
resource
.
Type
...
...
web/src/utils/resource.ts
View file @
16d3de63
...
...
@@ -5,7 +5,7 @@ export const getResourceUrl = (resource: Resource) => {
return
resource
.
externalLink
;
}
return
`
${
window
.
location
.
origin
}
/file/
${
resource
.
name
}
`
;
return
`
${
window
.
location
.
origin
}
/file/
${
resource
.
name
}
/
${
resource
.
filename
}
`
;
};
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