Skip to content

Commit

Permalink
feat(url): options "base" replace endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Monnet committed Feb 3, 2025
1 parent 2a1325e commit 8fd7419
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/drivers/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export interface S3DriverOptions {
* - For AWS S3: "https://s3.[region].amazonaws.com/"
* - For cloudflare R2: "https://[uid].r2.cloudflarestorage.com/"
*/
base: string;

/**
*
* @deprecated use `base` option
*
*/
endpoint: string;

/**
Expand All @@ -41,7 +48,7 @@ export interface S3DriverOptions {
/**
* The name of the bucket.
*/
bucket: string;
bucket?: string;

/**
* Enabled by default to speedup `clear()` operation. Set to `false` if provider is not implementing [DeleteObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html).
Expand Down Expand Up @@ -83,7 +90,13 @@ export default defineDriver((options: S3DriverOptions) => {
return _awsClient;
};

const baseURL = `${options.endpoint.replace(/\/$/, "")}/${options.bucket || ""}`;
if (!options.base && !options.endpoint) {
throw createRequiredError(DRIVER_NAME, "base");
}

const baseURL = options.base
? `${options.base.replace(/^\/\//, "https://")}${options.bucket?.replace(/^/, "/") ?? ""}`
: `${options.endpoint.replace(/\/$/, "")}/${options.bucket || ""}`;

const url = (key: string = "") => `${baseURL}/${normalizeKey(key, "/")}`;

Expand Down

0 comments on commit 8fd7419

Please sign in to comment.