|
1 | 1 | /* |
2 | | - * Copyright (c) 2022 Rob Royce |
| 2 | + * Copyright (c) 2022-2023 Rob Royce |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * 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 |
28 | 28 | import {FaviconService} from "../../services/ingest-services/favicon.service"; |
29 | 29 | import {HttpClient} from "@angular/common/http"; |
30 | 30 | import {DomSanitizer} from "@angular/platform-browser"; |
| 31 | +import {ConfirmationService} from "primeng/api"; |
31 | 32 |
|
32 | 33 | @Component({ |
33 | 34 | selector: 'app-create', |
@@ -94,6 +95,7 @@ export class CreateComponent implements OnInit { |
94 | 95 | files: any[] = []; |
95 | 96 |
|
96 | 97 | constructor(private dialog: DialogService, |
| 98 | + private confirm: ConfirmationService, |
97 | 99 | private factory: KsFactoryService, |
98 | 100 | private ingest: IngestService, |
99 | 101 | private notifications: NotificationsService, |
@@ -146,17 +148,63 @@ export class CreateComponent implements OnInit { |
146 | 148 |
|
147 | 149 | this.factory.many(req).then((ksList) => { |
148 | 150 | 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); |
150 | 152 | return; |
151 | 153 | } |
152 | 154 |
|
153 | 155 | this.ingest.enqueue(ksList); |
154 | 156 |
|
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 | + } |
157 | 207 | }); |
158 | | - }, (_) => { |
159 | | - this.notifications.error('Source Import', 'Invalid URL', value); |
160 | 208 | return; |
161 | 209 | }); |
162 | 210 |
|
|
0 commit comments