Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions apps/server/src/provider/documentTextWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,12 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
return { name: "root", attrs: {}, children: [] };
}
};
const partRels = (name: string) =>
NodePath.posix.join(
NodePath.posix.dirname(name),
"_rels",
`${NodePath.posix.basename(name)}.rels`,
);
const relations = (name: string) =>
new Map(
[...all(read(name), "Relationship")]
Expand Down Expand Up @@ -708,9 +714,7 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
const resolveWorkbookPart = (target: string) =>
NodePath.posix.resolve(`/${workbookDir}`, target).slice(1);
const workbook = read(workbookPath);
const rels = relations(
NodePath.posix.join(workbookDir, "_rels", `${NodePath.posix.basename(workbookPath)}.rels`),
);
const rels = relations(partRels(workbookPath));
const workbookRelations = [...rels.values()];
const workbookPartPath = (part: string) => {
const target = workbookRelations.find((rel) => rel.Type?.endsWith(`/${part}`))?.Target;
Expand Down Expand Up @@ -802,8 +806,10 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
}
}
} else if (extension === ".pptx") {
const rels = relations("ppt/_rels/presentation.xml.rels");
const [presentation] = children(read("ppt/presentation.xml"));
const presentationPath = mainPart("ppt/presentation.xml");
const presentationDir = NodePath.posix.dirname(presentationPath);
const rels = relations(partRels(presentationPath));
const [presentation] = children(read(presentationPath));
const slideList = children(presentation).find((node) => node.name === "sldIdLst");
const inheritedAttributes = { ...presentation?.attrs, ...slideList?.attrs };
let index = 0;
Expand All @@ -814,15 +820,9 @@ async function* document(path: string, extension: string): AsyncGenerator<TextPa
skip(`slide relationship ${index}`);
continue;
}
const name = target.startsWith("/")
? target.slice(1)
: NodePath.posix.normalize(`ppt/${target}`);
const name = NodePath.posix.resolve(`/${presentationDir}`, target).slice(1);
yield* paragraphs(read(name));
const slideRels = NodePath.posix.join(
NodePath.posix.dirname(name),
"_rels",
`${NodePath.posix.basename(name)}.rels`,
);
const slideRels = partRels(name);
if (!has(slideRels)) continue;
for (const rel of all(read(slideRels), "Relationship")) {
const target = rel.attrs.Target;
Expand Down
22 changes: 22 additions & 0 deletions apps/server/src/provider/userInputAttachments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,28 @@ describe("question answer paths", () => {
expected: ["Slide text"],
absent: ["Notes:", "57"],
},
...[
{ target: "deck/main.xml", prefix: "deck/" },
{ target: "/main.xml", prefix: "" },
].map(({ target, prefix }) => ({
ext: "pptx",
bounded: true,
parts: {
"_rels/.rels": `<Relationships><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="${target}"/></Relationships>`,
[`${prefix}main.xml`]:
'<presentation><sldIdLst><sldId r:id="a"/></sldIdLst></presentation>',
[`${prefix}_rels/main.xml.rels`]:
'<Relationships><Relationship Id="a" Target="slides/one.xml"/></Relationships>',
[`${prefix}slides/one.xml`]:
"<p:sld><a:p><a:r><a:t>Harbor launch</a:t></a:r></a:p></p:sld>",
[`${prefix}slides/_rels/one.xml.rels`]:
'<Relationships><Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide" Target="../notes/n1.xml"/></Relationships>',
[`${prefix}notes/n1.xml`]:
"<p:notes><a:p><a:r><a:t>Check tide table</a:t></a:r></a:p></p:notes>",
},
expected: ["## Slide 1", "Harbor launch\nNotes:\nCheck tide table"],
absent: ["[Skipped document part"],
})),
...[false, true].map((missing) => ({
ext: "pptx",
bounded: true,
Expand Down
Loading