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
6c3ff6de
Unverified
Commit
6c3ff6de
authored
Jan 25, 2023
by
boojack
Committed by
GitHub
Jan 25, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: get resource blob optional (#991)
parent
dd5a23e3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
17 deletions
+20
-17
resource.go
api/resource.go
+1
-0
resource.go
server/resource.go
+3
-0
server.go
server/server.go
+0
-3
resource.go
store/resource.go
+16
-14
No files found.
api/resource.go
View file @
6c3ff6de
...
@@ -40,6 +40,7 @@ type ResourceFind struct {
...
@@ -40,6 +40,7 @@ type ResourceFind struct {
// Domain specific fields
// Domain specific fields
Filename
*
string
`json:"filename"`
Filename
*
string
`json:"filename"`
MemoID
*
int
MemoID
*
int
GetBlob
bool
}
}
type
ResourcePatch
struct
{
type
ResourcePatch
struct
{
...
...
server/resource.go
View file @
6c3ff6de
...
@@ -153,6 +153,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -153,6 +153,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
resourceFind
:=
&
api
.
ResourceFind
{
resourceFind
:=
&
api
.
ResourceFind
{
ID
:
&
resourceID
,
ID
:
&
resourceID
,
CreatorID
:
&
userID
,
CreatorID
:
&
userID
,
GetBlob
:
true
,
}
}
resource
,
err
:=
s
.
Store
.
FindResource
(
ctx
,
resourceFind
)
resource
,
err
:=
s
.
Store
.
FindResource
(
ctx
,
resourceFind
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -180,6 +181,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -180,6 +181,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
resourceFind
:=
&
api
.
ResourceFind
{
resourceFind
:=
&
api
.
ResourceFind
{
ID
:
&
resourceID
,
ID
:
&
resourceID
,
CreatorID
:
&
userID
,
CreatorID
:
&
userID
,
GetBlob
:
true
,
}
}
resource
,
err
:=
s
.
Store
.
FindResource
(
ctx
,
resourceFind
)
resource
,
err
:=
s
.
Store
.
FindResource
(
ctx
,
resourceFind
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -290,6 +292,7 @@ func (s *Server) registerResourcePublicRoutes(g *echo.Group) {
...
@@ -290,6 +292,7 @@ func (s *Server) registerResourcePublicRoutes(g *echo.Group) {
resourceFind
:=
&
api
.
ResourceFind
{
resourceFind
:=
&
api
.
ResourceFind
{
ID
:
&
resourceID
,
ID
:
&
resourceID
,
Filename
:
&
filename
,
Filename
:
&
filename
,
GetBlob
:
true
,
}
}
resource
,
err
:=
s
.
Store
.
FindResource
(
ctx
,
resourceFind
)
resource
,
err
:=
s
.
Store
.
FindResource
(
ctx
,
resourceFind
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
server/server.go
View file @
6c3ff6de
...
@@ -98,9 +98,6 @@ func NewServer(ctx context.Context, profile *profile.Profile) (*Server, error) {
...
@@ -98,9 +98,6 @@ func NewServer(ctx context.Context, profile *profile.Profile) (*Server, error) {
rootGroup
:=
e
.
Group
(
""
)
rootGroup
:=
e
.
Group
(
""
)
s
.
registerRSSRoutes
(
rootGroup
)
s
.
registerRSSRoutes
(
rootGroup
)
webhookGroup
:=
e
.
Group
(
"/h"
)
s
.
registerResourcePublicRoutes
(
webhookGroup
)
publicGroup
:=
e
.
Group
(
"/o"
)
publicGroup
:=
e
.
Group
(
"/o"
)
s
.
registerResourcePublicRoutes
(
publicGroup
)
s
.
registerResourcePublicRoutes
(
publicGroup
)
registerGetterPublicRoutes
(
publicGroup
)
registerGetterPublicRoutes
(
publicGroup
)
...
...
store/resource.go
View file @
6c3ff6de
...
@@ -295,21 +295,18 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
...
@@ -295,21 +295,18 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
where
,
args
=
append
(
where
,
"id in (SELECT resource_id FROM memo_resource WHERE memo_id = ?)"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"id in (SELECT resource_id FROM memo_resource WHERE memo_id = ?)"
),
append
(
args
,
*
v
)
}
}
query
:=
`
fields
:=
[]
string
{
"id"
,
"filename"
,
"external_link"
,
"type"
,
"size"
,
"creator_id"
,
"created_ts"
,
"updated_ts"
}
if
find
.
GetBlob
{
fields
=
append
(
fields
,
"blob"
)
}
query
:=
fmt
.
Sprintf
(
`
SELECT
SELECT
id,
%s
filename,
blob,
external_link,
type,
size,
creator_id,
created_ts,
updated_ts
FROM resource
FROM resource
WHERE
`
+
strings
.
Join
(
where
,
" AND "
)
+
`
WHERE
%s
ORDER BY id DESC
ORDER BY id DESC
`
`
,
strings
.
Join
(
fields
,
", "
),
strings
.
Join
(
where
,
" AND "
))
rows
,
err
:=
tx
.
QueryContext
(
ctx
,
query
,
args
...
)
rows
,
err
:=
tx
.
QueryContext
(
ctx
,
query
,
args
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
FormatError
(
err
)
return
nil
,
FormatError
(
err
)
...
@@ -319,16 +316,21 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
...
@@ -319,16 +316,21 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
resourceRawList
:=
make
([]
*
resourceRaw
,
0
)
resourceRawList
:=
make
([]
*
resourceRaw
,
0
)
for
rows
.
Next
()
{
for
rows
.
Next
()
{
var
resourceRaw
resourceRaw
var
resourceRaw
resourceRaw
if
err
:=
rows
.
Scan
(
dest
:=
[]
interface
{}{
&
resourceRaw
.
ID
,
&
resourceRaw
.
ID
,
&
resourceRaw
.
Filename
,
&
resourceRaw
.
Filename
,
&
resourceRaw
.
Blob
,
&
resourceRaw
.
ExternalLink
,
&
resourceRaw
.
ExternalLink
,
&
resourceRaw
.
Type
,
&
resourceRaw
.
Type
,
&
resourceRaw
.
Size
,
&
resourceRaw
.
Size
,
&
resourceRaw
.
CreatorID
,
&
resourceRaw
.
CreatorID
,
&
resourceRaw
.
CreatedTs
,
&
resourceRaw
.
CreatedTs
,
&
resourceRaw
.
UpdatedTs
,
&
resourceRaw
.
UpdatedTs
,
}
if
find
.
GetBlob
{
dest
=
append
(
dest
,
&
resourceRaw
.
Blob
)
}
if
err
:=
rows
.
Scan
(
dest
...
,
);
err
!=
nil
{
);
err
!=
nil
{
return
nil
,
FormatError
(
err
)
return
nil
,
FormatError
(
err
)
}
}
...
...
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