Skip to content

Commit ee834c6

Browse files
fix: sf images list and sf images upload 400 errors by passing workspace param (#260)
Co-authored-by: Daniel Tao <danieltaox@gmail.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 41f4aa2 commit ee834c6

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/lib/images/list.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ora from "ora";
66
import { apiClient } from "../../apiClient.ts";
77
import { logAndQuit } from "../../helpers/errors.ts";
88
import { formatDate } from "../../helpers/format-time.ts";
9+
import { getDefaultWorkspace } from "./utils.ts";
910

1011
const list = new Command("list")
1112
.alias("ls")
@@ -28,9 +29,12 @@ Examples:\n
2829
)
2930
.action(async (options) => {
3031
const client = await apiClient();
32+
const workspace = await getDefaultWorkspace();
3133

3234
const spinner = ora("Fetching images...").start();
33-
const { data: result, response } = await client.GET("/v2/images");
35+
const { data: result, response } = await client.GET("/v2/images", {
36+
params: { query: { workspace } },
37+
});
3438
spinner.stop();
3539

3640
if (!response.ok || !result) {

src/lib/images/upload.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import cliSpinners from "cli-spinners";
1212
import ora, { type Ora } from "ora";
1313
import { getAuthToken, loadConfig } from "../../helpers/config.ts";
1414
import { logAndQuit } from "../../helpers/errors.ts";
15+
import { getDefaultWorkspace } from "./utils.ts";
1516

1617
async function readChunk(
1718
filePath: string,
@@ -84,11 +85,13 @@ const upload = new Command("upload")
8485

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

88+
const workspace = await getDefaultWorkspace();
89+
8790
// Create image via v2 API
8891
const startResponse = await fetch(`${config.api_url}/v2/images`, {
8992
method: "POST",
9093
headers: apiHeaders,
91-
body: JSON.stringify({ name }),
94+
body: JSON.stringify({ name, workspace }),
9295
});
9396

9497
if (!startResponse.ok) {

src/lib/images/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { apiClient } from "../../apiClient.ts";
2+
import { loadConfig, saveConfig } from "../../helpers/config.ts";
3+
4+
export async function getDefaultWorkspace(): Promise<string> {
5+
const config = await loadConfig();
6+
let accountId = config.account_id;
7+
if (!accountId) {
8+
const client = await apiClient();
9+
const { data } = await client.GET("/v0/me");
10+
if (data?.id) {
11+
await saveConfig({ ...config, account_id: data.id });
12+
accountId = data.id;
13+
} else {
14+
throw new Error("Could not determine account ID. Run 'sf login' first.");
15+
}
16+
}
17+
return `sfc:workspace:${accountId}:default`;
18+
}

src/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,8 @@ export interface components {
24142414
};
24152415
vmorch_StartUploadRequest: {
24162416
name: components["schemas"]["vmorch_Name"];
2417+
/** @description Workspace URN (e.g. sfc:workspace:{account_id}:default). */
2418+
workspace?: string;
24172419
};
24182420
/**
24192421
* Format: int64
@@ -4988,6 +4990,8 @@ export interface operations {
49884990
starting_after?: components["schemas"]["vmorch_ImagesCursor"];
49894991
/** @description Cursor for backward pagination. */
49904992
ending_before?: components["schemas"]["vmorch_ImagesCursor"];
4993+
/** @description Workspace URN (e.g. sfc:workspace:{account_id}:default). */
4994+
workspace?: string;
49914995
};
49924996
header?: never;
49934997
path?: never;

0 commit comments

Comments
 (0)