Browse Source

add: varName

Ben 10 months ago
parent
commit
46a044aec4
6 changed files with 46 additions and 49 deletions
  1. 29 40
      js/deploy.js
  2. 4 1
      js/extract_function.js
  3. 2 2
      js/video.html
  4. 6 3
      js/video.js
  5. 1 1
      js/video_test.js
  6. 4 2
      js/webpack.config.js

+ 29 - 40
js/deploy.js

@@ -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!');
+});
+
+
+

+ 4 - 1
js/extract_function.js

@@ -14,6 +14,9 @@ extractFunction = (jsCode, regexp) => {
             if (existDependencies.includes(varName)) {
                 continue
             }
+            if (!/^[$A-Z]+$/.test(varName)) {
+                continue
+            }
             let reg = "var (\$)?" + varName + "={(.|\\n)*?};"
             const varNameMatch = jsCode.match(new RegExp(reg), 'ig');
             if (varNameMatch && varNameMatch.length >= 1) {
@@ -33,4 +36,4 @@ const result = extractFunction(fileContent.toString(), /([a-zA-Z0-9]+)=function\
 console.log(result('adoidjaijdioawjiodjaaa'))
 
 const result2 = extractFunction(fileContent.toString(), /([a-zA-Z0-9]+)=function\([a-zA-Z0-9]+\)\{var b=a\.split\(""\)[\s\S]*?};/)
-console.log(result2);
+console.log(result2("dwjaiodjaiowidwa"));

+ 2 - 2
js/index.html → js/video.html

@@ -3,7 +3,7 @@
 <head>
     <meta charset="UTF-8">
     <title>JavaScript in Browser</title>
-    <script src="info.js"></script>
-    <script src="test.js"></script>
+    <script src="video.js"></script>
+    <script src="video_test.js"></script>
 </head>
 </html>

+ 6 - 3
js/info.js → js/video.js

@@ -85,9 +85,9 @@ parseSetCookie = (headers) => {
 }
 
 request = async (method, url, data = null, headers = {}, platform) => {
-    if (platform === "WEB") {
-        url = url.replace("https://www.youtube.com", "http://127.0.0.1");
-    }
+    // if (platform === "WEB") {
+    //     url = url.replace("https://www.youtube.com", "http://127.0.0.1");
+    // }
     console.log(`request url:${url}`)
     console.log(`request data:${data}`)
     console.log(`request method:${method}`)
@@ -140,6 +140,9 @@ findFunction = (jsCode, regexp, platform) => {
             if (existDependencies.includes(varName)) {
                 continue
             }
+            if (!/^[$A-Z]+$/.test(varName)) {
+                continue
+            }
             const varNameMatch = jsCode.match(new RegExp(`var \\${varName}={(.|\\n)*?};`), 'ig');
             if (varNameMatch && varNameMatch.length >= 1) {
                 result += varNameMatch[0] + "\n";

+ 1 - 1
js/test.js → js/video_test.js

@@ -5,7 +5,7 @@ detail(`https://www.youtube.com/watch?v=bu7nU9Mhpyo`, 'WEB')
     .catch(e => {
         console.log(e);
     })
-
+//
 // search("周 杰伦", null, "WEB")
 //     .then(res => {
 //         console.log(res);

+ 4 - 2
js/webpack.config.js

@@ -5,10 +5,12 @@ const WebpackObfuscator = require('webpack-obfuscator');
 
 module.exports = {
     mode: 'production',
-    entry: './info.js',
+    entry: {
+        video: './video.js',
+    },
     output: {
         path: path.resolve(__dirname),
-        filename: `bundle.js`,
+        filename: '[name].bundle.js',
     },
 
     optimization: {