Add system variable to character

This commit is contained in:
Calli
2024-04-27 22:26:57 +03:00
parent 7d8c622711
commit cfa0a86b99
6 changed files with 29 additions and 11 deletions

View File

@@ -17,10 +17,12 @@ export const CharacterDialog = ({
}) => { }) => {
const [account, setAccount] = useState(""); const [account, setAccount] = useState("");
const [comment, setComment] = useState(""); const [comment, setComment] = useState("");
const [system, setSystem] = useState("");
useEffect(() => { useEffect(() => {
if (character?.account) setAccount(character.account); if (character?.account) setAccount(character.account);
if (character?.comment) setComment(character.comment); if (character?.comment) setComment(character.comment);
if (character?.system) setSystem(character.system);
}, [character]); }, [character]);
const logout = (character: AccessToken) => { const logout = (character: AccessToken) => {
@@ -52,6 +54,15 @@ export const CharacterDialog = ({
onChange={(event) => setAccount(event.target.value)} onChange={(event) => setAccount(event.target.value)}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
/> />
<TextField
id="outlined-basic"
label="System"
variant="outlined"
value={system ?? ""}
sx={{ margin: 1 }}
minRows={6}
onChange={(event) => setSystem(event.target.value)}
/>
<TextField <TextField
id="outlined-basic" id="outlined-basic"
label="Comment / Plan" label="Comment / Plan"
@@ -62,10 +73,12 @@ export const CharacterDialog = ({
minRows={6} minRows={6}
onChange={(event) => setComment(event.target.value)} onChange={(event) => setComment(event.target.value)}
/> />
<DialogActions> <DialogActions>
<Button <Button
onClick={() => { onClick={() => {
character && updateCharacter(character, { account, comment }); character &&
updateCharacter(character, { account, comment, system });
closeDialog(); closeDialog();
}} }}
variant="contained" variant="contained"

View File

@@ -67,5 +67,5 @@ export const ColorContext = createContext<{
setColors: (colors: ColorSelectionType) => void; setColors: (colors: ColorSelectionType) => void;
}>({ }>({
colors: defaultColors, colors: defaultColors,
setColors: () => {} setColors: () => {},
}); });

View File

@@ -51,6 +51,7 @@ const Home = () => {
...c, ...c,
...(updates.account ? { account: updates.account } : {}), ...(updates.account ? { account: updates.account } : {}),
...(updates.comment ? { comment: updates.comment } : {}), ...(updates.comment ? { comment: updates.comment } : {}),
...(updates.system ? { system: updates.system } : {}),
}; };
return c; return c;
}); });

View File

@@ -1,7 +1,7 @@
import { AccessToken } from "@/types"; import { AccessToken } from "@/types";
import { extractCharacterFromToken } from "@/utils"; import { extractCharacterFromToken } from "@/utils";
import crypto from "crypto-js";
import { NextApiRequest, NextApiResponse } from "next"; import { NextApiRequest, NextApiResponse } from "next";
import crypto from "crypto-js";
const EVE_SSO_TOKEN_URL = "https://login.eveonline.com/v2/oauth/token"; const EVE_SSO_TOKEN_URL = "https://login.eveonline.com/v2/oauth/token";
const EVE_SSO_CLIENT_ID = process.env.EVE_SSO_CLIENT_ID ?? ""; const EVE_SSO_CLIENT_ID = process.env.EVE_SSO_CLIENT_ID ?? "";
@@ -14,14 +14,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
grant_type: "refresh_token", grant_type: "refresh_token",
refresh_token: crypto.AES.decrypt( refresh_token: crypto.AES.decrypt(
accessToken.refresh_token, accessToken.refresh_token,
EVE_SSO_SECRET EVE_SSO_SECRET,
).toString(crypto.enc.Utf8), ).toString(crypto.enc.Utf8),
}).toString(); }).toString();
const headers = { const headers = {
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${Buffer.from( Authorization: `Basic ${Buffer.from(
`${EVE_SSO_CLIENT_ID}:${EVE_SSO_SECRET}` `${EVE_SSO_CLIENT_ID}:${EVE_SSO_SECRET}`,
).toString("base64")}`, ).toString("base64")}`,
Host: "login.eveonline.com", Host: "login.eveonline.com",
"User-Agent": "https://github.com/calli-eve/eve-pi", "User-Agent": "https://github.com/calli-eve/eve-pi",
@@ -40,13 +40,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
token_type: response.token_type, token_type: response.token_type,
refresh_token: crypto.AES.encrypt( refresh_token: crypto.AES.encrypt(
response.refresh_token, response.refresh_token,
EVE_SSO_SECRET EVE_SSO_SECRET,
).toString(), ).toString(),
expires_at: Date.now() + response.expires_in * 1000, expires_at: Date.now() + response.expires_in * 1000,
character, character,
needsLogin: false, needsLogin: false,
account: accessToken.account, account: accessToken.account,
comment: accessToken.comment comment: accessToken.comment,
system: accessToken.system,
}; };
console.log("Refresh", character.name, character.characterId); console.log("Refresh", character.name, character.characterId);

View File

@@ -20,7 +20,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const headers = { const headers = {
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${Buffer.from( Authorization: `Basic ${Buffer.from(
`${EVE_SSO_CLIENT_ID}:${EVE_SSO_SECRET}` `${EVE_SSO_CLIENT_ID}:${EVE_SSO_SECRET}`,
).toString("base64")}`, ).toString("base64")}`,
Host: "login.eveonline.com", Host: "login.eveonline.com",
"User-Agent": "https://github.com/calli-eve/eve-pi", "User-Agent": "https://github.com/calli-eve/eve-pi",
@@ -41,13 +41,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
token_type: response.token_type, token_type: response.token_type,
refresh_token: crypto.AES.encrypt( refresh_token: crypto.AES.encrypt(
response.refresh_token, response.refresh_token,
EVE_SSO_SECRET EVE_SSO_SECRET,
).toString(), ).toString(),
expires_at: Date.now() + response.expires_in * 1000, expires_at: Date.now() + response.expires_in * 1000,
character, character,
needsLogin: false, needsLogin: false,
account: "-", account: "-",
comment: "", comment: "",
system: "",
}; };
res.json(token); res.json(token);
} else { } else {

View File

@@ -9,6 +9,7 @@ export interface AccessToken {
account: string; account: string;
needsLogin: boolean; needsLogin: boolean;
comment: string; comment: string;
system: string;
} }
export interface Character { export interface Character {
@@ -30,6 +31,7 @@ export interface CharacterPlanets {
export interface CharacterUpdate { export interface CharacterUpdate {
account?: string; account?: string;
comment?: string; comment?: string;
system?: string;
} }
export type Planet = EsiType<"v1", "getCharactersCharacterIdPlanets">[number]; export type Planet = EsiType<"v1", "getCharactersCharacterIdPlanets">[number];
@@ -52,11 +54,11 @@ type EsiApiPathType<V extends EsiApiVersionType> = keyof InstanceType<
>[V]; >[V];
type EsiApiResponseType< type EsiApiResponseType<
V extends EsiApiVersionType, V extends EsiApiVersionType,
T extends EsiApiPathType<V> T extends EsiApiPathType<V>,
> = Awaited<ReturnType<InstanceType<typeof Api<unknown>>[V][T]>>; > = Awaited<ReturnType<InstanceType<typeof Api<unknown>>[V][T]>>;
export type EsiType< export type EsiType<
V extends EsiApiVersionType, V extends EsiApiVersionType,
T extends EsiApiPathType<V> T extends EsiApiPathType<V>,
> = EsiApiResponseType<V, T> extends { data: any } > = EsiApiResponseType<V, T> extends { data: any }
? EsiApiResponseType<V, T>["data"] ? EsiApiResponseType<V, T>["data"]
: never; : never;