2 Commits

Author SHA1 Message Date
Space-Banane 7b659b1ef5 version-bump: commit of shame 2026-03-27 16:36:48 +01:00
Space-Banane 3261cc1830 unslopped file operations 2026-03-27 16:35:43 +01:00
6 changed files with 59 additions and 92 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "shsf-cli",
"version": "2.1.9",
"version": "2.2.0",
"description": "",
"type": "module",
"files": [
+8 -8
View File
@@ -4,10 +4,10 @@ import { getApiClient } from "../../api.js";
export const fileCreateDefinition = {
name: "create",
description: "Create a file in a storage.",
description: "Create or update a file in a function.",
options: [
{ name: "--storage-id <id>", description: "Storage ID", required: true },
{ name: "--path <path>", description: "Remote file path", required: true },
{ name: "--function-id <id>", description: "Function ID", required: true },
{ name: "--filename <name>", description: "Remote filename", required: true },
{ name: "--content <content>", description: "Inline file content" },
{ name: "--source <source>", description: "Local source file path" },
],
@@ -34,16 +34,16 @@ export const fileCreateDefinition = {
const client = await getApiClient();
const payload = {
path: options.path,
content,
filename: options.filename,
code: content,
};
try {
const response = await client.post(`/api/storage/${options.storageId}/files`, payload);
const response = await client.put(`/api/function/${options.functionId}/file`, payload);
if (response.status === 200 || response.status === 201) {
console.log(
`${chalk.green("✓")} File ${chalk.cyan(options.path)} created successfully in storage ${chalk.cyan(options.storageId)}.`,
`${chalk.green("✓")} File ${chalk.cyan(options.filename)} created/updated successfully in function ${chalk.cyan(options.functionId)}.`,
);
} else {
console.log(`${chalk.yellow("!")} Unexpected response from server: ${response.status}`);
@@ -51,7 +51,7 @@ export const fileCreateDefinition = {
} catch (error: any) {
if (error.response) {
console.error(
`${chalk.red("✗")} Failed to create file: ${chalk.yellow(error.response.data?.message || "Unknown error")}`,
`${chalk.red("✗")} Failed to create/update file: ${chalk.yellow(error.response.data?.message || "Unknown error")}`,
);
} else if (error.request) {
console.error(`${chalk.red("✗")} No response received from server.`);
+6 -8
View File
@@ -3,22 +3,20 @@ import { getApiClient } from "../../api.js";
export const fileDeleteDefinition = {
name: "delete",
description: "Delete a file from a storage.",
description: "Delete a file from a function.",
options: [
{ name: "--storage-id <id>", description: "Storage ID", required: true },
{ name: "--path <path>", description: "Remote file path", required: true },
{ name: "--function-id <id>", description: "Function ID", required: true },
{ name: "--file-id <id>", description: "File ID (from 'file list')", required: true },
],
action: async (options: any) => {
const client = await getApiClient();
try {
const response = await client.delete(`/api/storage/${options.storageId}/files`, {
data: { path: options.path },
});
const response = await client.delete(`/api/function/${options.functionId}/file/${options.fileId}`);
if (response.status === 200) {
console.log(
`${chalk.green("✓")} File ${chalk.cyan(options.path)} deleted from storage ${chalk.cyan(options.storageId)}.`,
`${chalk.green("✓")} File ${chalk.cyan(options.fileId)} deleted from function ${chalk.cyan(options.functionId)}.`,
);
} else {
console.log(`${chalk.yellow("!")} Unexpected response from server: ${response.status}`);
@@ -26,7 +24,7 @@ export const fileDeleteDefinition = {
} catch (error: any) {
if (error.response) {
if (error.response.status === 404) {
console.error(`${chalk.red("✗")} File ${chalk.yellow(options.path)} not found.`);
console.error(`${chalk.red("✗")} File or Function not found.`);
} else {
console.error(
`${chalk.red("✗")} Failed to delete file: ${chalk.yellow(error.response.data?.message || "Unknown error")}`,
+5 -8
View File
@@ -3,18 +3,15 @@ import { getApiClient } from "../../api.js";
export const fileListDefinition = {
name: "list",
description: "List files in a storage.",
description: "List files in a function.",
options: [
{ name: "--storage-id <id>", description: "Storage ID", required: true },
{ name: "--prefix <prefix>", description: "Optional path prefix filter" },
{ name: "--function-id <id>", description: "Function ID", required: true },
],
action: async (options: any) => {
const client = await getApiClient();
try {
const response = await client.get(`/api/storage/${options.storageId}/files`, {
params: options.prefix ? { prefix: options.prefix } : undefined,
});
const response = await client.get(`/api/function/${options.functionId}/files`);
if (response.status === 200 && response.data.data) {
const files = response.data.data;
@@ -25,9 +22,9 @@ export const fileListDefinition = {
}
console.log(chalk.blue("Files:"));
console.log(chalk.gray(`${"ID".padEnd(25)} ${"Filename"}`));
files.forEach((file: any) => {
const path = file.path || file.name || "(unknown)";
console.log(`- ${chalk.cyan(path)}`);
console.log(`${chalk.cyan(file.id.padEnd(25))} ${chalk.white(file.filename)}`);
});
console.log(`\n${chalk.green("✓")} Found ${chalk.bgGreen.black(` ${files.length} `)} files.`);
} else {
-67
View File
@@ -1,67 +0,0 @@
import chalk from "chalk";
import fs from "fs/promises";
import { getApiClient } from "../../api.js";
export const fileOverwriteDefinition = {
name: "overwrite",
description: "Overwrite an existing file in a storage.",
options: [
{ name: "--storage-id <id>", description: "Storage ID", required: true },
{ name: "--path <path>", description: "Remote file path", required: true },
{ name: "--content <content>", description: "Inline file content" },
{ name: "--source <source>", description: "Local source file path" },
],
action: async (options: any) => {
if (!options.content && !options.source) {
console.error(`${chalk.red("✗")} You must provide either --content or --source.`);
return;
}
if (options.content && options.source) {
console.error(`${chalk.red("✗")} Please provide only one of --content or --source.`);
return;
}
let content = options.content;
if (options.source) {
try {
content = await fs.readFile(options.source, "utf8");
} catch (error: any) {
console.error(`${chalk.red("✗")} Failed to read source file: ${chalk.yellow(error.message)}`);
return;
}
}
const client = await getApiClient();
const payload = {
path: options.path,
content,
};
try {
const response = await client.put(`/api/storage/${options.storageId}/files`, payload);
if (response.status === 200) {
console.log(
`${chalk.green("✓")} File ${chalk.cyan(options.path)} overwritten successfully in storage ${chalk.cyan(options.storageId)}.`,
);
} else {
console.log(`${chalk.yellow("!")} Unexpected response from server: ${response.status}`);
}
} catch (error: any) {
if (error.response) {
if (error.response.status === 404) {
console.error(`${chalk.red("✗")} File ${chalk.yellow(options.path)} not found.`);
} else {
console.error(
`${chalk.red("✗")} Failed to overwrite file: ${chalk.yellow(error.response.data?.message || "Unknown error")}`,
);
}
} else if (error.request) {
console.error(`${chalk.red("✗")} No response received from server.`);
} else {
console.error(`${chalk.red("✗")} Error: ${error.message}`);
}
}
},
};
+39
View File
@@ -0,0 +1,39 @@
import chalk from "chalk";
import { getApiClient } from "../../api.js";
export const fileRenameDefinition = {
name: "rename",
description: "Rename a file in a function.",
options: [
{ name: "--function-id <id>", description: "Function ID", required: true },
{ name: "--file-id <id>", description: "File ID", required: true },
{ name: "--new-filename <name>", description: "New filename", required: true },
],
action: async (options: any) => {
const client = await getApiClient();
try {
const response = await client.patch(`/api/function/${options.functionId}/file/${options.fileId}/rename`, {
newFilename: options.newFilename,
});
if (response.status === 200) {
console.log(
`${chalk.green("✓")} File ${chalk.cyan(options.fileId)} renamed to ${chalk.cyan(options.newFilename)} successfully.`,
);
} else {
console.log(`${chalk.yellow("!")} Unexpected response from server: ${response.status}`);
}
} catch (error: any) {
if (error.response) {
console.error(
`${chalk.red("✗")} Failed to rename file: ${chalk.yellow(error.response.data?.message || "Unknown error")}`,
);
} else if (error.request) {
console.error(`${chalk.red("✗")} No response received from server.`);
} else {
console.error(`${chalk.red("✗")} Error: ${error.message}`);
}
}
},
};