mirror of
https://github.com/zadam/trilium.git
synced 2025-10-19 22:58:52 +02:00
test(server/share): attachment links
This commit is contained in:
parent
8b5e53e579
commit
614a8f177c
@ -21,14 +21,37 @@ describe("content_renderer", () => {
|
||||
Welcome to Trilium Notes!
|
||||
</strong>
|
||||
</p>`;
|
||||
const note = buildShareNote({
|
||||
title: "Note",
|
||||
content
|
||||
});
|
||||
const note = buildShareNote({ content });
|
||||
const result = getContent(note);
|
||||
expect(result.content).toStrictEqual(content);
|
||||
});
|
||||
|
||||
it("handles attachment link", () => {
|
||||
const content = trimIndentation`\
|
||||
<h1>Test</h1>
|
||||
<p>
|
||||
<a class="reference-link" href="#root/iwTmeWnqBG5Q?viewMode=attachments&attachmentId=q14s2Id7V6pp">
|
||||
5863845791835102555.mp4
|
||||
</a>
|
||||
|
||||
</p>
|
||||
`;
|
||||
const note = buildShareNote({
|
||||
content,
|
||||
attachments: [ { id: "q14s2Id7V6pp" } ]
|
||||
});
|
||||
const result = getContent(note);
|
||||
expect(result.content).toStrictEqual(trimIndentation`\
|
||||
<h1>Test</h1>
|
||||
<p>
|
||||
<a class="reference-link attachment-link role-file" href="api/attachments/q14s2Id7V6pp/download">
|
||||
5863845791835102555.mp4
|
||||
</a>
|
||||
|
||||
</p>
|
||||
`);
|
||||
});
|
||||
|
||||
it("renders included notes", () => {
|
||||
buildShareNotes([
|
||||
{ id: "subnote1", content: `<p>Foo</p><div>Bar</div>` },
|
||||
|
@ -1,4 +1,5 @@
|
||||
import utils from "../services/utils.js";
|
||||
import SAttachment from "../share/shaca/entities/sattachment.js";
|
||||
import SAttribute from "../share/shaca/entities/sattribute.js";
|
||||
import SNote from "../share/shaca/entities/snote.js";
|
||||
import shaca from "../share/shaca/shaca.js";
|
||||
@ -6,11 +7,19 @@ import shaca from "../share/shaca/shaca.js";
|
||||
type AttributeDefinitions = { [key in `#${string}`]: string; };
|
||||
type RelationDefinitions = { [key in `~${string}`]: string; };
|
||||
|
||||
interface AttachementDefinition {
|
||||
id?: string;
|
||||
role?: string;
|
||||
mime?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
interface NoteDefinition extends AttributeDefinitions, RelationDefinitions {
|
||||
id?: string | undefined;
|
||||
title?: string;
|
||||
content?: string | Buffer<ArrayBufferLike>;
|
||||
children?: NoteDefinition[];
|
||||
attachments?: AttachementDefinition[];
|
||||
isProtected?: boolean;
|
||||
}
|
||||
|
||||
@ -60,6 +69,21 @@ export function buildShareNote(noteDef: NoteDefinition) {
|
||||
};
|
||||
}
|
||||
|
||||
// Handle attachments.
|
||||
if (noteDef.attachments) {
|
||||
for (const attachmentDef of noteDef.attachments) {
|
||||
new SAttachment([
|
||||
attachmentDef.id ?? utils.randomString(12),
|
||||
note.noteId,
|
||||
attachmentDef.role ?? "file",
|
||||
attachmentDef.mime ?? "application/blob",
|
||||
attachmentDef.title ?? "New attachment",
|
||||
blobId,
|
||||
new Date().toUTCString(), // utcDateModified
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle children.
|
||||
if (noteDef.children) {
|
||||
for (const childDef of noteDef.children) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user