mirror of
https://github.com/chaitin/SafeLine.git
synced 2026-02-18 14:43:52 +08:00
feat: new version of website
This commit is contained in:
42
website/src/api/detection.ts
Normal file
42
website/src/api/detection.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
export { submitSampleSet, getSampleSet, getSampleSetResult, getSampleDetail };
|
||||
|
||||
const BASE_API = "/api/poc/";
|
||||
|
||||
function submitSampleSet(data: {
|
||||
pocs: Array<{ content: string; tag: string }>;
|
||||
record_it: boolean;
|
||||
}) {
|
||||
return fetch(BASE_API + "list", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
mode: "cors",
|
||||
// credentials: "include",
|
||||
body: JSON.stringify(data),
|
||||
}).then((res) => res.json());
|
||||
}
|
||||
|
||||
function getSampleSet(id: string) {
|
||||
return fetch(BASE_API + "list?id=" + id).then((res) => res.json());
|
||||
}
|
||||
|
||||
function getSampleDetail(id: string) {
|
||||
return fetch(BASE_API + "detail?id=" + id).then((res) => res.json());
|
||||
}
|
||||
|
||||
async function getSampleSetResult(id: string, timeout: number = 60) {
|
||||
const startAt = new Date().getTime();
|
||||
const isTimeout = () => new Date().getTime() - startAt > timeout * 1000;
|
||||
const maxRetry = 20;
|
||||
|
||||
for (let i = 0; i < maxRetry; i++) {
|
||||
const res = await fetch(BASE_API + "results?id=" + id).then((res) =>
|
||||
res.json()
|
||||
);
|
||||
if (res.code == 0 && res.data.data) {
|
||||
return { data: res.data.data, timeout: false };
|
||||
}
|
||||
if (isTimeout()) break;
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
}
|
||||
return { data: [], timeout: true };
|
||||
}
|
||||
5
website/src/api/home.ts
Normal file
5
website/src/api/home.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export { getSetupCount };
|
||||
|
||||
function getSetupCount() {
|
||||
return fetch("/api/count").then((res) => res.json());
|
||||
}
|
||||
Reference in New Issue
Block a user