Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions download-frp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ const downloadFile = require("./download-file")
const path = require("path")
const fs = require("fs")
const tar = require("tar")

const compressing = require("compressing")
const getJSON = bent("json", {
"User-Agent": "seveibar, frpc-bin (an npm module)",
})

const platform = os.platform()

const arch = os.arch()
let osRelease = null

switch (platform) {
case "win32":
osRelease = `windows_${arch}`
osRelease = `windows_${arch.replace("x64", "amd64").replace("x32", "386")}`
break
case "darwin":
osRelease = "darwin_amd64"
Expand Down Expand Up @@ -74,10 +75,19 @@ module.exports = async () => {
// e.g. download something like frpc-ubuntu.tar.xz

const downloadPath = path.resolve(__dirname, myAsset.name)
const extractDirPath = path.resolve(
__dirname,
myAsset.name.replace(".tar.gz", "")
)
let extractDirPath;
if(platform == "win32"){
extractDirPath = path.resolve(
__dirname,
myAsset.name.replace(".zip", "")
)
}else{
extractDirPath = path.resolve(
__dirname,
myAsset.name.replace(".tar.gz", "")
)
}

const frpcPath = path.resolve(extractDirPath, "frpc")
const frpsPath = path.resolve(extractDirPath, "frps")

Expand All @@ -101,10 +111,16 @@ module.exports = async () => {
if (!fs.existsSync(extractDirPath)) {
console.log(`extracting ${myAsset.name}...`)
let tarXPath = downloadPath
await tar.x({
file: tarXPath,
z: true,
})

if(platform == "win32"){
await compressing.zip.uncompress(`${extractDirPath}.zip`,__dirname);
}else{
await tar.x({
file: tarXPath,
z: true,
})
}

fs.unlinkSync(tarXPath)

if (!fs.existsSync(frpcPath)) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"decompress-tar": "^4.1.1",
"follow-redirects": "^1.13.0",
"tar": "^6.0.5",
"tmp": "^0.2.1"
"tmp": "^0.2.1",
"compressing": "^1.5.1"
},
"devDependencies": {
"@semantic-release/commit-analyzer": "^8.0.1",
Expand Down