Skip to content

Commit

Permalink
修复COSR匹配问题
Browse files Browse the repository at this point in the history
  • Loading branch information
MonoLogueChi committed Oct 23, 2019
1 parent 95a7e67 commit 7661b45
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 39 deletions.
2 changes: 2 additions & 0 deletions MetingJS.Server/MetingJS.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
<PackageReference Include="Meting4Net" Version="1.1.4" />
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>

</Project>
2 changes: 0 additions & 2 deletions MetingJS.Server/Models/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace MetingJS.Server.Models
{
public class AppSettings
{
public static AppSettings Config { get; set; }

public AppSettings(IConfiguration configuration)
{
configuration.Bind(this);
Expand Down
16 changes: 5 additions & 11 deletions MetingJS.Server/Models/MusicList.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
using Meting4Net.Core;
using Meting4Net.Core.Models.Standard;
using static MetingJS.Server.Models.AppSettings;

namespace MetingJS.Server.Models
{
public class MusicList
{
public MusicList()
{
}

public MusicList(Music_search_item aItem, ServerProvider server)
public MusicList(Music_search_item aItem, ServerProvider server, AppSettings appSettings)
{
Title = aItem.name;
Author = string.Join(" / ", aItem.artist);
Url = $"{Config.Url}?server={server:G}&type=url&id={aItem.url_id}";
Pic = $"{Config.Url}?server={server:G}&type=pic&id={aItem.pic_id}";
Lrc = $"{Config.Url}?server={server:G}&type=lrc&id={aItem.lyric_id}";
Url = $"{appSettings.Url}?server={server:G}&type=url&id={aItem.url_id}";
Pic = $"{appSettings.Url}?server={server:G}&type=pic&id={aItem.pic_id}";
Lrc = $"{appSettings.Url}?server={server:G}&type=lrc&id={aItem.lyric_id}";
}

[JsonPropertyName("title")] public string Title { get; set; }
Expand Down
18 changes: 6 additions & 12 deletions MetingJS.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using static MetingJS.Server.Models.AppSettings;

namespace MetingJS.Server
{
Expand All @@ -14,35 +13,30 @@ public class Startup
public Startup(IConfiguration configuration)
{
Configuration = configuration;
Config = new AppSettings(configuration);
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<AppSettings>(new AppSettings(Configuration));
services.AddSingleton<IMeting, Meting>();
services.AddControllers();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, AppSettings appSettings)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseCors(builder =>
builder.WithOrigins(Config.WithOrigins).WithMethods("GET", "OPTIONS")
.AllowAnyHeader().AllowCredentials());
}
else
{
app.UseCors(builder =>
builder.WithOrigins(Config.WithOrigins).WithMethods("GET", "OPTIONS")
.AllowAnyHeader().AllowCredentials());
}

app.UseCors(builder =>
builder.WithOrigins(appSettings.WithOrigins).SetIsOriginAllowedToAllowWildcardSubdomains().WithMethods("GET", "OPTIONS")
.AllowAnyHeader());

app.UseRouting();

app.UseAuthorization();
Expand Down
30 changes: 18 additions & 12 deletions MetingJS.Server/Utils/Meting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,33 @@
using Meting4Net.Core;
using MetingJS.Server.Models;
using MMeting = Meting4Net.Core.Meting;
using static MetingJS.Server.Models.AppSettings;
using static MetingJS.Server.Models.QueryType;

namespace MetingJS.Server.Utils
{
public class Meting : IMeting
{
private readonly AppSettings _config;

public Meting(AppSettings appSettings)
{
_config = appSettings;
}


public string GetLrc(ServerProvider server, string id)
{
var lrc = new MMeting(server) {TryCount = 20}.LyricObj(id);
var lrc = new MMeting(server) { TryCount = 20 }.LyricObj(id);
return lrc.lyric;
}

public string GetPic(ServerProvider server, string id)
{
var meting = new MMeting(server) {TryCount = 10};
var meting = new MMeting(server) { TryCount = 10 };
var pic = meting.PicObj(id, 90);
var picUrl = pic.url;
if (!string.IsNullOrEmpty(picUrl) && Config.Replace.Pic != null)
picUrl = Replace(picUrl, Config.Replace.Pic);
if (!string.IsNullOrEmpty(picUrl) && _config.Replace.Pic != null)
picUrl = Replace(picUrl, _config.Replace.Pic);
return picUrl;
}

Expand All @@ -33,8 +39,8 @@ public string GetUrl(ServerProvider server, string id)
var meting = new MMeting(server) { TryCount = 10 };
var url = meting.UrlObj(id);
var urlUrl = url.url;
if (!string.IsNullOrEmpty(urlUrl) && Config.Replace.Url != null)
urlUrl = Replace(urlUrl, Config.Replace.Url);
if (!string.IsNullOrEmpty(urlUrl) && _config.Replace.Url != null)
urlUrl = Replace(urlUrl, _config.Replace.Url);
return urlUrl;
}

Expand All @@ -45,19 +51,19 @@ public string Search(ServerProvider server, QueryType type, string id)
switch (type)
{
case Album:
list = meting.AlbumObj(id).Select(s => new MusicList(s, server)).ToList();
list = meting.AlbumObj(id).Select(s => new MusicList(s, server, _config)).ToList();
break;
case Artist:
list = meting.ArtistObj(id).Select(s => new MusicList(s, server)).ToList();
list = meting.ArtistObj(id).Select(s => new MusicList(s, server, _config)).ToList();
break;
case PlayList:
list = meting.PlaylistObj(id).Select(s => new MusicList(s, server)).ToList();
list = meting.PlaylistObj(id).Select(s => new MusicList(s, server, _config)).ToList();
break;
case QueryType.Search:
list = meting.SearchObj(id).Select(s => new MusicList(s, server)).ToList();
list = meting.SearchObj(id).Select(s => new MusicList(s, server, _config)).ToList();
break;
case Song:
list = new List<MusicList> {new MusicList(meting.SongObj(id), server)};
list = new List<MusicList> { new MusicList(meting.SongObj(id), server, _config) };
break;
}

Expand Down
2 changes: 1 addition & 1 deletion MetingJS.Server/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"WithOrigins": [
"*"
],
"Urls": "http://localhost:5000;http://localhost:5001",
"Urls": "http://localhost:5000",
"Url": "http://localhost:5001/api/music",
"Replace": {
"Url": [
Expand Down
2 changes: 1 addition & 1 deletion MetingJS.Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"AllowedHosts": "*",
"WithOrigins": [
"https://*.xxwhite.com",
"https://*.xwhite.studio"
"*"
],
"Urls": "http://localhost:5001",
"Url": "",
Expand Down

0 comments on commit 7661b45

Please sign in to comment.