Rewild Your Web
18
fork

Configure Feed

Select the types of activity you want to include in your feed.

tiles: auto-registration

Signed-off-by: webbeef <me@webbeef.org>

webbeef a13cd7f7 e53a113f

+54 -4
+54 -4
patches/components/net/protocols/web_tiles.rs.patch
··· 1 1 --- original 2 2 +++ modified 3 - @@ -0,0 +1,161 @@ 3 + @@ -0,0 +1,211 @@ 4 4 +// SPDX-License-Identifier: AGPL-3.0-or-later 5 5 + 6 6 +/// Implementation of the tile:// protocol handler. ··· 19 19 +use log::error; 20 20 +use net_traits::fetch::utils::http_response; 21 21 +use net_traits::request::Request; 22 - +use net_traits::response::Response; 22 + +use net_traits::response::{Response, ResponseBody}; 23 23 +use servo_url::ServoUrl; 24 24 + 25 25 +use crate::atproto::pds::get_endpoint_for_subject; ··· 98 98 + return http_response(url, StatusCode::BAD_REQUEST, "Invalid rkey.subject format"); 99 99 + }; 100 100 + 101 - + let Some(tile) = context2.state.get_webtile(subject, rkey) else { 102 - + return http_response(url, StatusCode::BAD_REQUEST, "No such tile registered"); 101 + + // Look up the tile, or auto-fetch the manifest if not registered. 102 + + let tile = if let Some(tile) = context2.state.get_webtile(subject, rkey) { 103 + + tile 104 + + } else { 105 + + // Tile not registered — fetch the ing.dasl.masl record to register it. 106 + + let Ok((manifest_endpoint, manifest_document)) = get_endpoint_for_subject( 107 + + subject, 108 + + Some(document_storage.clone()), 109 + + Some(dns_resolver.clone()), 110 + + ) 111 + + .await 112 + + else { 113 + + return http_response( 114 + + url, 115 + + StatusCode::BAD_REQUEST, 116 + + "Failed to resolve endpoint for subject", 117 + + ); 118 + + }; 119 + + let manifest_client = XrpcClient::new( 120 + + manifest_endpoint, 121 + + url.clone(), 122 + + &manifest_document.id, 123 + + context2.clone(), 124 + + ); 125 + + let Ok(response) = manifest_client.get_record("ing.dasl.masl", rkey).await else { 126 + + return http_response( 127 + + url, 128 + + StatusCode::NOT_FOUND, 129 + + "Failed to fetch tile manifest", 130 + + ); 131 + + }; 132 + + // Register the tile from the response body. 133 + + let body = response.body.lock(); 134 + + let ResponseBody::Done(ref json) = *body else { 135 + + return http_response( 136 + + url, 137 + + StatusCode::INTERNAL_SERVER_ERROR, 138 + + "Incomplete manifest response", 139 + + ); 140 + + }; 141 + + context2.state.register_webtile(subject, rkey, json); 142 + + drop(body); 143 + + 144 + + // Retrieve the freshly registered tile. 145 + + let Some(tile) = context2.state.get_webtile(subject, rkey) else { 146 + + return http_response( 147 + + url, 148 + + StatusCode::BAD_REQUEST, 149 + + "Failed to parse tile manifest", 150 + + ); 151 + + }; 152 + + tile 103 153 + }; 104 154 + 105 155 + let Ok((endpoint_url, document)) =