Skip to content

Commit b0f87d1

Browse files
committed
Add document conversion API endpoints and components
1 parent 622777f commit b0f87d1

File tree

9 files changed

+1707
-0
lines changed

9 files changed

+1707
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { BaseComponent } from '../base-component.js';
2+
import './api-html-to-pdf.js';
3+
import './api-html-to-doc.js';
4+
import './api-html-to-epub.js';
5+
import './api-html-to-excel.js';
6+
import './api-html-to-ppt.js';
7+
import './api-html-to-markdown.js';
8+
import './api-markdown-to-html.js';
9+
10+
/**
11+
* Document Generation section component
12+
* Displays the document generation endpoints section
13+
*/
14+
export class ApiDocGeneration extends BaseComponent {
15+
/**
16+
* Create a new document generation section component
17+
*/
18+
constructor() {
19+
super();
20+
}
21+
22+
/**
23+
* Get the component's styles
24+
* @returns {string} - CSS styles
25+
*/
26+
getStyles() {
27+
return `
28+
:host {
29+
display: block;
30+
}
31+
32+
h2 {
33+
margin-bottom: var(--spacing-md);
34+
color: var(--text-primary);
35+
}
36+
`;
37+
}
38+
39+
/**
40+
* Get the component's template
41+
* @returns {string} - HTML template
42+
*/
43+
getTemplate() {
44+
return `
45+
<h2>Document Generation Endpoints</h2>
46+
<api-html-to-pdf></api-html-to-pdf>
47+
<api-html-to-doc></api-html-to-doc>
48+
<api-html-to-epub></api-html-to-epub>
49+
<api-html-to-excel></api-html-to-excel>
50+
<api-html-to-ppt></api-html-to-ppt>
51+
<api-html-to-markdown></api-html-to-markdown>
52+
<api-markdown-to-html></api-markdown-to-html>
53+
`;
54+
}
55+
}
56+
57+
// Define the custom element
58+
if (!customElements.get('api-doc-generation')) {
59+
customElements.define('api-doc-generation', ApiDocGeneration);
60+
console.log('API document generation section component registered');
61+
}

public/js/components/api-keys/api-docs.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BaseComponent } from '../base-component.js';
22
import './api-auth.js';
3+
import './api-doc-generation.js';
34
import './api-get-keys.js';
45
import './api-post-key.js';
56
import './api-put-key.js';
@@ -55,6 +56,10 @@ export class ApiDocs extends BaseComponent {
5556
<api-auth></api-auth>
5657
</div>
5758
59+
<div class="api-section">
60+
<api-doc-generation></api-doc-generation>
61+
</div>
62+
5863
<div class="api-section">
5964
<h2>API Key Management</h2>
6065
<api-get-keys></api-get-keys>
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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

Comments
 (0)