1+ import { ApiEndpointBase } from './api-endpoint-base.js' ;
2+
3+ /**
4+ * POST /api/1/html-to-doc endpoint component
5+ * Displays the documentation for the POST /api/1/html-to-doc endpoint
6+ */
7+ export class ApiHtmlToDoc extends ApiEndpointBase {
8+ /**
9+ * Create a new POST /api/1/html-to-doc endpoint component
10+ */
11+ constructor ( ) {
12+ super ( ) ;
13+ this . _method = 'POST' ;
14+ this . _path = '/api/1/html-to-doc' ;
15+ this . _description = 'Converts HTML content to a Microsoft Word document.' ;
16+ this . _parameters = [
17+ {
18+ name : 'html' ,
19+ type : 'string' ,
20+ required : true ,
21+ description : 'The HTML content to convert to Word'
22+ } ,
23+ {
24+ name : 'filename' ,
25+ type : 'string' ,
26+ required : false ,
27+ description : 'Output filename (default: "document.doc")'
28+ } ,
29+ {
30+ name : 'store' ,
31+ type : 'boolean' ,
32+ required : false ,
33+ description : 'Whether to store the document in Supabase (default: false)'
34+ }
35+ ] ;
36+ this . _requestExample = `{
37+ "html": "<html><body><h1>Hello, World!</h1></body></html>",
38+ "filename": "document.doc",
39+ "store": false
40+ }` ;
41+ this . _codeExamples = {
42+ curl : `curl -X POST "https://api.example.com/api/1/html-to-doc" \\
43+ -H "Authorization: Bearer YOUR_JWT_TOKEN" \\
44+ -H "Content-Type: application/json" \\
45+ -d '{
46+ "html": "<html><body><h1>Hello, World!</h1></body></html>",
47+ "filename": "document.doc",
48+ "store": false
49+ }'` ,
50+ fetch : `fetch('https://api.example.com/api/1/html-to-doc', {
51+ method: 'POST',
52+ headers: {
53+ 'Authorization': 'Bearer YOUR_JWT_TOKEN',
54+ 'Content-Type': 'application/json'
55+ },
56+ body: JSON.stringify({
57+ html: '<html><body><h1>Hello, World!</h1></body></html>',
58+ filename: 'document.doc',
59+ store: false
60+ })
61+ })
62+ .then(response => response.blob())
63+ .then(blob => {
64+ // Create a link to download the Word document
65+ const url = window.URL.createObjectURL(blob);
66+ const a = document.createElement('a');
67+ a.href = url;
68+ a.download = 'document.doc';
69+ document.body.appendChild(a);
70+ a.click();
71+ window.URL.revokeObjectURL(url);
72+ })
73+ .catch(error => console.error('Error:', error));` ,
74+ nodejs : `const axios = require('axios');
75+ const fs = require('fs');
76+
77+ axios.post('https://api.example.com/api/1/html-to-doc', {
78+ html: '<html><body><h1>Hello, World!</h1></body></html>',
79+ filename: 'document.doc',
80+ store: false
81+ }, {
82+ headers: {
83+ 'Authorization': 'Bearer YOUR_JWT_TOKEN',
84+ 'Content-Type': 'application/json'
85+ },
86+ responseType: 'arraybuffer'
87+ })
88+ .then(response => {
89+ fs.writeFileSync('document.doc', response.data);
90+ console.log('Word document saved to document.doc');
91+ })
92+ .catch(error => {
93+ console.error('Error:', error);
94+ });` ,
95+ python : `import requests
96+ import json
97+
98+ headers = {
99+ 'Authorization': 'Bearer YOUR_JWT_TOKEN',
100+ 'Content-Type': 'application/json'
101+ }
102+
103+ data = {
104+ 'html': '<html><body><h1>Hello, World!</h1></body></html>',
105+ 'filename': 'document.doc',
106+ 'store': False
107+ }
108+
109+ response = requests.post('https://api.example.com/api/1/html-to-doc',
110+ headers=headers,
111+ data=json.dumps(data))
112+
113+ # Save the Word document to a file
114+ with open('document.doc', 'wb') as f:
115+ f.write(response.content)
116+ print('Word document saved to document.doc')` ,
117+ php : `<?php
118+ $curl = curl_init();
119+
120+ $data = [
121+ 'html' => '<html><body><h1>Hello, World!</h1></body></html>',
122+ 'filename' => 'document.doc',
123+ 'store' => false
124+ ];
125+
126+ curl_setopt_array($curl, [
127+ CURLOPT_URL => "https://api.example.com/api/1/html-to-doc",
128+ CURLOPT_RETURNTRANSFER => true,
129+ CURLOPT_CUSTOMREQUEST => "POST",
130+ CURLOPT_POSTFIELDS => json_encode($data),
131+ CURLOPT_HTTPHEADER => [
132+ "Authorization: Bearer YOUR_JWT_TOKEN",
133+ "Content-Type: application/json"
134+ ],
135+ ]);
136+
137+ $response = curl_exec($curl);
138+ $err = curl_error($curl);
139+
140+ curl_close($curl);
141+
142+ if ($err) {
143+ echo "Error: " . $err;
144+ } else {
145+ // Save the Word document to a file
146+ file_put_contents('document.doc', $response);
147+ echo "Word document saved to document.doc";
148+ }` ,
149+ ruby : `require 'net/http'
150+ require 'uri'
151+ require 'json'
152+
153+ uri = URI.parse('https://api.example.com/api/1/html-to-doc')
154+ request = Net::HTTP::Post.new(uri)
155+ request['Authorization'] = 'Bearer YOUR_JWT_TOKEN'
156+ request['Content-Type'] = 'application/json'
157+ request.body = JSON.dump({
158+ 'html' => '<html><body><h1>Hello, World!</h1></body></html>',
159+ 'filename' => 'document.doc',
160+ 'store' => false
161+ })
162+
163+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
164+ http.request(request)
165+ end
166+
167+ # Save the Word document to a file
168+ File.open('document.doc', 'wb') do |file|
169+ file.write(response.body)
170+ end
171+ puts 'Word document saved to document.doc'`
172+ } ;
173+ }
174+
175+ /**
176+ * Get the component's template
177+ * @returns {string } - HTML template
178+ */
179+ getTemplate ( ) {
180+ return `
181+ <div class="endpoint-header">
182+ <span class="http-method method-${ this . _method . toLowerCase ( ) } ">${ this . _method } </span>
183+ <span class="endpoint-path">${ this . _path } </span>
184+ </div>
185+
186+ <div class="endpoint-description">
187+ <p>${ this . _description } </p>
188+ </div>
189+
190+ ${ this . renderParametersTable ( this . _parameters ) }
191+
192+ <div class="section-title">Example Request</div>
193+ <div class="code-block">
194+ <pre>${ this . _requestExample } </pre>
195+ </div>
196+
197+ ${ this . renderCodeExamples ( this . _codeExamples ) }
198+
199+ <div class="section-title">Response</div>
200+ <p>Returns the raw Word document file with the following headers:</p>
201+ <ul>
202+ <li><code>Content-Type: application/msword</code></li>
203+ <li><code>Content-Disposition: attachment; filename="document.doc"</code></li>
204+ <li><code>X-Storage-Path: documents/...</code> (if stored in Supabase)</li>
205+ </ul>
206+ ` ;
207+ }
208+ }
209+
210+ // Define the custom element
211+ if ( ! customElements . get ( 'api-html-to-doc' ) ) {
212+ customElements . define ( 'api-html-to-doc' , ApiHtmlToDoc ) ;
213+ console . log ( 'API HTML to DOC component registered' ) ;
214+ }
0 commit comments