Skip to content

Commit b0dac17

Browse files
committed
add error handling
1 parent 91ecd04 commit b0dac17

File tree

4 files changed

+12
-418
lines changed

4 files changed

+12
-418
lines changed

service/npm-shrinkwrap.json

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"wms-capabilities": "0.6.0",
7979
"xmlbuilder2": "3.1.1",
8080
"xpath": "0.0.34",
81-
"xslt-processor": "^3.3.1",
8281
"yaml": "1.10.2"
8382
},
8483
"devDependencies": {

service/src/routes/imports.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import fs from 'fs-extra';
66
import Zip from 'adm-zip';
77
import { defaultHandler as upload } from '../upload';
88
import { DOMParser, Document } from '@xmldom/xmldom';
9-
import kml from '../utilities/transformKML'
10-
import { Xslt, XmlParser } from 'xslt-processor';
9+
import kml from '../utilities/transformKML';
1110

1211
interface SecurityConfig {
1312
authentication: {
@@ -63,10 +62,10 @@ const validate = async (req: Request, res: Response, next: NextFunction): Promis
6362

6463
if (fileExtension === 'kmz') {
6564
try {
65+
// TODO: Update how images are handled in KMZ files to prevent duplication. Move images to a separate directory and store their paths in the KML.
6666
const zip = new Zip(layRequest.file.path);
6767
const zipEntries = zip.getEntries();
6868
const kmlEntry = zipEntries.find(entry => entry.entryName.toLowerCase().endsWith('.kml'));
69-
// const xslEntry = zipEntries.find(entry => entry.entryName.toLowerCase().endsWith('.xsl') || entry.entryName.toLowerCase().endsWith('.xslt'));
7069

7170
if (!kmlEntry) {
7271
return res.status(400).send('No KML file found inside.');
@@ -75,31 +74,20 @@ const validate = async (req: Request, res: Response, next: NextFunction): Promis
7574
const images: { [key: string]: string } = {};
7675
zipEntries.forEach(entry => {
7776
const entryName = entry.entryName;
78-
if (!entry.isDirectory && /\.(png|jpg|jpeg|gif|bmp)$/i.test(entryName)) {
79-
const buffer = entry.getData();
80-
const base64 = buffer.toString('base64');
81-
const mimeType = getMimeType(entryName);
82-
images[entryName] = `data:${mimeType};base64,${base64}`;
77+
try {
78+
if (!entry.isDirectory && /\.(png|jpg|jpeg|gif|bmp)$/i.test(entryName)) {
79+
const buffer = entry.getData();
80+
const base64 = buffer.toString('base64');
81+
const mimeType = getMimeType(entryName);
82+
images[entryName] = `data:${mimeType};base64,${base64}`;
83+
}
84+
} catch (error) {
85+
console.error(`Error processing entry ${entryName}:`, error);
8386
}
8487
});
8588

8689
const kmlString = kmlEntry.getData().toString('utf8');
8790

88-
// if (xslEntry) {
89-
// const xslString = xslEntry.getData().toString('utf8');
90-
91-
// const xslt = new Xslt({ cData: true, escape: false });
92-
// const xmlParser = new XmlParser();
93-
94-
// const outXmlString = await xslt.xsltProcess(
95-
// xmlParser.xmlParse(kmlString),
96-
// xmlParser.xmlParse(xslString)
97-
// );
98-
// console.log('outXmlString', outXmlString);
99-
// const transformedDocument = parser.parseFromString(outXmlString, 'text/xml');
100-
// geoJson = toGeoJson.kml(transformedDocument);
101-
// }
102-
10391
const kmlDocument = parser.parseFromString(kmlString, 'text/xml');
10492
geoJson = kml(kmlDocument as any, images);
10593

0 commit comments

Comments
 (0)