@@ -6,8 +6,7 @@ import fs from 'fs-extra';
66import Zip from 'adm-zip' ;
77import { defaultHandler as upload } from '../upload' ;
88import { 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
1211interface 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 && / \. ( p n g | j p g | j p e g | g i f | b m p ) $ / 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 && / \. ( p n g | j p g | j p e g | g i f | b m p ) $ / 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