mirror of
https://github.com/yawaflua/yaflay.ru.git
synced 2025-12-09 20:19:32 +02:00
bugfix
This commit is contained in:
@@ -77,19 +77,15 @@ namespace yaflay.ru.Новая_папка
|
||||
{
|
||||
try
|
||||
{
|
||||
Author author = new()
|
||||
{
|
||||
discordId = ulong.Parse(response["user"]["id"].ToString()),
|
||||
discordNickName = response["user"]["global_name"].ToString()
|
||||
};
|
||||
Blogs article = new()
|
||||
{
|
||||
Annotation = body.annotation,
|
||||
author = author,
|
||||
authorId = response["user"]["id"].ToString(),
|
||||
dateTime = DateTime.Now,
|
||||
ImageUrl = body.image,
|
||||
Text = body.text,
|
||||
Title = body.title
|
||||
Title = body.title,
|
||||
authorNickname = response["user"]["global_name"].ToString()
|
||||
};
|
||||
await Startup.dbContext.Blogs.AddAsync(article);
|
||||
await Startup.dbContext.SaveChangesAsync();
|
||||
|
||||
115
Migrations/20231223164820_Migrate321220231944.Designer.cs
generated
Normal file
115
Migrations/20231223164820_Migrate321220231944.Designer.cs
generated
Normal file
@@ -0,0 +1,115 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using yaflay.ru.Models;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace yaflay.ru.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20231223164820_Migrate321220231944")]
|
||||
partial class Migrate321220231944
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.12")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Annotation")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ImageUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("authorId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("authorNickname")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("dateTime")
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Blogs", "public");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("yaflay.ru.Models.Tables.Comments", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("creatorMail")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long>("dateTime")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("postId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Comments", "public");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("yaflay.ru.Models.Tables.Redirects", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("redirectTo")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("uri")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Redirects");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
111
Migrations/20231223164820_Migrate321220231944.cs
Normal file
111
Migrations/20231223164820_Migrate321220231944.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace yaflay.ru.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Migrate321220231944 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Blogs_Author_authorId",
|
||||
schema: "public",
|
||||
table: "Blogs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Author");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Blogs_authorId",
|
||||
schema: "public",
|
||||
table: "Blogs");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "dateTime",
|
||||
schema: "public",
|
||||
table: "Blogs",
|
||||
type: "timestamp without time zone",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "timestamp with time zone");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "authorId",
|
||||
schema: "public",
|
||||
table: "Blogs",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "integer");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "authorNickname",
|
||||
schema: "public",
|
||||
table: "Blogs",
|
||||
type: "text",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "authorNickname",
|
||||
schema: "public",
|
||||
table: "Blogs");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "dateTime",
|
||||
schema: "public",
|
||||
table: "Blogs",
|
||||
type: "timestamp with time zone",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "timestamp without time zone");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "authorId",
|
||||
schema: "public",
|
||||
table: "Blogs",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "text");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Author",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
discordId = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
||||
discordNickName = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Author", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Blogs_authorId",
|
||||
schema: "public",
|
||||
table: "Blogs",
|
||||
column: "authorId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Blogs_Author_authorId",
|
||||
schema: "public",
|
||||
table: "Blogs",
|
||||
column: "authorId",
|
||||
principalTable: "Author",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,26 +22,6 @@ namespace yaflay.ru.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("yaflay.ru.Models.Tables.Author", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<decimal>("discordId")
|
||||
.HasColumnType("numeric(20,0)");
|
||||
|
||||
b.Property<string>("discordNickName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -65,16 +45,19 @@ namespace yaflay.ru.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("authorId")
|
||||
.HasColumnType("integer");
|
||||
b.Property<string>("authorId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("authorNickname")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("dateTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
.HasColumnType("timestamp without time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("authorId");
|
||||
|
||||
b.ToTable("Blogs", "public");
|
||||
});
|
||||
|
||||
@@ -123,17 +106,6 @@ namespace yaflay.ru.Migrations
|
||||
|
||||
b.ToTable("Redirects");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("yaflay.ru.Models.Tables.Blogs", b =>
|
||||
{
|
||||
b.HasOne("yaflay.ru.Models.Tables.Author", "author")
|
||||
.WithMany()
|
||||
.HasForeignKey("authorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("author");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ namespace yaflay.ru.Models.Tables
|
||||
public string Annotation { get; set; }
|
||||
public string? ImageUrl { get; set; }
|
||||
public DateTime dateTime { get; set; }
|
||||
public Author author { get; set; }
|
||||
public string authorId { get; set; }
|
||||
public string authorNickname { get; set; }
|
||||
}
|
||||
|
||||
public class Author
|
||||
{
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
public ulong discordId { get; set; }
|
||||
public string discordNickName { get; set; }
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
@if (Request.Cookies["melon"] != null)
|
||||
{
|
||||
|
||||
if (Startup.ownerId.FirstOrDefault(Request.Cookies["cable"]) == null)
|
||||
if (Startup.ownerId.FirstOrDefault(Request.Cookies["cable"]).isNull())
|
||||
{
|
||||
<h1 align="center">Вы не авторизованы! Сасни хуйца, олух</h1>
|
||||
isAllowed = false;
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
@page "{id?}"
|
||||
@model BlogModel
|
||||
@using yaflay.ru.Models.Tables
|
||||
@{
|
||||
if (Model.Id == 0)
|
||||
ViewData["Title"] = "Blog";
|
||||
}
|
||||
@{
|
||||
string path = $"{this.Request.Scheme}://{this.Request.Host}";
|
||||
}
|
||||
@{
|
||||
if (Model.Id != 0)
|
||||
{
|
||||
|
||||
@@ -29,48 +23,49 @@
|
||||
<p align="left">
|
||||
<h1 align="left">@Html.Raw(Post.Title)</h1>
|
||||
<h5>@Post.dateTime</h5>
|
||||
</p>
|
||||
<div id="blogId" style="display:none;">@Model.Id</div>
|
||||
<p align="center"><img src="@Post.ImageUrl" style="width:50vmax;"/></p>
|
||||
<p align="center">@Html.Raw(Post.Text)</p>
|
||||
string userId = "https://discord.com/users/"+Post.author.discordId;
|
||||
<h6 align="left">Статья подготовлена <a href="@userId">@Post.author.discordNickName</a></h6>
|
||||
<div class="container my-5 py-5 bg-dark text-muted">
|
||||
<div class="row d-flex justify-content-center">
|
||||
<div class="col-md-12 col-lg-10">
|
||||
<div class="card text-muted bg-dark">
|
||||
<div class="card-body position-static p-4" id="allComments">
|
||||
<h4 class="mb-0" id="commentBar">Последние комментарии</h4>
|
||||
</p>
|
||||
<div id="blogId" style="display:none;">@Model.Id</div>
|
||||
<p align="center"><img src="@Post.ImageUrl" style="width:50vmax;"/></p>
|
||||
<p align="center">@Html.Raw(Post.Text)</p>
|
||||
string userUrl = "https://discord.com/users/" + Post.authorId;
|
||||
<h6 align="left">Статья подготовлена <a href="@userUrl">@Post.authorNickname</a></h6>
|
||||
<div class="container my-5 py-5 bg-dark text-muted">
|
||||
<div class="row d-flex justify-content-center">
|
||||
<div class="col-md-12 col-lg-10">
|
||||
<div class="card text-muted bg-dark">
|
||||
<div class="card-body position-static p-4" id="allComments">
|
||||
<h4 class="mb-0" id="commentBar">Последние комментарии</h4>
|
||||
|
||||
<h1 align="center">Дальше тьма...</h1>
|
||||
<h1 align="center">Дальше тьма...</h1>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="card-footer text-white bg-dark mb-3 py-3 border-0" >
|
||||
<div class="d-flex flex-start w-100">
|
||||
<div class="form-outline w-100">
|
||||
<label for="userEmail" class="form-label">Адрес электронной почты</label>
|
||||
<input type="email" class="form-control bg-dark text-white" id="userEmail" placeholder="name@example.com" name="userEmail">
|
||||
<label for="commentText" class="form-label">Комментарий</label>
|
||||
<input type="text" class="form-control bg-dark text-white" id="commentText" rows="4" name="commentText">
|
||||
<div class="card-footer text-white bg-dark mb-3 py-3 border-0" >
|
||||
<div class="d-flex flex-start w-100">
|
||||
<div class="form-outline w-100">
|
||||
<label for="userEmail" class="form-label">Адрес электронной почты</label>
|
||||
<input type="email" class="form-control bg-dark text-white" id="userEmail" placeholder="name@example.com" name="userEmail">
|
||||
<label for="commentText" class="form-label">Комментарий</label>
|
||||
<input type="text" class="form-control bg-dark text-white" id="commentText" rows="4" name="commentText">
|
||||
</div>
|
||||
</div>
|
||||
<div class="float-end mt-2 pt-1">
|
||||
<button type="button" class="btn btn-primary btn-sm" id="postComment" >Запостить коммент</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="float-end mt-2 pt-1">
|
||||
<button type="button" class="btn btn-primary btn-sm" id="postComment" >Запостить коммент</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
ViewData["Title"] = "Blog";
|
||||
var allBlogs = Startup.dbContext.Blogs.ToArray();
|
||||
if (allBlogs.Length == 0)
|
||||
{
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
}
|
||||
string responseBody = await message.Content.ReadAsStringAsync();
|
||||
JsonNode response = JsonNode.Parse(responseBody);
|
||||
if (response["user"] != null)
|
||||
if (!response["user"].isNull())
|
||||
{
|
||||
Context.Response.Cookies.Append("cable", response["user"]["id"].ToString());
|
||||
string userName = response["user"]["global_name"].ToString();
|
||||
|
||||
18
Program.cs
18
Program.cs
@@ -10,9 +10,16 @@ public class Program
|
||||
Startup.clientId = parse("CLIENTID");
|
||||
Startup.clientSecret = parse("CLIENTSECRET");
|
||||
Startup.redirectUrl = parse("REDIRECTURL");
|
||||
Startup.connectionString = $"Host={parse("PSQL_HOST")};Username={parse("PSQL_USER")};Password={parse("PSQL_PASSWORD")};Database={parse("PSQL_DATABASE")}";
|
||||
Startup.ownerId = new[] { parse("OWNERID") };
|
||||
if (!(parse("PSQL_HOST") == null | parse("PSQL_USER") == null | parse("PSQL_PASSWORD") == null | parse("PSQL_DATABASE") == null))
|
||||
{
|
||||
Startup.connectionString = $"Host={parse("PSQL_HOST")};Username={parse("PSQL_USER")};Password={parse("PSQL_PASSWORD")};Database={parse("PSQL_DATABASE")}";
|
||||
}
|
||||
if (parse("OWNERID") != null)
|
||||
{
|
||||
Startup.ownerId = new string?[] { parse("OWNERID") };
|
||||
}
|
||||
Startup.readmeFile = parse("READMEFILE");
|
||||
|
||||
CreateHostBuilder()
|
||||
.Build()
|
||||
.Run();
|
||||
@@ -27,4 +34,11 @@ public class Program
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
public static class StaticProgram
|
||||
{
|
||||
public static bool isNull(this object? value)
|
||||
{
|
||||
return value == null;
|
||||
}
|
||||
}
|
||||
11
Startup.cs
11
Startup.cs
@@ -38,10 +38,19 @@ namespace yaflay.ru
|
||||
if (connectionString == null)
|
||||
{
|
||||
connectionString = configuration.GetValue<string>("connectionString");
|
||||
Console.WriteLine("Connectionstring" + connectionString);
|
||||
if (connectionString == null)
|
||||
{
|
||||
throw new ArgumentException("ConnectionString is null!");
|
||||
}
|
||||
}
|
||||
if (ownerId.Length == 0)
|
||||
if (ownerId == null)
|
||||
{
|
||||
ownerId = new[] { configuration.GetValue<string>("ownerId") };
|
||||
if (ownerId?.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("Owner id is null!");
|
||||
}
|
||||
}
|
||||
if (readmeFile == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user