Skip to content

Commit

Permalink
feat(afdian.server): update
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyungent committed Dec 9, 2021
1 parent 683c4b6 commit ac7482e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/Afdian.Server/Afdian.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<UserSecretsId>ed01adf5-b266-4e3b-befc-e8a50604c672</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
<Version>0.2.5</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions src/Afdian.Server/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Afdian.Server.Controllers
{
[ApiExplorerSettings(IgnoreApi = true)]
[Route("api/[controller]/[action]")]
[ApiController]
public class HomeController : ControllerBase
{
[HttpGet]
public async Task<string> Version()
{
string version = Utils.CommonUtil.Version();

return await Task.FromResult(version);
}

}
}
18 changes: 14 additions & 4 deletions src/Afdian.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ public void ConfigureServices(IServiceCollection services)
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
string version = Utils.CommonUtil.Version();
// https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-6.0&tabs=visual-studio
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
options.SwaggerDoc($"v{version}", new Microsoft.OpenApi.Models.OpenApiInfo
{
Version = "v1",
Version = $"v{version}",
Title = "爱发电 Badge",
Description = "爱发电 Badge - 由 Afdian.Server 构建",
TermsOfService = new Uri("https://github.com/yiyungent/Afdian.Sdk"),
Expand Down Expand Up @@ -108,8 +109,17 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseDeveloperExceptionPage();
}

app.UseSwagger();
app.UseSwaggerUI();
app.UseSwagger(options =>
{
//options
});
app.UseSwaggerUI(options =>
{
options.InjectJavascript("/swagger-ui/baidu-tongji.js");
options.DocumentTitle = "Afdian.Server | 基于 Afdian.Sdk 的 非官方 爱发电 在线辅助服务";
string version = Utils.CommonUtil.Version();
options.SwaggerEndpoint($"/swagger/v{version}/swagger.json", $"Afdian.Server-v{version}");
});

app.UseRouting();
app.UseCors();
Expand Down
12 changes: 12 additions & 0 deletions src/Afdian.Server/Utils/CommonUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Afdian.Server.Utils
{
public class CommonUtil
{
public static string Version()
{
string version = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(Server.Startup).Assembly.Location).ProductVersion.Split('+').First();

return version;
}
}
}
34 changes: 18 additions & 16 deletions src/Afdian.Server/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
<html>
<head>
<meta charset="utf-8" />
<title>Afdian.Server | Afdian.Sdk | 爱发电 非官方 .NET SDK</title>
<title>Afdian.Server | 爱发电 徽章 Badge | Afdian.Sdk | 爱发电 非官方 .NET SDK</title>
<!-- 移动端设置 -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script>
var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?b44e4240604b579c37c97f2956a333be";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<div class="container">
<div class="row align-items-center">
<div class="col align-self-center">
<div class="form">
<div class="form-group">
<label>user_id</label>
<input id="js-input-userId" type="text" class="form-control">
</div>
<div class="form-group">
<label>token</label>
<input id="js-input-token" type="text" class="form-control">
</div>
<button id="js-btn-getBadge-1" class="btn btn-info btn-block" style="margin-top:14px;">获取Badge - 显式UserId,Token</button>
</div>
</div>
<div style="margin:20px auto;text-align:center;">
<h1>Afdian.Server</h1>
<h2>开发中</h2>
<div>
<a target="_blank" href="/swagger">创建 爱发电 徽章 Badge</a>
</div>
<div>
<a target="_blank" href="https://github.com/yiyungent/Afdian.Sdk">GitHub 仓库</a>
</div>
</div>
<!-- JavaScript Bundle with Popper -->
Expand Down
7 changes: 7 additions & 0 deletions src/Afdian.Server/wwwroot/swagger-ui/baidu-tongji.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var _hmt = _hmt || [];
(function () {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?b44e4240604b579c37c97f2956a333be";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();

0 comments on commit ac7482e

Please sign in to comment.