Utility functions for qiniu-oss
- Description:
Utility functions for qiniu-oss
- Source:
Example
import {
getConfigFromQiniuOSS,
getMacFromQiniuOSS,
joinPath,
refreshUrlsFromQiniuOSS,
uploadDirToQiniuOSS,
} from "nsuite";
process.env.QINIU_HTTP_CLIENT_TIMEOUT = "120000";
const mac = getMacFromQiniuOSS({
accessKey: QINIU_ACCESS_KEY,
secretKey: QINIU_SECRET_KEY,
});
const config = getConfigFromQiniuOSS({});
const { uploadedList } = await uploadDirToQiniuOSS({
config,
mac,
bucket: QINIU_BUCKET_NAME,
baseUrl: QINIU_PUBLIC_BUCKET_DOMAIN,
keyPrefix: CDN_PATH_PREFIX,
putPolicyOptions: {
scope: QINIU_BUCKET_NAME,
expires: 7200,
},
localPath: PATH_PUBLIC,
ignorePathList: ["node_modules/**"],
refresh: false,
recursive: true,
dryRun: false,
uploadCallback: (curIdx, totalCount, fileInfo) => {
logger.info(`Uploaded ${curIdx + 1}/${totalCount} ${fileInfo.key}`);
},
});
const urlsToRefresh = uploadedList
.filter((item) => {
return item.key.endsWith(".css") || item.key.endsWith(".js");
})
.map((item) => item.url);
logger.info(`Start refreshing CDN: ${urlsToRefresh.join(", ")}.`);
const refreshedUrls = await refreshUrlsFromQiniuOSS({
urls: urlsToRefresh,
mac,
});
logger.info(`Refreshed urls: ${refreshedUrls.join(", ")}.`);
Methods
(static) deleteRemotePathListFromQiniuOSS(payload) → {Promise.<module:OSS~ReturnQiniuOSSDeleteRemotePathList>}
- Description:
Delete files
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
module:OSS~ParamsQiniuOSSDeleteRemotePathList |
Returns:
- Type
- Promise.<module:OSS~ReturnQiniuOSSDeleteRemotePathList>
(static) getBucketManagerFromQiniuOSS(payload) → {module:OSS~QiniuBucketManager}
- Description:
Get bucket manager from qiniu
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
module:OSS~ParamsQiniuOSSGetBucketManager |
Returns:
- Type
- module:OSS~QiniuBucketManager
(static) getConfigFromQiniuOSS(options) → {module:OSS~QiniuConfig}
- Description:
Get
- Source:
Parameters:
Name | Type | Description |
---|---|---|
options |
module:qiniu~conf.ConfigOptions |
Returns:
- Type
- module:OSS~QiniuConfig
(static) getMacFromQiniuOSS(payload) → {module:OSS~QiniuMac}
- Description:
Get mac from qiniu
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
module:OSS~ParamsQiniuOSSGetMac |
Returns:
- Type
- module:OSS~QiniuMac
(static) getPublicDownloadUrlFromQiniuOSS(payload) → {string}
- Description:
Get public download url
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
module:OSS~ParamsQiniuOSSGetPublicDownloadUrl |
Returns:
- Type
- string
(static) refreshUrlsFromQiniuOSS(payload) → {Promise.<Array.<string>>}
- Description:
Refresh cdn urls
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
module:OSS~ParamsQiniuOSSRefreshUrls |
Returns:
- Type
- Promise.<Array.<string>>
(static) uploadDirToQiniuOSS(payload) → {Promise.<module:OSS~ReturnQiniuOSSUploadDir>}
- Description:
Upload directory to Qiniu OSS
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
module:OSS~ParamsQiniuOSSUploadDir |
Returns:
- Type
- Promise.<module:OSS~ReturnQiniuOSSUploadDir>
(static) uploadLocalFileToQiniuOSS(payload) → {Promise.<module:OSS~ReturnQiniuOSSUploadLocalFile>}
- Description:
Upload local file to Qiniu
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
module:OSS~ParamsQiniuOSSUploadLocalFile |
Returns:
- Type
- Promise.<module:OSS~ReturnQiniuOSSUploadLocalFile>
(inner) getQiniuCacheRefreshCodeMessage(code) → {string}
- Description:
获取七牛云自定义错误码的错误信息
reference: https://developer.qiniu.com/fusion/1229/cache-refresh 200 success 成功 400031 invalid url 请求中存在无效的 url,请确保 url 格式正确 400032 invalid host 请求中存在无效的域名,请确保域名格式正确 400034 refresh url limit error 请求次数超出当日刷新限额 400036 invalid request id 无效的请求 id 400037 url has existed url 正在刷新中 400038 refresh dir authority error 没有刷新目录的权限, 如果需要请联系技术支持 403024 single user QPS Rate limited 请求达到单用户QPS限制,请重试或联系我们 403022 server QPS Rate limited 请求达到全局QPS限制,请联系我们 500000 internal error 服务端内部错误,请联系技术支持
- Source:
Parameters:
Name | Type | Description |
---|---|---|
code |
number |
Returns:
- Type
- string
Type Definitions
FuncQiniuOSSUploadFileCallback(payload) → {void}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
payload |
module:OSS~ParamsQiniuOSSUploadFileCallbackWithoutError | module:OSS~ParamsQiniuOSSUploadFileCallbackWithError |
Returns:
- Type
- void
FuncReturnPromiseQiniuOSSUploadLocalFile() → {Promise.<(module:OSS~ReturnQiniuOSSUploadLocalFile|void)>}
- Source:
Returns:
- Type
- Promise.<(module:OSS~ReturnQiniuOSSUploadLocalFile|void)>
ParamsQiniuOSSDeleteRemotePathList
- Source:
Properties:
Name | Type | Description |
---|---|---|
bucketManager |
module:OSS~QiniuBucketManager | |
remotePathList |
Array.<string> | |
bucket |
string |
Type:
- Object
ParamsQiniuOSSGetBucketManager
- Source:
Properties:
Name | Type | Description |
---|---|---|
mac |
module:OSS~QiniuMac | |
config |
module:OSS~QiniuConfig |
Type:
- Object
ParamsQiniuOSSGetMac
- Source:
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
accessKey |
string | ||
secretKey |
string | ||
options |
module:OSS~QiniuMacOptions |
<optional> |
Type:
- Object
ParamsQiniuOSSGetPublicDownloadUrl
- Source:
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
bucketManager |
module:OSS~QiniuBucketManager | ||
key |
string | ||
baseUrl |
string |
<optional> |
Type:
- Object
ParamsQiniuOSSListFiles
- Source:
Properties:
Name | Type | Description |
---|---|---|
bucketManager |
module:OSS~QiniuBucketManager | |
bucket |
string | |
options |
module:OSS~QiniuListPrefixOptions |
Type:
- Object
ParamsQiniuOSSRefreshUrls
- Source:
Properties:
Name | Type | Description |
---|---|---|
urls |
Array.<string> | |
mac |
module:OSS~QiniuMac |
Type:
- Object
ParamsQiniuOSSUploadDir
- Source:
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
config |
module:OSS~QiniuConfig | |||
mac |
module:OSS~QiniuMac | |||
bucket |
string | |||
baseUrl |
string |
<optional> |
needed if refresh is set true |
|
keyPrefix |
string |
<optional> |
''
|
|
putPolicyOptions |
module:OSS~QiniuPutPolicyOptions |
<optional> |
{}
|
|
localPath |
string | |||
ignorePathList |
Array.<string> |
<optional> |
[]
|
|
refresh |
boolean |
<optional> |
false
|
|
recursive |
boolean |
<optional> |
false
|
|
dryRun |
boolean |
<optional> |
false
|
set to true if you want to check which files will be deployed before real deployment |
uploadCallback |
FuncQiniuOSSUploadFileCallback |
<optional> |
callback function for upload progress |
Type:
- Object
ParamsQiniuOSSUploadFileCallbackWithError
- Source:
Properties:
Name | Type | Description |
---|---|---|
err |
Error | |
curIdx |
number | current index, starting from 0, ranging from 0 to (total - 1) |
total |
number | total count |
file |
null | file info |
Type:
- Object
ParamsQiniuOSSUploadFileCallbackWithoutError
- Source:
Properties:
Name | Type | Description |
---|---|---|
err |
null | |
curIdx |
number | current index, starting from 0, ranging from 0 to (total - 1) |
total |
number | total count |
file |
module:OSS~ReturnQiniuOSSUploadLocalFile | file info |
Type:
- Object
ParamsQiniuOSSUploadLocalFile
- Source:
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
config |
module:OSS~QiniuConfig | ||
mac |
module:OSS~QiniuMac | ||
localPath |
string | ||
key |
string | ||
baseUrl |
string | ||
bucket |
string | ||
putPolicyOptions |
module:OSS~QiniuPutPolicyOptions |
<optional> |
Type:
- Object
QiniuHttpClientOptions
- Source:
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
timeout |
number |
<optional> |
Type:
- module:OSS~QiniuHttpClientRawOptions
QiniuHttpClientRawOptions
- Source:
Type:
- qiniu.httpc.HttpClientOptions
QiniuOSSLocalPathAndKey
- Source:
Properties:
Name | Type | Description |
---|---|---|
localPath |
string | |
key |
string |
Type:
- Object
QiniuOperationResponse
- Source:
Type:
- 'Zone_z0' | 'Zone_z1' | 'Zone_z2' | 'Zone_na0' | 'Zone_as0'
QiniuRefreshUrlsRespBody
- Source:
Properties:
Name | Type | Description |
---|---|---|
code |
number | 200 if success |
error |
string | 'success' is success |
requestId |
string | |
taskIds |
null | Record.<string, unknown> |
Type:
- Object
QiniuRefreshUrlsRespInfo
- Source:
Properties:
Name | Type | Description |
---|---|---|
status |
number | 200 if success |
statusCode |
number | 200 if success |
statusMessage |
string | 'OK' if success |
headers |
Record.<string, string> | |
size |
number | |
aborted |
boolean | |
rt |
number | |
data |
module:OSS~QiniuRefreshUrlsRespBody | |
requestUrls |
Array.<string> | |
timing |
number | null | |
remoteAddress |
string | |
remotePort |
number | |
socketHandledRequests |
number | |
socketHandledResponses |
number |
Type:
- Object
ReturnQiniuOSSDeleteRemotePathList
- Source:
Properties:
Name | Type | Description |
---|---|---|
successItems |
Array.<string> | |
failItems |
Array.<string> |
Type:
- Object
ReturnQiniuOSSUploadDir
- Source:
Properties:
Name | Type | Description |
---|---|---|
uploadedList |
Array.<module:OSS~ReturnQiniuOSSUploadLocalFile> | |
refreshedUrlList |
Array.<string> | |
allPaths |
Array.<module:OSS~QiniuOSSLocalPathAndKey> |
Type:
- Object
ReturnQiniuOSSUploadLocalFile
- Source:
Properties:
Name | Type | Description |
---|---|---|
key |
string | |
etag |
string | |
fileSize |
number | |
bucket |
string | |
name |
string | |
url |
string |
Type:
- Object