aboutsummaryrefslogtreecommitdiff
path: root/src/scraping/buxton/final/BuxtonImporter.ts
diff options
context:
space:
mode:
authorSam Wilkins <35748010+samwilkins333@users.noreply.github.com>2020-02-12 03:35:02 -0500
committerSam Wilkins <35748010+samwilkins333@users.noreply.github.com>2020-02-12 03:35:02 -0500
commit307e011a5fbe0433b75cd3d00c0d4d50d578fea0 (patch)
tree028c1c833e6321041694215bf0d3d6817c4b0c7f /src/scraping/buxton/final/BuxtonImporter.ts
parent11a909858e4e6fe66d5c19041bf7a8c5c1e4a547 (diff)
fixed bugs and intentional behaviors of importer, namely destroying the size stream and making DOF and price optional fields, respectively
Diffstat (limited to 'src/scraping/buxton/final/BuxtonImporter.ts')
-rw-r--r--src/scraping/buxton/final/BuxtonImporter.ts22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/scraping/buxton/final/BuxtonImporter.ts b/src/scraping/buxton/final/BuxtonImporter.ts
index 3e067bc6a..3d7421e90 100644
--- a/src/scraping/buxton/final/BuxtonImporter.ts
+++ b/src/scraping/buxton/final/BuxtonImporter.ts
@@ -84,7 +84,6 @@ namespace Utilities {
if (error) {
reject(error);
}
- console.log(stream);
stream.on('data', (chunk: any) => body += chunk.toString());
stream.on('end', () => resolve(body));
});
@@ -121,17 +120,20 @@ const RegexMap = new Map<keyof DeviceDocument, Processor<any>>([
transformer: raw => ({ transformed: Utilities.collectUniqueTokens(raw).transformed[0] }),
}],
["originalPrice", {
- exp: /Original Price \(USD\)\:\s+(\$[0-9]+\.[0-9]+|NFS)/,
+ exp: /Original Price \(USD\)\:\s+(\$[0-9\,]+\.[0-9]+|NFS)/,
transformer: (raw: string) => {
+ raw = raw.replace(/\,/g, "");
if (raw === "NFS") {
return { transformed: -1 };
}
return Utilities.numberValue(raw.slice(1));
- }
+ },
+ required: false
}],
["degreesOfFreedom", {
exp: /Degrees of Freedom:\s+([0-9]+)/,
- transformer: Utilities.numberValue
+ transformer: Utilities.numberValue,
+ required: false
}],
["dimensions", {
exp: /Dimensions\s+\(L x W x H\):\s+([0-9\.]+\s+x\s+[0-9\.]+\s+x\s+[0-9\.]+\s\([A-Za-z]+\))/,
@@ -226,9 +228,7 @@ const hyperlinkXPath = '//*[name()="Relationship" and contains(@Type, "hyperlink
async function extractFileContents(pathToDocument: string): Promise<DocumentContents> {
console.log('Extracting text...');
const zip = new StreamZip({ file: pathToDocument, storeEntries: true });
- console.log(zip);
await new Promise<void>(resolve => zip.on('ready', resolve));
- console.log("Zip ready!");
// extract the body of the document and, specifically, its captions
const document = await Utilities.readAndParseXml(zip, "word/document.xml");
@@ -276,20 +276,22 @@ async function writeImages(zip: any): Promise<string[]> {
const imageUrls: string[] = [];
for (const mediaPath of imageEntries) {
- console.log(`Considering ${mediaPath}`);
const streamImage = () => new Promise<any>((resolve, reject) => {
zip.stream(mediaPath, (error: any, stream: any) => error ? reject(error) : resolve(stream));
});
const { width, height, type } = await new Promise<Dimensions>(async resolve => {
- const sizeStream = createImageSizeStream().on('size', resolve);
- (await streamImage()).pipe(sizeStream);
+ const sizeStream = createImageSizeStream().on('size', (dimensions: Dimensions) => {
+ readStream.destroy();
+ resolve(dimensions)
+ });
+ const readStream = await streamImage();
+ readStream.pipe(sizeStream);
});
if (Math.abs(width - height) < 10) {
continue;
}
- console.log(`Streaming!`);
const ext = `.${type}`.toLowerCase();
const generatedFileName = `upload_${Utils.GenerateGuid()}${ext}`;