Expose permission-checked immutable asset metadata for shared depot adoption
Foundry Go checks / check (push) Failing after 6m24s
Foundry Go checks / check (pull_request) Failing after 4m36s

This commit is contained in:
2026-11-09 15:47:19 +08:00
parent 6a0a2e1912
commit 6b07c19728
3 changed files with 71 additions and 1 deletions
+45
View File
@@ -271,6 +271,51 @@ func assetReadable(r *http.Request, tx *sql.Tx, project, workspace, id, account
}
return false, nil
}
// Metadata uses the same read policy as original bytes; it is not a persistent grant.
func (s *service) getAssetMetadata(w http.ResponseWriter, r *http.Request, project, account string) error {
if r.Method != http.MethodGet {
reject(w, 405, "method_not_allowed")
return nil
}
id, workspace := r.PathValue("asset"), r.PathValue("workspace")
if !uuidSlugPattern.MatchString(id) {
reject(w, 404, "not_found")
return nil
}
tx, err := s.db.BeginTx(r.Context(), nil)
if err != nil {
return err
}
defer tx.Rollback()
var locked string
err = tx.QueryRowContext(r.Context(), `SELECT id::text FROM workspaces WHERE project=$1 AND id=$2 FOR UPDATE`, project, workspace).Scan(&locked)
if err != nil {
return err
}
allowed, err := assetReadable(r, tx, project, workspace, id, account)
if err != nil {
return err
}
if !allowed {
reject(w, 404, "not_found")
return nil
}
var info assetInfo
var digest string
err = tx.QueryRowContext(r.Context(), `SELECT id::text,mime_type,octet_length(bytes),width,height,digest FROM canvas_assets WHERE project=$1 AND workspace_id=$2 AND id=$3`, project, workspace, id).Scan(&info.ID, &info.MIME, &info.Bytes, &info.Width, &info.Height, &digest)
if err != nil {
return err
}
if err = tx.Commit(); err != nil {
return err
}
info.URL = s.assetURL(project, workspace, id)
w.Header().Set("Cache-Control", "private, no-store")
reply(w, 200, response{"metadata_version": 1, "asset": info, "sha256": digest})
return nil
}
func (s *service) getAsset(w http.ResponseWriter, r *http.Request, project, account string) error {
if r.Method != http.MethodGet {
reject(w, 405, "method_not_allowed")