Change Admin Verfify to a list of opinions
This commit is contained in:
parent
b98d050c7b
commit
bc2fecc50d
2 changed files with 72 additions and 46 deletions
|
@ -29,6 +29,7 @@ const POST = z.object({
|
||||||
const Panel = () => {
|
const Panel = () => {
|
||||||
const [posts, setPosts] = useState<z.infer<typeof POST>[]>([])
|
const [posts, setPosts] = useState<z.infer<typeof POST>[]>([])
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [verifyli, setVerifyli] = useState<{ id: number, ck: Boolean }[]>([])
|
||||||
const load = () => {
|
const load = () => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
fetch(rootstr + "/api/admin/fetch_post", { credentials: "include" }).then(async val => {
|
fetch(rootstr + "/api/admin/fetch_post", { credentials: "include" }).then(async val => {
|
||||||
|
@ -41,9 +42,22 @@ const Panel = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const verify = (check: boolean, post: number) => {
|
const verify = (check: boolean, post: number) => {
|
||||||
fetch(rootstr + "/api/admin/verify_post", { method: "PUT", credentials: "include", body: JSON.stringify({ "post": post, "check": check, }), headers: { "Content-Type": "application/json" } }).then(async e => {
|
setVerifyli([...verifyli, { ck: check, id: post }])
|
||||||
if (e.status == 200) {
|
|
||||||
setPosts(posts.filter(v => v.id != post))
|
setPosts(posts.filter(v => v.id != post))
|
||||||
|
|
||||||
|
}
|
||||||
|
const Send = () => {
|
||||||
|
fetch(rootstr + "/api/admin/verify_post",
|
||||||
|
{
|
||||||
|
method: "put",
|
||||||
|
credentials: "include",
|
||||||
|
body: JSON.stringify({ "choice": verifyli }),
|
||||||
|
headers: { "content-type": "application/json" }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(async e => {
|
||||||
|
if (e.status == 200) {
|
||||||
|
alert("成功")
|
||||||
} else
|
} else
|
||||||
if ((e.status == 401 || e.status == 400) && await e.text() == "missing or malformed JWT") {
|
if ((e.status == 401 || e.status == 400) && await e.text() == "missing or malformed JWT") {
|
||||||
window.location.href = "/admin/login"
|
window.location.href = "/admin/login"
|
||||||
|
@ -51,8 +65,6 @@ const Panel = () => {
|
||||||
alert(e.statusText)
|
alert(e.statusText)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (<div className="w-full h-dvh bg-stone-700 relative">
|
return (<div className="w-full h-dvh bg-stone-700 relative">
|
||||||
|
@ -73,9 +85,10 @@ const Panel = () => {
|
||||||
</NavigationMenuList>
|
</NavigationMenuList>
|
||||||
</NavigationMenu>
|
</NavigationMenu>
|
||||||
</div>
|
</div>
|
||||||
<div className="h-full w-full flex flex-row px-10 pt-20">
|
<div className="h-full w-full flex flex-col md:flex-row px-10 pt-20">
|
||||||
<Button onClick={load} disabled={loading}>Load</Button>
|
<Button onClick={load} disabled={loading}>Load</Button>
|
||||||
<div className="grid grid-cols-3 border-3 border-stone-400 rounded w-[80dvw] text-white gap-3 overflow-scroll">
|
<Button onClick={Send}>Load</Button>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-3 border-3 border-stone-400 rounded w-[80dvw] text-white gap-3 overflow-scroll">
|
||||||
{posts.length > 0 ? posts.map(post => {
|
{posts.length > 0 ? posts.map(post => {
|
||||||
return (<div key={post.id} className="border rounded h-fit">
|
return (<div key={post.id} className="border rounded h-fit">
|
||||||
<p>
|
<p>
|
||||||
|
@ -92,11 +105,9 @@ const Panel = () => {
|
||||||
<div className="flex flex-row gap-3 ml-2">
|
<div className="flex flex-row gap-3 ml-2">
|
||||||
<Button onClick={() => verify(true, post.id)}><LucideCheck /></Button>
|
<Button onClick={() => verify(true, post.id)}><LucideCheck /></Button>
|
||||||
<Button onClick={() => verify(false, post.id)}><LucideX /></Button>
|
<Button onClick={() => verify(false, post.id)}><LucideX /></Button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>)
|
</div>)
|
||||||
}) : "NULL"}
|
}) : "NULL"}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>)
|
</div>)
|
||||||
|
|
|
@ -160,6 +160,9 @@ type Verify struct {
|
||||||
Id int32 `json:"post"`
|
Id int32 `json:"post"`
|
||||||
Check bool `json:"check"`
|
Check bool `json:"check"`
|
||||||
}
|
}
|
||||||
|
type VerifyList struct {
|
||||||
|
Choice []Verify `json:"choice"`
|
||||||
|
}
|
||||||
|
|
||||||
func AdminVerify(c *fiber.Ctx) error {
|
func AdminVerify(c *fiber.Ctx) error {
|
||||||
user := c.Locals("user").(*jwt.Token)
|
user := c.Locals("user").(*jwt.Token)
|
||||||
|
@ -172,13 +175,15 @@ func AdminVerify(c *fiber.Ctx) error {
|
||||||
return c.SendStatus(fiber.StatusInternalServerError)
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
qtx := internal.NIMDB.WithTx(tx)
|
qtx := internal.NIMDB.WithTx(tx)
|
||||||
post_verify := new(Verify)
|
post_verify_list := new(VerifyList)
|
||||||
log.Println(string(c.Body()))
|
log.Println(string(c.Body()))
|
||||||
if err = c.BodyParser(post_verify); err != nil {
|
if err = c.BodyParser(post_verify_list); err != nil {
|
||||||
return c.SendStatus(fiber.StatusBadRequest)
|
return c.SendStatus(fiber.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !super {
|
if !super {
|
||||||
|
for _, post_verify := range post_verify_list.Choice {
|
||||||
|
|
||||||
if post_verify.Check {
|
if post_verify.Check {
|
||||||
_, err = qtx.AdminVerify(ctx, nimdb.AdminVerifyParams{ID: post_verify.Id, Phase: nimdb.PostPhaseOk})
|
_, err = qtx.AdminVerify(ctx, nimdb.AdminVerifyParams{ID: post_verify.Id, Phase: nimdb.PostPhaseOk})
|
||||||
|
|
||||||
|
@ -189,7 +194,20 @@ func AdminVerify(c *fiber.Ctx) error {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
return c.SendStatus(fiber.StatusBadRequest)
|
return c.SendStatus(fiber.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = qtx.AdminUpdateImage(ctx, pgtype.Int4{Int32: post_verify.Id, Valid: true})
|
||||||
|
if err != nil {
|
||||||
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verified and send to IGAPI to handle synchronization of IG posts
|
||||||
|
if internal.IGAPI_ACTIVATE {
|
||||||
|
internal.IGAPI_CHAN <- internal.PR{ACT_TYPE: 0, ID: post_verify.Id}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
for _, post_verify := range post_verify_list.Choice {
|
||||||
if post_verify.Check {
|
if post_verify.Check {
|
||||||
_, err = qtx.SuperAdminVerify(ctx, nimdb.SuperAdminVerifyParams{ID: post_verify.Id, Phase: nimdb.PostPhaseOk})
|
_, err = qtx.SuperAdminVerify(ctx, nimdb.SuperAdminVerifyParams{ID: post_verify.Id, Phase: nimdb.PostPhaseOk})
|
||||||
|
|
||||||
|
@ -200,9 +218,6 @@ func AdminVerify(c *fiber.Ctx) error {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
return c.SendStatus(fiber.StatusBadRequest)
|
return c.SendStatus(fiber.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
err = qtx.AdminUpdateImage(ctx, pgtype.Int4{Int32: post_verify.Id, Valid: true})
|
err = qtx.AdminUpdateImage(ctx, pgtype.Int4{Int32: post_verify.Id, Valid: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.SendStatus(fiber.StatusInternalServerError)
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
|
@ -212,9 +227,9 @@ func AdminVerify(c *fiber.Ctx) error {
|
||||||
if internal.IGAPI_ACTIVATE {
|
if internal.IGAPI_ACTIVATE {
|
||||||
internal.IGAPI_CHAN <- internal.PR{ACT_TYPE: 0, ID: post_verify.Id}
|
internal.IGAPI_CHAN <- internal.PR{ACT_TYPE: 0, ID: post_verify.Id}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return tx.Commit(ctx)
|
return tx.Commit(ctx)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const adminpage_basepath = "./admin_panel/dist"
|
const adminpage_basepath = "./admin_panel/dist"
|
||||||
|
|
Loading…
Add table
Reference in a new issue