MCPcopy Index your code
hub / github.com/OneNoteDev/WebClipper / OneNoteSaveablePdf

Class OneNoteSaveablePdf

src/scripts/saveToOneNote/oneNoteSaveablePdf.ts:7–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import {OneNoteSaveable} from "./oneNoteSaveable";
6
7export class OneNoteSaveablePdf implements OneNoteSaveable {
8 private static maxImagesPerPatchRequest = 15;
9
10 private page: OneNoteApi.OneNotePage;
11 private pdf: PdfDocument;
12 private buckets: number[][];
13 private pageData: any;
14
15 constructor(page: OneNoteApi.OneNotePage, pdf: PdfDocument, pageIndexes?: number[], necessaryPdfOptions?: any) {
16 this.page = page;
17 this.pdf = pdf;
18 this.buckets = ArrayUtils.partition(pageIndexes, OneNoteSaveablePdf.maxImagesPerPatchRequest);
19 this.pageData = necessaryPdfOptions;
20 }
21
22 public getPage(): Promise<OneNoteApi.OneNotePage> {
23 return Promise.resolve(this.page);
24 }
25
26 public getNumPages(): number {
27 return 1;
28 }
29
30 public getPatch(index: number): Promise<OneNoteApi.Revision[]> {
31 return this.pdf.getPageListAsDataUrls(this.buckets[index]).then(this.createPatchRequestBody);
32 }
33
34 private createPatchRequestBody(dataUrls: string[]): OneNoteApi.Revision[] {
35 let requestBody = [];
36 dataUrls.forEach((dataUrl) => {
37 let content = "<p><img src=\"" + dataUrl + "\" /></p>&nbsp;";
38 requestBody.push({
39 target: "body",
40 action: "append",
41 content: content
42 });
43 });
44 return requestBody;
45 }
46
47 public getNumPatches(): number {
48 return this.buckets.length;
49 }
50
51 public getNumBatches(): number {
52 return 0;
53 }
54
55 public getBatch(index: number): Promise<OneNoteApi.BatchRequest> {
56 return Promise.resolve(undefined);
57 }
58}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected