File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 3
3
import type { Item } from " @prisma/client" ;
4
4
import Backdrop from " $lib/components/Backdrop.svelte" ;
5
5
import { env } from " $env/dynamic/public" ;
6
+ import { getToastStore } from " @skeletonlabs/skeleton" ;
6
7
7
8
export let data: Item ;
8
9
export let buttonText: string ;
9
10
10
11
$ : form = $page .form ;
11
12
let loading = false ;
12
13
let urlChanged = false ;
14
+ const toastStore = getToastStore ();
13
15
14
16
const formatPrice = (price : number | null , currency : string | null ) => {
15
17
if (! price ) return null ;
28
30
return null ;
29
31
};
30
32
33
+ const triggerToast = () => {
34
+ toastStore .trigger ({
35
+ message: ` Unable to find product information. You can still fill in the details manually. ` ,
36
+ background: " variant-filled-warning" ,
37
+ autohide: true ,
38
+ timeout: 5000
39
+ });
40
+ };
41
+
31
42
const getInfo = async () => {
32
43
if (data .url && urlChanged ) {
33
44
loading = true ;
40
51
data .image_url = productData .image ;
41
52
data .price = formatPrice (productData .price , productData .currency );
42
53
} else {
43
- console . log ( " invalid url " );
54
+ triggerToast ( );
44
55
}
45
56
loading = false ;
46
57
urlChanged = false ;
Original file line number Diff line number Diff line change @@ -18,8 +18,13 @@ const scraper = metascraper([
18
18
] ) ;
19
19
20
20
const goShopping = async ( targetUrl : string ) => {
21
- const { body : html , url } = await gotScraping ( targetUrl ) ;
22
- const metadata = await scraper ( { html, url } ) ;
21
+ const resp = await gotScraping ( {
22
+ url : targetUrl ,
23
+ headerGeneratorOptions : {
24
+ devices : [ "desktop" ]
25
+ }
26
+ } ) ;
27
+ const metadata = await scraper ( { html : resp . body , url : resp . url } ) ;
23
28
return metadata ;
24
29
} ;
25
30
@@ -44,6 +49,9 @@ export const GET: RequestHandler = async ({ request }) => {
44
49
// retry with the resolved URL
45
50
metadata = await goShopping ( metadata . url ) ;
46
51
}
52
+ if ( isCaptchaResponse ( metadata ) ) {
53
+ error ( 424 , "product information not available" ) ;
54
+ }
47
55
48
56
return new Response ( JSON . stringify ( metadata ) ) ;
49
57
} else {
You can’t perform that action at this time.
0 commit comments