Comparing version 0.2.10 to 1.0.0
{ | ||
"name": "s3u", | ||
"version": "0.2.10", | ||
"version": "1.0.0", | ||
"description": "S3 URL manipulation helper similar to standard URL class", | ||
@@ -23,8 +23,15 @@ "main": "src/index.js", | ||
"keywords": [ | ||
"s3", | ||
"aws", | ||
"url", | ||
"amazon", | ||
"digitalocean", | ||
"digitalocean-spaces", | ||
"link", | ||
"parse", | ||
"presigned", | ||
"s3", | ||
"sign", | ||
"spaces", | ||
"stackpath", | ||
"spaces" | ||
"storage", | ||
"url" | ||
], | ||
@@ -31,0 +38,0 @@ "author": "Alexey Prokhorov", |
@@ -37,2 +37,3 @@ export class S3Url { | ||
setProtocol(protocol: string): this; | ||
setProvider(provider: S3Provider | string): this; | ||
setRegion(region: string): this; | ||
@@ -39,0 +40,0 @@ |
@@ -5,5 +5,5 @@ 'use strict'; | ||
/** | ||
* @param {Partial<S3Url>} attrs | ||
* @param {Partial<S3Url> | string} options | ||
*/ | ||
constructor(attrs = {}) { | ||
constructor(options = {}) { | ||
this.bucket = ''; | ||
@@ -25,9 +25,16 @@ this.bucketPosition = 'hostname'; | ||
if (typeof attrs === 'string') { | ||
if (typeof options === 'string') { | ||
// eslint-disable-next-line no-constructor-return | ||
return this.constructor.fromUrl({ url: attrs }); | ||
return this.constructor.fromUrl({ url: options }); | ||
} | ||
const { dirPath, fileName, provider, ...attrs } = options; | ||
Object.assign(this, attrs); | ||
if (!(options instanceof S3Url)) { | ||
dirPath && this.setFileName(dirPath); | ||
fileName && this.setFileName(fileName); | ||
provider && this.setProvider(provider); | ||
} | ||
this.updateBucketPosition(); | ||
@@ -68,21 +75,2 @@ } | ||
async sign({ | ||
accessKeyId, | ||
expires, | ||
method, | ||
secretAccessKey, | ||
} = {}) { | ||
if (!this.provider) { | ||
throw new Error('Cannot sign url from invalid S3Url'); | ||
} | ||
return this.provider.buildSignedUrl({ | ||
accessKeyId, | ||
expires, | ||
method, | ||
s3Url: this, | ||
secretAccessKey, | ||
}); | ||
} | ||
clone(newAttrs = {}) { | ||
@@ -133,2 +121,16 @@ return new S3Url({ ...this, ...newAttrs }); | ||
setProvider(provider) { | ||
if (provider && provider.buildUrl) { | ||
this.provider = provider; | ||
return this; | ||
} | ||
if (typeof provider === 'string' && this.constructor.parser) { | ||
this.provider = this.constructor.parser.getProviderById(provider); | ||
return this; | ||
} | ||
return this; | ||
} | ||
setRegion(region) { | ||
@@ -139,2 +141,21 @@ this.region = region; | ||
async sign({ | ||
accessKeyId, | ||
expires, | ||
method, | ||
secretAccessKey, | ||
} = {}) { | ||
if (!this.provider) { | ||
throw new Error('Cannot sign url from invalid S3Url'); | ||
} | ||
return this.provider.buildSignedUrl({ | ||
accessKeyId, | ||
expires, | ||
method, | ||
s3Url: this, | ||
secretAccessKey, | ||
}); | ||
} | ||
trimSlashes({ begin = false, end = false } = {}) { | ||
@@ -141,0 +162,0 @@ let key = this.key; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
25267
712
0