Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

created a user interface using Next.js. #330

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions README.md → midjourney-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
> - [x] 支持niji bot机器人
> - [x] 支持InsightFace人脸替换机器人
> - [x] 内嵌管理后台页面

## 使用前提
1. 注册并订阅 MidJourney,创建`自己的服务器和频道`,参考 https://docs.midjourney.com/docs/quick-start
2. 获取用户Token、服务器ID、频道ID:[获取方式](./docs/discord-params.md)
Expand Down Expand Up @@ -77,4 +76,4 @@
## 其它
如果觉得这个项目对您有所帮助,请帮忙点个star

[![Star History Chart](https://api.star-history.com/svg?repos=novicezk/midjourney-proxy&type=Date)](https://star-history.com/#novicezk/midjourney-proxy&Date)
[![Star History Chart](https://api.star-history.com/svg?repos=novicezk/midjourney-proxy&type=Date)](https://star-history.com/#novicezk/midjourney-proxy&Date)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public final class Constants {

public static final String API_SECRET_HEADER_NAME = "mj-api-secret";
public static final String DEFAULT_DISCORD_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ public static class DiscordAccountConfig {
/**
* 服务器ID.
*/
private String guildId;
private String guildId = "";
/**
* 频道ID.
*/
private String channelId;
private String channelId = "";
/**
* 用户Token.
*/
private String userToken;
private String userToken= "";
/**
* 用户UserAgent.
*/
Expand Down Expand Up @@ -208,4 +208,4 @@ public static class TaskQueueConfig {
*/
private int timeoutMinutes = 5;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "账号查询")
@RestController
@RequestMapping("/account")
@RequiredArgsConstructor
@CrossOrigin("*")
public class AccountController {
private final DiscordLoadBalancer loadBalancer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.net.MalformedURLException;
import java.util.ArrayList;
Expand All @@ -49,6 +46,7 @@
@RestController
@RequestMapping("/submit")
@RequiredArgsConstructor
@CrossOrigin("*")
public class SubmitController {
private final TranslateService translateService;
private final TaskStoreService taskStoreService;
Expand Down Expand Up @@ -237,4 +235,4 @@ private String translatePrompt(String prompt) {
return imageStr + text + paramStr;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.Comparator;
Expand All @@ -25,6 +20,7 @@
@RestController
@RequestMapping("/task")
@RequiredArgsConstructor
@CrossOrigin("*")
public class TaskController {
private final TaskStoreService taskStoreService;
private final DiscordLoadBalancer discordLoadBalancer;
Expand Down Expand Up @@ -61,4 +57,4 @@ public List<Task> listByIds(@RequestBody TaskConditionDTO conditionDTO) {
return conditionDTO.getIds().stream().map(this.taskStoreService::get).filter(Objects::nonNull).toList();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public class DiscordAccount extends DomainObject {
public String getDisplay() {
return this.channelId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DomainObject implements Serializable {
protected String id;

@Setter
protected Map<String, Object> properties; // 扩展属性,仅支持基本类型
protected Map<String, Object> properties; // 확장 속성, 기본 데이터 유형만 지원됩니다.

@JsonIgnore
private final transient Object lock = new Object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public abstract class BaseSubmitDTO {

@ApiModelProperty("回调地址, 为空时使用全局notifyHook")
protected String notifyHook;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public class SubmitBlendDTO extends BaseSubmitDTO {

@ApiModelProperty(value = "比例: PORTRAIT(2:3); SQUARE(1:1); LANDSCAPE(3:2)", example = "SQUARE")
private BlendDimensions dimensions = BlendDimensions.SQUARE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public class SubmitChangeDTO extends BaseSubmitDTO {
@ApiModelProperty(value = "序号(1~4), action为UPSCALE,VARIATION时必传", allowableValues = "range[1, 4]", example = "1")
private Integer index;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public class SubmitDescribeDTO extends BaseSubmitDTO {

@ApiModelProperty(value = "图片base64", required = true, example = "data:image/png;base64,xxx")
private String base64;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public class SubmitImagineDTO extends BaseSubmitDTO {
@Deprecated(since = "3.0", forRemoval = true)
private String base64;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public class SubmitSimpleChangeDTO extends BaseSubmitDTO {
@ApiModelProperty(value = "变化描述: ID $action$index", required = true, example = "1320098173412546 U2")
private String content;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public class TaskConditionDTO {

private List<String> ids;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
import java.util.Map;

@Data
@ApiModel("提交结果")
@ApiModel("제출 결과")
public class SubmitResultVO {

@ApiModelProperty(value = "状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误)", required = true, example = "1")
@ApiModelProperty(value = "상태 코드: 1(제출 성공), 21(이미 존재), 22(대기 중), 그 외(오류)", required = true, example = "1")
private int code;

@ApiModelProperty(value = "描述", required = true, example = "提交成功")
@ApiModelProperty(value = "설명", required = true, example = "제출 성공")
private String description;

@ApiModelProperty(value = "任务ID", example = "1320098173412546")
@ApiModelProperty(value = "Task ID", example = "1320098173412546")
private String result;

@ApiModelProperty(value = "扩展字段")
@ApiModelProperty(value = "확장 필드")
private Map<String, Object> properties = new HashMap<>();

public SubmitResultVO setProperty(String name, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,24 @@ public Message<String> upload(String fileName, DataUrl dataUrl) {
.put("files", new JSONArray().put(fileObj));
ResponseEntity<String> responseEntity = postJson(this.discordAttachmentUrl, params.toString());
if (responseEntity.getStatusCode() != HttpStatus.OK) {
log.error("上传图片到discord失败, status: {}, msg: {}", responseEntity.getStatusCodeValue(), responseEntity.getBody());
return Message.of(ReturnCode.VALIDATION_ERROR, "上传图片到discord失败");
log.error("디스코드로 이미지 업로드 실패, 상태: {}, 메시지: {}", responseEntity.getStatusCodeValue(), responseEntity.getBody());
return Message.of(ReturnCode.VALIDATION_ERROR, "디스코드로 이미지 업로드 실패");
}
JSONArray array = new JSONObject(responseEntity.getBody()).getJSONArray("attachments");
if (array.length() == 0) {
return Message.of(ReturnCode.VALIDATION_ERROR, "上传图片到discord失败");
return Message.of(ReturnCode.VALIDATION_ERROR, "디스코드로 이미지 업로드 실패");
}
String uploadUrl = array.getJSONObject(0).getString("upload_url");
String uploadFilename = array.getJSONObject(0).getString("upload_filename");
putFile(uploadUrl, dataUrl);
return Message.success(uploadFilename);
} catch (Exception e) {
log.error("上传图片到discord失败", e);
return Message.of(ReturnCode.FAILURE, "上传图片到discord失败");
log.error("디스코드로 이미지 업로드 실패", e);
return Message.of(ReturnCode.FAILURE, "디스코드로 이미지 업로드 실패");
}
}


@Override
public Message<String> sendImageMessage(String content, String finalFileName) {
String fileName = CharSequenceUtil.subAfter(finalFileName, "/", true);
Expand All @@ -162,15 +163,15 @@ public Message<String> sendImageMessage(String content, String finalFileName) {
.replace("$final_file_name", finalFileName);
ResponseEntity<String> responseEntity = postJson(this.discordMessageUrl, paramsStr);
if (responseEntity.getStatusCode() != HttpStatus.OK) {
log.error("发送图片消息到discord失败, status: {}, msg: {}", responseEntity.getStatusCodeValue(), responseEntity.getBody());
return Message.of(ReturnCode.VALIDATION_ERROR, "发送图片消息到discord失败");
log.error("디스코드로 이미지 메시지를 보내지 못했습니다., status: {}, msg: {}", responseEntity.getStatusCodeValue(), responseEntity.getBody());
return Message.of(ReturnCode.VALIDATION_ERROR, "디스코드로 이미지 메시지를 보내지 못했습니다");
}
JSONObject result = new JSONObject(responseEntity.getBody());
JSONArray attachments = result.optJSONArray("attachments");
if (!attachments.isEmpty()) {
return Message.success(attachments.getJSONObject(0).optString("url"));
}
return Message.failure("发送图片消息到discord失败: 图片不存在");
return Message.failure("디스코드로 이미지 메시지 전송 실패");
}

private void putFile(String uploadUrl, DataUrl dataUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class TaskServiceImpl implements TaskService {
public SubmitResultVO submitImagine(Task task, List<DataUrl> dataUrls) {
DiscordInstance instance = this.discordLoadBalancer.chooseInstance();
if (instance == null) {
return SubmitResultVO.fail(ReturnCode.NOT_FOUND, "无可用的账号实例");
return SubmitResultVO.fail(ReturnCode.NOT_FOUND, "사용 가능한 계정 인스턴스가 없습니다");
}
task.setProperty(Constants.TASK_PROPERTY_DISCORD_INSTANCE_ID, instance.getInstanceId());
return instance.submitTask(task, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public String translateToEnglish(String prompt) {
}
return CharSequenceUtil.join("\n", strings);
} catch (Exception e) {
log.warn("调用百度翻译失败: {}", e.getMessage());
log.warn("바이두 번역 호출 실패: {}", e.getMessage());
}
return prompt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class GPTTranslateServiceImpl implements TranslateService {
public GPTTranslateServiceImpl(ProxyProperties properties) {
this.openaiConfig = properties.getOpenai();
if (CharSequenceUtil.isBlank(this.openaiConfig.getGptApiKey())) {
throw new BeanDefinitionValidationException("mj.openai.gpt-api-key未配置");
throw new BeanDefinitionValidationException("mj.openai.gpt-api-key설정되지 않음");
}
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new OpenAILogger());
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
Expand Down Expand Up @@ -61,7 +61,7 @@ public String translateToEnglish(String prompt) {
if (!containsChinese(prompt)) {
return prompt;
}
Message m1 = Message.builder().role(Message.Role.SYSTEM).content("把中文翻译成英文").build();
Message m1 = Message.builder().role(Message.Role.SYSTEM).content("중국어를 영어로 번역하다").build();
Message m2 = Message.builder().role(Message.Role.USER).content(prompt).build();
ChatCompletion chatCompletion = ChatCompletion.builder()
.messages(Arrays.asList(m1, m2))
Expand All @@ -76,7 +76,7 @@ public String translateToEnglish(String prompt) {
return choices.get(0).getMessage().getContent();
}
} catch (Exception e) {
log.warn("调用chat-gpt接口翻译中文失败: {}", e.getMessage());
log.warn("Chat-GPT 인터페이스를 사용하여 중국어 번역에 실패하다: {}", e.getMessage());
}
return prompt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ public void run(ApplicationArguments args) throws Exception {
log.info("当前可用账号数 [{}] - {}", enableInstanceIds.size(), String.join(", ", enableInstanceIds));
}

}
}
3 changes: 3 additions & 0 deletions my-next-app/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions my-next-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
7 changes: 7 additions & 0 deletions my-next-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node v20.11.0
npm v10.2.4

command to start :

npm run build
npm run start
4 changes: 4 additions & 0 deletions my-next-app/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}

module.exports = nextConfig
Loading