Skip to content

Commit 6b458b7

Browse files
committed
部署在服务器的玩家头像上传模块
1 parent 8af02ef commit 6b458b7

35 files changed

+10999
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Http;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Newtonsoft.Json.Linq;
9+
using SixLabors.ImageSharp;
10+
using SixLabors.ImageSharp.Processing;
11+
12+
namespace HelperSrv_2.Controllers
13+
{
14+
[Produces("application/json")]
15+
[Route("api/ImgUpload")]
16+
public class ImgUploadController : Controller
17+
{
18+
//懒得弄到依赖注入里面了,嘤嘤嘤
19+
private static Dictionary<string, string> pendingAvater = new Dictionary<string, string>();
20+
[HttpPost("Upload")]
21+
public string Upload([FromForm] string UserName, [FromForm] IFormFile userAvater)
22+
{
23+
try
24+
{
25+
using (var stream = userAvater.OpenReadStream())
26+
{
27+
string guid = Guid.NewGuid().ToString() + ".png";
28+
string dstPath = Path.Combine("Images", guid);
29+
using (var img = Image.Load(stream))
30+
{
31+
img.Mutate(x => x.Resize(96, 96));
32+
img.Save(Path.Combine(dstPath));
33+
}
34+
pendingAvater.Add(UserName,dstPath);
35+
}
36+
}
37+
catch (Exception e)
38+
{
39+
return (new JObject {{"status", "1"},{"error", e.ToString()}}).ToString();
40+
}
41+
return (new JObject {{ "status", "0" }}).ToString();
42+
}
43+
44+
[HttpGet("List")]
45+
public string List()
46+
{
47+
var obj = new JObject();
48+
JArray datas = new JArray();
49+
foreach (var entry in pendingAvater)
50+
{
51+
datas.Add(new JObject
52+
{
53+
{"name",entry.Key },
54+
{"img",entry.Value }
55+
});
56+
}
57+
obj.Add("datas", datas);
58+
return obj.ToString();
59+
}
60+
}
61+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
namespace HelperSrv_2.Controllers
8+
{
9+
[Route("api/[controller]")]
10+
public class ValuesController : Controller
11+
{
12+
// GET api/values
13+
[HttpGet]
14+
public IEnumerable<string> Get()
15+
{
16+
return new string[] { "value1", "value2" };
17+
}
18+
19+
// GET api/values/5
20+
[HttpGet("{id}")]
21+
public string Get(int id)
22+
{
23+
return "value";
24+
}
25+
26+
// POST api/values
27+
[HttpPost]
28+
public void Post([FromBody]string value)
29+
{
30+
}
31+
32+
// PUT api/values/5
33+
[HttpPut("{id}")]
34+
public void Put(int id, [FromBody]string value)
35+
{
36+
}
37+
38+
// DELETE api/values/5
39+
[HttpDelete("{id}")]
40+
public void Delete(int id)
41+
{
42+
}
43+
}
44+
}

HelperSrv_2/HelperSrv_2.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Folder Include="wwwroot\" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
13+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.3" />
14+
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
15+
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0005" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
20+
</ItemGroup>
21+
22+
</Project>
14.6 KB
Loading
14.6 KB
Loading

HelperSrv_2/Program.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace HelperSrv_2
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
BuildWebHost(args).Run();
18+
}
19+
20+
public static IWebHost BuildWebHost(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
22+
.UseStartup<Startup>()
23+
.Build();
24+
}
25+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:57545/",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"launchUrl": "api/values",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"HelperSrv_2": {
20+
"commandName": "Project",
21+
"launchBrowser": true,
22+
"launchUrl": "api/values",
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development"
25+
},
26+
"applicationUrl": "http://localhost:57546/"
27+
}
28+
}
29+
}

HelperSrv_2/Startup.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Builder;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.FileProviders;
11+
using Microsoft.Extensions.Logging;
12+
using Microsoft.Extensions.Options;
13+
14+
namespace HelperSrv_2
15+
{
16+
public class Startup
17+
{
18+
public Startup(IConfiguration configuration)
19+
{
20+
Configuration = configuration;
21+
}
22+
23+
public IConfiguration Configuration { get; }
24+
25+
// This method gets called by the runtime. Use this method to add services to the container.
26+
public void ConfigureServices(IServiceCollection services)
27+
{
28+
services.AddMvc();
29+
}
30+
31+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
32+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
33+
{
34+
if (env.IsDevelopment())
35+
{
36+
app.UseDeveloperExceptionPage();
37+
}
38+
39+
if (!Directory.Exists("Images"))
40+
Directory.CreateDirectory("Images");
41+
app.UseStaticFiles(new StaticFileOptions
42+
{
43+
FileProvider = new PhysicalFileProvider(
44+
Path.Combine(Directory.GetCurrentDirectory(), "Images")),
45+
RequestPath = "/Images"
46+
});
47+
48+
app.UseMvc();
49+
}
50+
}
51+
}

HelperSrv_2/WebContent/.babelrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7+
}
8+
}],
9+
"stage-2"
10+
],
11+
"plugins": ["transform-runtime"],
12+
"env": {
13+
"test": {
14+
"presets": ["env", "stage-2"],
15+
"plugins": ["istanbul"]
16+
}
17+
}
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

0 commit comments

Comments
 (0)