feat: support local storage (#1383)

* feat: support local storage

* update

* update

* update

* update
This commit is contained in:
Zeng1998
2023-03-19 19:37:57 +08:00
committed by GitHub
parent a21ff5c2e3
commit f3090b115d
10 changed files with 224 additions and 48 deletions

View File

@@ -24,6 +24,7 @@ type resourceRaw struct {
// Domain specific fields
Filename string
Blob []byte
InternalPath string
ExternalLink string
Type string
Size int64
@@ -43,6 +44,7 @@ func (raw *resourceRaw) toResource() *api.Resource {
// Domain specific fields
Filename: raw.Filename,
Blob: raw.Blob,
InternalPath: raw.InternalPath,
ExternalLink: raw.ExternalLink,
Type: raw.Type,
Size: raw.Size,
@@ -195,9 +197,9 @@ func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api.
values := []any{create.Filename, create.Blob, create.ExternalLink, create.Type, create.Size, create.CreatorID}
placeholders := []string{"?", "?", "?", "?", "?", "?"}
if s.profile.IsDev() {
fields = append(fields, "visibility")
values = append(values, create.Visibility)
placeholders = append(placeholders, "?")
fields = append(fields, "visibility", "internal_path")
values = append(values, create.Visibility, create.InternalPath)
placeholders = append(placeholders, "?", "?")
}
query := `
@@ -218,7 +220,7 @@ func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api.
&resourceRaw.CreatorID,
}
if s.profile.IsDev() {
dests = append(dests, &resourceRaw.Visibility)
dests = append(dests, &resourceRaw.Visibility, &resourceRaw.InternalPath)
}
dests = append(dests, []any{&resourceRaw.CreatedTs, &resourceRaw.UpdatedTs}...)
if err := tx.QueryRowContext(ctx, query, values...).Scan(dests...); err != nil {
@@ -247,7 +249,7 @@ func (s *Store) patchResourceImpl(ctx context.Context, tx *sql.Tx, patch *api.Re
fields := []string{"id", "filename", "external_link", "type", "size", "creator_id", "created_ts", "updated_ts"}
if s.profile.IsDev() {
fields = append(fields, "visibility")
fields = append(fields, "visibility", "internal_path")
}
query := `
@@ -267,7 +269,7 @@ func (s *Store) patchResourceImpl(ctx context.Context, tx *sql.Tx, patch *api.Re
&resourceRaw.UpdatedTs,
}
if s.profile.IsDev() {
dests = append(dests, &resourceRaw.Visibility)
dests = append(dests, &resourceRaw.Visibility, &resourceRaw.InternalPath)
}
if err := tx.QueryRowContext(ctx, query, args...).Scan(dests...); err != nil {
return nil, FormatError(err)
@@ -297,7 +299,7 @@ func (s *Store) findResourceListImpl(ctx context.Context, tx *sql.Tx, find *api.
fields = append(fields, "resource.blob")
}
if s.profile.IsDev() {
fields = append(fields, "resource.visibility")
fields = append(fields, "visibility", "internal_path")
}
query := fmt.Sprintf(`
@@ -334,7 +336,7 @@ func (s *Store) findResourceListImpl(ctx context.Context, tx *sql.Tx, find *api.
dests = append(dests, &resourceRaw.Blob)
}
if s.profile.IsDev() {
dests = append(dests, &resourceRaw.Visibility)
dests = append(dests, &resourceRaw.Visibility, &resourceRaw.InternalPath)
}
if err := rows.Scan(dests...); err != nil {
return nil, FormatError(err)