firebase / firebase/firebase-admin-node

FR: Support direct lookup of Storage objects by `metadata.id`

未关闭
#2,939 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
type: feature request
主要语言
TypeScript
星标
1.7k
派生
419
平均合并
3 天 10 小时
30 天内合并 PR
16

描述

**Title:**
FR: Support direct lookup of Storage objects by `metadata.id`

---

**Is your feature request related to a problem? Please describe.**
Currently in the Admin SDK there is no way to fetch a file reference directly by its internal `metadata.id`. Users must call `bucket.getFiles()` (optionally with a prefix) and then iterate through every file’s metadata until they find a match. This approach is painfully inefficient for buckets with hundreds or thousands of objects, and leads to high latency and extra egress charges just to resolve a single file by its ID.

---

**Describe the solution you’d like**
Add a first-class API—e.g.

```ts
const file = await bucket.fileById('ABCD1234-xyz');
```

under the Admin SDK’s `Bucket` class (and optionally in the underlying `@google-cloud/storage` client). Internally it could leverage a server-side lookup or index rather than requiring a full listing scan. The returned object should behave identically to `bucket.file(path)` so you can immediately call `getMetadata()`, `download()`, or `getSignedUrl()`.

---

**Describe alternatives you’ve considered**

* **Client-side scan:**

```js
const [files] = await bucket.getFiles();
for (const f of files) {
const [m] = await f.getMetadata();
if (m.id === targetId) return f;
}
```

Works, but requires listing every object + extra round-trips.
* **Storing custom metadata:** You could save your own “id” in `metadata.custom` and index it in Firestore, but that duplicates what the server already knows, and still needs a separate database lookup.

---

**Additional context**

* This feature is especially important for multi-tenant or large-scale apps where buckets routinely hit thousands of files.
* Without it, reverse-lookup patterns become a maintenance burden and performance bottleneck.
* Screenshot of current workaround and templates attached.

贡献指南

打开贡献指南

调研方向

从 Admin SDK 的 Bucket 类开始,追踪它如何创建文件引用;将这一路径与 issue 中提到的底层 @google-cloud/storage 客户端进行比较。定义如何支持 metadata.id 查找,然后验证返回的对象是否像 bucket.file(path) 一样支持 getMetadata()、download() 和 getSignedUrl()。

由索引模型根据 Issue 内容生成。

评估

技术栈
google-cloud, node.js, typescript
领域
api, backend, cloud
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。