-
-
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
3e42b97
commit ada023e
Showing
4 changed files
with
3 additions
and
60 deletions.
There are no files selected for viewing
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_screenshot | ||
prod: @+example_threads | ||
}, | ||
|
||
location: stage { | ||
prod: @+unyt_eu1 | ||
}, | ||
|
||
domain: stage { | ||
prod: 'screenshot.unyt.app' | ||
prod: 'threads.example.unyt.org' | ||
} |
This file was deleted.
Oops, something went wrong.
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,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<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 { | ||
'/': null, | ||
'/image/*': new UIX.FileProvider(UIX_CACHE_PATH) | ||
} satisfies UIX.Entrypoint; |