Skip to content

Commit

Permalink
minor refactoring, fix type error
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Strehle committed Sep 16, 2023
1 parent 23c8738 commit fcecd03
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 298 deletions.
2 changes: 1 addition & 1 deletion backend/Capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Capture {
});
const result = await page.screenshot({
fullPage
}) as Buffer;
}) as Uint8Array;
await browser.close();
return result;
}
Expand Down
3 changes: 2 additions & 1 deletion backend/entrypoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Path } from "uix/utils/path.ts";
import { timeout } from "unyt_core/datex_all.ts";

@endpoint export class Screenshot {

@timeout(40_000)
@property static async take(url: string | URL, config?: {
width: number,
Expand All @@ -27,7 +28,7 @@ import { timeout } from "unyt_core/datex_all.ts";
return this.getImage(filePath);
}

static getImage(filePath: Path<`${string}:`, boolean>) {
private static getImage(filePath: Path<`${string}:`, boolean>) {
return <img src={'/image/'.concat(filePath.name)}/> as HTMLImageElement;
}
}
Expand Down
16 changes: 9 additions & 7 deletions common/components/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { UIX } from "uix";
import { Screenshot } from 'backend/entrypoint.tsx';
import { Path } from "uix/utils/path.ts";

@UIX.template(function(this: MainPage) {
return <div>
<h1>UIX Screenshot <b>App</b></h1>
<span>Get a screenshot of any given URL.</span>

<input id="url" value="https://example.com" type={"url"} placeholder={"Enter URL here..."}/>
<div id="submit" onclick={UIX.inDisplayContext(()=>this.capture())} class="submit active">Capture</div>
<input id="url" value="https://example.com" type="url" placeholder="Enter URL here..."/>
<div id="submit" onclick={()=>this.capture()} class="submit active">Capture</div>

<p>Screenshot</p>
<div id="images"/>
Expand All @@ -31,12 +32,13 @@ export class MainPage extends UIX.BaseComponent {
try {
const image = await Screenshot.take(url);
this.images.prepend(image);
} catch (error) {
}
catch (error) {
console.error(error);
alert("Oups, could not create screenshot!");
} finally {
this.submit.classList.toggle("active", true);
this.url.disabled = false;
}
}

this.submit.classList.toggle("active", true);
this.url.disabled = false;
}
}
Loading

0 comments on commit fcecd03

Please sign in to comment.