Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
MonoLogueChi committed Oct 13, 2019
2 parents 09a2917 + e20ca6e commit cbcc81c
Show file tree
Hide file tree
Showing 50 changed files with 1,142 additions and 600 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Expand Up @@ -5,7 +5,6 @@

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

Expand All @@ -26,6 +25,7 @@ bld/

# Visual Studio 2015/2017 cache/options directory
.vs/
.vscode/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

Expand Down Expand Up @@ -169,7 +169,6 @@ publish/
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# Microsoft Azure Web App publish settings. Comment the next line if you want to
Expand Down Expand Up @@ -328,3 +327,6 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/


*.db
22 changes: 14 additions & 8 deletions Danmaku.sln
@@ -1,25 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29009.5
VisualStudioVersion = 16.0.29209.152
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Danmaku", "Danmaku\Danmaku.csproj", "{1FC2FA6B-6D9D-4D77-A175-EF41762512FD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Danmaku", "Danmaku\Danmaku.csproj", "{D15E57FF-E4E0-4252-B862-88517FFB7156}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Release-Linux32|Any CPU = Release-Linux32|Any CPU
Release-Linux64|Any CPU = Release-Linux64|Any CPU
Release-Win|Any CPU = Release-Win|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1FC2FA6B-6D9D-4D77-A175-EF41762512FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FC2FA6B-6D9D-4D77-A175-EF41762512FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FC2FA6B-6D9D-4D77-A175-EF41762512FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FC2FA6B-6D9D-4D77-A175-EF41762512FD}.Release|Any CPU.Build.0 = Release|Any CPU
{D15E57FF-E4E0-4252-B862-88517FFB7156}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D15E57FF-E4E0-4252-B862-88517FFB7156}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D15E57FF-E4E0-4252-B862-88517FFB7156}.Release-Linux32|Any CPU.ActiveCfg = Release-Linux32|Any CPU
{D15E57FF-E4E0-4252-B862-88517FFB7156}.Release-Linux32|Any CPU.Build.0 = Release-Linux32|Any CPU
{D15E57FF-E4E0-4252-B862-88517FFB7156}.Release-Linux64|Any CPU.ActiveCfg = Release-Linux64|x64
{D15E57FF-E4E0-4252-B862-88517FFB7156}.Release-Linux64|Any CPU.Build.0 = Release-Linux64|x64
{D15E57FF-E4E0-4252-B862-88517FFB7156}.Release-Win|Any CPU.ActiveCfg = Release-Win|Any CPU
{D15E57FF-E4E0-4252-B862-88517FFB7156}.Release-Win|Any CPU.Build.0 = Release-Win|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {58C37507-935E-45D9-BAE9-DE527FF5817D}
SolutionGuid = {123045BC-218E-445A-8A75-BB2EC747A128}
EndGlobalSection
EndGlobal
64 changes: 64 additions & 0 deletions Danmaku/Controllers/AccountController.cs
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Danmaku.Model;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc;

namespace Danmaku.Controllers
{

public class AccountController : Controller
{
private readonly Admin _admin;

public AccountController()
{
_admin = AppConfiguration.Config.Admin;
}



public ActionResult Login()
{
return View();
}

[HttpPost]
public async Task<IActionResult> Login(string userName, string password, string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;

// Normally Identity handles sign in, but you can do it directly
if (userName == _admin.User && password == _admin.Password)
{
var claims = new List<Claim>
{
new Claim("user", userName),
new Claim("role", "Member")
};

await HttpContext.SignInAsync(new ClaimsPrincipal(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme, "user", "role")));

if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return Redirect("/");
}
}

return View();
}

[HttpGet]
public async Task<IActionResult> Logout()
{
await HttpContext.SignOutAsync();
return Redirect("/");
}
}
}
16 changes: 16 additions & 0 deletions Danmaku/Controllers/Base/DanmakuDaoBaseController.cs
@@ -0,0 +1,16 @@
using Danmaku.Utils.Dao;
using Microsoft.AspNetCore.Mvc;

namespace Danmaku.Controllers.Base
{
[ApiController]
public class DanmakuDaoBaseController : Controller
{
private protected readonly IDanmakuDao Dao;

public DanmakuDaoBaseController(IDanmakuDao danmakuDao)
{
Dao = danmakuDao;
}
}
}
34 changes: 34 additions & 0 deletions Danmaku/Controllers/Dplayer/DanmakuList/DanmakuListController.cs
@@ -0,0 +1,34 @@
using Danmaku.Controllers.Base;
using Danmaku.Utils.Dao;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Danmaku.Controllers.Dplayer.DanmakuList
{
[Route("dplayer/danmakulist")]
[Authorize]
public class DanmakuListController : DanmakuDaoBaseController
{
public DanmakuListController(IDanmakuDao danmakuDao) : base(danmakuDao)
{
}


public ActionResult Index()
{
return View(Dao.DanmakuBaseQuery(1, 10));
}

// [HttpPost]
// public ActionResult Index(int page, int size = 10)
// {
// return View(Dao.DanmakuBaseQuery(page, size));
// }

[HttpPost]
public ActionResult Index(string vid)
{
return View(Dao.DanmakuBasesQueryByVid(vid, 1, 10));
}
}
}
43 changes: 43 additions & 0 deletions Danmaku/Controllers/Dplayer/V3/BiliBiliController.cs
@@ -0,0 +1,43 @@
using System;
using Danmaku.Model;
using Danmaku.Utils.BiliBili;
using Microsoft.AspNetCore.Mvc;

namespace Danmaku.Controllers.Dplayer.V3
{
[Route("api/dplayer/v3")]
[ApiController]
public class BiliBiliController : ControllerBase
{
private readonly IBiliBiliHelp _biliBili;

public BiliBiliController(IBiliBiliHelp biliBiliHelp)
{
_biliBili = biliBiliHelp;
}

// GET: api/dplayer/v3/bilibili
[HttpGet("bilibili")]
public string Get()
{
var request = Request.Query;

string[] date = request["date"];
var cid = request["cid"].ToString();
if (string.IsNullOrEmpty(cid))
{
var aid = request["aid"];
string p = request["p"];
p = string.IsNullOrEmpty(p) ? "1" : p;
if (!int.TryParse(p, out var page)) return new DanmakuWebResult(1);
cid = _biliBili.GetCid(aid, page).ToString();
}

return String.IsNullOrWhiteSpace(cid)
? new DanmakuWebResult(1)
: date.Length == 0
? new DanmakuWebResult(_biliBili.GetBiDanmaku(cid))
: new DanmakuWebResult(_biliBili.GetBiDanmaku(cid, date));
}
}
}
41 changes: 41 additions & 0 deletions Danmaku/Controllers/Dplayer/V3/DplayerController.cs
@@ -0,0 +1,41 @@
using System.Linq;
using System.Net;
using Danmaku.Controllers.Base;
using Danmaku.Model;
using Danmaku.Utils.Dao;
using Microsoft.AspNetCore.Mvc;

namespace Danmaku.Controllers.Dplayer.V3
{
[Route("api/dplayer/v3")]
[ApiController]
public class DplayerController : DanmakuDaoBaseController
{
public DplayerController(IDanmakuDao danmakuDao) : base(danmakuDao)
{
}

// GET: api/dplayer/v3/
[HttpGet]
public string Get()
{
string id = Request.Query["id"];
return string.IsNullOrEmpty(id) ? new DanmakuWebResult(1) : new DanmakuWebResult(Dao.DanmakuQuery(id));
}

// POST: api/dplayer/v3/
[HttpPost]
public string Post([FromBody] DanmakuDataInsert data)
{
if (string.IsNullOrWhiteSpace(data.Id) || string.IsNullOrWhiteSpace(data.Text))
return new DanmakuWebResult(1);
data.Ip = IPAddress.TryParse(Request.Headers["X-Real-IP"], out var ip)
? ip
: Request.HttpContext.Connection.RemoteIpAddress;
data.Referer = Request.Headers["Referer"].FirstOrDefault();

var result = Dao.DanmakuInsert(data);
return result == 0 ? new DanmakuWebResult(1) : new DanmakuWebResult(0);
}
}
}
103 changes: 0 additions & 103 deletions Danmaku/Controllers/DplayerController.cs

This file was deleted.

0 comments on commit cbcc81c

Please sign in to comment.