Address artifact PR review feedback

This commit is contained in:
Dotta 2026-05-30 20:51:46 +00:00
parent bbf77fcb69
commit 04a19cbc6e
8 changed files with 59 additions and 38 deletions

View file

@ -134,10 +134,14 @@ function createStorageService(body = Buffer.from("test")): TestStorageService {
originalFilename: input.originalFilename,
};
},
getObject: vi.fn(async () => ({
stream: Readable.from(body),
contentLength: body.length,
})),
getObject: vi.fn(async (_companyId, _objectKey, options) => {
const range = options?.range;
const streamBody = range ? body.subarray(range.start, range.end + 1) : body;
return {
stream: Readable.from(streamBody),
contentLength: streamBody.length,
};
}),
headObject: vi.fn(),
deleteObject: vi.fn(),
};
@ -401,6 +405,11 @@ describe("issue attachment routes", () => {
expect(res.headers["content-length"]).toBe("3");
expect(res.headers["content-disposition"]).toBe('inline; filename="clip.mp4"');
expect(Buffer.from(res.body).toString("utf8")).toBe("bcd");
expect(storage.getObject).toHaveBeenCalledWith(
"company-1",
"issues/issue-1/clip.mp4",
{ range: { start: 1, end: 3 } },
);
});
it("forces video downloads when the download path is requested", async () => {

View file

@ -42,6 +42,26 @@ describe("local disk storage provider", () => {
expect(stored.sha256).toHaveLength(64);
});
it("streams only requested byte ranges", async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-storage-"));
tempRoots.push(root);
const service = createStorageService(createLocalDiskStorageProvider(root));
const stored = await service.putFile({
companyId: "company-1",
namespace: "issues/issue-1",
originalFilename: "demo.mp4",
contentType: "video/mp4",
body: Buffer.from("0123456789", "utf8"),
});
const fetched = await service.getObject("company-1", stored.objectKey, { range: { start: 2, end: 5 } });
const fetchedBody = await readStreamToBuffer(fetched.stream);
expect(fetchedBody.toString("utf8")).toBe("2345");
expect(fetched.contentLength).toBe(4);
});
it("blocks cross-company object access", async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-storage-"));
tempRoots.push(root);