From ada023ed911134d96548bec59e9e2589fd792280 Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Tue, 19 Sep 2023 16:32:41 +0200 Subject: [PATCH] Fix deployment --- app.dx | 2 +- backend/.dx | 4 ++-- backend/Capture.ts | 24 ------------------------ backend/entrypoint.tsx | 33 --------------------------------- 4 files changed, 3 insertions(+), 60 deletions(-) delete mode 100644 backend/Capture.ts diff --git a/app.dx b/app.dx index 6ea6afb..d28064f 100644 --- a/app.dx +++ b/app.dx @@ -1,4 +1,4 @@ -name: "Website Screenshot Example", +name: "Threads Example", icon_path: "https://cdn.unyt.org/unyt-resources/logos/unyt/square-dark-background.png"; plugin git_deploy ( diff --git a/backend/.dx b/backend/.dx index f798781..2d59424 100644 --- a/backend/.dx +++ b/backend/.dx @@ -1,7 +1,7 @@ use stage from #public.uix; endpoint: stage { - prod: @+example_screenshot + prod: @+example_threads }, location: stage { @@ -9,5 +9,5 @@ location: stage { }, domain: stage { - prod: 'screenshot.unyt.app' + prod: 'threads.example.unyt.org' } \ No newline at end of file diff --git a/backend/Capture.ts b/backend/Capture.ts deleted file mode 100644 index 8d54634..0000000 --- a/backend/Capture.ts +++ /dev/null @@ -1,24 +0,0 @@ -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; - } -} \ No newline at end of file diff --git a/backend/entrypoint.tsx b/backend/entrypoint.tsx index be0de49..b898f71 100644 --- a/backend/entrypoint.tsx +++ b/backend/entrypoint.tsx @@ -1,39 +1,6 @@ import { UIX } from "uix/uix.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"; - -@endpoint export class Screenshot { - @timeout(40_000) - @property static async take(url: string | URL, config?: { - width: number, - height: number, - fullSize?: boolean - }): Promise { - 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 as HTMLImageElement; - } -} // The backend routes definition export default { '/': null, - '/image/*': new UIX.FileProvider(UIX_CACHE_PATH) } satisfies UIX.Entrypoint; \ No newline at end of file