mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-04 22:56:20 +08:00
server(attachments): render empty SVGs properly (closes #1378)
This commit is contained in:
parent
be6e56fbe8
commit
e129e0369d
32
src/routes/api/image.spec.ts
Normal file
32
src/routes/api/image.spec.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { note } from "../../../spec/support/becca_mocking.js";
|
||||||
|
import { renderSvgAttachment } from "./image.js";
|
||||||
|
|
||||||
|
describe("Image API", () => {
|
||||||
|
it("renders empty SVG properly", () => {
|
||||||
|
const parentNote = note("note").note;
|
||||||
|
const response = new MockResponse();
|
||||||
|
renderSvgAttachment(parentNote, response as any, "attachment");
|
||||||
|
expect(response.headers["Content-Type"]).toBe("image/svg+xml");
|
||||||
|
expect(response.body).toBe(`<svg xmlns="http://www.w3.org/2000/svg"></svg>`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
class MockResponse {
|
||||||
|
|
||||||
|
body?: string;
|
||||||
|
headers: Record<string, string>;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.headers = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
set(name: string, value: string) {
|
||||||
|
this.headers[name] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
send(body: string) {
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -41,8 +41,8 @@ function returnImageInt(image: BNote | BRevision | null, res: Response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderSvgAttachment(image: BNote | BRevision, res: Response, attachmentName: string) {
|
export function renderSvgAttachment(image: BNote | BRevision, res: Response, attachmentName: string) {
|
||||||
let svg: string | Buffer = "<svg/>";
|
let svg: string | Buffer = `<svg xmlns="http://www.w3.org/2000/svg"></svg>`;
|
||||||
const attachment = image.getAttachmentByTitle(attachmentName);
|
const attachment = image.getAttachmentByTitle(attachmentName);
|
||||||
|
|
||||||
if (attachment) {
|
if (attachment) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user