puter-cli 1.7.1 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/commands/apps.js +8 -1
- package/src/commands/files.js +57 -26
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,20 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### [v1.7.3](https://github.com/HeyPuter/puter-cli/compare/v1.7.2...v1.7.3)
|
|
8
|
+
|
|
9
|
+
- fix: absolute remote path treated as relative in update #10 [`cb716a3`](https://github.com/HeyPuter/puter-cli/commit/cb716a37afdd9f552c53244a3eb63d7a649e244c)
|
|
10
|
+
|
|
11
|
+
#### [v1.7.2](https://github.com/HeyPuter/puter-cli/compare/v1.7.1...v1.7.2)
|
|
12
|
+
|
|
13
|
+
> 4 March 2025
|
|
14
|
+
|
|
15
|
+
- fix: mv command for both rename/move files [`0b944c8`](https://github.com/HeyPuter/puter-cli/commit/0b944c8295f615427bd90d19a6058b2053c1b3dc)
|
|
16
|
+
|
|
7
17
|
#### [v1.7.1](https://github.com/HeyPuter/puter-cli/compare/v1.7.0...v1.7.1)
|
|
8
18
|
|
|
19
|
+
> 4 March 2025
|
|
20
|
+
|
|
9
21
|
- fix: update command [`38ca9e8`](https://github.com/HeyPuter/puter-cli/commit/38ca9e824642cbf8b1ffdb0d2a6e5426f84c7371)
|
|
10
22
|
- docs: update README [`6e658f6`](https://github.com/HeyPuter/puter-cli/commit/6e658f6a117ee1ba206768905d53fb61c78e136d)
|
|
11
23
|
|
package/package.json
CHANGED
package/src/commands/apps.js
CHANGED
|
@@ -284,7 +284,14 @@ export async function updateApp(args = []) {
|
|
|
284
284
|
return;
|
|
285
285
|
}
|
|
286
286
|
const name = args[0]; // App name (required)
|
|
287
|
-
|
|
287
|
+
// Fix: Properly handle absolute paths by checking if the path starts with '/'
|
|
288
|
+
let remoteDir;
|
|
289
|
+
if (args[1] && args[1].startsWith('/')) {
|
|
290
|
+
remoteDir = args[1]; // Use the absolute path as-is
|
|
291
|
+
} else {
|
|
292
|
+
remoteDir = resolvePath(getCurrentDirectory(), args[1] || '.');
|
|
293
|
+
}
|
|
294
|
+
|
|
288
295
|
const remoteDirExists = await pathExists(remoteDir);
|
|
289
296
|
|
|
290
297
|
if (!remoteDirExists){
|
package/src/commands/files.js
CHANGED
|
@@ -117,54 +117,87 @@ export async function makeDirectory(args = []) {
|
|
|
117
117
|
*/
|
|
118
118
|
export async function renameFileOrDirectory(args = []) {
|
|
119
119
|
if (args.length < 2) {
|
|
120
|
-
console.log(chalk.red('Usage: mv <
|
|
120
|
+
console.log(chalk.red('Usage: mv <source> <destination>'));
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
const newName = args[1];
|
|
124
|
+
const sourcePath = args[0].startsWith('/') ? args[0] : resolvePath(getCurrentDirectory(), args[0]);
|
|
125
|
+
const destPath = args[1].startsWith('/') ? args[1] : resolvePath(getCurrentDirectory(), args[1]);
|
|
127
126
|
|
|
128
|
-
console.log(chalk.green(`
|
|
127
|
+
console.log(chalk.green(`Moving "${sourcePath}" to "${destPath}"...\n`));
|
|
129
128
|
|
|
130
129
|
try {
|
|
131
|
-
// Step 1: Get the
|
|
130
|
+
// Step 1: Get the source file/directory info
|
|
132
131
|
const statResponse = await fetch(`${API_BASE}/stat`, {
|
|
133
132
|
method: 'POST',
|
|
134
133
|
headers: getHeaders(),
|
|
135
|
-
body: JSON.stringify({
|
|
136
|
-
path: `${currentPath}/${oldName}`
|
|
137
|
-
})
|
|
134
|
+
body: JSON.stringify({ path: sourcePath })
|
|
138
135
|
});
|
|
139
136
|
|
|
140
137
|
const statData = await statResponse.json();
|
|
141
138
|
if (!statData || !statData.uid) {
|
|
142
|
-
console.log(chalk.red(`Could not find
|
|
139
|
+
console.log(chalk.red(`Could not find source "${sourcePath}".`));
|
|
143
140
|
return;
|
|
144
141
|
}
|
|
145
142
|
|
|
146
|
-
const
|
|
143
|
+
const sourceUid = statData.uid;
|
|
144
|
+
const sourceName = statData.name;
|
|
147
145
|
|
|
148
|
-
// Step 2:
|
|
149
|
-
const
|
|
146
|
+
// Step 2: Check if destination is an existing directory
|
|
147
|
+
const destStatResponse = await fetch(`${API_BASE}/stat`, {
|
|
150
148
|
method: 'POST',
|
|
151
149
|
headers: getHeaders(),
|
|
152
|
-
body: JSON.stringify({
|
|
153
|
-
uid: uid,
|
|
154
|
-
new_name: newName
|
|
155
|
-
})
|
|
150
|
+
body: JSON.stringify({ path: destPath })
|
|
156
151
|
});
|
|
157
152
|
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
153
|
+
const destData = await destStatResponse.json();
|
|
154
|
+
|
|
155
|
+
// Determine if this is a rename or move operation
|
|
156
|
+
const isMove = destData && destData.is_dir;
|
|
157
|
+
const newName = isMove ? sourceName : path.basename(destPath);
|
|
158
|
+
const destination = isMove ? destPath : path.dirname(destPath);
|
|
159
|
+
|
|
160
|
+
if (isMove) {
|
|
161
|
+
// Move operation: use /move endpoint
|
|
162
|
+
const moveResponse = await fetch(`${API_BASE}/move`, {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
headers: getHeaders(),
|
|
165
|
+
body: JSON.stringify({
|
|
166
|
+
source: sourceUid,
|
|
167
|
+
destination: destination,
|
|
168
|
+
overwrite: false,
|
|
169
|
+
new_name: newName,
|
|
170
|
+
create_missing_parents: false,
|
|
171
|
+
new_metadata: {}
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const moveData = await moveResponse.json();
|
|
176
|
+
if (moveData && moveData.moved) {
|
|
177
|
+
console.log(chalk.green(`Successfully moved "${sourcePath}" to "${moveData.moved.path}"!`));
|
|
178
|
+
} else {
|
|
179
|
+
console.log(chalk.red('Failed to move item. Please check your input.'));
|
|
180
|
+
}
|
|
163
181
|
} else {
|
|
164
|
-
|
|
182
|
+
// Rename operation: use /rename endpoint
|
|
183
|
+
const renameResponse = await fetch(`${API_BASE}/rename`, {
|
|
184
|
+
method: 'POST',
|
|
185
|
+
headers: getHeaders(),
|
|
186
|
+
body: JSON.stringify({
|
|
187
|
+
uid: sourceUid,
|
|
188
|
+
new_name: newName
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const renameData = await renameResponse.json();
|
|
193
|
+
if (renameData && renameData.uid) {
|
|
194
|
+
console.log(chalk.green(`Successfully renamed "${sourcePath}" to "${renameData.path}"!`));
|
|
195
|
+
} else {
|
|
196
|
+
console.log(chalk.red('Failed to rename item. Please check your input.'));
|
|
197
|
+
}
|
|
165
198
|
}
|
|
166
199
|
} catch (error) {
|
|
167
|
-
console.log(chalk.red('Failed to rename item.'));
|
|
200
|
+
console.log(chalk.red('Failed to move/rename item.'));
|
|
168
201
|
console.error(chalk.red(`Error: ${error.message}`));
|
|
169
202
|
}
|
|
170
203
|
}
|
|
@@ -206,7 +239,6 @@ async function findMatchingFiles(files, pattern, basePath) {
|
|
|
206
239
|
return matchedPaths;
|
|
207
240
|
}
|
|
208
241
|
|
|
209
|
-
|
|
210
242
|
/**
|
|
211
243
|
* Find files matching the pattern in the local directory (DEPRECATED: Not used)
|
|
212
244
|
* @param {string} localDir - Local directory path.
|
|
@@ -1196,7 +1228,6 @@ async function resolveLocalDirectory(localPath) {
|
|
|
1196
1228
|
return absolutePath;
|
|
1197
1229
|
}
|
|
1198
1230
|
|
|
1199
|
-
|
|
1200
1231
|
/**
|
|
1201
1232
|
* Ensure a remote directory exists, creating it if necessary
|
|
1202
1233
|
* @param {string} remotePath - The remote directory path
|