Spaces:
Sleeping
Sleeping
remove admin token from video connect
Browse files- app/api/video.py +1 -18
- frontend/dist/index.html +1 -1
- frontend/src/pages/CreateVideo.jsx +3 -11
- frontend/src/stores/videoGenStore.jsx +1 -3
app/api/video.py
CHANGED
|
@@ -12,7 +12,6 @@ from fastapi import APIRouter, HTTPException, UploadFile, File, Form
|
|
| 12 |
from fastapi.responses import FileResponse, Response, StreamingResponse
|
| 13 |
from pydantic import BaseModel
|
| 14 |
|
| 15 |
-
from ..config import settings
|
| 16 |
from ..services.videogen.service import (
|
| 17 |
get_proxy,
|
| 18 |
connect as svc_connect,
|
|
@@ -31,23 +30,11 @@ from ..services.videogen.service import (
|
|
| 31 |
router = APIRouter(prefix="/api/video", tags=["videogen"])
|
| 32 |
|
| 33 |
|
| 34 |
-
def _admin_token_ok(token: str = "") -> bool:
|
| 35 |
-
admin_token = settings.VIDEO_ADMIN_TOKEN
|
| 36 |
-
if not admin_token:
|
| 37 |
-
return True
|
| 38 |
-
return token == admin_token
|
| 39 |
-
|
| 40 |
-
|
| 41 |
# ─── Request models ───
|
| 42 |
|
| 43 |
|
| 44 |
class ConnectBody(BaseModel):
|
| 45 |
url: str
|
| 46 |
-
token: str = ""
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
class DisconnectBody(BaseModel):
|
| 50 |
-
token: str = ""
|
| 51 |
|
| 52 |
|
| 53 |
class SubmitBody(BaseModel):
|
|
@@ -75,8 +62,6 @@ def status_connection():
|
|
| 75 |
|
| 76 |
@router.post("/connect")
|
| 77 |
def api_connect(body: ConnectBody):
|
| 78 |
-
if not _admin_token_ok(body.token):
|
| 79 |
-
raise HTTPException(403, "Sai mã quản trị.")
|
| 80 |
url = body.url.strip()
|
| 81 |
if not url:
|
| 82 |
raise HTTPException(400, "Cần nhập link.")
|
|
@@ -89,9 +74,7 @@ def api_connect(body: ConnectBody):
|
|
| 89 |
|
| 90 |
|
| 91 |
@router.post("/disconnect")
|
| 92 |
-
def api_disconnect(
|
| 93 |
-
if not _admin_token_ok(body.token):
|
| 94 |
-
raise HTTPException(403, "Sai mã quản trị.")
|
| 95 |
return svc_disconnect()
|
| 96 |
|
| 97 |
|
|
|
|
| 12 |
from fastapi.responses import FileResponse, Response, StreamingResponse
|
| 13 |
from pydantic import BaseModel
|
| 14 |
|
|
|
|
| 15 |
from ..services.videogen.service import (
|
| 16 |
get_proxy,
|
| 17 |
connect as svc_connect,
|
|
|
|
| 30 |
router = APIRouter(prefix="/api/video", tags=["videogen"])
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# ─── Request models ───
|
| 34 |
|
| 35 |
|
| 36 |
class ConnectBody(BaseModel):
|
| 37 |
url: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
class SubmitBody(BaseModel):
|
|
|
|
| 62 |
|
| 63 |
@router.post("/connect")
|
| 64 |
def api_connect(body: ConnectBody):
|
|
|
|
|
|
|
| 65 |
url = body.url.strip()
|
| 66 |
if not url:
|
| 67 |
raise HTTPException(400, "Cần nhập link.")
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
@router.post("/disconnect")
|
| 77 |
+
def api_disconnect():
|
|
|
|
|
|
|
| 78 |
return svc_disconnect()
|
| 79 |
|
| 80 |
|
frontend/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
<link rel="icon" type="image/png" href="/logo.png" />
|
| 7 |
<title>TNT Group · AI Content Create</title>
|
| 8 |
-
<script type="module" crossorigin src="/assets/index-
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-D2piAy9f.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
|
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
<link rel="icon" type="image/png" href="/logo.png" />
|
| 7 |
<title>TNT Group · AI Content Create</title>
|
| 8 |
+
<script type="module" crossorigin src="/assets/index-nBCQz-kr.js"></script>
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-D2piAy9f.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
frontend/src/pages/CreateVideo.jsx
CHANGED
|
@@ -4,7 +4,7 @@ import { useDirty } from "../stores/dirtyStore";
|
|
| 4 |
import { IcVideo } from "../components/Icons";
|
| 5 |
|
| 6 |
export default function CreateVideo() {
|
| 7 |
-
const { connected, url,
|
| 8 |
const { makeDirty, makeClean } = useDirty();
|
| 9 |
const [connectUrl, setConnectUrl] = useState(url || "");
|
| 10 |
const [busy, setBusy] = useState(false);
|
|
@@ -29,7 +29,7 @@ export default function CreateVideo() {
|
|
| 29 |
const r = await fetch("/api/video/connect", {
|
| 30 |
method: "POST",
|
| 31 |
headers: { "Content-Type": "application/json" },
|
| 32 |
-
body: JSON.stringify({ url: connectUrl
|
| 33 |
});
|
| 34 |
const data = await r.json();
|
| 35 |
if (!r.ok) throw new Error(data.detail || data.error || "Lỗi kết nối");
|
|
@@ -45,11 +45,7 @@ export default function CreateVideo() {
|
|
| 45 |
makeClean();
|
| 46 |
setBusy(true);
|
| 47 |
try {
|
| 48 |
-
await fetch("/api/video/disconnect", {
|
| 49 |
-
method: "POST",
|
| 50 |
-
headers: { "Content-Type": "application/json" },
|
| 51 |
-
body: JSON.stringify({ token: adminToken }),
|
| 52 |
-
});
|
| 53 |
disconnect();
|
| 54 |
} catch (e) {
|
| 55 |
alert("Lỗi: " + e.message);
|
|
@@ -83,10 +79,6 @@ export default function CreateVideo() {
|
|
| 83 |
onChange={e => setConnectUrl(e.target.value)}
|
| 84 |
placeholder="https://xxxx.gradio.live/"
|
| 85 |
style={{ flex: 1, maxWidth: 400, padding: "7px 12px", fontSize: 13, border: "2px solid var(--line)", borderRadius: "var(--radius-sm)", background: "#fff" }} />
|
| 86 |
-
<input type="password" value={adminToken}
|
| 87 |
-
onChange={e => setAdminToken(e.target.value)}
|
| 88 |
-
placeholder="Admin token"
|
| 89 |
-
style={{ width: 140, padding: "7px 12px", fontSize: 13, border: "2px solid var(--line)", borderRadius: "var(--radius-sm)", background: "#fff" }} />
|
| 90 |
<button className="btn primary sm" disabled={busy || !connectUrl.trim()}
|
| 91 |
onClick={handleConnect}>
|
| 92 |
{busy ? "⏳" : "🔌 Kết nối"}
|
|
|
|
| 4 |
import { IcVideo } from "../components/Icons";
|
| 5 |
|
| 6 |
export default function CreateVideo() {
|
| 7 |
+
const { connected, url, connect, disconnect } = useVideoGen();
|
| 8 |
const { makeDirty, makeClean } = useDirty();
|
| 9 |
const [connectUrl, setConnectUrl] = useState(url || "");
|
| 10 |
const [busy, setBusy] = useState(false);
|
|
|
|
| 29 |
const r = await fetch("/api/video/connect", {
|
| 30 |
method: "POST",
|
| 31 |
headers: { "Content-Type": "application/json" },
|
| 32 |
+
body: JSON.stringify({ url: connectUrl }),
|
| 33 |
});
|
| 34 |
const data = await r.json();
|
| 35 |
if (!r.ok) throw new Error(data.detail || data.error || "Lỗi kết nối");
|
|
|
|
| 45 |
makeClean();
|
| 46 |
setBusy(true);
|
| 47 |
try {
|
| 48 |
+
await fetch("/api/video/disconnect", { method: "POST" });
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
disconnect();
|
| 50 |
} catch (e) {
|
| 51 |
alert("Lỗi: " + e.message);
|
|
|
|
| 79 |
onChange={e => setConnectUrl(e.target.value)}
|
| 80 |
placeholder="https://xxxx.gradio.live/"
|
| 81 |
style={{ flex: 1, maxWidth: 400, padding: "7px 12px", fontSize: 13, border: "2px solid var(--line)", borderRadius: "var(--radius-sm)", background: "#fff" }} />
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
<button className="btn primary sm" disabled={busy || !connectUrl.trim()}
|
| 83 |
onClick={handleConnect}>
|
| 84 |
{busy ? "⏳" : "🔌 Kết nối"}
|
frontend/src/stores/videoGenStore.jsx
CHANGED
|
@@ -6,8 +6,6 @@ export function VideoGenProvider({ children }) {
|
|
| 6 |
const [connected, setConnected] = useState(false);
|
| 7 |
const [url, setUrl] = useState(null);
|
| 8 |
const [connectedAt, setConnectedAt] = useState(null);
|
| 9 |
-
const [adminToken, setAdminToken] = useState("");
|
| 10 |
-
|
| 11 |
const connect = (u, info) => {
|
| 12 |
setUrl(u);
|
| 13 |
setConnected(true);
|
|
@@ -21,7 +19,7 @@ export function VideoGenProvider({ children }) {
|
|
| 21 |
};
|
| 22 |
|
| 23 |
return (
|
| 24 |
-
<Ctx.Provider value={{ connected, url, connectedAt,
|
| 25 |
{children}
|
| 26 |
</Ctx.Provider>
|
| 27 |
);
|
|
|
|
| 6 |
const [connected, setConnected] = useState(false);
|
| 7 |
const [url, setUrl] = useState(null);
|
| 8 |
const [connectedAt, setConnectedAt] = useState(null);
|
|
|
|
|
|
|
| 9 |
const connect = (u, info) => {
|
| 10 |
setUrl(u);
|
| 11 |
setConnected(true);
|
|
|
|
| 19 |
};
|
| 20 |
|
| 21 |
return (
|
| 22 |
+
<Ctx.Provider value={{ connected, url, connectedAt, connect, disconnect }}>
|
| 23 |
{children}
|
| 24 |
</Ctx.Provider>
|
| 25 |
);
|