Skip to content

Commit

Permalink
add 图片查看,反向代理配置
Browse files Browse the repository at this point in the history
  • Loading branch information
Zo3i committed May 20, 2023
1 parent 66d9d31 commit 68cf90f
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 5,651 deletions.
7 changes: 7 additions & 0 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
selectOrCopy,
autoGrowTextArea,
useMobileScreen,
openInNewWindow,
} from "../utils";

import dynamic from "next/dynamic";
Expand Down Expand Up @@ -789,6 +790,12 @@ export function Chat() {
>
{Locale.Chat.Actions.Copy}
</div>
<div
className={styles["chat-message-top-action"]}
onClick={() => openInNewWindow(message.content)}
>
{Locale.Chat.Actions.Open}
</div>
</div>
)}
<Markdown
Expand Down
10 changes: 10 additions & 0 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,16 @@ export function Settings() {
}
></input>
</ListItem>
<ListItem title={Locale.Settings.MjProxyUrl.name}>
<input
type="input"
value={accessStore.proxyUrl}
placeholder={Locale.Settings.MjProxyUrl.Placeholder}
onChange={(e) =>
accessStore.updateMJProxyUrl(e.currentTarget.value)
}
></input>
</ListItem>
</List>

<List>
Expand Down
6 changes: 6 additions & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const cn = {
ChatList: "查看消息列表",
CompressedHistory: "查看压缩后的历史 Prompt",
Export: "导出聊天记录",
Open: "查看",
Copy: "复制",
Stop: "停止",
Retry: "重试",
Expand Down Expand Up @@ -157,6 +158,11 @@ const cn = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ 反向代理",
Placeholder: "包含http(s)//",
},

MJAccessCode: {
Title: "访问密码",
SubTitle: "管理员已开启加密访问",
Expand Down
6 changes: 6 additions & 0 deletions app/locales/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const cs: LocaleType = {
ChatList: "Přejít na seznam chatů",
CompressedHistory: "Pokyn z komprimované paměti historie",
Export: "Exportovat všechny zprávy jako Markdown",
Open: "Zobrazit",
Copy: "Kopírovat",
Stop: "Zastavit",
Retry: "Zopakovat",
Expand Down Expand Up @@ -158,6 +159,11 @@ const cs: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ Proxy",
Placeholder: "Obsahuje http(s)//",
},

MJAccessCode: {
Title: "Přístupové heslo",
SubTitle: "Správce povolil šifrovaný přístup",
Expand Down
6 changes: 6 additions & 0 deletions app/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const de: LocaleType = {
ChatList: "Zur Chat-Liste gehen",
CompressedHistory: "Komprimierter Gedächtnis-Prompt",
Export: "Alle Nachrichten als Markdown exportieren",
Open: "Anzeigen",
Copy: "Kopieren",
Stop: "Stop",
Retry: "Wiederholen",
Expand Down Expand Up @@ -160,6 +161,11 @@ const de: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ Proxy",
Placeholder: "Enthält http(s)//",
},

MJAccessCode: {
Title: "Zugangscode",
SubTitle:
Expand Down
6 changes: 6 additions & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const en: LocaleType = {
ChatList: "Go To Chat List",
CompressedHistory: "Compressed History Memory Prompt",
Export: "Export All Messages as Markdown",
Open: "Open",
Copy: "Copy",
Stop: "Stop",
Retry: "Retry",
Expand Down Expand Up @@ -158,6 +159,11 @@ const en: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ Proxy",
Placeholder: "Contains http(s)//",
},

MJAccessCode: {
Title: "Access Code",
SubTitle: "Admin has enabled encrypted access",
Expand Down
6 changes: 6 additions & 0 deletions app/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const es: LocaleType = {
ChatList: "Ir a la lista de chats",
CompressedHistory: "Historial de memoria comprimido",
Export: "Exportar todos los mensajes como Markdown",
Open: "Ver",
Copy: "Copiar",
Stop: "Detener",
Retry: "Reintentar",
Expand Down Expand Up @@ -158,6 +159,11 @@ const es: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ Proxy",
Placeholder: "Contiene http(s)//",
},

MJAccessCode: {
Title: "Código de acceso",
SubTitle: "El administrador ha habilitado el acceso encriptado",
Expand Down
6 changes: 6 additions & 0 deletions app/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const it: LocaleType = {
ChatList: "Vai alla Chat List",
CompressedHistory: "Prompt di memoria della cronologia compressa",
Export: "Esportazione di tutti i messaggi come Markdown",
Open: "Apri",
Copy: "Copia",
Stop: "Stop",
Retry: "Riprova",
Expand Down Expand Up @@ -159,6 +160,11 @@ const it: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ Proxy",
Placeholder: "Contiene http(s)//",
},

MJAccessCode: {
Title: "Codice di accesso",
SubTitle: "L'amministratore ha abilitato l'accesso crittografato",
Expand Down
6 changes: 6 additions & 0 deletions app/locales/jp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const jp: LocaleType = {
ChatList: "メッセージリストを表示",
CompressedHistory: "圧縮された履歴プロンプトを表示",
Export: "チャット履歴をエクスポート",
Open: "表示する",
Copy: "コピー",
Stop: "停止",
Retry: "リトライ",
Expand Down Expand Up @@ -160,6 +161,11 @@ const jp: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ プロキシ",
Placeholder: "http(s)//を含む",
},

MJAccessCode: {
Title: "アクセスコード",
SubTitle: "管理者によって暗号化アクセスが有効化されています",
Expand Down
6 changes: 6 additions & 0 deletions app/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const ru: LocaleType = {
ChatList: "Перейти к списку чатов",
CompressedHistory: "Сжатая история памяти",
Export: "Экспортировать все сообщения в формате Markdown",
Open: "Открыть",
Copy: "Копировать",
Stop: "Остановить",
Retry: "Повторить",
Expand Down Expand Up @@ -159,6 +160,11 @@ const ru: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ Прокси",
Placeholder: "Содержит http(s)//",
},

MJAccessCode: {
Title: "Код доступа",
SubTitle: "Администратор активировал зашифрованный доступ",
Expand Down
6 changes: 6 additions & 0 deletions app/locales/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const tr: LocaleType = {
ChatList: "Sohbet Listesine Git",
CompressedHistory: "Sıkıştırılmış Geçmiş Bellek Komutu",
Export: "Tüm Mesajları Markdown Olarak Dışa Aktar",
Open: "Açık",
Copy: "Kopyala",
Stop: "Durdur",
Retry: "Tekrar Dene",
Expand Down Expand Up @@ -158,6 +159,11 @@ const tr: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ Proxy",
Placeholder: "http(s)// içerir",
},

MJAccessCode: {
Title: "Erişim Kodu",
SubTitle: "Yönetici şifreli erişimi etkinleştirdi",
Expand Down
6 changes: 6 additions & 0 deletions app/locales/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const tw: LocaleType = {
ChatList: "查看訊息列表",
CompressedHistory: "查看壓縮後的歷史 Prompt",
Export: "匯出聊天紀錄",
Open: "開啟",
Copy: "複製",
Stop: "停止",
Retry: "重試",
Expand Down Expand Up @@ -155,6 +156,11 @@ const tw: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ 代理",
Placeholder: "包含 http(s)//",
},

MJAccessCode: {
Title: "存取密碼",
SubTitle: "管理員已開啟加密存取",
Expand Down
6 changes: 6 additions & 0 deletions app/locales/vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const vi: LocaleType = {
ChatList: "Xem danh sách chat",
CompressedHistory: "Nén tin nhắn trong quá khứ",
Export: "Xuất tất cả tin nhắn dưới dạng Markdown",
Open: "Mở",
Copy: "Sao chép",
Stop: "Dừng",
Retry: "Thử lại",
Expand Down Expand Up @@ -157,6 +158,11 @@ const vi: LocaleType = {
fastMode: false,
},

MjProxyUrl: {
name: "MJ Proxy",
Placeholder: "Chứa http(s)//",
},

MJAccessCode: {
Title: "Mã Truy cập",
SubTitle: "Quản trị viên đã bật chế độ truy cập mã hóa",
Expand Down
5 changes: 4 additions & 1 deletion app/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ export async function requestImage(
export async function requestImageResult(taskId: string) {
try {
const midJourneyAPI = useAccessStore.getState().midJourneyAPI;
const res = await requestMidjourney("/v1/webhook/" + taskId)({});
const proxyUrl = useAccessStore.getState().proxyUrl;
const res = await requestMidjourney(
"/v1/webhook/" + taskId + "?proxyUrl=" + proxyUrl,
)({});
return res.json();
// handle the response here, for example:
} catch (error) {
Expand Down
6 changes: 6 additions & 0 deletions app/store/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export interface AccessControlStore {
midJourneyKey: string;
midJourneyAPIURL: string;
mjMode: boolean;
proxyUrl: string;

updateMJMode: (_: boolean) => void;
updateMJProxyUrl: (_: string) => void;
updateToken: (_: string) => void;
updateMJKey: (_: string) => void;
updateAPIURL: (_: string) => void;
Expand All @@ -41,6 +43,7 @@ export const useAccessStore = create<AccessControlStore>()(
midJourneyKey: "",
midJourneyAPIURL: "",
mjMode: true,
proxyUrl: "",

enabledAccessControl() {
get().fetch();
Expand All @@ -62,6 +65,9 @@ export const useAccessStore = create<AccessControlStore>()(
updateMJMode(mjMode: boolean) {
set(() => ({ mjMode }));
},
updateMJProxyUrl(proxyUrl: string) {
set(() => ({ proxyUrl }));
},
isAuthorized() {
get().fetch();

Expand Down
8 changes: 7 additions & 1 deletion app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,13 @@ export const useChatStore = create<ChatStore>()(
ops[1],
);
} else {
res = await requestImage("CREATE_IMAGE", true, lastMessage.content);
res = await requestImage(
"CREATE_IMAGE",
true,
lastMessage.content,
undefined,
undefined,
);
}

let hisMsg = new Array();
Expand Down
8 changes: 8 additions & 0 deletions app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export async function copyToClipboard(text: string) {
}
}

export async function openInNewWindow(text: string) {
var url = /\((.*?)\)/.exec(text);
const win = window.open(url ? url[1] : "", "_blank");
if (win) {
win.focus();
}
}

export function downloadAs(text: string, filename: string) {
const element = document.createElement("a");
element.setAttribute(
Expand Down
Loading

0 comments on commit 68cf90f

Please sign in to comment.