get image

This commit is contained in:
zjt 2024-05-25 23:00:52 +08:00
parent caeab65d85
commit 486f1e8e65
2 changed files with 35 additions and 0 deletions

32
src/biz/like.ts Normal file
View File

@ -0,0 +1,32 @@
import { RequestHandler, Txt2ImgRequest } from "../type/request";
import { txt2imgAPIformatJSON, txt2imgAPIformatExtraData } from "../comfyJson/txt2img";
import axios from "axios";
import { selectNodeFromApiJSONbyID } from "../utils/editComfyJson";
import WebSocket from "ws";
import { readJSONFile, saveJSONFile } from "../utils/jsonReader";
const baseUrl = "http://47.108.92.176:20000";
const baseWsUrl = "ws://47.108.92.176:20000";
// const baseUrl = "http://localhost:8188";
// const baseWsUrl = "ws://localhost:8188";
axios.defaults.baseURL = baseUrl;
const LikeImageHandler: RequestHandler<any, any> = async (ctx, next) => {
console.log(ctx.method);
ctx.set('Access-Control-Allow-Origin', '*')
ctx.set('Access-Control-Allow-Headers', 'Content-Type,Content-Length,Authorization,Accept,X-Requested-With')
ctx.set('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
if (ctx.method == 'OPTIONS') {
ctx.body = 200;
return;
}
const index = ctx.request.body.index;
const data = await readJSONFile("./data.json") as any[];
for (const image of data) {
if (image.index == index) {
image.like ++;
break;
}
}
saveJSONFile("./data.json", data);
ctx.body = 200
}
export default LikeImageHandler;

View File

@ -1,4 +1,5 @@
import GetImageHandler from "../biz/getimg";
import LikeImageHandler from "../biz/like";
import Txt23DHandler from "../biz/txt23d";
import Txt2ImgHandler from "../biz/txt2img";
import UpscaleHandler from "../biz/upScale";
@ -16,6 +17,8 @@ const InitHandler = () => {
RegistHandler("post", "/upscale", UpscaleHandler);
RegistHandler("options", "/get", GetImageHandler);
RegistHandler("post", "/get", GetImageHandler);
RegistHandler("options", "/like", LikeImageHandler);
RegistHandler("post", "/like", LikeImageHandler);
}