Fix media post failure by reading the real presigned-url response shape
Image and video posts failed at the presigned-url step: the reader looked
for the upload slot under data keys files/urls/attachments/presignedUrls but
Minnect returns it under `uploads` ({ data: { uploads: [{ attachmentId,
presignedUrl, s3Key, index }] } }), so no slot was found and every media
post returned post_failed.
Read the `uploads` key (under data or at the root), add per-step pipeline
logging that names the failing step with its status and message (never a
token, URL or bytes), and add a regression test for the real response shape.
This commit is contained in:
@@ -100,6 +100,32 @@ describe("POST /api/posts (image)", () => {
|
||||
expect(calls.filter((c) => c.url.includes("/api/v1/")).every((c) => c.auth === "Bearer T")).toBe(true);
|
||||
});
|
||||
|
||||
it("reads the real { data: { uploads: [{ presignedUrl, ... }] } } shape", async () => {
|
||||
const sid = session();
|
||||
const calls: { url: string; method: string }[] = [];
|
||||
const fn = vi.fn(async (url: string | URL, init?: RequestInit) => {
|
||||
const u = String(url);
|
||||
calls.push({ url: u, method: String(init?.method ?? "GET") });
|
||||
if (u.endsWith("/api/v1/posts")) return jsonRes({ data: { id: "p9", status: "draft" } }, 201);
|
||||
if (u.endsWith("/attachments/presigned-urls"))
|
||||
return jsonRes(
|
||||
{ data: { uploads: [{ attachmentId: "a1", presignedUrl: "https://s3.example/put?sig=9", s3Key: "k/1.jpg", index: 0 }] } },
|
||||
200,
|
||||
);
|
||||
if (u === "https://s3.example/put?sig=9") return new Response(null, { status: 200 });
|
||||
if (u.endsWith("/attachments/confirm-uploads")) return jsonRes({ data: { success: true } }, 200);
|
||||
if (u.includes("/publish")) return jsonRes({ data: { success: true } }, 200);
|
||||
return new Response("{}", { status: 404 });
|
||||
});
|
||||
const res = await withFetch(fn as unknown as typeof fetch, () =>
|
||||
POST(multipart("look", imageFile(), sid)),
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.json()).toEqual({ id: "p9" });
|
||||
const put = calls.find((c) => c.method === "PUT");
|
||||
expect(put?.url).toBe("https://s3.example/put?sig=9");
|
||||
});
|
||||
|
||||
it("never returns the feed token to the browser", async () => {
|
||||
const sid = session();
|
||||
const fn = vi.fn(async (url: string | URL) => {
|
||||
|
||||
Reference in New Issue
Block a user