blob: 893d9a523a3f08bd2e7696a54cf96318c0e4144c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using StardewModdingAPI.Web.Framework;
using StardewModdingAPI.Web.Framework.ConfigModels;
using StardewModdingAPI.Web.Framework.LogParser;
namespace StardewModdingAPI.Web.Controllers
{
/// <summary>Provides a web UI and API for parsing SMAPI log files.</summary>
internal class LogParserController : Controller
{
/*********
** Properties
*********/
/// <summary>The underlying Pastebin client.</summary>
private readonly PastebinClient PastebinClient;
/*********
** Public methods
*********/
/***
** Constructor
***/
/// <summary>Construct an instance.</summary>
/// <param name="configProvider">The log parser config settings.</param>
public LogParserController(IOptions<LogParserConfig> configProvider)
{
// init Pastebin client
LogParserConfig config = configProvider.Value;
string version = this.GetType().Assembly.GetName().Version.ToString(3);
string userAgent = string.Format(config.PastebinUserAgent, version);
this.PastebinClient = new PastebinClient(config.PastebinBaseUrl, userAgent, config.PastebinDevKey);
}
/***
** Web UI
***/
/// <summary>Render the log parser UI.</summary>
[HttpGet]
[Route("log")]
public ViewResult Index()
{
return this.View("Index");
}
/***
** JSON
***/
/// <summary>Fetch raw text from Pastebin.</summary>
/// <param name="id">The Pastebin paste ID.</param>
[HttpGet, Produces("application/json")]
[Route("log/fetch/{id}")]
public async Task<GetPasteResponse> GetAsync(string id)
{
return await this.PastebinClient.GetAsync(id);
}
/// <summary>Save raw log data.</summary>
/// <param name="content">The log content to save.</param>
[HttpPost, Produces("application/json"), AllowLargePosts]
[Route("log/save")]
public async Task<SavePasteResponse> PostAsync([FromBody] string content)
{
return await this.PastebinClient.PostAsync(content);
}
}
}
|