|
@@ -11,43 +11,32 @@ AWS.config.update({
|
|
|
const s3 = new AWS.S3();
|
|
|
|
|
|
const bucketName = 'justlistenmusic4560.com';
|
|
|
-const filePath = 'bundle.js';
|
|
|
-const destinationPath = `${uuid.v4()}`;
|
|
|
-
|
|
|
-const fileContent = fs.readFileSync(filePath);
|
|
|
-
|
|
|
-const params = {
|
|
|
- Bucket: bucketName,
|
|
|
- Key: destinationPath,
|
|
|
- Body: fileContent,
|
|
|
-};
|
|
|
-
|
|
|
-s3.upload(params)
|
|
|
- .promise()
|
|
|
- .then(data => {
|
|
|
- console.log('File uploaded successfully. Location:', Object.assign({
|
|
|
- "Location2": data.Location.replace("https://s3.amazonaws.com/justlistenmusic4560.com", "https://d3crpuooyqht8f.cloudfront.net")
|
|
|
- }, data));
|
|
|
- // const cloudfront = new AWS.CloudFront();
|
|
|
- // const params = {
|
|
|
- // DistributionId: 'E1OARMP9V91HD1',
|
|
|
- // InvalidationBatch: {
|
|
|
- // CallerReference: Date.now().toString(),
|
|
|
- // Paths: {
|
|
|
- // Quantity: 1,
|
|
|
- // Items: ['/*'],
|
|
|
- // },
|
|
|
- // },
|
|
|
- // };
|
|
|
- // cloudfront.createInvalidation(params)
|
|
|
- // .promise()
|
|
|
- // .then(data => {
|
|
|
- // console.log('CloudFront cache has been successfully refreshed.', data);
|
|
|
- // })
|
|
|
- // .catch(err => {
|
|
|
- // console.error('Error refreshing CloudFront cache:', err);
|
|
|
- // });
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- console.error('Error uploading file:', err);
|
|
|
- });
|
|
|
+
|
|
|
+async function upload(filePath) {
|
|
|
+ const fileContent = fs.readFileSync(filePath);
|
|
|
+ const params = {
|
|
|
+ Bucket: bucketName,
|
|
|
+ Key: `${uuid.v4()}`,
|
|
|
+ Body: fileContent,
|
|
|
+ };
|
|
|
+ return s3.upload(params)
|
|
|
+ .promise()
|
|
|
+ .then(data => {
|
|
|
+ console.log(`${filePath} upload success:
|
|
|
+ ${data.Location.replace("https://s3.amazonaws.com/justlistenmusic4560.com",
|
|
|
+ "https://d3crpuooyqht8f.cloudfront.net")}`)
|
|
|
+ return data
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.error('Error uploading file:', err);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+Promise.all(
|
|
|
+ [upload('video.bundle.js')]
|
|
|
+).then(() => {
|
|
|
+ console.log('All files uploaded successfully!');
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
+
|