rework oembed, because he didn`t work as well

This commit is contained in:
Дмитрий Шиманский
2023-10-22 13:10:43 +03:00
parent 5471ad08ba
commit b3b570f56e
4 changed files with 27 additions and 37 deletions

View File

@@ -6,7 +6,9 @@ using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Xml.Schema;
using HeyRed.OEmbed.Abstractions;
using HeyRed.OEmbed.Models;
using HeyRed.OEmbed;
namespace yaflay.ru.Новая_папка
{
@@ -40,11 +42,12 @@ namespace yaflay.ru.Новая_папка
public async Task<IActionResult> fromGitHub(string? uri)
{
if (uri == "Robots.txt") { return Ok("User-Agent: * \n Disallow: \"/*\""); }
if (uri == "Robots.txt") { return Ok("User-Agent: * \n Disallow: /*"); }
string? url = await getUrlFromGit(uri);
return Redirect(url != null ? url : "https://yaflay.ru/");
await Console.Out.WriteLineAsync(url == null ? "Null" : $"notNull {url}");
return Redirect(url ?? "https://yaflay.ru/");
}
// GET: HomeController/Create

View File

@@ -6,7 +6,8 @@
<title>@ViewData["Title"] - yaflay.ru</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/yaflay.ru.styles.css" asp-append-version="true" />
<!-- <link rel="stylesheet" href="~/yaflay.ru.styles.css" asp-append-version="true" /> --!/>
<link type="application/json+oembed" href="~/json/oembed.json" />
</head>
<body>
<header>

View File

@@ -1,52 +1,22 @@
using Microsoft.Extensions.Options;
using HeyRed.OEmbed;
using HeyRed.OEmbed.Providers;

namespace yaflay.ru
{
public class Startup
{
private readonly IConfiguration configuration;
private readonly OEmbedOptions options;
public Startup()
{
configuration = new ConfigurationBuilder()
.AddEnvironmentVariables(prefix: "m.")
.AddJsonFile("appsettings.json", optional: true)
.Build();
options = new OEmbedOptions()
{
EnableCache = true
};
}
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddRouting();
services.AddRazorPages();
services.AddOEmbed(options =>
{
options.EnableCache = true; // true by default
options.EnsureNotNull();
})
.ClearProviders()
.AddProvider<YoutubeProvider>()
.AddProvider<YandexMusicProvider>()
.AddProvider<FlickrProvider>()
.AddProvider<TwitterProvider>(options =>
{
options.Parameters = new Dictionary<string, string?>
{
["theme"] = "dark"
};
})
.AddProvider<FacebookProvider>(options =>
{
options.Parameters = new Dictionary<string, string?>
{
["access_token"] = "app_id|token"
};
});
services.AddMvc()
.AddRazorPagesOptions(options =>
{

16
wwwroot/json/oembed.json Normal file
View File

@@ -0,0 +1,16 @@
{
"embeds": [
{
"type": "link",
"url": "https://yaflay.ru/",
"title": "YaFlay ReadMe",
"description": "Here you can learn about YaFlay: social networks, programming languages that he knows and his projects.",
"thumbnail": {
"url": "https://avatars.githubusercontent.com/u/93622229?v=4",
"proxy_url": "https://avatars.githubusercontent.com/u/93622229?v=4",
"width": 1200,
"height": 1200
}
}
]
}