Skip to content

Commit 2da679a

Browse files
committed
feat: add move file method
1 parent 73c92c2 commit 2da679a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.changeset/rotten-rocks-agree.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@squarecloud/api": minor
3+
---
4+
5+
New `Application#files#move` for moving or renaming files

src/managers/application/files.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export class ApplicationFilesManager {
5252
*/
5353
async create(file: string | Buffer, fileName: string, path = "/") {
5454
assertPathLike(file, "CREATE_FILE");
55+
assertString(fileName, "CREATE_FILE_NAME");
56+
assertString(path, "CREATE_FILE_PATH");
5557

5658
if (typeof file === "string") {
5759
file = await readFile(file);
@@ -77,9 +79,30 @@ export class ApplicationFilesManager {
7779
* @param path - The absolute file path
7880
*/
7981
async edit(file: string | Buffer, path = "/") {
82+
assertPathLike(file, "EDIT_FILE");
83+
assertString(path, "EDIT_FILE_PATH");
84+
8085
return this.create(file, "", path);
8186
}
8287

88+
/**
89+
* Moves or renames a file
90+
*
91+
* @param path - The current absolute file path
92+
* @param newPath - The new absolute file path
93+
*/
94+
async move(path: string, newPath: string) {
95+
assertString(path, "MOVE_FILE_PATH");
96+
assertString(newPath, "MOVE_FILE_NEW_PATH");
97+
98+
const { status } = await this.application.client.api.request(
99+
Routes.apps.files.move(this.application.id),
100+
{ method: "PATCH", body: { path, to: newPath } },
101+
);
102+
103+
return status === "success";
104+
}
105+
83106
/**
84107
* Deletes the specified file or directory
85108
*

0 commit comments

Comments
 (0)