orator-conversion 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +15 -0
- package/.vscode/launch.json +47 -0
- package/Dockerfile +60 -0
- package/LICENSE +21 -0
- package/README.md +166 -0
- package/debug/Harness.js +48 -0
- package/debug/PostJPGToDebugServer.sh +44 -0
- package/debug/PostPDFToDebugServer.sh +54 -0
- package/debug/PostPNGToDebugServer.sh +44 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +68 -0
- package/docs/_sidebar.md +16 -0
- package/docs/api-reference.md +146 -0
- package/docs/configuration.md +77 -0
- package/docs/cover.md +13 -0
- package/docs/endpoints/001-jpg-to-png.md +60 -0
- package/docs/endpoints/002-png-to-jpg.md +60 -0
- package/docs/endpoints/003-pdf-to-page-png.md +93 -0
- package/docs/endpoints/004-pdf-to-page-jpg.md +94 -0
- package/docs/endpoints/README.md +75 -0
- package/docs/getting-started.md +113 -0
- package/docs/index.html +39 -0
- package/package.json +55 -0
- package/source/Orator-File-Translation.js +504 -0
- package/source/endpoints/Endpoint-Image-JpgToPng.js +34 -0
- package/source/endpoints/Endpoint-Image-PngToJpg.js +34 -0
- package/source/endpoints/Endpoint-Pdf-PageToJpg-Sized.js +43 -0
- package/source/endpoints/Endpoint-Pdf-PageToJpg.js +36 -0
- package/source/endpoints/Endpoint-Pdf-PageToPng-Sized.js +43 -0
- package/source/endpoints/Endpoint-Pdf-PageToPng.js +36 -0
- package/test/Orator-File-Translation_basic_tests.js +371 -0
- package/test/Orator-File-Translation_tests.js +694 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install orator-conversion
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
### System Dependencies
|
|
10
|
+
|
|
11
|
+
PDF page extraction requires `pdftoppm` (part of the poppler-utils package):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# macOS
|
|
15
|
+
brew install poppler
|
|
16
|
+
|
|
17
|
+
# Debian/Ubuntu
|
|
18
|
+
apt-get install poppler-utils
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Basic Setup
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
const libFable = require('fable');
|
|
25
|
+
const libOrator = require('orator');
|
|
26
|
+
const libOratorServiceServerRestify = require('orator-serviceserver-restify');
|
|
27
|
+
const libOratorFileTranslation = require('orator-conversion');
|
|
28
|
+
|
|
29
|
+
const _Fable = new libFable({
|
|
30
|
+
Product: 'MyConversionServer',
|
|
31
|
+
APIServerPort: 8080
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Register service types
|
|
35
|
+
_Fable.serviceManager.addServiceType('Orator', libOrator);
|
|
36
|
+
_Fable.serviceManager.addServiceType('OratorServiceServer', libOratorServiceServerRestify);
|
|
37
|
+
_Fable.serviceManager.addServiceType('OratorFileTranslation', libOratorFileTranslation);
|
|
38
|
+
|
|
39
|
+
// Instantiate services
|
|
40
|
+
_Fable.serviceManager.instantiateServiceProvider('Orator');
|
|
41
|
+
_Fable.serviceManager.instantiateServiceProvider('OratorServiceServer');
|
|
42
|
+
_Fable.serviceManager.instantiateServiceProvider('OratorFileTranslation');
|
|
43
|
+
|
|
44
|
+
// Start and connect routes
|
|
45
|
+
_Fable.Orator.startService(
|
|
46
|
+
() =>
|
|
47
|
+
{
|
|
48
|
+
_Fable.OratorFileTranslation.connectRoutes();
|
|
49
|
+
console.log('Conversion server running on port 8080');
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Adding Custom Converters
|
|
54
|
+
|
|
55
|
+
You can register custom converters before calling `connectRoutes()`:
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const tmpFileTranslation = _Fable.serviceManager.instantiateServiceProvider('OratorFileTranslation');
|
|
59
|
+
|
|
60
|
+
// Add a custom converter
|
|
61
|
+
tmpFileTranslation.addConverter('document/csv-to-json',
|
|
62
|
+
(pInputBuffer, pRequest, fCallback) =>
|
|
63
|
+
{
|
|
64
|
+
try
|
|
65
|
+
{
|
|
66
|
+
let tmpCSV = pInputBuffer.toString('utf8');
|
|
67
|
+
let tmpJSON = parseCSV(tmpCSV);
|
|
68
|
+
return fCallback(null, Buffer.from(JSON.stringify(tmpJSON)), 'application/json');
|
|
69
|
+
}
|
|
70
|
+
catch (pError)
|
|
71
|
+
{
|
|
72
|
+
return fCallback(pError);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Then start Orator and connect routes
|
|
77
|
+
_Fable.Orator.startService(
|
|
78
|
+
() =>
|
|
79
|
+
{
|
|
80
|
+
tmpFileTranslation.connectRoutes();
|
|
81
|
+
// Now available: POST /conversion/1.0/document/csv-to-json
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Using the Endpoints
|
|
86
|
+
|
|
87
|
+
All endpoints are versioned. Send file data as the raw request body:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Convert JPG to PNG
|
|
91
|
+
curl -X POST --data-binary @photo.jpg \
|
|
92
|
+
-H "Content-Type: application/octet-stream" \
|
|
93
|
+
http://localhost:8080/conversion/1.0/image/jpg-to-png \
|
|
94
|
+
-o photo.png
|
|
95
|
+
|
|
96
|
+
# Convert PNG to JPG
|
|
97
|
+
curl -X POST --data-binary @image.png \
|
|
98
|
+
-H "Content-Type: application/octet-stream" \
|
|
99
|
+
http://localhost:8080/conversion/1.0/image/png-to-jpg \
|
|
100
|
+
-o image.jpg
|
|
101
|
+
|
|
102
|
+
# Extract page 1 from a PDF as PNG
|
|
103
|
+
curl -X POST --data-binary @document.pdf \
|
|
104
|
+
-H "Content-Type: application/octet-stream" \
|
|
105
|
+
http://localhost:8080/conversion/1.0/pdf-to-page-png/1 \
|
|
106
|
+
-o page1.png
|
|
107
|
+
|
|
108
|
+
# Extract page 3 from a PDF as JPEG
|
|
109
|
+
curl -X POST --data-binary @document.pdf \
|
|
110
|
+
-H "Content-Type: application/octet-stream" \
|
|
111
|
+
http://localhost:8080/conversion/1.0/pdf-to-page-jpg/3 \
|
|
112
|
+
-o page3.jpg
|
|
113
|
+
```
|
package/docs/index.html
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
7
|
+
<meta name="description" content="Documentation powered by pict-docuserve">
|
|
8
|
+
|
|
9
|
+
<title>Documentation</title>
|
|
10
|
+
|
|
11
|
+
<!-- Application Stylesheet -->
|
|
12
|
+
<link href="https://cdn.jsdelivr.net/npm/pict-docuserve@0/dist/css/docuserve.css" rel="stylesheet">
|
|
13
|
+
<!-- KaTeX stylesheet for LaTeX equation rendering -->
|
|
14
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css">
|
|
15
|
+
<!-- PICT Dynamic View CSS Container -->
|
|
16
|
+
<style id="PICT-CSS"></style>
|
|
17
|
+
|
|
18
|
+
<!-- Load the PICT library from jsDelivr CDN -->
|
|
19
|
+
<script src="https://cdn.jsdelivr.net/npm/pict@1/dist/pict.min.js" type="text/javascript"></script>
|
|
20
|
+
<!-- Bootstrap the Application -->
|
|
21
|
+
<script type="text/javascript">
|
|
22
|
+
//<![CDATA[
|
|
23
|
+
Pict.safeOnDocumentReady(() => { Pict.safeLoadPictApplication(PictDocuserve, 2)});
|
|
24
|
+
//]]>
|
|
25
|
+
</script>
|
|
26
|
+
</head>
|
|
27
|
+
<body>
|
|
28
|
+
<!-- The root container for the Pict application -->
|
|
29
|
+
<div id="Docuserve-Application-Container"></div>
|
|
30
|
+
|
|
31
|
+
<!-- Mermaid diagram rendering -->
|
|
32
|
+
<script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script>
|
|
33
|
+
<script>mermaid.initialize({ startOnLoad: false, theme: 'default' });</script>
|
|
34
|
+
<!-- KaTeX for LaTeX equation rendering -->
|
|
35
|
+
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.js"></script>
|
|
36
|
+
<!-- Load the Docuserve PICT Application Bundle from jsDelivr CDN -->
|
|
37
|
+
<script src="https://cdn.jsdelivr.net/npm/pict-docuserve@0/dist/pict-docuserve.min.js" type="text/javascript"></script>
|
|
38
|
+
</body>
|
|
39
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "orator-conversion",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "File format conversion endpoints for Orator service servers.",
|
|
5
|
+
"main": "source/Orator-File-Translation.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "./node_modules/mocha/bin/_mocha --exit -u tdd -R spec",
|
|
8
|
+
"coverage": "./node_modules/.bin/nyc --reporter=lcov --reporter=text-lcov ./node_modules/mocha/bin/_mocha -- -u tdd -R spec",
|
|
9
|
+
"start": "node debug/Harness.js",
|
|
10
|
+
"tests": "npx mocha -u tdd --exit -R spec --grep",
|
|
11
|
+
"docker-build": "docker build -t retold/orator-conversion:local .",
|
|
12
|
+
"docker-run": "docker run -p 8765:8765 --name orator-conversion retold/orator-conversion:local",
|
|
13
|
+
"docker-shell": "docker exec -it orator-conversion /bin/bash"
|
|
14
|
+
},
|
|
15
|
+
"mocha": {
|
|
16
|
+
"diff": true,
|
|
17
|
+
"extension": [
|
|
18
|
+
"js"
|
|
19
|
+
],
|
|
20
|
+
"package": "./package.json",
|
|
21
|
+
"reporter": "spec",
|
|
22
|
+
"slow": "75",
|
|
23
|
+
"timeout": "5000",
|
|
24
|
+
"ui": "tdd",
|
|
25
|
+
"watch-files": [
|
|
26
|
+
"source/**/*.js",
|
|
27
|
+
"test/**/*.js"
|
|
28
|
+
],
|
|
29
|
+
"watch-ignore": [
|
|
30
|
+
"lib/vendor"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/stevenvelozo/orator-conversion.git"
|
|
36
|
+
},
|
|
37
|
+
"author": "steven velozo <steven@velozo.com>",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/stevenvelozo/orator-conversion/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/stevenvelozo/orator-conversion#readme",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"fable-serviceproviderbase": "^3.0.13",
|
|
45
|
+
"sharp": "^0.33.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"chai": "^4.3.7",
|
|
49
|
+
"fable": "^3.1.51",
|
|
50
|
+
"mocha": "^10.2.0",
|
|
51
|
+
"orator": "^5.0.1",
|
|
52
|
+
"orator-serviceserver-restify": "^2.0.5",
|
|
53
|
+
"quackage": "^1.0.45"
|
|
54
|
+
}
|
|
55
|
+
}
|