Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: get resource blob optional (#991)

boojack6c3ff6de630b
diff --git a/api/resource.go b/api/resource.go
index 606b5d4d5..c69a8557c 100644
--- a/api/resource.go
+++ b/api/resource.go
@@ -40,6 +40,7 @@ type ResourceFind struct {
// Domain specific fields
Filename *string `json:"filename"`
MemoID *int
+ GetBlob bool
}
type ResourcePatch struct {
diff --git a/server/resource.go b/server/resource.go
index fb7d4ab85..579ec7b57 100644
--- a/server/resource.go
+++ b/server/resource.go
@@ -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 {
diff --git a/server/server.go b/server/server.go
index 6cbff9485..98a83cc4c 100644
--- a/server/server.go
+++ b/server/server.go
@@ -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)
diff --git a/store/resource.go b/store/resource.go
index 1e469fb11..943b29577 100644
--- a/store/resource.go
+++ b/store/resource.go
@@ -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)
}