From 486f1e8e657a0e489567167203e2f3eaeb82959e Mon Sep 17 00:00:00 2001 From: zjt <937178071@qq.com> Date: Sat, 25 May 2024 23:00:52 +0800 Subject: [PATCH] get image --- src/biz/like.ts | 32 ++++++++++++++++++++++++++++++++ src/routers/handler.ts | 3 +++ 2 files changed, 35 insertions(+) create mode 100644 src/biz/like.ts diff --git a/src/biz/like.ts b/src/biz/like.ts new file mode 100644 index 0000000..709ab27 --- /dev/null +++ b/src/biz/like.ts @@ -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 = 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; \ No newline at end of file diff --git a/src/routers/handler.ts b/src/routers/handler.ts index 9961f43..55385f4 100644 --- a/src/routers/handler.ts +++ b/src/routers/handler.ts @@ -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); }