Skip to content

Commit

Permalink
v5.2.1-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
trueai-org committed Aug 20, 2024
1 parent 085d049 commit 7e5e7da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/Midjourney.API/DiscordAccountInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void MongoIndexInit()
var index7 = new CreateIndexModel<TaskInfo>(Builders<TaskInfo>.IndexKeys.Ascending(c => c.Description));
coll.Indexes.CreateOne(index7);

var index8 = new CreateIndexModel<TaskInfo>(Builders<TaskInfo>.IndexKeys.Ascending(c => c.Description));
var index8 = new CreateIndexModel<TaskInfo>(Builders<TaskInfo>.IndexKeys.Ascending(c => c.ImageUrl));
coll.Indexes.CreateOne(index8);
});
}
Expand Down Expand Up @@ -320,12 +320,14 @@ public void AutoMigrationLocalFileToOss()
var oss = GlobalConfiguration.Setting.AliyunOss;
var dis = GlobalConfiguration.Setting.NgDiscord;
var coll = MongoHelper.GetCollection<TaskInfo>();
var cdn = dis.CustomCdn;

var localCdn = dis.CustomCdn;
var aliCdn = oss.CustomCdn;

// 并且开启了本地域名
// 并且已经开了 mongodb
var isMongo = GlobalConfiguration.Setting.IsMongo;
if (oss?.Enable == true && oss?.IsAutoMigrationLocalFile == true && !string.IsNullOrWhiteSpace(cdn) && isMongo)
if (oss?.Enable == true && oss?.IsAutoMigrationLocalFile == true && !string.IsNullOrWhiteSpace(localCdn) && isMongo)
{
var localPath1 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "attachments");
var localPath2 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "ephemeral-attachments");
Expand All @@ -342,7 +344,7 @@ public void AutoMigrationLocalFileToOss()
{
var fileName = Path.GetFileName(fileFullPath);

var model = coll.Find(c => c.ImageUrl.StartsWith(cdn) && c.ImageUrl.Contains(fileName)).FirstOrDefault();
var model = coll.Find(c => c.ImageUrl.StartsWith(localCdn) && c.ImageUrl.Contains(fileName)).FirstOrDefault();
if (model != null)
{
// 创建保存路径
Expand All @@ -361,7 +363,7 @@ public void AutoMigrationLocalFileToOss()
var result = ossService.SaveAsync(stream, localPath, mm);

// 替换 url
var aliCdn = oss.CustomCdn;

var url = $"{aliCdn?.Trim()?.Trim('/')}/{localPath}{uri?.Query}";

if (model.Action != TaskAction.SWAP_VIDEO_FACE)
Expand Down Expand Up @@ -390,8 +392,25 @@ public void AutoMigrationLocalFileToOss()
Log.Error(ex, "文件已自动迁移到阿里云异常 {@0}", fileFullPath);
}
}
}

Log.Information("文件已自动迁移到阿里云完成 {@0}", process);
Log.Information("文件已自动迁移到阿里云完成 {@0}", process);

// 二次临时修复,如果本地数据库是阿里云,但是 mongodb 不是阿里云,则将本地的 url 赋值到 mongodb
var localDb = DbHelper.TaskStore;
var localList = localDb.GetAll();
foreach (var localItem in localList)
{
if (localItem.ImageUrl?.StartsWith(aliCdn) == true)
{
var model = coll.Find(c => c.Id == localItem.Id).FirstOrDefault();
if (model != null && localItem.ImageUrl != model.ImageUrl)
{
model.ImageUrl = localItem.ImageUrl;
model.ThumbnailUrl = localItem.ThumbnailUrl;
coll.ReplaceOne(c => c.Id == model.Id, model);
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Midjourney.Infrastructure/GlobalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GlobalConfiguration
/// <summary>
/// 版本号
/// </summary>
public static string Version { get; set; } = "v5.2.0";
public static string Version { get; set; } = "v5.2.1-beta.1";

/// <summary>
/// 全局配置项
Expand Down

0 comments on commit 7e5e7da

Please sign in to comment.