Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/lib/images/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ora from "ora";
import { apiClient } from "../../apiClient.ts";
import { logAndQuit } from "../../helpers/errors.ts";
import { formatDate } from "../../helpers/format-time.ts";
import { getDefaultWorkspace } from "./utils.ts";

const list = new Command("list")
.alias("ls")
Expand All @@ -28,9 +29,12 @@ Examples:\n
)
.action(async (options) => {
const client = await apiClient();
const workspace = await getDefaultWorkspace();

const spinner = ora("Fetching images...").start();
const { data: result, response } = await client.GET("/v2/images");
const { data: result, response } = await client.GET("/v2/images", {
params: { query: { workspace } },
});
spinner.stop();

if (!response.ok || !result) {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/images/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import cliSpinners from "cli-spinners";
import ora, { type Ora } from "ora";
import { getAuthToken, loadConfig } from "../../helpers/config.ts";
import { logAndQuit } from "../../helpers/errors.ts";
import { getDefaultWorkspace } from "./utils.ts";

async function readChunk(
filePath: string,
Expand Down Expand Up @@ -84,11 +85,13 @@ const upload = new Command("upload")

preparingSpinner = ora(`Preparing upload for ${name}...`).start();

const workspace = await getDefaultWorkspace();

// Create image via v2 API
const startResponse = await fetch(`${config.api_url}/v2/images`, {
method: "POST",
headers: apiHeaders,
body: JSON.stringify({ name }),
body: JSON.stringify({ name, workspace }),
});

if (!startResponse.ok) {
Expand Down
18 changes: 18 additions & 0 deletions src/lib/images/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { apiClient } from "../../apiClient.ts";
import { loadConfig, saveConfig } from "../../helpers/config.ts";

export async function getDefaultWorkspace(): Promise<string> {
const config = await loadConfig();
let accountId = config.account_id;
if (!accountId) {
const client = await apiClient();
const { data } = await client.GET("/v0/me");
if (data?.id) {
await saveConfig({ ...config, account_id: data.id });
accountId = data.id;
} else {
throw new Error("Could not determine account ID. Run 'sf login' first.");
}
}
return `sfc:workspace:${accountId}:default`;
}
4 changes: 4 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,8 @@ export interface components {
};
vmorch_StartUploadRequest: {
name: components["schemas"]["vmorch_Name"];
/** @description Workspace URN (e.g. sfc:workspace:{account_id}:default). */
workspace?: string;
};
/**
* Format: int64
Expand Down Expand Up @@ -4988,6 +4990,8 @@ export interface operations {
starting_after?: components["schemas"]["vmorch_ImagesCursor"];
/** @description Cursor for backward pagination. */
ending_before?: components["schemas"]["vmorch_ImagesCursor"];
/** @description Workspace URN (e.g. sfc:workspace:{account_id}:default). */
workspace?: string;
};
header?: never;
path?: never;
Expand Down
Loading