Compare commits
4
Commits
aca23f2326
...
8c835b8f8c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c835b8f8c | ||
|
|
b4f0cceb48 | ||
|
|
28f7b0e9f2 | ||
|
|
1dd2d96eca |
No files matched your search
@@ -1,2 +1 @@
|
|||||||
.idea/
|
.idea/
|
||||||
.venv/
|
|
||||||
@@ -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
@@ -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
|
||||||
|
|||||||
Reference in new issue
Block a user