aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2020-02-10 16:15:09 -0500
committerSam Wilkins <samwilkins333@gmail.com>2020-02-10 16:15:09 -0500
commit12bbb2650a1afb4afb9c1774b756e9c3826367b7 (patch)
tree433555b424d1721d0d66540606634a60cc3af18e /src
parent1d9c316f397a8e6e5641e7d61e3fb6673554b479 (diff)
importer fixes
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/Documents.ts4
-rw-r--r--src/scraping/buxton/final/BuxtonImporter.ts26
2 files changed, 6 insertions, 24 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 29f253115..f9dab9738 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -18,7 +18,7 @@ import { AttributeTransformationModel } from "../northstar/core/attribute/Attrib
import { AggregateFunction } from "../northstar/model/idea/idea";
import { MINIMIZED_ICON_SIZE } from "../views/globalCssVariables.scss";
import { IconBox } from "../views/nodes/IconBox";
-import { OmitKeys, JSONUtils } from "../../Utils";
+import { OmitKeys, JSONUtils, Utils } from "../../Utils";
import { Field, Doc, Opt, DocListCastAsync, FieldResult, DocListCast } from "../../new_fields/Doc";
import { ImageField, VideoField, AudioField, PdfField, WebField, YoutubeField } from "../../new_fields/URLField";
import { HtmlField } from "../../new_fields/HtmlField";
@@ -373,7 +373,7 @@ export namespace Docs {
delete device.__images;
const { ImageDocument, StackingDocument } = Docs.Create;
if (Array.isArray(__images)) {
- const deviceImages = __images.map((url, i) => ImageDocument(url, { title: `image${i}.${extname(url)}` }));
+ const deviceImages = __images.map((url, i) => ImageDocument(Utils.prepend(url), { title: `image${i}.${extname(url)}` }));
const doc = StackingDocument(deviceImages, { title: device.title, _LODdisable: true });
const protoDoc = Doc.GetProto(doc);
protoDoc.hero = new ImageField(__images[0]);
diff --git a/src/scraping/buxton/final/BuxtonImporter.ts b/src/scraping/buxton/final/BuxtonImporter.ts
index 9da80e787..b8016be13 100644
--- a/src/scraping/buxton/final/BuxtonImporter.ts
+++ b/src/scraping/buxton/final/BuxtonImporter.ts
@@ -71,24 +71,6 @@ namespace Utilities {
return { transformed: raw };
}
- export function tryGetValidCapture(matches: RegExpExecArray | null, matchIndex: number): string | undefined {
- let captured: string;
- if (!matches || !(captured = matches[matchIndex])) {
- return undefined;
- }
- const lower = captured.toLowerCase();
- if (/to come/.test(lower)) {
- return undefined;
- }
- if (lower.includes("xxx")) {
- return undefined;
- }
- if (!captured.toLowerCase().replace(/[….\s]+/g, "").length) {
- return undefined;
- }
- return captured;
- }
-
export function capitalize(word: string): string {
const clean = word.trim();
if (!clean.length) {
@@ -128,7 +110,7 @@ const RegexMap = new Map<keyof DeviceDocument, Processor<any>>([
exp: /Original Price \(USD\)\:\s+(\$[0-9]+\.[0-9]+|NFS)/,
transformer: (raw: string) => {
if (raw === "NFS") {
- return { transformed: raw };
+ return { transformed: -1 };
}
return Utilities.numberValue(raw.slice(1));
}
@@ -313,7 +295,7 @@ async function writeImages(zip: any): Promise<string[]> {
out.on("error", reject);
});
}
- imageUrls.push(`http://localhost:1050/files/images/buxton/${generatedFileName}`);
+ imageUrls.push(`/files/images/buxton/${generatedFileName}`);
}
return imageUrls;
@@ -345,8 +327,8 @@ function analyze(fileName: string, { body, imageUrls, captions, hyperlinks }: Do
const { exp, transformer, matchIndex, required } = RegexMap.get(key)!;
const matches = exp.exec(body);
- let captured = Utilities.tryGetValidCapture(matches, matchIndex ?? 1);
- if (captured) {
+ let captured: string;
+ if (matches && (captured = matches[matchIndex ?? 1])) {
captured = captured.replace(/\s{2,}/g, " ");
if (transformer) {
const { error, transformed } = transformer(captured);