Skip to content

Commit 644e3d6

Browse files
authored
Merge pull request #46 from reynaldichernando/df-space
Update df drivers call to puter.fs.space
2 parents 7ea9db0 + b47389f commit 644e3d6

File tree

1 file changed

+7
-44
lines changed

1 file changed

+7
-44
lines changed

src/commands/files.js

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,10 @@ export async function changeDirectory(args) {
468468
*/
469469
export async function getDiskUsage(body = null) {
470470
console.log(chalk.green('Fetching disk usage information...\n'));
471+
const puter = getPuter();
471472
try {
472-
const response = await fetch(`${API_BASE}/df`, {
473-
method: 'POST',
474-
headers: getHeaders(),
475-
body: body ? JSON.stringify(body) : null
476-
});
477-
478-
const data = await response.json();
479-
if (response.ok && data) {
473+
const data = await puter.fs.space();
474+
if (data) {
480475
showDiskSpaceUsage(data);
481476
} else {
482477
console.error(chalk.red('Unable to fetch disk usage information.'));
@@ -554,18 +549,7 @@ export async function createFile(args = []) {
554549
}
555550

556551
// Step 2: Check disk space
557-
const dfResponse = await fetch(`${API_BASE}/df`, {
558-
method: 'POST',
559-
headers: getHeaders(),
560-
body: null
561-
});
562-
563-
if (!dfResponse.ok) {
564-
console.error(chalk.red('Unable to check disk space.'));
565-
return false;
566-
}
567-
568-
const dfData = await dfResponse.json();
552+
const dfData = await puter.fs.space();
569553
if (dfData.used >= dfData.capacity) {
570554
console.error(chalk.red('Not enough disk space to create the file.'));
571555
showDiskSpaceUsage(dfData); // Display disk usage info
@@ -706,6 +690,7 @@ export async function uploadFile(args = []) {
706690
const overwrite = args.length > 3 ? args[3] === 'true' : false; // Default: false
707691

708692
console.log(chalk.green(`Uploading files from "${localPath}" to "${remotePath}"...\n`));
693+
const puter = getPuter();
709694
try {
710695
// Step 1: Find all matching files (excluding hidden files)
711696
const files = glob.sync(localPath, { nodir: true, dot: false });
@@ -716,18 +701,7 @@ export async function uploadFile(args = []) {
716701
}
717702

718703
// Step 2: Check disk space
719-
const dfResponse = await fetch(`${API_BASE}/df`, {
720-
method: 'POST',
721-
headers: getHeaders(),
722-
body: null
723-
});
724-
725-
if (!dfResponse.ok) {
726-
console.error(chalk.red('Unable to check disk space.'));
727-
return;
728-
}
729-
730-
const dfData = await dfResponse.json();
704+
const dfData = await puter.fs.space();
731705
if (dfData.used >= dfData.capacity) {
732706
console.error(chalk.red('Not enough disk space to upload the files.'));
733707
showDiskSpaceUsage(dfData); // Display disk usage info
@@ -1298,18 +1272,7 @@ export async function editFile(args = []) {
12981272

12991273
// Step 7: Upload the updated file content
13001274
// Step 7.1: Check disk space
1301-
const dfResponse = await fetch(`${API_BASE}/df`, {
1302-
method: 'POST',
1303-
headers: getHeaders(),
1304-
body: null
1305-
});
1306-
1307-
if (!dfResponse.ok) {
1308-
console.log(chalk.red('Unable to check disk space.'));
1309-
return;
1310-
}
1311-
1312-
const dfData = await dfResponse.json();
1275+
const dfData = await puter.fs.space();
13131276
if (dfData.used >= dfData.capacity) {
13141277
console.log(chalk.red('Not enough disk space to upload the file.'));
13151278
showDiskSpaceUsage(dfData); // Display disk usage info

0 commit comments

Comments
 (0)