@bunbase-ae/js 1.0.0 → 1.0.1-next.3.ee6c18d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/index.ts +8 -1
- package/src/storage.ts +29 -2
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -38,7 +38,14 @@ export { AuthClient, type AuthSnapshot } from "./auth";
|
|
|
38
38
|
export { BunBaseClient } from "./client";
|
|
39
39
|
export { CollectionClient } from "./collection";
|
|
40
40
|
export { RealtimeClient, type SubscribeOptions } from "./realtime";
|
|
41
|
-
export {
|
|
41
|
+
export {
|
|
42
|
+
type ImageTransformFit,
|
|
43
|
+
type ImageTransformFormat,
|
|
44
|
+
type ImageTransformOptions,
|
|
45
|
+
type SignedUploadResult,
|
|
46
|
+
StorageClient,
|
|
47
|
+
type UploadOptions,
|
|
48
|
+
} from "./storage";
|
|
42
49
|
export {
|
|
43
50
|
type AggregateFunction,
|
|
44
51
|
type AggregateResult,
|
package/src/storage.ts
CHANGED
|
@@ -4,6 +4,22 @@ import type { HttpClient } from "./http";
|
|
|
4
4
|
import type { FileRecord } from "./types";
|
|
5
5
|
import { BunBaseError } from "./types";
|
|
6
6
|
|
|
7
|
+
export type ImageTransformFit = "cover" | "contain" | "inside";
|
|
8
|
+
export type ImageTransformFormat = "webp" | "jpeg" | "png";
|
|
9
|
+
|
|
10
|
+
export interface ImageTransformOptions {
|
|
11
|
+
/** Output width in pixels (1–4096). */
|
|
12
|
+
width?: number;
|
|
13
|
+
/** Output height in pixels (1–4096). */
|
|
14
|
+
height?: number;
|
|
15
|
+
/** How to fit the image into the given dimensions. Default: "inside". */
|
|
16
|
+
fit?: ImageTransformFit;
|
|
17
|
+
/** Convert to this output format. Omit to keep the original format. */
|
|
18
|
+
format?: ImageTransformFormat;
|
|
19
|
+
/** Quality for JPEG/WebP, 1–100. Default: 85. */
|
|
20
|
+
quality?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
7
23
|
export interface UploadOptions {
|
|
8
24
|
// Target storage bucket. Defaults to "default" if omitted.
|
|
9
25
|
bucket?: string;
|
|
@@ -190,10 +206,21 @@ export class StorageClient {
|
|
|
190
206
|
// Do NOT use this for private files — the browser cannot send the
|
|
191
207
|
// Authorization header via <img src>. For private files, call signedUrl()
|
|
192
208
|
// to get a time-limited signed URL instead.
|
|
193
|
-
downloadUrl(id: string, filename?: string | null): string {
|
|
209
|
+
downloadUrl(id: string, filename?: string | null, transform?: ImageTransformOptions): string {
|
|
194
210
|
if (id.startsWith("http")) return id;
|
|
195
211
|
const base = `${this.http.baseUrl}/api/v1/storage/${encodeURIComponent(id)}`;
|
|
196
|
-
|
|
212
|
+
let url = filename ? `${base}/${encodeURIComponent(filename)}` : base;
|
|
213
|
+
if (transform) {
|
|
214
|
+
const params = new URLSearchParams();
|
|
215
|
+
if (transform.width != null) params.set("w", String(transform.width));
|
|
216
|
+
if (transform.height != null) params.set("h", String(transform.height));
|
|
217
|
+
if (transform.fit) params.set("fit", transform.fit);
|
|
218
|
+
if (transform.format) params.set("format", transform.format);
|
|
219
|
+
if (transform.quality != null) params.set("q", String(transform.quality));
|
|
220
|
+
const qs = params.toString();
|
|
221
|
+
if (qs) url = `${url}?${qs}`;
|
|
222
|
+
}
|
|
223
|
+
return url;
|
|
197
224
|
}
|
|
198
225
|
|
|
199
226
|
async list(): Promise<FileRecord[]> {
|