@@ -16,18 +16,24 @@ import Karm.Http;
1616
1717namespace PaperMuncher {
1818
19- Rc<Http::Client> createHttpClient (bool sandboxed) {
20- auto client = Http::defaultClient ();
21-
22- if (sandboxed)
23- client = makeRc<Http::Client>(
24- Http::multiplexTransport ({
25- Http::pipeTransport (),
26- Http::localTransport ({" bundle" s}),
27- })
28- );
19+ Rc<Http::Client> createHttpClient (bool unsecure) {
20+ Vec<Rc<Http::Transport>> transports;
21+
22+ transports.pushBack (Http::pipeTransport ());
2923
24+ if (unsecure) {
25+ transports.pushBack (Http::httpTransport ());
26+ transports.pushBack (Http::localTransport ());
27+ } else {
28+ // NOTE: Only allow access to bundle assets and standard input/output.
29+ transports.pushBack (Http::localTransport ({" bundle" s, " fd" s}));
30+ }
31+
32+ auto client = makeRc<Http::Client>(
33+ Http::multiplexTransport (std::move (transports))
34+ );
3035 client->userAgent = " Paper-Muncher/" stringify$(__ck_version_value) " " s;
36+
3137 return client;
3238}
3339
@@ -176,7 +182,7 @@ Async::Task<> renderAsync(
176182 };
177183
178184 auto media = constructMediaForRender (options.scale , imageSize);
179- auto [layout, paint , frags] = Vaev::Driver::render (*dom, media, {.small = imageSize});
185+ auto [layout, scene , frags] = Vaev::Driver::render (*dom, media, {.small = imageSize});
180186
181187 auto image = Gfx::Surface::alloc (
182188 imageSize.cast <isize>() * options.density .toDppx (),
@@ -186,7 +192,7 @@ Async::Task<> renderAsync(
186192 Gfx::CpuCanvas g;
187193 g.begin (*image);
188194 g.scale (options.density .toDppx ());
189- paint ->paint (g);
195+ scene ->paint (g);
190196 if (options.wireframe )
191197 Vaev::Layout::wireframe (*frags, g);
192198 g.end ();
@@ -218,29 +224,19 @@ Async::Task<> renderAsync(
218224Async::Task<> entryPointAsync (Sys::Context& ctx) {
219225 auto inputArg = Cli::operand<Str>(" input" s, " Input file (default: stdin)" s, " -" s);
220226 auto outputArg = Cli::option<Str>(' o' , " output" s, " Output file (default: stdout)" s, " -" s);
221- auto outputMimeArg = Cli::option<Str>(NONE , " output-mime " s, " Overide the output MIME type " s, " " s);
222- auto sandboxArg = Cli::flag (NONE, " sandbox " s, " Allow only basic I/O, handle HTTP via stdin/stdout, and block all file access" s);
223- auto logLevelArg = Cli::option<Str>(NONE , " log-level " s, " Set lowest log level authorized : print, yappin', debug, info, warn, error, or fatal (default: print)" s);
227+ auto formatArg = Cli::option<Str>(' f ' , " format " s, " Override the output file format " s, " " s);
228+ auto unsecureArg = Cli::flag (NONE, " unsecure " s, " Allow local file and http access" s);
229+ auto verboseArg = Cli::flag ( ' v ' , " verbose " s, " Set lowest log level authorized : print, yappin', debug, info, warn, error, or fatal (default: print)" s);
224230
225231 Cli::Command cmd{
226232 " paper-muncher" s,
227233 NONE,
228234 " Munch the web into crisp documents" s,
229- {sandboxArg, logLevelArg },
235+ {unsecureArg, verboseArg },
230236 [=](Sys::Context&) -> Async::Task<> {
231- if (Str setLevel = logLevelArg) {
232- for (auto & level : {PRINT, YAP, DEBUG, INFO, WARNING, ERROR, FATAL}) {
233- if (startWith (Str (level.name ), setLevel) != Match::NO) {
234- setLogLevel (level);
235- break ;
236- }
237- }
238- }
239-
240- if (sandboxArg) {
241- logInfo (" running sandboxed" );
237+ setLogLevel (verboseArg ? PRINT : ERROR);
238+ if (not unsecureArg)
242239 co_try$(Sys::enterSandbox ());
243- }
244240 co_return Ok ();
245241 }
246242 };
@@ -260,7 +256,7 @@ Async::Task<> entryPointAsync(Sys::Context& ctx) {
260256 {
261257 inputArg,
262258 outputArg,
263- outputMimeArg ,
259+ formatArg ,
264260 densityArg,
265261
266262 paperArg,
@@ -293,11 +289,10 @@ Async::Task<> entryPointAsync(Sys::Context& ctx) {
293289 if (outputArg.unwrap () != " -" s)
294290 output = Mime::parseUrlOrPath (outputArg, co_try$(Sys::pwd ()));
295291
296- if (outputMimeArg.unwrap () != " " s)
297- options.outputFormat = co_try$(Mime::Uti::fromMime (Mime::Mime{outputMimeArg}));
298-
299- auto client = PaperMuncher::createHttpClient (sandboxArg);
292+ if (formatArg.unwrap () != " " s)
293+ options.outputFormat = co_try$(Mime::Uti::fromMime ({formatArg}));
300294
295+ auto client = PaperMuncher::createHttpClient (unsecureArg);
301296 co_return co_await PaperMuncher::printAsync (client, input, output, options);
302297 }
303298 );
@@ -309,7 +304,7 @@ Async::Task<> entryPointAsync(Sys::Context& ctx) {
309304 {
310305 inputArg,
311306 outputArg,
312- outputMimeArg ,
307+ formatArg ,
313308 densityArg,
314309
315310 widthArg,
@@ -340,10 +335,10 @@ Async::Task<> entryPointAsync(Sys::Context& ctx) {
340335 if (outputArg.unwrap () != " -" s)
341336 output = Mime::parseUrlOrPath (outputArg, co_try$(Sys::pwd ()));
342337
343- if (outputMimeArg .unwrap () != " " s)
344- options.outputFormat = co_try$(Mime::Uti::fromMime ({outputMimeArg }));
338+ if (formatArg .unwrap () != " " s)
339+ options.outputFormat = co_try$(Mime::Uti::fromMime ({formatArg }));
345340
346- auto client = PaperMuncher::createHttpClient (sandboxArg );
341+ auto client = PaperMuncher::createHttpClient (unsecureArg );
347342
348343 co_return co_await renderAsync (client, input, output, options);
349344 }
0 commit comments