-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
270 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace TheresaBot.Main.Model.DTO | ||
{ | ||
public record CookieDto | ||
{ | ||
public string pcookie { get; set; } | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
Theresa3rd-Bot/TheresaBot.Main/Controller/CookieController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using TheresaBot.Main.Datas; | ||
using TheresaBot.Main.Exceptions; | ||
using TheresaBot.Main.Model.DTO; | ||
using TheresaBot.Main.Model.Result; | ||
using TheresaBot.Main.Services; | ||
|
||
namespace TheresaBot.Main.Controller | ||
{ | ||
[ApiController] | ||
[Route("api/[controller]")] | ||
public class CookieController : BaseController | ||
{ | ||
private WebsiteService websiteService; | ||
|
||
public CookieController() | ||
{ | ||
websiteService = new WebsiteService(); | ||
} | ||
|
||
[HttpGet] | ||
[Authorize] | ||
[Route("get/pixiv")] | ||
public ApiResult GetPixiv() | ||
{ | ||
var data = new { cookie = WebsiteDatas.Pixiv?.Cookie ?? string.Empty }; | ||
return ApiResult.Success(data); | ||
} | ||
|
||
[HttpPost] | ||
[Authorize] | ||
[Route("set/pixiv")] | ||
public ApiResult SetPixiv([FromBody] CookieDto cookie) | ||
{ | ||
try | ||
{ | ||
var cookieStr = cookie.Cookie; | ||
if (string.IsNullOrWhiteSpace(cookieStr)) return ApiResult.ParamError; | ||
var website = websiteService.UpdatePixivCookie(cookieStr); | ||
WebsiteDatas.LoadWebsite(); | ||
return ApiResult.Success(); | ||
} | ||
catch (HandleException ex) | ||
{ | ||
return ApiResult.Fail(ex); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ApiResult.Fail(ex); | ||
} | ||
} | ||
|
||
[HttpGet] | ||
[Authorize] | ||
[Route("get/saucenao")] | ||
public ApiResult GetSaucenao() | ||
{ | ||
var data = new { cookie = WebsiteDatas.Saucenao?.Cookie ?? string.Empty }; | ||
return ApiResult.Success(data); | ||
} | ||
|
||
[HttpPost] | ||
[Authorize] | ||
[Route("set/saucenao")] | ||
public ApiResult SetSaucenao([FromBody] CookieDto cookie) | ||
{ | ||
try | ||
{ | ||
var cookieStr = cookie.Cookie; | ||
if (string.IsNullOrWhiteSpace(cookieStr)) return ApiResult.ParamError; | ||
var website = websiteService.UpdateSaucenaoCookie(cookieStr); | ||
WebsiteDatas.LoadWebsite(); | ||
return ApiResult.Success(); | ||
} | ||
catch (HandleException ex) | ||
{ | ||
return ApiResult.Fail(ex); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ApiResult.Fail(ex); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
Theresa3rd-Bot/TheresaBot.Main/Exceptions/HandleException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace TheresaBot.Main.Exceptions | ||
{ | ||
public class HandleException : Exception | ||
{ | ||
public string RemindMessage { get; init; } | ||
|
||
public HandleException(string message) : base(message) | ||
{ | ||
this.RemindMessage = message; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace TheresaBot.Main.Model.DTO | ||
{ | ||
public record CookieDto | ||
{ | ||
public string Cookie { get; set; } | ||
} | ||
} |
Oops, something went wrong.