27 lines
1.3 KiB
JavaScript
27 lines
1.3 KiB
JavaScript
const BASE = "http://localhost:8090";
|
|
const login = await (await fetch(BASE + "/api/v1/auth/login", {
|
|
method: "POST", headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ account: "root", password: "root" }),
|
|
})).json();
|
|
const tok = login.access_token;
|
|
const H = { "Content-Type": "application/json", Authorization: "Bearer " + tok };
|
|
if (!tok) { console.log("LOGIN_FAIL", JSON.stringify(login)); process.exit(1); }
|
|
|
|
const get = async () => {
|
|
const r = await fetch(BASE + "/api/v1/auth/history?page=1&per_page=24", { headers: H });
|
|
const j = await r.json();
|
|
return { status: r.status, items: j?.data?.items };
|
|
};
|
|
|
|
const post = async (body) => {
|
|
const r = await fetch(BASE + "/api/v1/auth/history", { method: "POST", headers: H, body: JSON.stringify(body) });
|
|
return { status: r.status, text: (await r.text()).slice(0, 120) };
|
|
};
|
|
|
|
console.log("1 GET empty =>", JSON.stringify(await get()));
|
|
console.log("2 NEW fmt POST =>", JSON.stringify(await post({ target_uid: "r0042h1mx" })));
|
|
console.log("3 GET after =>", JSON.stringify(await get()));
|
|
console.log("4 OLD fmt POST =>", JSON.stringify(await post({ kind: "gallery", target_type: "runway_looks", target_uid: "s0042h1my", title: "T", cover: "C", brand: "B" })));
|
|
console.log("5 GET after2 =>", JSON.stringify(await get()));
|
|
process.exit(0);
|