mirror of
https://github.com/usememos/memos.git
synced 2025-02-27 06:51:31 +08:00
chore: get resource blob optional (#991)
This commit is contained in:
parent
dd5a23e36e
commit
6c3ff6de63
4 changed files with 20 additions and 17 deletions
|
@ -40,6 +40,7 @@ type ResourceFind struct {
|
|||
// Domain specific fields
|
||||
Filename *string `json:"filename"`
|
||||
MemoID *int
|
||||
GetBlob bool
|
||||
}
|
||||
|
||||
type ResourcePatch struct {
|
||||
|
|
|
@ -153,6 +153,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
|
|||
resourceFind := &api.ResourceFind{
|
||||
ID: &resourceID,
|
||||
CreatorID: &userID,
|
||||
GetBlob: true,
|
||||
}
|
||||
resource, err := s.Store.FindResource(ctx, resourceFind)
|
||||
if err != nil {
|
||||
|
@ -180,6 +181,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
|
|||
resourceFind := &api.ResourceFind{
|
||||
ID: &resourceID,
|
||||
CreatorID: &userID,
|
||||
GetBlob: true,
|
||||
}
|
||||
resource, err := s.Store.FindResource(ctx, resourceFind)
|
||||
if err != nil {
|
||||
|
@ -290,6 +292,7 @@ func (s *Server) registerResourcePublicRoutes(g *echo.Group) {
|
|||
resourceFind := &api.ResourceFind{
|
||||
ID: &resourceID,
|
||||
Filename: &filename,
|
||||
GetBlob: true,
|
||||
}
|
||||
resource, err := s.Store.FindResource(ctx, resourceFind)
|
||||
if err != nil {
|
||||
|
|
|
@ -98,9 +98,6 @@ func NewServer(ctx context.Context, profile *profile.Profile) (*Server, error) {
|
|||
rootGroup := e.Group("")
|
||||
s.registerRSSRoutes(rootGroup)
|
||||
|
||||
webhookGroup := e.Group("/h")
|
||||
s.registerResourcePublicRoutes(webhookGroup)
|
||||
|
||||
publicGroup := e.Group("/o")
|
||||
s.registerResourcePublicRoutes(publicGroup)
|
||||
registerGetterPublicRoutes(publicGroup)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
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
|
||||
id,
|
||||
filename,
|
||||
blob,
|
||||
external_link,
|
||||
type,
|
||||
size,
|
||||
creator_id,
|
||||
created_ts,
|
||||
updated_ts
|
||||
%s
|
||||
FROM resource
|
||||
WHERE ` + strings.Join(where, " AND ") + `
|
||||
WHERE %s
|
||||
ORDER BY id DESC
|
||||
`
|
||||
`, strings.Join(fields, ", "), strings.Join(where, " AND "))
|
||||
rows, err := tx.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, FormatError(err)
|
||||
|
@ -319,16 +316,21 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) (
|
|||
resourceRawList := make([]*resourceRaw, 0)
|
||||
for rows.Next() {
|
||||
var resourceRaw resourceRaw
|
||||
if err := rows.Scan(
|
||||
dest := []interface{}{
|
||||
&resourceRaw.ID,
|
||||
&resourceRaw.Filename,
|
||||
&resourceRaw.Blob,
|
||||
&resourceRaw.ExternalLink,
|
||||
&resourceRaw.Type,
|
||||
&resourceRaw.Size,
|
||||
&resourceRaw.CreatorID,
|
||||
&resourceRaw.CreatedTs,
|
||||
&resourceRaw.UpdatedTs,
|
||||
}
|
||||
if find.GetBlob {
|
||||
dest = append(dest, &resourceRaw.Blob)
|
||||
}
|
||||
if err := rows.Scan(
|
||||
dest...,
|
||||
); err != nil {
|
||||
return nil, FormatError(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue