Compare commits
4
Commits
aca23f2326
...
8c835b8f8c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c835b8f8c | ||
|
|
b4f0cceb48 | ||
|
|
28f7b0e9f2 | ||
|
|
1dd2d96eca |
No files matched your search
@@ -1,2 +1 @@
|
||||
.idea/
|
||||
.venv/
|
||||
.idea/
|
||||
@@ -50,8 +50,7 @@ async def extract_watermark(image: UploadFile = File(...)):
|
||||
payload, has_watermark, schema = tm.decode(img)
|
||||
|
||||
return JSONResponse({
|
||||
"success": True,
|
||||
"has_watermark": has_watermark,
|
||||
"hasWatermark": has_watermark,
|
||||
"payload": payload 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 { onlySSG } from "hono/ssg";
|
||||
import { validator } from "hono/validator";
|
||||
import { isQuestionOrPlusOrMinusToken } from "typescript/unstable/ast";
|
||||
import { Signature } from "typescript/unstable/sync";
|
||||
|
||||
const appTmp = new Hono()
|
||||
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) {
|
||||
c.status(400)
|
||||
return c.json({
|
||||
@@ -130,6 +134,77 @@ app.post("/encode",
|
||||
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 {
|
||||
port: 8080,
|
||||
fetch: app.fetch
|
||||
|
||||
Reference in new issue
Block a user