Skip to content

Commit

Permalink
测试版
Browse files Browse the repository at this point in the history
  • Loading branch information
MonoLogueChi committed Mar 7, 2020
1 parent 4d23c0e commit d961431
Show file tree
Hide file tree
Showing 32 changed files with 487 additions and 165 deletions.
1 change: 1 addition & 0 deletions Danmu.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bili/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bilibili/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Danmu/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Danmus/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dplayer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Postgre/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@
using System.Security.Claims;
using System.Text.Json;
using System.Threading.Tasks;
using Danmu.Controllers.Base;
using Danmu.Model.DataTable;
using Danmu.Model.WebResult;
using Danmu.Utils.Configuration;
using Danmu.Utils.Dao;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using static Danmu.Utils.Global.VariableDictionary;

namespace Danmu.Controllers.Account
{
[Route("/admin")]
[EnableCors(AdminAllowSpecificOrigins)]
public class AccountController : ControllerBase
[Route("/api/admin")]
[AllowAnonymous]
public class AccountBaseController : AdminBaseController
{
private readonly Model.Config.Admin _admin;
private readonly UserDao _userDao;

public AccountController(AppConfiguration configuration, UserDao dao)
public AccountBaseController(AppConfiguration configuration, UserDao userDao, DanmuDao danmuDao,
VideoDao videoDao) : base(danmuDao, videoDao)
{
_admin = configuration.GetAppSetting().Admin;
_userDao = dao;
_userDao = userDao;
}

[HttpGet("login")]
Expand Down Expand Up @@ -86,4 +87,4 @@ public void Logout()
Response.StatusCode = 302;
}
}
}
}
41 changes: 32 additions & 9 deletions Danmu/Controllers/Admin/DanmakuListController.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
using Microsoft.AspNetCore.Authorization;
using System.Threading.Tasks;
using Danmu.Controllers.Base;
using Danmu.Model.DataTable;
using Danmu.Model.WebResult;
using Danmu.Utils.Dao;
using Microsoft.AspNetCore.Mvc;
using static Danmu.Utils.Global.VariableDictionary;

namespace Danmu.Controllers.Admin
{
[Authorize(Policy = AdminRolePolicy)]
[ApiController]
[Route("/admin/danmuList")]
public class DanmuListController : ControllerBase
[Route("/api/admin/danmulist")]
public class DanmuListController : AdminBaseController
{
public DanmuListController(DanmuDao danmuDao, VideoDao videoDao) : base(danmuDao, videoDao) { }

/// <summary>
/// 获取全部弹幕数量
/// </summary>
/// <returns></returns>
[HttpGet("count")]
public async Task<WebResult<int>> GetCount()
{
var count = await DanmuDao.GetAllDanmuAsync();
return new WebResult<int>
{
Code = 0,
Data = count
};
}

/// <summary>
/// 获取全部弹幕
/// </summary>
/// <returns></returns>
[HttpGet]
public string Get()
public async Task<WebResult<DanmuTable[]>> GetDanmuList(int page, int size, bool descending = true)
{
return "11111";
var allDanmu = await DanmuDao.GetAllDanmuAsync(page, size, descending);
return new WebResult<DanmuTable[]>(allDanmu);
}
}
}
}
37 changes: 37 additions & 0 deletions Danmu/Controllers/Admin/DanmuEditController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Threading.Tasks;
using Danmu.Controllers.Base;
using Danmu.Model.DataTable;
using Danmu.Model.WebResult;
using Danmu.Utils.Dao;
using Microsoft.AspNetCore.Mvc;

namespace Danmu.Controllers.Admin
{
[Route("/api/admin/danmuedit/")]
public class DanmuEditController : AdminBaseController
{
public DanmuEditController(DanmuDao danmuDao, VideoDao videoDao) : base(danmuDao, videoDao) { }

[HttpGet("get")]
public async Task<WebResult<DanmuTable>> Get(string id)
{
var danmu = await DanmuDao.QueryDanmuByIdAsync(id);
return new WebResult<DanmuTable>(danmu);
}

[HttpPost("edit")]
public async Task<WebResult<DanmuTable>> EditDanmu(DanmuTable data)
{
var result = await DanmuDao.EditDanmuAsync(data.Id, data.Data.Time, data.Data.Mode, data.Data.Color,
data.Data.Text);
return new WebResult<DanmuTable>(result);
}

[HttpGet("delete")]
public async Task<WebResult> DeleteDanmu(string id)
{
var result = await DanmuDao.DeleteDanmuAsync(id);
return new WebResult(result ? 0 : 1);
}
}
}
23 changes: 23 additions & 0 deletions Danmu/Controllers/Base/AdminBaseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Danmu.Utils.Dao;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using static Danmu.Utils.Global.VariableDictionary;

namespace Danmu.Controllers.Base
{
[ApiController]
[EnableCors(AdminAllowSpecificOrigins)]
[Authorize(Policy = AdminRolePolicy)]
public class AdminBaseController : ControllerBase
{
private protected DanmuDao DanmuDao;
private protected VideoDao VideoDao;

protected AdminBaseController(DanmuDao danmuDao, VideoDao videoDao)
{
DanmuDao = danmuDao;
VideoDao = videoDao;
}
}
}
9 changes: 5 additions & 4 deletions Danmu/Controllers/Danmu/ArtPlayer/V1/ArtPlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task<dynamic> Get(string id, string format)
id ??= Request.Query["id"];
if (string.IsNullOrEmpty(id)) return new WebResult(1);

var result = await DanmuDao.QueryByVidAsync(id);
var result = await DanmuDao.QueryDanmusByVidAsync(id);

if (!string.IsNullOrEmpty(format) && format.Equals("json"))
{
Expand All @@ -48,14 +48,15 @@ public async Task<WebResult> Post([FromBody] ArtPlayerDanmuDataIn data)
: Request.HttpContext.Connection.RemoteIpAddress;
data.Referer = Request.Headers["Referer"].FirstOrDefault();

var video = await VideoDao.InsertAsync(data.Id, new Uri(data.Referer));
var danmu = new DanmuTable
{
Vid = data.Id,
Data = data.ToBaseDanmuData(),
Ip = data.Ip
Ip = data.Ip,
Video = video
};
var result = await DanmuDao.InsertAsync(danmu);
await VideoDao.InsertAsync(data.Id, new Uri(data.Referer));
var result = await DanmuDao.InsertDanmuAsync(danmu);
return new WebResult(result ? 0 : 1);
}
}
Expand Down
17 changes: 6 additions & 11 deletions Danmu/Controllers/Danmu/Common/V1/CommonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ namespace Danmu.Controllers.Danmu.Common.V1
[FormatFilter]
public class CommonController : DanmuBaseController
{
private readonly UserDao _userDao;

public CommonController(DanmuDao danmuDao, VideoDao videoDao, UserDao userDao) : base(danmuDao, videoDao)
{
_userDao = userDao;
}
public CommonController(DanmuDao danmuDao, VideoDao videoDao) : base(danmuDao, videoDao) { }

[HttpGet]
[HttpGet("{id}.{format?}")]
Expand All @@ -30,7 +25,7 @@ public async Task<dynamic> Get(string id, string format)
id ??= Request.Query["id"];
if (string.IsNullOrEmpty(id)) return new WebResult(1);

var result = await DanmuDao.QueryByVidAsync(id);
var result = await DanmuDao.QueryDanmusByVidAsync(id);

if (!string.IsNullOrEmpty(format) && format.Equals("xml")) return (DanmuDataBiliBili) result;

Expand All @@ -46,15 +41,15 @@ public async Task<WebResult> Post([FromBody] BaseDanmuDataIn data)
? ip
: Request.HttpContext.Connection.RemoteIpAddress;
data.Referer = Request.Headers["Referer"].FirstOrDefault();

var video = await VideoDao.InsertAsync(data.Id, new Uri(data.Referer));
var danmu = new DanmuTable
{
Vid = data.Id,
Data = data,
Ip = data.Ip
Ip = data.Ip,
Video = video
};
var result = await DanmuDao.InsertAsync(danmu);
await VideoDao.InsertAsync(data.Id, new Uri(data.Referer));
var result = await DanmuDao.InsertDanmuAsync(danmu);
return new WebResult(result ? 0 : 1);
}
}
Expand Down
9 changes: 5 additions & 4 deletions Danmu/Controllers/Danmu/Dplayer/V3/DplayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task<DplayerWebResult> Get(string id)
id ??= Request.Query["id"];
return string.IsNullOrEmpty(id)
? new DplayerWebResult(1)
: new DplayerWebResult(await DanmuDao.QueryByVidAsync(id));
: new DplayerWebResult(await DanmuDao.QueryDanmusByVidAsync(id));
}

[HttpPost]
Expand All @@ -36,14 +36,15 @@ public async Task<WebResult> Post([FromBody] DplayerDanmuDataIn data)
: Request.HttpContext.Connection.RemoteIpAddress;
data.Referer = Request.Headers["Referer"].FirstOrDefault();

var video = await VideoDao.InsertAsync(data.Id, new Uri(data.Referer));
var danmu = new DanmuTable
{
Vid = data.Id,
Data = data.ToBaseDanmuData(),
Ip = data.Ip
Ip = data.Ip,
Video = video
};
var result = await DanmuDao.InsertAsync(danmu);
await VideoDao.InsertAsync(data.Id, new Uri(data.Referer));
var result = await DanmuDao.InsertDanmuAsync(danmu);
return new WebResult(result ? 0 : 1);
}
}
Expand Down
24 changes: 22 additions & 2 deletions Danmu/Model/Danmu/DanmuData/ArtPlayerDanmuData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,31 @@ public BaseDanmuData ToBaseDanmuData()
public static explicit operator ArtPlayerDanmuData(BaseDanmuData data)
{
var t = data.Mode;
if (t > 7) return null;
switch (t)
{
case 4:
t = 1;
break;
case 5:
t = 1;
break;
case 7:
t = 0;
data.Text = data.Text.Split(",")[4];
break;
case 8:
t = 0;
data.Text = null;
break;
default:
t = 0;
break;
}

return new ArtPlayerDanmuData
{
Time = data.Time,
Mode = t == 4 || t == 5 ? 1 : 0,
Mode = t,
Color = $"#{data.Color:X}",
Size = data.Size,
Text = data.Text
Expand Down
2 changes: 1 addition & 1 deletion Danmu/Model/Danmu/DanmuData/BaseDanmuData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BaseDanmuData : IDanmuData
/// <summary>
/// 弹幕大小
/// </summary>
public int Size { get; set; }
public int Size { get; set; } = 25;

/// <summary>
/// 弹幕颜色
Expand Down
24 changes: 22 additions & 2 deletions Danmu/Model/Danmu/DanmuData/DplayerDanmuData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,31 @@ public BaseDanmuData ToBaseDanmuData()
public static explicit operator DplayerDanmuData(BaseDanmuData data)
{
var t = data.Mode;
if (t > 7) return null;
switch (t)
{
case 4:
t = 2;
break;
case 5:
t = 1;
break;
case 7:
t = 0;
data.Text = data.Text.Split(",")[4];
break;
case 8:
t = 0;
data.Text = null;
break;
default:
t = 0;
break;
}

return new DplayerDanmuData
{
Time = data.Time,
Type = t == 4 ? 2 : t == 5 ? 1 : 0,
Type = t,
Color = data.Color,
Author = string.IsNullOrEmpty(data.Author) ? data.AuthorId.ToString() : data.Author,
Text = data.Text
Expand Down
12 changes: 10 additions & 2 deletions Danmu/Model/DataTable/DanmuTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DanmuTable
/// </summary>
[Key]
[Column("Id")]
public Guid Id { get; set; }
public Guid Id { get; set; } = new Guid();

/// <summary>
/// 弹幕所在视频
Expand Down Expand Up @@ -43,14 +43,22 @@ public class DanmuTable
[Required]
public bool IsDelete { get; set; } = false;

/// <summary>
/// 关联到video表
/// </summary>
[Column("VideoId")]
public VideoTable Video { get; set; }

/// <summary>
/// 生成时间 UTC
/// </summary>
[Column(TypeName = "timestamp(0)")]
public DateTime CreateTime { get; set; } = DateTime.UtcNow;

/// <summary>
/// 修改时间 UTC
/// </summary>
public DateTime UpDateTime { get; set; } = DateTime.UtcNow;
[Column(TypeName = "timestamp(0)")]
public DateTime UpdateTime { get; set; } = DateTime.UtcNow;
}
}
4 changes: 3 additions & 1 deletion Danmu/Model/DataTable/UserTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ public class UserTable
/// <summary>
/// 生成时间 UTC
/// </summary>
[Column(TypeName = "timestamp(3)")]
public DateTime CreateTime { get; set; } = DateTime.UtcNow;

/// <summary>
/// 修改时间 UTC
/// </summary>
[Column(TypeName = "timestamp(3)")]
public DateTime UpDateTime { get; set; } = DateTime.UtcNow;
}

Expand All @@ -69,4 +71,4 @@ public enum UserRole
Guests = 2,
GeneralUser = 3
}
}
}
Loading

0 comments on commit d961431

Please sign in to comment.