Skip to content

Commit 725f91b

Browse files
committed
fix: links can now be imported even if they are uncreachable.
1 parent fef1512 commit 725f91b

File tree

2 files changed

+78
-21
lines changed

2 files changed

+78
-21
lines changed

src/kc_angular/src/app/components/shared/create.component.ts

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Rob Royce
2+
* Copyright (c) 2022-2023 Rob Royce
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import {DragAndDropService} from "../../services/ingest-services/drag-and-drop.s
2828
import {FaviconService} from "../../services/ingest-services/favicon.service";
2929
import {HttpClient} from "@angular/common/http";
3030
import {DomSanitizer} from "@angular/platform-browser";
31+
import {ConfirmationService} from "primeng/api";
3132

3233
@Component({
3334
selector: 'app-create',
@@ -94,6 +95,7 @@ export class CreateComponent implements OnInit {
9495
files: any[] = [];
9596

9697
constructor(private dialog: DialogService,
98+
private confirm: ConfirmationService,
9799
private factory: KsFactoryService,
98100
private ingest: IngestService,
99101
private notifications: NotificationsService,
@@ -146,17 +148,63 @@ export class CreateComponent implements OnInit {
146148

147149
this.factory.many(req).then((ksList) => {
148150
if (!ksList || !ksList.length) {
149-
this.notifications.error('Source Import', 'Unable to import URL', value);
151+
this.notifications.error('Source Import', `Unable to import URL`, value);
150152
return;
151153
}
152154

153155
this.ingest.enqueue(ksList);
154156

155-
}).catch((_) => {
156-
this.notifications.error('Source Import', 'Unable to import URL', value);
157+
}).catch((error) => {
158+
this.notifications.error('Source Import', `Unable to import URL`, `Source Factory: ${value}`);
159+
});
160+
}, (error) => {
161+
this.notifications.error('Source Import', `Invalid URL`, `HTTP Client: ${value}`);
162+
console.log(error)
163+
164+
// If the link cannot be reached, ask the user if they still want to import it anyway
165+
this.confirm.confirm({
166+
header: "Link Unreachable",
167+
message: `
168+
<div>
169+
<div style="max-width: 12rem;">
170+
${url.href} is unreachable.
171+
</div>
172+
<br>
173+
<div style="max-width: 12rem;">
174+
Sometimes this happens when the website is behind a paywall, requires authentication, or expects certain cookies.
175+
</div>
176+
<br>
177+
<div>
178+
You can still add it to Knowledge and we will attempt to extract information from it later on.
179+
</div>
180+
<br>
181+
<div>
182+
Do you want to import it anyway?
183+
</div>
184+
</div>
185+
`,
186+
icon: 'pi pi-warn',
187+
acceptLabel: 'Import',
188+
rejectLabel: 'Cancel',
189+
accept: () => {
190+
let req: KnowledgeSourceFactoryRequest = {
191+
ingestType: 'website',
192+
links: [url]
193+
}
194+
195+
this.factory.many(req).then((ksList) => {
196+
if (!ksList || !ksList.length) {
197+
this.notifications.error('Source Import', `Unable to import URL`, value);
198+
return;
199+
}
200+
201+
this.ingest.enqueue(ksList);
202+
203+
}).catch((error) => {
204+
this.notifications.error('Source Import', `Unable to import URL`, `Source Factory: ${value}`);
205+
});
206+
}
157207
});
158-
}, (_) => {
159-
this.notifications.error('Source Import', 'Invalid URL', value);
160208
return;
161209
});
162210

src/kc_angular/src/app/services/ingest-services/extractor.service.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
/**
2-
Copyright 2022 Rob Royce
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
1+
/*
2+
* Copyright (c) 2023 Rob Royce
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616
import {Injectable} from '@angular/core';
1717
import {HttpClient} from "@angular/common/http";
1818
import {NotificationsService} from "../user-services/notifications.service";
19-
import {ArticleModel, CodeModel, WebsiteMetadataModel, WebsiteMetaTagsModel} from "../../../../../kc_shared/models/web.source.model";
19+
import {
20+
ArticleModel,
21+
CodeModel,
22+
WebsiteMetadataModel,
23+
WebsiteMetaTagsModel
24+
} from "../../../../../kc_shared/models/web.source.model";
2025

2126
@Injectable({
2227
providedIn: 'root'
@@ -175,6 +180,10 @@ export class ExtractorService {
175180
// Meta Tags
176181
metadata.meta = extractMetaTags(htmlDoc);
177182

183+
resolve(metadata);
184+
}, (error) => {
185+
this.notifications.error('ExtractorService', 'extractWebsiteMetadata', 'Error retrieving website.');
186+
metadata.title = url;
178187
resolve(metadata);
179188
});
180189
});

0 commit comments

Comments
 (0)