Skip to content

Commit

Permalink
feat: show job id
Browse files Browse the repository at this point in the history
  • Loading branch information
trueai-org committed Jul 28, 2024
1 parent 7b879bc commit 7c611df
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/locales/en-US/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export default {
'pages.draw.subSuccess':'Submit successful, please wait...',
'pages.draw.swapDesc':'Face replacement (the first image is used as the face source)',
'pages.draw.inputIdShow':'Enter the task ID to bring up tasks that are not displayed',
'pages.draw.inputJobIdShow':'Enter the job id or url to convert the midjourney task to the local system task',
'pages.draw.submitTask':'Submit Task',
'pages.draw.PORTRAIT':'Portrait(2:3)',
'pages.draw.SQUARE':'Square(1:1)',
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-CN/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export default {
'pages.draw.subSuccess':'提交成功,请稍等...',
'pages.draw.swapDesc':'人脸替换(第一张图作为人脸源)',
'pages.draw.inputIdShow':'输入任务ID, 调出未展示的任务',
'pages.draw.inputJobIdShow':'输入 job id 或 url, 将 midjourney 任务转为本系统任务',
'pages.draw.submitTask':'提交任务',
'pages.draw.PORTRAIT':'肖像(2:3)',
'pages.draw.SQUARE':'正方形(1:1)',
Expand Down
48 changes: 45 additions & 3 deletions src/pages/Draw/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
queryAccount,
queryTask,
queryTaskByIds,
submitShow,
submitTask,
swapFace,
} from '@/services/mj/api';
Expand Down Expand Up @@ -227,7 +228,31 @@ const Draw: React.FC = () => {
}
waitTaskIds.add(prompt);
setPrompt('');
} else if (action === 'imagine') {
}
else if (action === 'showjobid') {
if (!prompt) {
message.error(intl.formatMessage({ id: 'pages.draw.promptNotBlank' }));
return;
}
setSubmitLoading(true);
submitShow('show', {
botType,
jobId: prompt,
state: customState,
accountFilter: {
instanceId: curAccount,
},
}).then((res) => {
setSubmitLoading(false);
const success = submitResultCheck(res);
if (success) {
waitTaskIds.add(res.result);
setPrompt('');
setImages([]);
}
});
}
else if (action === 'imagine') {
if (!prompt) {
message.error(intl.formatMessage({ id: 'pages.draw.promptNotBlank' }));
return;
Expand Down Expand Up @@ -720,7 +745,23 @@ const Draw: React.FC = () => {
</Button>
</Space.Compact>
);
} else if (action === 'imagine') {
}
else if (action === 'showjobid') {
return (
<Space.Compact style={{ width: '100%' }}>
<Input
placeholder={intl.formatMessage({ id: 'pages.draw.inputJobIdShow' })}
value={prompt}
onChange={handlePromptChange}
onPressEnter={submit}
/>
<Button type="primary" onClick={submit} loading={submitLoading}>
{intl.formatMessage({ id: 'pages.draw.submitTask' })}
</Button>
</Space.Compact>
);
}
else if (action === 'imagine') {
return (
<Flex vertical>
<Upload {...props} listType="picture-card">
Expand Down Expand Up @@ -885,7 +926,8 @@ const Draw: React.FC = () => {
{ value: 'blend', label: '/blend' },
{ value: 'describe', label: '/describe' },
{ value: 'shorten', label: '/shorten' },
{ value: 'show', label: '/show' },
{ value: 'showjobid', label: '/show job_id' },
{ value: 'show', label: '/show task_id' },
];
}

Expand Down
8 changes: 8 additions & 0 deletions src/services/mj/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ export async function submitTask(action: string, data: object, options?: { [key:
});
}

export async function submitShow(action: string, data: object, options?: { [key: string]: any }) {
return request<any>(`/mj/submit/${action}`, {
method: 'POST',
data: data,
...(options || {}),
});
}

export async function cancelTask(id: string, options?: { [key: string]: any }) {
return request<API.ReturnMessage>(`/mj/task/${id}/cancel`, {
method: 'POST',
Expand Down

0 comments on commit 7c611df

Please sign in to comment.