Commit 865c9271 by haojie
parents 94019363 b18d567d
...@@ -27,9 +27,16 @@ public function handle() ...@@ -27,9 +27,16 @@ public function handle()
{ {
$data = $this->data; $data = $this->data;
$content = $data['message_content'] ?? ''; $content = $data['message_content'] ?? '';
preg_match('/\*\*<(.*)> (.*)\*\*/', $content, $matches);
if (blank($matches)) {
preg_match('/\*\*(.*)\*\*/', $content, $matches); preg_match('/\*\*(.*)\*\*/', $content, $matches);
if (isset($matches[1])) { $content = $matches[1] ?? '';
$key = app(TaskService::class)->getDiscordMessageKey($matches[1]); } else {
$content = $matches[2] ?? '';
}
if (isset($content) && filled($content)) {
$key = app(TaskService::class)->getDiscordMessageKey($content);
$cachePrompt = Cache::get($key); $cachePrompt = Cache::get($key);
if (!empty($cachePrompt)) { if (!empty($cachePrompt)) {
$updateData = [ $updateData = [
...@@ -38,6 +45,7 @@ public function handle() ...@@ -38,6 +45,7 @@ public function handle()
]; ];
PromptTask::where('id', $cachePrompt['prompt_task_id']) PromptTask::where('id', $cachePrompt['prompt_task_id'])
->update($updateData); ->update($updateData);
Cache::forget($key);
} }
} }
} }
......
...@@ -26,13 +26,13 @@ public function __construct(array $data = []) ...@@ -26,13 +26,13 @@ public function __construct(array $data = [])
public function handle() public function handle()
{ {
$data = $this->data; $data = $this->data;
$key = app(TaskService::class)->getDiscordMessageKey($data['prompt']);
Cache::set($key, ['prompt_task_id' => $data['prompt_id']], (60 * 60 * 24));
// 处理图转图 // 处理图转图
if ($data['type'] == TaskService::TYPE_IMG_TO_IMG) { if ($data['type'] == TaskService::TYPE_IMG_TO_IMG) {
$promptImg = json_decode(($data['prompt_img'] ?? '')); $promptImg = json_decode(($data['prompt_img'] ?? ''));
$data['prompt'] = ($promptImg[0] ?? '') . ' ' . $data['prompt']; $data['prompt'] = ($promptImg[0] ?? '') . ' ' . $data['prompt'];
} }
$key = app(TaskService::class)->getDiscordMessageKey($data['prompt']);
Cache::set($key, ['prompt_task_id' => $data['prompt_id']], (60 * 60 * 24));
app(ExternalApiService::class)->imagine($data); app(ExternalApiService::class)->imagine($data);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment