Skip to content

Commit

Permalink
Merge pull request #62 from TypingMind/plugin-word-generator
Browse files Browse the repository at this point in the history
Add plugin word generator
  • Loading branch information
dat-devuap authored Jan 4, 2025
2 parents b6ce768 + 2dfbe2d commit 60cc613
Show file tree
Hide file tree
Showing 6 changed files with 831 additions and 0 deletions.
69 changes: 69 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"body-parser": "^1.20.2",
"cheerio": "^1.0.0-rc.12",
"cors": "^2.8.5",
"docx": "^9.1.0",
"dotenv": "^16.4.5",
"envalid": "^8.0.0",
"express": "^4.19.2",
Expand Down
2 changes: 2 additions & 0 deletions src/api-docs/openAPIDocumentGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { OpenApiGeneratorV3, OpenAPIRegistry } from '@asteasolutions/zod-to-open
import { articleReaderRegistry } from '@/routes/articleReader/articleReaderRouter';
import { healthCheckRegistry } from '@/routes/healthCheck/healthCheckRouter';
import { powerpointGeneratorRegistry } from '@/routes/powerpointGenerator/powerpointGeneratorRouter';
import { wordGeneratorRegistry } from '@/routes/wordGenerator/wordGeneratorRouter';
import { transcriptRegistry } from '@/routes/youtubeTranscript/transcriptRouter';

export function generateOpenAPIDocument() {
Expand All @@ -11,6 +12,7 @@ export function generateOpenAPIDocument() {
transcriptRegistry,
articleReaderRegistry,
powerpointGeneratorRegistry,
wordGeneratorRegistry,
]);
const generator = new OpenApiGeneratorV3(registry.definitions);

Expand Down
138 changes: 138 additions & 0 deletions src/routes/wordGenerator/wordGeneratorModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
import { z } from 'zod';

extendZodWithOpenApi(z);

// Define Word Generator Response Schema
export type WordGeneratorResponse = z.infer<typeof WordGeneratorResponseSchema>;
export const WordGeneratorResponseSchema = z.object({
filepath: z.string().openapi({
description: 'The file path where the generated Word document is saved.',
}),
});

// Define Cell Schema
const CellSchema = z.object({
text: z.string().optional().openapi({
description: 'Text content within a cell.',
}),
});

// Define Row Schema
const RowSchema = z.object({
cells: z.array(CellSchema).optional().openapi({
description: 'Array of cells within a row.',
}),
});

// Define Content Schema
const ContentSchema = z.object({
type: z.enum(['paragraph', 'listing', 'table', 'pageBreak', 'emptyLine']).openapi({
description: 'Type of the content item.',
}),
text: z.string().optional().openapi({
description: 'Text content for paragraphs or listings.',
}),
items: z.array(z.string()).optional().openapi({
description: 'Items in a list for listing type content.',
}),
headers: z.array(z.string()).optional().openapi({
description: 'Headers for table content.',
}),
rows: z.array(RowSchema).optional().openapi({
description: 'Rows for table content.',
}),
});

// Define the base schema for a section
const BaseSectionSchema = z.object({
heading: z.string().optional().openapi({
description: 'Heading of the section.',
}),
headingLevel: z.number().int().min(1).optional().openapi({
description: 'Level of the heading (e.g., 1 for main heading, 2 for subheading).',
}),
content: z.array(ContentSchema).optional().openapi({
description: 'Content contained within the section, including paragraphs, tables, etc.',
}),
});

// Extend the base schema with subSections
const SectionSchema = BaseSectionSchema.extend({
subSections: z.array(BaseSectionSchema).optional().openapi({
description: 'Subsections within the main section.',
}),
});

// Request Body Schema
export const WordGeneratorRequestBodySchema = z.object({
title: z.string().openapi({
description: 'Title of the document.',
}),
header: z.object({
text: z.string().openapi({
description: 'Text content for the header.',
}),
alignment: z.enum(['left', 'center', 'right']).default('left').openapi({
description: 'Alignment of the header text.',
}),
}),
footer: z.object({
text: z.string().openapi({
description: 'Text content for the footer.',
}),
alignment: z.enum(['left', 'center', 'right']).default('left').openapi({
description: 'Alignment of the footer text.',
}),
}),
sections: z.array(SectionSchema).openapi({
description: 'Sections of the document, which may include sub-sections.',
}),
wordConfig: z
.object({
fontSize: z.number().default(12).openapi({
description: 'Font size for the slides, default is 12 pt.',
}),
lineHeight: z.enum(['1', '1.15', '1.25', '1.5', '2']).default('1').openapi({
description: 'Line height for text content.',
}),
fontFamily: z
.enum(['Arial', 'Calibri', 'Times New Roman', 'Courier New', 'Verdana', 'Tahoma', 'Georgia', 'Comic Sans MS'])
.default('Arial')
.openapi({
description: 'Font family for the slides, default is Arial.',
}),
showPageNumber: z.boolean().default(false).openapi({
description: 'Option to display page numbers in the document.',
}),
showTableOfContent: z.boolean().default(false).openapi({
description: 'Option to display a table of contents.',
}),
showNumberingInHeader: z.boolean().default(false).openapi({
description: 'Option to display numbering in the header.',
}),
numberingReference: z
.enum([
'1.1.1.1 (Decimal)',
'I.1.a.i (Roman -> Decimal > Lower Letter -> Lower Roman)',
'I.A.1.a (Roman -> Upper Letter -> Decimal -> Lower Letter)',
'1)a)i)(i) (Decimal -> Lower Letter -> Lower Roman -> Lower Roman with Parentheses)',
'A.1.a.i (Upper Letter -> Decimal -> Lower Letter -> Lower Roman)',
])
.default('1.1.1.1 (Decimal)')
.openapi({
description: 'Set numbering hierarchy format for the document.',
}),
pageOrientation: z.enum(['portrait', 'landscape']).default('portrait').openapi({
description: 'Set the page orientation for the document.',
}),
margins: z.enum(['normal', 'narrow', 'moderate', 'wide', 'mirrored']).default('normal').openapi({
description: 'Set page margins for the document.',
}),
})
.openapi({
description: 'Word configuration settings for generating the document.',
}),
});

export type WordGeneratorRequestBody = z.infer<typeof WordGeneratorRequestBodySchema>;
Loading

0 comments on commit 60cc613

Please sign in to comment.