update response route by mime type

This commit is contained in:
yggverse 2024-09-16 14:31:04 +03:00
parent a478e31bd5
commit ebadc548c0

View File

@ -370,33 +370,21 @@ void Page::navigation_reload(
action__update->activate(); action__update->activate();
// Parse meta // Parse meta
Socket::Client::Gemini::Response::Status status; Socket::Client::Gemini::Response::Status status; // @TODO make page global?
Socket::Client::Gemini::Response::Match::meta( Socket::Client::Gemini::Response::Match::meta(
buffer, buffer,
status, status,
mime mime
); );
// Try detect mime by file extension on still undefined @TODO // MIME type not detected
if (mime == MIME::UNDEFINED) if (mime == MIME::UNDEFINED)
{ {
// Try detect by file extension
if (Glib::str_has_suffix(g_uri_get_path(uri), ".gmi")) if (Glib::str_has_suffix(g_uri_get_path(uri), ".gmi"))
{ {
mime = MIME::TEXT_GEMINI; mime = MIME::TEXT_GEMINI;
} }
else
{
// Update
title = _("Oops");
description = _("MIME type not supported");
progress_fraction = 1;
action__update->activate();
}
} }
// Route by status code // Route by status code
@ -404,6 +392,42 @@ void Page::navigation_reload(
{ {
case Socket::Client::Gemini::Response::Status::SUCCESS: case Socket::Client::Gemini::Response::Status::SUCCESS:
// Route by MIME
switch (mime)
{
case MIME::TEXT_GEMINI:
progress_fraction = 1;
// Set content driver
pageContent->update(
page::Content::TEXT_GEMINI,
buffer,
uri
);
// Update title on detected by document provider
if (!pageContent->get_title().empty())
{
title = pageContent->get_title();
}
action__update->activate();
break;
default:
// Update
title = _("Oops");
description = _("MIME type not supported");
progress_fraction = 1;
action__update->activate();
}
// Update // Update
title = _("Done"); // @TODO page title title = _("Done"); // @TODO page title
@ -411,23 +435,6 @@ void Page::navigation_reload(
uri uri
); );
progress_fraction = 1;
// Set content driver
pageContent->update(
page::Content::TEXT_GEMINI,
buffer,
uri
);
// Update title on detected by document provider
if (!pageContent->get_title().empty())
{
title = pageContent->get_title();
}
action__update->activate();
break; break;
// @TODO other statuses.. // @TODO other statuses..