Compare commits

...
4 Commits
Author SHA1 Message Date
cancerai 8c835b8f8c change: 删除多余依赖引用 2026-09-28 22:32:18 +08:00
cancerai b4f0cceb48 done: 完成提取盲水印API 2026-09-28 22:31:44 +08:00
cancerai 28f7b0e9f2 change: 修改decode响应体 2026-09-28 22:23:59 +08:00
cancerai 1dd2d96eca change: 删除忽略.venv目录 2026-09-28 22:15:33 +08:00
3 changed files with 81 additions and 8 deletions

No files matched your search

+1 -2
View File
@@ -1,2 +1 @@
.idea/ .idea/
.venv/
+1 -2
View File
@@ -50,8 +50,7 @@ async def extract_watermark(image: UploadFile = File(...)):
payload, has_watermark, schema = tm.decode(img) payload, has_watermark, schema = tm.decode(img)
return JSONResponse({ return JSONResponse({
"success": True, "hasWatermark": has_watermark,
"has_watermark": has_watermark,
"payload": payload if has_watermark else None, "payload": payload if has_watermark else None,
"schema": schema if has_watermark else None "schema": schema if has_watermark else None
}) })
+79 -4
View File
@@ -1,9 +1,5 @@
import { pathToFileURL } from "bun";
import { Hono } from "hono"; import { Hono } from "hono";
import { onlySSG } from "hono/ssg";
import { validator } from "hono/validator"; import { validator } from "hono/validator";
import { isQuestionOrPlusOrMinusToken } from "typescript/unstable/ast";
import { Signature } from "typescript/unstable/sync";
const appTmp = new Hono() const appTmp = new Hono()
const app = appTmp.basePath("/watermark") const app = appTmp.basePath("/watermark")
@@ -33,6 +29,14 @@ app.post("/encode",
}) })
} }
if ((image as File[]).length >= 2) {
c.status(400)
return c.json({
code: 400,
msg: "Only support upload one image"
})
}
if ((image as File).size == 0) { if ((image as File).size == 0) {
c.status(400) c.status(400)
return c.json({ return c.json({
@@ -130,6 +134,77 @@ app.post("/encode",
return c.body(resImage) return c.body(resImage)
}) })
app.post("/decode",
validator("form", (val, c) => {
const image = val.image
if (image == undefined) {
c.status(400)
return c.json({
code: 400,
msg: "Paarameter is invalid"
})
}
if ((image as File[]).length >= 2) {
c.status(400)
return c.json({
code: 400,
msg: "Only support upload one image"
})
}
if ((image as File).size == 0) {
c.status(400)
return c.json({
code: 400,
msg: "Image is empty"
})
}
const MAX_IMAGE_SIZE = 10 * 1024 * 1024
if ((image as File).size > MAX_IMAGE_SIZE) {
c.status(400)
return c.json({
code: 400,
msg: "Image size is too large, must<=10MB"
})
}
},),
async (c) => {
const formData = await c.req.formData()
const image: File = formData.get("image") as File
const data = new FormData()
let canFetch: boolean = true
data.append("image", image)
const response = await fetch("http://localhost:8081/watermark/decode", {
method: "POST",
body: data
}).catch((e) => {
canFetch = false
})
if (!canFetch) {
c.status(500)
return c.json({
code: 500,
msg: "Cannot fetch http://localhost:8081/watermark/decode"
})
}
const res = await response!.json()
/**
* Response struct
* {
* "hasWatermark": true|false,
* "payload": "abc" | null,
* "schema": 1 | null
* }
*/
return c.body(JSON.stringify(res))
}
)
export default { export default {
port: 8080, port: 8080,
fetch: app.fetch fetch: app.fetch