chore: add presign background service

This commit is contained in:
Steven
2024-05-02 22:08:45 +08:00
parent 05f73a2236
commit 74145157a0
7 changed files with 144 additions and 0 deletions

View File

@ -66,6 +66,9 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
if find.HasRelatedMemo {
where = append(where, "`memo_id` IS NOT NULL")
}
if find.StorageType != nil {
where, args = append(where, "`storage_type` = ?"), append(args, find.StorageType.String())
}
fields := []string{"`id`", "`uid`", "`filename`", "`type`", "`size`", "`creator_id`", "`created_ts`", "`updated_ts`", "`memo_id`", "`storage_type`", "`reference`", "`payload`"}
if find.GetBlob {
@ -159,6 +162,16 @@ func (d *DB) UpdateResource(ctx context.Context, update *store.UpdateResource) e
if v := update.MemoID; v != nil {
set, args = append(set, "`memo_id` = ?"), append(args, *v)
}
if v := update.Reference; v != nil {
set, args = append(set, "`reference` = ?"), append(args, *v)
}
if v := update.Payload; v != nil {
bytes, err := protojson.Marshal(v)
if err != nil {
return errors.Wrap(err, "failed to marshal resource payload")
}
set, args = append(set, "`payload` = ?"), append(args, string(bytes))
}
args = append(args, update.ID)
stmt := "UPDATE `resource` SET " + strings.Join(set, ", ") + " WHERE `id` = ?"