Skip to content

Commit

Permalink
2.12.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Dooy committed Dec 15, 2023
1 parent eb3cacf commit a585336
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 19 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/Dooy/chatgpt-web-midjourney-proxy&env=OPENAI_API_BASE_URL&env=OPENAI_API_KEY&env=MJ_SERVER&env=MJ_API_SECRET&project-name=chatgpt-web-midjourney-proxy&repository-name=chatgpt-web-midjourney-proxy)

## env 环境变量

| 环境变量 | 说明 | 默认值 |docker等部署| vercel 部署|
| --- | --- | --- | --- | --- |
| OPENAI_API_BASE_URL | OpenAI API 接口地址 | https://api.openai.com |||
| OPENAI_API_KEY | OpenAI API 密钥 | sk-xxxxx |||
| OPENAI_API_MODEL | 默认模型 | gpt-3.5-turbo |||
| MJ_SERVER | mj proxy 接口地址 | https://api.openai.com |||
| MJ_API_SECRET | mj proxy ||||
| AUTH_SECRET_KEY | 验证密码 ||||
| API_UPLOADER | 支持上传 | 关闭 || x|
| HIDE_SERVER | 前端ui隐藏服务端| || x|

## docker 部署
**假设**:
Expand Down
1 change: 1 addition & 0 deletions api/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = (req, res) => {
"auth": process.env.AUTH_SECRET_KEY?true:false ,
"model": "ChatGPTAPI",
"amodel": process.env.OPENAI_API_MODEL?? "gpt-3.5-turbo"
,isApiGallery: process.env.MJ_API_GALLERY ? true : false
}
}
res.writeHead(200).end(
Expand Down
5 changes: 5 additions & 0 deletions changlog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# 功能升级日志

## 2.12.9
- 🐞 修复:按住回车不放,会一直触发提交刷新页面 #24
- 🔨 优化:我的画廊 支持来之服务端的数据(适合自建服务器)
- 🔨 优化:midjourney 新增 `原始链接` 按钮

## 2.12.8
- 😄 新增:我的画廊
- 🐞 修复:重试按钮、停止按钮功能 #15
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chatgpt-web-midjourney-proxy",
"version": "2.12.8",
"version": "2.12.9",
"private": false,
"description": "ChatGPT Web Midjourney Proxy",
"author": "Dooy <[email protected]>",
Expand Down
3 changes: 2 additions & 1 deletion service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ router.post('/session', async (req, res) => {
const isUpload= isNotEmptyString( process.env.API_UPLOADER )
const isHideServer= isNotEmptyString( process.env.HIDE_SERVER );
const amodel= process.env.OPENAI_API_MODEL?? "gpt-3.5-turbo" ;
res.send({ status: 'Success', message: '', data: {isHideServer,isUpload, auth: hasAuth, model: currentModel(),amodel } })
const isApiGallery= isNotEmptyString( process.env.MJ_API_GALLERY );
res.send({ status: 'Success', message: '', data: {isHideServer,isUpload, auth: hasAuth, model: currentModel(),amodel,isApiGallery } })
}
catch (error) {
res.send({ status: 'Fail', message: error.message, data: null })
Expand Down
29 changes: 29 additions & 0 deletions src/api/mjapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import { gptConfigStore, gptServerStore, homeStore } from "@/store";
import { copyToClip } from "@/utils/copy";
import { isNumber } from "@/utils/is";
import { localGet, localSaveAny } from "./mjsave";
//import { useMessage } from "naive-ui";
export interface gptsType{
gid:string
Expand Down Expand Up @@ -281,3 +283,30 @@ export const canVisionModel= (model:string)=>{
if(model.indexOf('gpt-4-gizmo')>-1 )return true;
return false;
}

function isStringOnlyDigits(input: string): boolean {
// 使用正则表达式检查字符串是否只包含数字
const regex = /^[0-9]+$/;
return regex.test(input);
}
export const loadGallery = async ()=>{
let localKey= 'mj-list-condition';
const d2:any = await localGet(localKey);
//mlog('d2',d2 , (Date.now()- d2.ctime));
if(d2 && (Date.now()- d2.ctime)<300*1000 ){

return d2.d as any[];
}
let d = await mjFetch(`/mj/gallery`);
//mlog('tsList', d.data.list );
if( !d.data.list || d.data.list.length ==0 ) return [];
const list =d.data.list as any[];
const ids = list.filter(v=> isStringOnlyDigits(v.reqid)).map(v=> +v.reqid ) ;
mlog('ids', ids );
if(ids.length==0) return [];
///mj/task/list-by-condition
d= await mjFetch('/mj/task/list-by-condition',{ids } );

if( d.length>0 ) localSaveAny({ctime: Date.now(), d}, localKey);
return d as any[] ;
}
1 change: 1 addition & 0 deletions src/store/homeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const homeStore = reactive({
actData:{} //动作类别
,local:'' //当前所处的版本
,session:{} as any
,isLoader:false

}

Expand Down
16 changes: 10 additions & 6 deletions src/views/chat/components/Message/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,19 @@ function handleRegenerate2() {
<AvatarComponent :image="inversion" :logo="chat.logo"/>
</div>
<div class="overflow-hidden text-sm " :class="[inversion ? 'items-end' : 'items-start']">
<p class="text-xs text-[#b4bbc4] flex justify-start items-center space-x-2 " :class="[inversion ? 'text-right' : 'text-left']">
<p class="text-xs group text-[#b4bbc4] flex justify-start items-center space-x-2 " :class="[inversion ? 'text-right' : 'text-left']">
<span>{{ dateTime }}</span>
<span v-if="chat.model" class="text-[#b4bbc4]/50">{{ chat.model }}</span>
<!-- <span>{{ chat.opt?.progress }}</span> -->
<SvgIcon icon="ri:restart-line" @click="sendReload" class="cursor-pointer text-neutral-300 hover:text-neutral-800 dark:hover:text-neutral-300 " v-if="chat.opt?.status=='SUCCESS'"></SvgIcon>
<div v-if="chat.opt?.status=='SUCCESS'" @click="getSeed(chat, message )" class="cursor-pointer">
<span v-if="chat.opt?.seed">Seed:{{ chat.opt?.seed }}</span>
<span v-else>Seed</span>
</div>
<template v-if="chat.opt?.status=='SUCCESS'">
<SvgIcon icon="ri:restart-line" @click="sendReload" class="cursor-pointer text-neutral-300 hover:text-neutral-800 dark:hover:text-neutral-300 " ></SvgIcon>

<div @click="getSeed(chat, message )" class="cursor-pointer">
<span v-if="chat.opt?.seed">Seed:{{ chat.opt?.seed }}</span>
<span v-else>Seed</span>
</div>
<a :href="chat.opt?.imageUrl" class="hidden group-hover:block active cursor-pointer underline " target="_blank">原图链接</a>
</template>
</p>

<div
Expand Down
6 changes: 4 additions & 2 deletions src/views/chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,9 @@ onMounted(() => {
})
onUnmounted(() => {
if (loading.value)
controller.abort()
if (loading.value) controller.abort()
homeStore.setMyData({isLoader:false});
})
const local= computed(()=>homeStore.myData.local );
Expand All @@ -483,6 +484,7 @@ watch(()=>homeStore.myData.act,(n)=>{
});
const st =ref({inputme:true});
watch( ()=>loading.value ,(n)=> homeStore.setMyData({isLoader:n }))
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion src/views/mj/aiGallery.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { ref,watch ,onMounted } from "vue";
import { ref,watch } from "vue";
import gallery from './aiGalleryItem.vue'
import { homeStore } from "@/store";
import { useRoute } from 'vue-router';
Expand Down
76 changes: 69 additions & 7 deletions src/views/mj/aiGalleryItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { LazyImg, Waterfall } from 'vue-waterfall-plugin-next'
import 'vue-waterfall-plugin-next/dist/style.css'
//import { ajax } from '@/api'
import {ref,nextTick} from "vue"
import {NSpin ,NEmpty,NImage } from 'naive-ui'
import {NSpin ,NEmpty,NImage, NTag } from 'naive-ui'
//import {copyText3} from "@/utils/format";
//import { copyText } from 'vue3-clipboard'
//import { copyToClip } from "@/utils/copy";
//import AiMsg from "@/views/aidutu/aiMsg.vue";
import { homeStore ,useChatStore} from "@/store"
import { useBasicLayout } from '@/hooks/useBasicLayout'
import { ViewCard } from 'vue-waterfall-plugin-next/dist/types/types/waterfall'
import { getMjAll, localGet, mlog } from '@/api'
import { getMjAll, localGet, mlog ,loadGallery, url2base64 } from '@/api'
const chatStore = useChatStore()
Expand All @@ -20,16 +20,20 @@ const { isMobile } = useBasicLayout()
const emit = defineEmits(['close']);
//import {hom}
const st =ref({show:true
,showImg:''
});
const st =ref({show:true ,showImg:'' ,isLoad:false });
const showImg= ref<typeof NImage>();
const list = ref<ViewCard[]>([])
const breakpoints= {
2000: { //当屏幕宽度小于等于1200
rowPerView: 6,
},
1600: { //当屏幕宽度小于等于1200
rowPerView: 5,
},
1200: { //当屏幕宽度小于等于1200
rowPerView: 4,
},
Expand All @@ -41,7 +45,53 @@ const breakpoints= {
}
}
const loadImg= async ( )=>{
const loadImg= ()=>{
//mlog('local',homeStore.myData.session.isApiGallery );
if( homeStore.myData.session.isApiGallery ) loadApiGallery();
else loadImagFormLocal();
}
const loadApiGallery= async ()=>{
st.value.isLoad= true;
let d= await loadGallery();
mlog('loadApiGallery',d);
st.value.isLoad= false;
if( !d || d.length==0 ) return;
let rz = d.map((v:any)=>{
return {
mjID: v.id,
src: v.imageUrl,isLoad:0, prompt: v.prompt,
image_url: v.imageUrl,
action: v.action
,time: v.startTime
}
});
for(let i in rz ){
let v = rz[i];
try {
if( v.image_url){
//await loadImg(chat.value.opt?.imageUrl);
let key= 'img:'+v.mjID;
let base64 = await localGet(key );
if(!base64) {
url2base64( v.image_url ,key ).then((v:any)=>{
mlog('图片已保存>>', key )
});
}else {
rz[i].image_url = rz[i].src =base64;
}
}
} catch (error) {
mlog('图片保存失败',error);
}
}
list.value= rz.sort((a:any,b:any)=> ( b.time - a.time) ) ;
}
const loadImagFormLocal= async ( )=>{
let d = await getMjAll( chatStore.$state);
if( !d || d.length==0 ) return;
//mlog('loadImg', d );
Expand All @@ -54,6 +104,8 @@ const loadImg= async ( )=>{
mjID: v.mjID,
src: v.opt.imageUrl,isLoad:0, prompt: v.opt.promptEn,
image_url: v.opt.imageUrl
,action: v.opt.action
,time: v.opt.startTime
}
});
list.value=[];
Expand Down Expand Up @@ -119,7 +171,13 @@ loadImg();
</div>
<div class="absolute w-full bottom-0 backdrop-blur-sm text-white/70 invisible group-hover/item:visible ">
<div class="p-3">
<div class="line-clamp-2 text-[13px]">{{ item.prompt }}</div>
<div class="line-clamp-2 text-[13px]">
<template v-if="item.prompt">{{ item.prompt }}</template>
<NTag v-else-if="item.action=='SWAP_FACE'" type="success" size="small" round >变脸</NTag>
<NTag v-else-if="item.action=='BLEND'" type="success" size="small" round >混图</NTag>
<NTag v-else type="success" size="small" round >{{ item.action }}</NTag>
</div>
<div class="line-clamp-1 text-[12px] text-right">{{ new Date( item.time).toLocaleString() }}</div>
<div class="space-x-2">

<!-- <NButton type="primary" size="small" @click="copy(item )" >复制</NButton> -->
Expand All @@ -134,6 +192,10 @@ loadImg();
</div>
</template>
</Waterfall>
<div v-else-if="st.isLoad" class="w-full h-full flex justify-center items-center">
<n-spin size="large" />
<div>Loading....</div>
</div>
<div v-else class="w-full h-full flex justify-center items-center">
<n-empty description="画廊还没有您的作品" />
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/views/mj/aiGpt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ watch(()=>homeStore.myData.act, async (n)=>{
}
})
homeStore.setMyData({isLoader:false});
</script>
<template>

Expand Down
6 changes: 5 additions & 1 deletion src/views/mj/aiGptInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const placeholder = computed(() => {
})
const handleSubmit = ( ) => {
if( mvalue.value=='' ) return ;
if( homeStore.myData.isLoader ) {
return ;
}
let obj={
prompt: mvalue.value,
fileBase64:st.value.fileBase64
Expand Down Expand Up @@ -141,7 +145,7 @@ const acceptData = computed(() => {
<template #suffix>
<div class=" relative; w-[40px] ">
<div class="absolute bottom-[-3px] right-[0px] ">
<NButton type="primary" :disabled="disabled" @click="handleSubmit" >
<NButton type="primary" :disabled="disabled || homeStore.myData.isLoader " @click="handleSubmit" >
<template #icon>
<span class="dark:text-black">
<SvgIcon icon="ri:send-plane-fill" />
Expand Down

0 comments on commit a585336

Please sign in to comment.