Mass Implement of basic features

This commit is contained in:
Space-Banane
2026-03-18 17:02:30 +01:00
parent 9aec36d0e8
commit f8730b2044
22 changed files with 925 additions and 17 deletions
+20
View File
@@ -14,8 +14,26 @@ export const createFunctionDefinition = {
{ name: "--docker-mount", description: "Enable Docker mount", type: "boolean" },
{ name: "--ffmpeg-install", description: "Install ffmpeg in container", type: "boolean" },
{ name: "--imported", description: "Marks the function as imported", type: "boolean" },
{ name: "--cache-enabled <enabled>", description: "Enable response caching (true/false)" },
{ name: "--cache-ttl <seconds>", description: "Cache TTL in seconds" },
],
action: async (options: any) => {
let parsedCacheEnabled: boolean | undefined;
if (options.cacheEnabled !== undefined) {
const normalized = String(options.cacheEnabled).toLowerCase();
if (normalized !== "true" && normalized !== "false") {
console.error(`${chalk.red("✗")} Invalid value for --cache-enabled. Use true or false.`);
return;
}
parsedCacheEnabled = normalized === "true";
}
const parsedCacheTtl = options.cacheTtl !== undefined ? Number(options.cacheTtl) : undefined;
if (parsedCacheTtl !== undefined && Number.isNaN(parsedCacheTtl)) {
console.error(`${chalk.red("✗")} Invalid value for --cache-ttl. Please provide a number.`);
return;
}
const data = {
name: options.name,
description: options.description,
@@ -26,6 +44,8 @@ export const createFunctionDefinition = {
docker_mount: !!options.dockerMount,
ffmpeg_install: !!options.ffmpegInstall,
imported: !!options.imported,
cache_enabled: parsedCacheEnabled,
cache_ttl: parsedCacheTtl,
};
const client = await getApiClient();
+41
View File
@@ -0,0 +1,41 @@
import chalk from "chalk";
import { getApiClient } from "../../api.js";
export const createNamespaceDefinition = {
name: "namespace",
description: "Create a new namespace.",
options: [
{ name: "--name <name>", description: "Namespace name", required: true },
{ name: "--description <description>", description: "Namespace description", required: true },
],
action: async (options: any) => {
const data = {
name: options.name,
description: options.description,
};
const client = await getApiClient();
try {
const response = await client.post("/api/namespaces", data);
if (response.status === 200 || response.status === 201) {
console.log(
`${chalk.green("✓")} Namespace ${chalk.cyan(data.name)} created successfully! ID: ${chalk.bgGreen.black(` ${response.data.data.id} `)}`,
);
} else {
console.log(
`${chalk.yellow("!")} Unexpected response from server: ${response.status}`,
);
}
} catch (error: any) {
if (error.response) {
console.error(
`${chalk.red("✗")} Failed to create namespace: ${chalk.yellow(error.response.data.message || "Unknown error")}`,
);
} else {
console.error(`${chalk.red("✗")} Error: ${error.message}`);
}
}
},
};
+44
View File
@@ -0,0 +1,44 @@
import chalk from "chalk";
import { getApiClient } from "../../api.js";
export const createTriggerDefinition = {
name: "trigger",
description: "Create a new trigger for a function.",
options: [
{ name: "--function-id <id>", description: "The ID of the function to add the trigger to", required: true },
{ name: "--name <name>", description: "Trigger name", required: true },
{ name: "--description <description>", description: "Trigger description", required: true },
],
action: async (options: any) => {
const { functionId, name, description } = options;
const data = {
name,
description,
};
const client = await getApiClient();
try {
const response = await client.post(`/api/functions/${functionId}/triggers`, data);
if (response.status === 200 || response.status === 201) {
console.log(
`${chalk.green("✓")} Trigger ${chalk.cyan(name)} created successfully for function ID ${chalk.cyan(functionId)}! ID: ${chalk.bgGreen.black(` ${response.data.data.id} `)}`,
);
} else {
console.log(
`${chalk.yellow("!")} Unexpected response from server: ${response.status}`,
);
}
} catch (error: any) {
if (error.response) {
console.error(
`${chalk.red("✗")} Failed to create trigger: ${chalk.yellow(error.response.data.message || "Unknown error")}`,
);
} else {
console.error(`${chalk.red("✗")} Error: ${error.message}`);
}
}
},
};