-module(og_image@fetch). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/og_image/fetch.gleam"). -export([fetch_all/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/og_image/fetch.gleam", 18). -spec fetch_url(binary()) -> {ok, bitstring()} | {error, nil}. fetch_url(Url) -> gleam@result:'try'( begin _pipe = gleam@http@request:to(Url), gleam@result:replace_error(_pipe, nil) end, fun(Req) -> Req@1 = gleam@http@request:set_body(Req, <<>>), gleam@result:'try'( begin _pipe@1 = gleam@httpc:send_bits(Req@1), gleam@result:replace_error(_pipe@1, nil) end, fun(Resp) -> case erlang:element(2, Resp) of 200 -> {ok, erlang:element(4, Resp)}; _ -> {error, nil} end end ) end ). -file("src/og_image/fetch.gleam", 8). ?DOC( " Fetch all URLs and return a list of (url, bytes) tuples\n" " Failed fetches are silently skipped\n" ). -spec fetch_all(list(binary())) -> list({binary(), bitstring()}). fetch_all(Urls) -> _pipe = Urls, gleam@list:filter_map(_pipe, fun(Url) -> case fetch_url(Url) of {ok, Bytes} -> {ok, {Url, Bytes}}; {error, _} -> {error, nil} end end).