get image
This commit is contained in:
parent
6f43190f9d
commit
a32007c8fd
@ -20,7 +20,8 @@ const Txt23DHandler: RequestHandler<any, any> = async (ctx) => {
|
||||
const { prompt, url } = requestBody;
|
||||
const inputNode = selectNodeFromApiJSONbyID(txt23dApiFormatJSON, "33");
|
||||
inputNode.inputs.string = prompt;
|
||||
ctx.body = {
|
||||
try {
|
||||
ctx.body = {
|
||||
url: ctx.body = baseUrl + '/view?filename=' + await new Promise((resolve, reject) => {
|
||||
const taskID = Math.random().toFixed(10);
|
||||
const ws = new WebSocket(`${baseWsUrl}/ws?clientId=${taskID}`);
|
||||
@ -52,5 +53,9 @@ const Txt23DHandler: RequestHandler<any, any> = async (ctx) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
}
|
||||
export default Txt23DHandler;
|
@ -22,58 +22,63 @@ const Txt2ImgHandler: RequestHandler<Txt2ImgRequest, any> = async (ctx, next) =>
|
||||
const { prompt, loraDetail, loraModel } = requestBody;
|
||||
const inputNode = selectNodeFromApiJSONbyID(txt2imgAPIformatJSON, "33");
|
||||
let temp = "";
|
||||
let preViewBlobs:any = [];
|
||||
let preViewBlobs: any = [];
|
||||
inputNode.inputs.string = prompt;
|
||||
ctx.body = {
|
||||
data: await new Promise((resolve, reject) => {
|
||||
const taskID = Math.random().toFixed(10);
|
||||
const ws = new WebSocket(`${baseWsUrl}/ws?clientId=${taskID}`);
|
||||
ws.onopen = () => {
|
||||
try {
|
||||
axios.post("/prompt", {
|
||||
client_id: taskID,
|
||||
prompt: txt2imgAPIformatJSON,
|
||||
// extra_data: txt2imgAPIformatExtraData
|
||||
});
|
||||
console.log(`ok`);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
try {
|
||||
ctx.body = {
|
||||
data: await new Promise((resolve, reject) => {
|
||||
const taskID = Math.random().toFixed(10);
|
||||
const ws = new WebSocket(`${baseWsUrl}/ws?clientId=${taskID}`);
|
||||
ws.onopen = () => {
|
||||
try {
|
||||
axios.post("/prompt", {
|
||||
client_id: taskID,
|
||||
prompt: txt2imgAPIformatJSON,
|
||||
// extra_data: txt2imgAPIformatExtraData
|
||||
});
|
||||
console.log(`ok`);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
ws.onmessage = (event) => {
|
||||
if (typeof event.data === "string") {
|
||||
const { type, data } = JSON.parse(event.data);
|
||||
// if (type === "executed") {
|
||||
// if (data.node === '94') {
|
||||
// resolve(data.output.images[0].filename)
|
||||
// }
|
||||
// }
|
||||
if (type === "executed") {
|
||||
if (data.node === '21') {
|
||||
temp = data.output.text[0];
|
||||
}
|
||||
if (data.node === '94') {
|
||||
console.log(data.output);
|
||||
const filePath = './data.json';
|
||||
ws.onmessage = (event) => {
|
||||
if (typeof event.data === "string") {
|
||||
const { type, data } = JSON.parse(event.data);
|
||||
// if (type === "executed") {
|
||||
// if (data.node === '94') {
|
||||
// resolve(data.output.images[0].filename)
|
||||
// }
|
||||
// }
|
||||
if (type === "executed") {
|
||||
if (data.node === '21') {
|
||||
temp = data.output.text[0];
|
||||
}
|
||||
if (data.node === '94') {
|
||||
console.log(data.output);
|
||||
const filePath = './data.json';
|
||||
|
||||
readJSONFile(filePath)
|
||||
.then((data: any) => {
|
||||
console.log('读取的JSON数据:', data);
|
||||
// 修改对象
|
||||
data.push({ prompt: prompt, url: baseUrl + '/view?filename=' + data.output.images[0].filename, like: 0, index: data.length })
|
||||
// 保存回JSON文件
|
||||
saveJSONFile(filePath, data);
|
||||
})
|
||||
resolve({ prompt: temp, url: baseUrl + '/view?filename=' + data.output.images[0].filename });
|
||||
readJSONFile(filePath)
|
||||
.then((data: any) => {
|
||||
console.log('读取的JSON数据:', data);
|
||||
// 修改对象
|
||||
data.push({ prompt: prompt, url: baseUrl + '/view?filename=' + data.output.images[0].filename, like: 0, index: data.length })
|
||||
// 保存回JSON文件
|
||||
saveJSONFile(filePath, data);
|
||||
})
|
||||
resolve({ prompt: temp, url: baseUrl + '/view?filename=' + data.output.images[0].filename });
|
||||
}
|
||||
} else if (type === "executing") {
|
||||
}
|
||||
}else if (type === "executing") {
|
||||
} else if (event.data instanceof Buffer) {
|
||||
|
||||
}
|
||||
} else if (event.data instanceof Buffer) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
}
|
||||
export default Txt2ImgHandler;
|
@ -21,7 +21,8 @@ const UpscaleHandler: RequestHandler<any ,any> = async (ctx) => {
|
||||
const { prompt, url } = requestBody;
|
||||
const inputNode = selectNodeFromApiJSONbyID(upScaleAPIFormatJSON, "12");
|
||||
inputNode.inputs.image = url;
|
||||
ctx.body = {
|
||||
try {
|
||||
ctx.body = {
|
||||
url: baseUrl + '/view?filename=' + await new Promise((resolve, reject) => {
|
||||
const taskID = Math.random().toFixed(10);
|
||||
const ws = new WebSocket(`${baseWsUrl}/ws?clientId=${taskID}`);
|
||||
@ -52,5 +53,9 @@ const UpscaleHandler: RequestHandler<any ,any> = async (ctx) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
}catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
}
|
||||
export default UpscaleHandler;
|
Loading…
x
Reference in New Issue
Block a user