@wildberries/service-cdn-uploader
Advanced tools
Comparing version 2.0.6 to 3.0.0-beta.1
52
index.js
@@ -21,3 +21,3 @@ /* eslint-disable import/no-unresolved */ | ||
const renderGoAuth = process.env.CDN_API_TOKEN; | ||
const renderGoAuth = process.env.CDN_API_TOKEN_BASE_64; | ||
const CI_COMMIT_TAG = process.env.CI_COMMIT_TAG; | ||
@@ -64,45 +64,34 @@ const APP_STATIC_NAMESPACE = process.env.APP_STATIC_NAMESPACE; | ||
const fetchFile = async params => { | ||
const { | ||
staticPath, | ||
renderGoUrl, | ||
file, | ||
filePath, | ||
requestId, | ||
tryNumber, | ||
} = params; | ||
const fetchFile = async ({ | ||
renderGoUrl, | ||
file, | ||
filePath, | ||
requestId, | ||
tryNumber, | ||
}) => { | ||
try { | ||
console.log( | ||
`File ${filePath} start uploading: try ${tryNumber}, Request_Id: ${ | ||
params.requestId | ||
}, timestamp: ${new Date().toISOString()}`.yellow, | ||
`File ${filePath} start uploading: try ${tryNumber}, Request_Id: ${requestId}, timestamp: ${new Date().toISOString()}` | ||
.yellow, | ||
); | ||
const formData = new FormData(); | ||
const task = { | ||
request_id: requestId, | ||
expires: '2050-07-12T14:14:18Z', | ||
export: [{ target: BUCKET, key: staticPath }], | ||
}; | ||
formData.append('file', fs.createReadStream(file)); | ||
formData.append('task', JSON.stringify(task)); | ||
const uploadResponse = await fetch(renderGoUrl, { | ||
const uploadResponse = await fetch(`${renderGoUrl}/${newStaticPath}`, { | ||
method: 'POST', | ||
body: formData, | ||
headers: { | ||
Authorization: `bearer ${renderGoAuth}`, | ||
Authorization: `Basic ${renderGoAuth}`, | ||
}, | ||
}); | ||
}).then(data => data.json()); | ||
if (uploadResponse.status !== 200) { | ||
throw new Error(`Status code – ${uploadResponse.status}`.red); | ||
if (uploadResponse.state !== 0) { | ||
throw new Error(`Status code – ${uploadResponse.state}`.red); | ||
} | ||
console.log( | ||
`File ${filePath} start downloading: try ${tryNumber}, Request_Id: ${ | ||
params.requestId | ||
}, timestamp: ${new Date().toISOString()}`.yellow, | ||
`File ${filePath} start downloading: try ${tryNumber}, Request_Id: ${requestId}, timestamp: ${new Date().toISOString()}` | ||
.yellow, | ||
); | ||
@@ -119,5 +108,4 @@ | ||
console.log( | ||
`File ${filePath} uploaded - try ${tryNumber}, Request_Id: ${ | ||
params.requestId | ||
}, timestamp: ${new Date().toISOString()}`.green, | ||
`File ${filePath} uploaded - try ${tryNumber}, Request_Id: ${requestId}, timestamp: ${new Date().toISOString()}` | ||
.green, | ||
); | ||
@@ -179,4 +167,2 @@ } catch (error) { | ||
renderGoUrl: SERVICE_URL, | ||
fileName: file.replace(`${pathToStaticFolder}`, ''), | ||
staticPath, | ||
filePath: `${WB_STATIC_URL}/${staticPath}`, | ||
@@ -183,0 +169,0 @@ requestId, |
{ | ||
"name": "@wildberries/service-cdn-uploader", | ||
"version": "2.0.6", | ||
"version": "3.0.0-beta.1", | ||
"main": "./index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
7590
152
2