-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add progress, remove wallet configs, better list (#12)
- Loading branch information
Showing
11 changed files
with
288 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,3 @@ bin | |
|
||
.yarn | ||
|
||
# wallets and such | ||
wallet.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "dria-cli", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A command-line tool for Dria", | ||
"author": "FirstBatch Team <[email protected]>", | ||
"contributors": [ | ||
|
@@ -23,19 +23,22 @@ | |
"dria": "yarn build && yarn start", | ||
"test": "npx jest" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"dependencies": { | ||
"adm-zip": "^0.5.10", | ||
"axios": "^1.6.7", | ||
"dockerode": "^4.0.2", | ||
"loglevel": "^1.9.1", | ||
"unzipper": "^0.10.14", | ||
"yargs": "^17.7.2" | ||
}, | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"@types/adm-zip": "^0", | ||
"@types/dockerode": "^3.3.23", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.11.16", | ||
"@types/unzipper": "^0", | ||
"@types/yargs": "^17.0.32", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
"@typescript-eslint/parser": "^6.21.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,60 @@ | ||
import axios from "axios"; | ||
import AdmZip from "adm-zip"; | ||
import Axios from "axios"; | ||
import unzipper from "unzipper"; | ||
import constants from "../constants"; | ||
import { logger } from "."; | ||
import { createReadStream, createWriteStream, rmSync } from "fs"; | ||
|
||
/** Download a zipped data from Arweave, unzip & extract it at a given path. | ||
* | ||
* Uses streaming to write request to tmp disk, and then to target folder due to large size. | ||
* | ||
* @param txid txID on Arweave | ||
* @param outDir output directory for the extraction file | ||
*/ | ||
export async function downloadAndUnzip(contractId: string, outDir: string) { | ||
const url = `${constants.ARWEAVE.DOWNLOAD_URL}/${contractId}`; | ||
|
||
logger.debug("Downloading..."); | ||
const response = await axios.get<Buffer>(url, { | ||
logger.info("Downloading from", url); | ||
|
||
// download the file using a stream (due to large size) | ||
const tmpPath = `/tmp/${contractId}.zip`; | ||
const writer = createWriteStream(tmpPath); | ||
await Axios({ | ||
url, | ||
method: "get", | ||
timeout: constants.ARWEAVE.DOWNLOAD_TIMEOUT, | ||
responseType: "arraybuffer", | ||
responseType: "stream", | ||
// show download progress here | ||
onDownloadProgress(progressEvent) { | ||
if (progressEvent.total) { | ||
const percentCompleted = ((progressEvent.loaded / progressEvent.total) * 100).toFixed(2); | ||
logger.info(`Progress: ${percentCompleted}%`); | ||
} | ||
}, | ||
}).then((response) => { | ||
return new Promise((resolve, reject) => { | ||
response.data.pipe(writer); | ||
|
||
let error: Error | null = null; | ||
|
||
writer.on("error", (err) => { | ||
error = err; | ||
writer.close(); | ||
reject(err); | ||
}); | ||
|
||
writer.on("close", () => { | ||
if (!error) resolve(true); | ||
// if error, we've rejected above | ||
}); | ||
}); | ||
}); | ||
if (response.status !== 200) { | ||
throw new Error(`Arweave Download failed with ${response.status}`); | ||
} | ||
logger.debug(`${response.data.length} bytes downloaded.`); | ||
|
||
const zip = new AdmZip(response.data); | ||
zip.extractAllTo(outDir, true); // overwrite existing data at path | ||
// unzip to correct folder | ||
// TODO: connecting axios stream to unzipper could work, but couldnt solve it yet | ||
createReadStream(tmpPath).pipe(unzipper.Extract({ path: outDir })); | ||
logger.info("Knowledge extracted at", outDir); | ||
|
||
// cleanup temporary zip | ||
rmSync(tmpPath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.