Skip to content

Commit

Permalink
feat: upload build
Browse files Browse the repository at this point in the history
  • Loading branch information
lecepin committed Mar 7, 2024
1 parent a8dfb82 commit 1283b23
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
"foreman": "^3.0.1",
"less": "^3.10.3",
"less-loader": "^5.0.0",
"webpack-cli": "^3.3.11"
"webpack-cli": "^3.3.11",
"axios": "^1.6.7",
"form-data": "^4.0.0"
},
"babel": {},
"build": {
Expand Down
54 changes: 54 additions & 0 deletions scripts/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const axios = require("axios");
const FormData = require("form-data");
const fs = require("fs");
const path = require("path");

const packsDir = path.join(__dirname, "../packs");
let dmgFile = null;

try {
const files = fs.readdirSync(packsDir);
for (let file of files) {
if (path.extname(file).toLowerCase() === ".dmg") {
dmgFile = path.join(packsDir, file);
break;
}
}
} catch (error) {
console.error("Error reading the packs directory", error.message);
process.exit(1);
}

if (!dmgFile) {
console.log("No .dmg file found in packs directory.");
process.exit(1);
}

if (dmgFile) {
const form = new FormData();
form.append("fileToUpload", fs.createReadStream(dmgFile));

const config = {
headers: {
...form.getHeaders(),
},
onUploadProgress: (progressEvent) => {
let percentCompleted = Math.round(
(progressEvent.loaded * 100) / progressEvent.total
);
console.log(`${percentCompleted}% completed`);
},
};

axios
.post("http://u.leping.fun/upload", form, config)
.then((response) => {
console.log("File uploaded successfully", response.data);
})
.catch((error) => {
console.error(
"Error uploading file",
error.response ? error.response.data : error.message
);
});
}

0 comments on commit 1283b23

Please sign in to comment.