-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34e4029
commit d93f7f6
Showing
16 changed files
with
598 additions
and
383 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
use stage from #public.uix; | ||
|
||
endpoint: stage { | ||
prod: @+example_list | ||
prod: @+example_screenshot | ||
}, | ||
|
||
location: stage { | ||
prod: @+unyt_eu1 | ||
}, | ||
|
||
domain: stage { | ||
prod: 'shared-list.unyt.app' | ||
prod: 'screenshot.unyt.app' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import puppeteer from "https://deno.land/x/puppeteer@16.2.0/mod.ts"; | ||
|
||
export default class Capture { | ||
static async take(url: string | URL, fullPage = false, size = { | ||
width: 1920, | ||
height: 1080 | ||
}) { | ||
const browser = await puppeteer.launch({ | ||
headless: true, | ||
ignoreHTTPSErrors: true, | ||
timeout: 60_000, | ||
}); | ||
const page = await browser.newPage(); | ||
await page.setViewport(size); | ||
await page.goto(url.toString(), { | ||
waitUntil: "networkidle2" | ||
}); | ||
const result = await page.screenshot({ | ||
fullPage | ||
}) as Buffer; | ||
await browser.close(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
import { UIX } from "uix/uix.ts"; | ||
import "common/theme.ts"; | ||
import { Overview } from "common/components/Overview.tsx"; | ||
import { listStorage } from "backend/lists.ts"; | ||
import { UIX_CACHE_PATH } from "uix/uix_all.ts"; | ||
import Capture from './Capture.ts'; | ||
import { Path } from "uix/utils/path.ts"; | ||
import { timeout } from "unyt_core/datex_all.ts"; | ||
|
||
// The frontend routes definition | ||
@endpoint export class Screenshot { | ||
@timeout(40_000) | ||
@property static async take(url: string | URL, config?: { | ||
width: number, | ||
height: number, | ||
fullSize?: boolean | ||
}): Promise<HTMLImageElement> { | ||
const fileName = `${url.toString().replaceAll(/[^a-zA-Z0-9\?\-\.]+/g, '_')}.png`; | ||
const filePath = UIX_CACHE_PATH.getChildPath(fileName); | ||
if (filePath.fs_exists) | ||
return this.getImage(filePath); | ||
|
||
const fileData = await Capture.take( | ||
url, | ||
config?.fullSize, { | ||
width: config?.width ?? 1920, | ||
height: config?.height ?? 1080 | ||
} | ||
); | ||
await Deno.writeFile(filePath, fileData); | ||
return this.getImage(filePath); | ||
} | ||
|
||
static getImage(filePath: Path<`${string}:`, boolean>) { | ||
return <img src={'/image/'.concat(filePath.name)}/> as HTMLImageElement; | ||
} | ||
} | ||
|
||
// The backend routes definition | ||
export default { | ||
'/': UIX.renderStatic(<Overview lists={listStorage}/>), // On '/'-route display the overview component | ||
'*': null // Letting the frontend handle all other routes | ||
'/': null, | ||
'/image/*': new UIX.FileProvider(UIX_CACHE_PATH) | ||
} satisfies UIX.Entrypoint; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.