Skip to content

Commit 434e7f4

Browse files
committed
freesql init retry, youchuan relax action, defalut bandwords
1 parent 8762de0 commit 434e7f4

5 files changed

Lines changed: 119 additions & 69 deletions

File tree

src/Midjourney.API/Controllers/SubmitController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using System.Net;
2626
using System.Text.RegularExpressions;
2727
using Microsoft.AspNetCore.Mvc;
28+
using Microsoft.AspNetCore.WebUtilities;
2829
using Microsoft.Extensions.Caching.Memory;
2930

3031
namespace Midjourney.API.Controllers
@@ -455,7 +456,18 @@ public async Task<ActionResult<SubmitResultVO>> Action([FromBody] SubmitActionDT
455456
var parentTaskUrl = parentEle.GetString();
456457
if (!string.IsNullOrWhiteSpace(parentTaskUrl))
457458
{
459+
var uri = new Uri(parentTaskUrl);
460+
var query = QueryHelpers.ParseQuery(uri.Query);
461+
var token = query.ContainsKey("token") ? query["token"].ToString() : string.Empty;
458462
using var client = new HttpClient() { Timeout = TimeSpan.FromMinutes(1) };
463+
464+
if (!string.IsNullOrWhiteSpace(token))
465+
{
466+
//client.DefaultRequestHeaders.Remove("Authorization");
467+
//client.DefaultRequestHeaders.Add("Authorization", token);
468+
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(token);
469+
}
470+
459471
var response = await client.GetAsync(parentTaskUrl);
460472
if (response.IsSuccessStatusCode)
461473
{

src/Midjourney.API/Midjourney.API.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
1010
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
1111
<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages>
12-
<AssemblyVersion>11.7.5</AssemblyVersion>
12+
<AssemblyVersion>11.7.6</AssemblyVersion>
1313
<DockerfileContext>..\..</DockerfileContext>
1414
</PropertyGroup>
1515

src/Midjourney.API/Program.cs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,48 @@ public static async Task Main(string[] args)
145145
}
146146

147147
// 验证数据库是否可连接
148-
if (!await FreeSqlHelper.VerifyConfigure())
148+
// 增加重试机制,第1次10秒,第2次60秒,第3次360秒,3次失败后才切换为本地 SQLite 数据库
149+
// 使用 SQLite 数据库时,超级管理员 admin 密码一定要修改,避免服务挂起时自动切换 SQLite 数据库导致配置泄露
150+
var retryCount = 0;
151+
while (!await FreeSqlHelper.VerifyConfigure())
149152
{
150-
// 切换为本地数据库
151-
setting.DatabaseType = DatabaseType.SQLite;
152-
isSaveSetting = true;
153+
retryCount++;
153154

154-
// 切换为 SQLite
155-
var freeSql = FreeSqlHelper.Init(setting.DatabaseType, setting.DatabaseConnectionString, true);
156-
if (freeSql != null)
155+
if (retryCount == 1)
156+
{
157+
// 等待 10 秒后重试
158+
Log.Warning("数据库连接失败,正在进行第 {0} 次重试,等待 10 秒后重试...", retryCount);
159+
await Task.Delay(1000 * 10);
160+
}
161+
else if(retryCount == 2)
162+
{
163+
// 等待 60 秒后重试
164+
Log.Warning("数据库连接失败,正在进行第 {0} 次重试,等待 60 秒后重试...", retryCount);
165+
await Task.Delay(1000 * 60);
166+
}
167+
else if (retryCount == 3)
157168
{
158-
FreeSqlHelper.Configure(freeSql);
169+
// 等待 360 秒后重试
170+
Log.Warning("数据库连接失败,正在进行第 {0} 次重试,等待 360 秒后重试...", retryCount);
171+
await Task.Delay(1000 * 360);
159172
}
173+
else
174+
{
175+
// 超过重试次数,切换数据库
176+
// 切换为本地数据库
177+
setting.DatabaseType = DatabaseType.SQLite;
178+
isSaveSetting = true;
179+
180+
// 切换为 SQLite
181+
var freeSql = FreeSqlHelper.Init(setting.DatabaseType, setting.DatabaseConnectionString, true);
182+
if (freeSql != null)
183+
{
184+
FreeSqlHelper.Configure(freeSql);
185+
}
160186

161-
Log.Error("数据库连接失败,自动切换为 SQLite 数据库");
187+
Log.Error("数据库连接失败,已进行 {0} 次重试,仍然无法连接数据库,正在切换为 SQLite 数据库", retryCount);
188+
break;
189+
}
162190
}
163191

164192
Log.Information("数据库类型:{0}", setting.DatabaseType);

src/Midjourney.Base/Utils/MjBannedWordsHelper.cs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -35,108 +35,51 @@ public static class MjBannedWordsHelper
3535
private const string BANNED_WORDS = """
3636
ahegao
3737
anus
38-
ass
3938
ballgag
40-
barely dressed
4139
bloodbath
42-
bloody
4340
bodily fluids
44-
boobs
45-
breasts
4641
brothel
47-
brown pudding
48-
bruises
4942
bunghole
5043
cannibal
5144
cannibalism
52-
car crash
53-
cleavage
54-
clunge
5545
cocaine
5646
coon
57-
corpse
58-
crack
59-
crotch
60-
crucifixion
6147
decapitate
62-
deepfake
6348
dick
6449
dominatrix
65-
erotic
6650
excrement
67-
explicit
68-
fart
69-
farts
7051
feces
71-
flesh
7252
fuck
73-
full frontal
7453
gore
75-
gory
76-
gruesome
7754
guts
78-
hardcore
7955
hentai
8056
heroin
81-
hitler
82-
honkey
8357
incest
84-
infected
85-
intimate parts
8658
jav
87-
kill
88-
killing
8959
kinbaku
9060
labia
9161
legs spread
92-
lingerie
9362
loli
94-
lolita
95-
making love
96-
mammaries
9763
massacre
9864
meth
99-
naked
100-
negligee
10165
nipple
10266
no clothes
10367
nude
104-
organs
10568
orgy
106-
ovaries
10769
penis
108-
phallus
10970
porn
11071
rape
111-
rear nude
11272
rule34
113-
scantily clad
114-
see-through
115-
sexual
116-
sexualized
117-
shag
118-
shibari
119-
shit
12073
skeletal gore
12174
slaughter
122-
slave
12375
smut
12476
sperm
125-
suicide
126-
tied up
127-
torture
12877
unclothed
12978
vagina
13079
veiny penis
131-
violence
132-
visceral
13380
vivisection
134-
vomit
135-
wang
136-
warts
13781
wearing nothing
13882
wincest
139-
wound
14083
zero clothes
14184
""";
14285

src/Midjourney.Services/TaskService.cs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
// invasion of privacy, or any other unlawful purposes is strictly prohibited.
2323
// Violation of these terms may result in termination of the license and may subject the violator to legal action.
2424

25-
using System.Globalization;
2625
using System.Text.RegularExpressions;
27-
using Midjourney.Base;
2826
using RestSharp;
2927
using Serilog;
3028

@@ -1263,6 +1261,75 @@ public DiscordService GetInstanceByTask(TaskInfo task, TaskInfo targetTask, out
12631261

12641262
var instance = _accountService.GetDiscordInstanceIsAlive(task.SubInstanceId ?? task.InstanceId);
12651263

1264+
// 悠船慢速变化任务特殊处理
1265+
// 如果父级是悠船慢速任务,且当前账号没有慢速额度的情况下,交由其他慢速账号出图
1266+
if (task.IsPartner && task.Action != null)
1267+
{
1268+
if (targetTask.Mode == GenerationSpeedMode.RELAX
1269+
&& task.Action != TaskAction.VIDEO
1270+
&& task.Action != TaskAction.UPSCALE)
1271+
{
1272+
// Vary Region、Vary Subtle, Vary Strong、缩放、平移 -> 可以在当前账号快速模式下继续执行
1273+
1274+
// 如果父级是慢速,且属于以下操作,则只能通过其他慢速账号继续执行
1275+
// UPSCALE_HD
1276+
// V1, V2, V3, V4
1277+
// ::reroll
1278+
var relaxActions = new List<TaskAction>()
1279+
{
1280+
TaskAction.UPSCALE_HD,
1281+
};
1282+
1283+
var forceRelax = false;
1284+
1285+
var customId = task.GetProperty<string>(Constants.TASK_PROPERTY_CUSTOM_ID, default);
1286+
1287+
// 低变化/高变化 - 暂时也强制慢速
1288+
if (relaxActions.Contains(task.Action.Value)
1289+
|| customId?.Contains("::low_variation") == true
1290+
|| customId?.Contains("::high_variation") == true
1291+
|| customId?.Contains("::variation") == true
1292+
|| customId?.Contains("::reroll") == true)
1293+
{
1294+
forceRelax = true;
1295+
}
1296+
else
1297+
{
1298+
// 如果没有快速或极速,则依然强制慢速处理
1299+
if (!modes.Contains(GenerationSpeedMode.FAST)
1300+
&& !modes.Contains(GenerationSpeedMode.TURBO))
1301+
{
1302+
forceRelax = true;
1303+
}
1304+
}
1305+
1306+
// 还是精确一些 - 如果后续处理麻烦,可以统一慢速处理
1307+
// 简单点 -> 虽然 Vary Subtle、Vary Strong、缩放、平移 可以通过快速模式继续生成,但是原始任务是慢速任务
1308+
// 简单点统一用慢速变化操作
1309+
1310+
// 强制慢速账号衍生
1311+
if (forceRelax)
1312+
{
1313+
mode = GenerationSpeedMode.RELAX;
1314+
modes = [GenerationSpeedMode.RELAX];
1315+
1316+
task.AccountFilter ??= new();
1317+
task.AccountFilter.Modes = modes;
1318+
1319+
// 判断此账号是否有慢速额度,如果没有则需要换账号
1320+
if (instance != null && instance.IsAllowContinue(GenerationSpeedMode.RELAX) && instance.Account.IsAcceptActionTask())
1321+
{
1322+
// 允许在当前账号继续执行
1323+
}
1324+
else
1325+
{
1326+
// 不允许在当前账号继续执行,交由其他慢速账号出图
1327+
instance = null;
1328+
}
1329+
}
1330+
}
1331+
}
1332+
12661333
// 是否允许继续任务
12671334
var isContinue = false;
12681335

0 commit comments

Comments
 (0)