-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(daemon): screenshot endpoint and fixed exec
Co-authored-by: IncognitoTGT <[email protected]>
- Loading branch information
1 parent
21a448c
commit 71c8a2c
Showing
4 changed files
with
58 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { docker } from "~/lib/docker.js"; | ||
export default async function screenshot(id: string) { | ||
const container = docker.getContainer(id); | ||
const exec = await container.exec({ | ||
Cmd: ["sh", "-c", "xwd -root | convert xwd:- png:- | base64"], | ||
AttachStdout: true, | ||
AttachStderr: true, | ||
}); | ||
|
||
const stream = await exec.start({ hijack: true, stdin: true }); | ||
const encoded = await new Promise<string>((res, err) => { | ||
const out: string[] = []; | ||
stream.on("error", err); | ||
stream.on("data", (chunk) => out.push(chunk.toString())); | ||
stream.on("end", () => res(out.join(""))); | ||
}); | ||
const file = Buffer.from(encoded, "base64"); | ||
return file; | ||
} |