-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: putBucketWebsite support new parameter (#736)
- Loading branch information
Showing
10 changed files
with
214 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const proto = exports; | ||
|
||
proto.deleteBucketWebsite = async function deleteBucketWebsite(name, options) { | ||
this._checkBucketName(name); | ||
const params = this._bucketRequestParams('DELETE', name, 'website', options); | ||
params.successStatuses = [204]; | ||
const result = await this.request(params); | ||
return { | ||
res: result.res | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const isObject = require('../utils/isObject'); | ||
|
||
const proto = exports; | ||
|
||
proto.getBucketWebsite = async function getBucketWebsite(name, options) { | ||
this._checkBucketName(name); | ||
const params = this._bucketRequestParams('GET', name, 'website', options); | ||
params.successStatuses = [200]; | ||
params.xmlResponse = true; | ||
const result = await this.request(params); | ||
let routingRules = []; | ||
if (result.data.RoutingRules && result.data.RoutingRules.RoutingRule) { | ||
if (isObject(result.data.RoutingRules.RoutingRule)) { | ||
routingRules = [result.data.RoutingRules.RoutingRule]; | ||
} else { | ||
routingRules = result.data.RoutingRules.RoutingRule; | ||
} | ||
} | ||
return { | ||
index: (result.data.IndexDocument && result.data.IndexDocument.Suffix) || '', | ||
supportSubDir: (result.data.IndexDocument && result.data.IndexDocument.SupportSubDir) || 'false', | ||
type: (result.data.IndexDocument && result.data.IndexDocument.Type), | ||
routingRules, | ||
error: (result.data.ErrorDocument && result.data.ErrorDocument.Key) || null, | ||
res: result.res | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const obj2xml = require('../utils/obj2xml'); | ||
const isArray = require('../utils/isArray'); | ||
|
||
const proto = exports; | ||
proto.putBucketWebsite = async function putBucketWebsite(name, config = {}, options) { | ||
this._checkBucketName(name); | ||
const params = this._bucketRequestParams('PUT', name, 'website', options); | ||
const IndexDocument = { | ||
Suffix: config.index || 'index.html' | ||
}; | ||
const WebsiteConfiguration = { | ||
IndexDocument | ||
}; | ||
let website = { | ||
WebsiteConfiguration | ||
}; | ||
|
||
if (config.supportSubDir) { | ||
IndexDocument.SupportSubDir = config.supportSubDir; | ||
} | ||
|
||
if (config.type) { | ||
IndexDocument.Type = config.type; | ||
} | ||
|
||
if (config.error) { | ||
WebsiteConfiguration.ErrorDocument = { | ||
Key: config.error | ||
}; | ||
} | ||
|
||
if (config.routingRules !== undefined) { | ||
if (!isArray(config.routingRules)) { | ||
throw new Error('RoutingRules must be Array'); | ||
} | ||
WebsiteConfiguration.RoutingRules = { | ||
RoutingRule: config.routingRules | ||
}; | ||
} | ||
|
||
website = obj2xml(website); | ||
params.content = website; | ||
params.mime = 'xml'; | ||
params.successStatuses = [200]; | ||
const result = await this.request(params); | ||
return { | ||
res: result.res | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function isArray(obj) { | ||
return Object.prototype.toString.call(obj) === '[object Array]'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters