Removed frontend and moved out of sln into solely csproj style
This commit is contained in:
57
Controllers/Admin.cs
Normal file
57
Controllers/Admin.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Hangfire.Storage;
|
||||
|
||||
namespace YTManager.Controllers {
|
||||
[Produces("application/json")]
|
||||
[Route("api/admin")]
|
||||
public class AdminController : Controller {
|
||||
// Get the mass update daemon job.
|
||||
private static RecurringJobDto get_massupdatedaemon() {
|
||||
return Hangfire.JobStorage
|
||||
.Current
|
||||
.GetConnection()
|
||||
.GetRecurringJobs()
|
||||
.SingleOrDefault(j => j.Id == Mass_Updater_ID);
|
||||
}
|
||||
|
||||
// ID for mass update job, used to tell if the job is running or not.
|
||||
public static string Mass_Updater_ID { get; } = "2013066213";
|
||||
|
||||
// POST api/Admin/Trigger_Mass_Update
|
||||
// Trigger a mass channel update.
|
||||
[HttpPost("Trigger_Mass_Update")]
|
||||
public IActionResult Trigger_Mass_Update() {
|
||||
Hangfire.RecurringJob.Trigger(Mass_Updater_ID);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
// POST api/Admin/Update/YTChannelID
|
||||
// Update the videos for a specific channel.
|
||||
[HttpPost("Update/{YoutubeID}")]
|
||||
public IActionResult Update([FromRoute] string YoutubeID) {
|
||||
Hangfire.BackgroundJob.Enqueue(() => Tasks.FetchVideos.ChannelUpdate(Startup.DBStr, YoutubeID));
|
||||
return Ok();
|
||||
}
|
||||
|
||||
// POST api/Admin/Start_Updater
|
||||
// Ensures that the background YT Channel update API is running.
|
||||
[HttpPost("Start_Updater")]
|
||||
public IActionResult Start_Updater() {
|
||||
if (get_massupdatedaemon() == null) {
|
||||
Hangfire.RecurringJob.AddOrUpdate(
|
||||
Mass_Updater_ID,
|
||||
() => Tasks.FetchVideos.MassUpdate(Startup.DBStr), Hangfire.Cron.Minutely);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
// GET api/Admin/Updater
|
||||
// Check if the periodic update job is enqued.
|
||||
[HttpGet("Update")]
|
||||
public IActionResult Get_Update_Status() {
|
||||
return Ok(get_massupdatedaemon() == null ? "false" : "true");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user