fix: use SDK.fetchJSON for auth, Optional[str] for Python 3.9 compat
This commit is contained in:
parent
7435a418c8
commit
7a6871e1e9
|
|
@ -6,34 +6,11 @@
|
||||||
const { useState, useEffect, useCallback } = SDK.hooks;
|
const { useState, useEffect, useCallback } = SDK.hooks;
|
||||||
const { Card, CardHeader, CardTitle, CardContent, Button } = SDK.components;
|
const { Card, CardHeader, CardTitle, CardContent, Button } = SDK.components;
|
||||||
|
|
||||||
// Use native fetch with session token header for remote dashboard
|
const fetchJSON = SDK.fetchJSON;
|
||||||
function getSessionToken() {
|
|
||||||
return window.__HERMES_SESSION_TOKEN__ || "";
|
|
||||||
}
|
|
||||||
|
|
||||||
async function apiFetch(path) {
|
|
||||||
const res = await fetch(path, {
|
|
||||||
credentials: "include",
|
|
||||||
headers: { "x-hermes-session-token": getSessionToken() }
|
|
||||||
});
|
|
||||||
if (!res.ok) {
|
|
||||||
const text = await res.text();
|
|
||||||
throw new Error("API error " + res.status + ": " + text.slice(0, 100));
|
|
||||||
}
|
|
||||||
return res.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function apiPost(path) {
|
async function apiPost(path) {
|
||||||
const res = await fetch(path, {
|
const res = await fetchJSON(path, { method: "POST" });
|
||||||
method: "POST",
|
return res;
|
||||||
credentials: "include",
|
|
||||||
headers: { "x-hermes-session-token": getSessionToken() }
|
|
||||||
});
|
|
||||||
if (!res.ok) {
|
|
||||||
const text = await res.text();
|
|
||||||
throw new Error("API error " + res.status + ": " + text.slice(0, 100));
|
|
||||||
}
|
|
||||||
return res.json();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function SSHXPage() {
|
function SSHXPage() {
|
||||||
|
|
@ -45,7 +22,7 @@
|
||||||
setStatus("loading");
|
setStatus("loading");
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch("/api/plugins/sshx-link/start");
|
const res = await fetchJSON("/api/plugins/sshx-link/start");
|
||||||
if (res.link) {
|
if (res.link) {
|
||||||
setLink(res.link);
|
setLink(res.link);
|
||||||
setStatus("running");
|
setStatus("running");
|
||||||
|
|
@ -71,7 +48,7 @@
|
||||||
|
|
||||||
const checkStatus = useCallback(async function () {
|
const checkStatus = useCallback(async function () {
|
||||||
try {
|
try {
|
||||||
const res = await apiFetch("/api/plugins/sshx-link/status");
|
const res = await fetchJSON("/api/plugins/sshx-link/status");
|
||||||
if (res.status === "running" && res.link) {
|
if (res.status === "running" && res.link) {
|
||||||
setLink(res.link);
|
setLink(res.link);
|
||||||
setStatus("running");
|
setStatus("running");
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import subprocess
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Optional
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
|
|
@ -20,7 +21,7 @@ _sshx_process = None
|
||||||
_sshx_link = None
|
_sshx_link = None
|
||||||
|
|
||||||
|
|
||||||
def _find_link(text: str) -> str | None:
|
def _find_link(text: str) -> Optional[str]:
|
||||||
"""Extract sshx link from output."""
|
"""Extract sshx link from output."""
|
||||||
match = re.search(r"https://sshx\.io/s/[A-Za-z0-9_-]+", text)
|
match = re.search(r"https://sshx\.io/s/[A-Za-z0-9_-]+", text)
|
||||||
return match.group(0) if match else None
|
return match.group(0) if match else None
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue