renamed vars

This commit is contained in:
ACoolName 2024-05-21 20:27:44 +03:00
parent 871f61e910
commit c7667ec5b5
5 changed files with 53 additions and 53 deletions

View File

@ -11,13 +11,13 @@ const browserContext: Context<Browser> = createContext({} as Browser)
const browserActionContext: Context<ActionInfo[]|null> = createContext(null as ActionInfo[]|null) const browserActionContext: Context<ActionInfo[]|null> = createContext(null as ActionInfo[]|null)
function FakeAction(props: {action: ActionInfo, browser: Browser}){ function FakeAction(props: {action: ActionInfo, browser: Browser}){
return <Button rel="noopener noreferrer" target="_blank" href={`https://${props.browser.url}`}>{props.action.name}</Button> return <Button rel="noopener noreferrer" target="_blank" href={`https://${props.browser.Url}`}>{props.action.name}</Button>
} }
function BrowserActions() { function BrowserActions() {
const actions = useContext(browserActionContext) const actions = useContext(browserActionContext)
const browser = useContext(browserContext) const browser = useContext(browserContext)
return <actionIdentifierContext.Provider value={browser.id_}> return <actionIdentifierContext.Provider value={browser.Id}>
<ActionGroup actions={actions? actions:[]} identifierSubstring="browser_id"> <ActionGroup actions={actions? actions:[]} identifierSubstring="browser_id">
<FakeAction action={{name: 'Browse', requestType: 'post', endpoint: '', args:{}}} browser={browser}/> <FakeAction action={{name: 'Browse', requestType: 'post', endpoint: '', args:{}}} browser={browser}/>
</ActionGroup> </ActionGroup>
@ -73,10 +73,10 @@ export function BrowsersPage({ }) {
browserComponents.push( browserComponents.push(
<browserContext.Provider value={browser}> <browserContext.Provider value={browser}>
<TableRow> <TableRow>
<TableCell>{browser.owner_id}</TableCell> <TableCell>{browser.OwnerId}</TableCell>
<TableCell>{browser.connected_to.user_id}</TableCell> <TableCell>{browser.ConnectedTo.OwnerId}</TableCell>
<TableCell>{browser.connected_to.image.name}</TableCell> <TableCell>{browser.ConnectedTo.Image.Name}</TableCell>
<TableCell>{browser.connected_to.image.version}</TableCell> <TableCell>{browser.ConnectedTo.Image.Version}</TableCell>
<TableCell> <TableCell>
<BrowserActions/> <BrowserActions/>
</TableCell> </TableCell>

View File

@ -257,7 +257,7 @@ function isUserAllowed(user: User|null, action: ActionInfo): boolean{
return false return false
} }
const isAdmin = (user.permissions & Permission.Admin) === Permission.Admin const isAdmin = (user.Permissions & Permission.Admin) === Permission.Admin
if (isAdmin){ if (isAdmin){
return true return true
} }
@ -266,7 +266,7 @@ function isUserAllowed(user: User|null, action: ActionInfo): boolean{
return true return true
} }
if ((action.permissions & user.permissions) == action.permissions){ if ((action.permissions & user.Permissions) == action.permissions){
return true return true
} }

View File

@ -1,51 +1,51 @@
import { JSONSchema6, JSONSchema7 } from "json-schema" import { JSONSchema6, JSONSchema7 } from "json-schema"
export interface Port { export interface Port {
number: number Number: number
protocol: 'tcp' | 'udp' Protocol: 'tcp' | 'udp'
} }
export interface ImageInfo { export interface ImageInfo {
id_: string Id: string
name: string Name: string
version: string Version: string
ports: Port[] Ports: Port[]
} }
export interface ServerInfo { export interface ServerInfo {
id_: string Id: string
name: string Name: string
on: boolean On: boolean
user_id: string OwnerId: string
image: ImageInfo Image: ImageInfo
ports: Port[] | null Ports: Port[] | null
domain: string Domain: string
nickname?: string Nickname?: string
} }
export interface User { export interface User {
username: string Username: string
email: string Email: string
permissions: number Permissions: number
} }
export interface Browser { export interface Browser {
id_: string Id: string
domain: string Domain: string
url: string Url: string
owner_id: string OwnerId: string
connected_to: ServerInfo ConnectedTo: ServerInfo
} }
export interface OpenApiMethodSchema { export interface OpenApiMethodSchema {
summary: string summary: string
requestBody: {content: Record<string, {schema: JSONSchema7}>} requestBody: {content: Record<string, {schema: JSONSchema7}>}
api_response: 'Ignore' | 'Browse' api_response: 'Ignore' | 'Browse' | 'Terminal'
permissions: number permissions: number
} }

View File

@ -4,7 +4,7 @@ import React, { Context, Dispatch, createContext, useContext, useEffect, useStat
import { TableRow, TableCell, Chip } from "@mui/material" import { TableRow, TableCell, Chip } from "@mui/material"
import { ImageInfo, ServerInfo } from "./interfaces" import { ImageInfo, ServerInfo } from "./interfaces"
import { JSONSchema7 } from "json-schema" import { JSONSchema7 } from "json-schema"
import { Permission } from "./actions" import { Permission, SERVER_ACTIONS } from "./actions"
@ -25,36 +25,36 @@ function ServerItem(props: { server_info: ServerInfo }) {
const user = useContext(UserInfoContext) const user = useContext(UserInfoContext)
let permissions = 0 let permissions = 0
if (props.server_info.user_id === user?.username){ if (props.server_info.OwnerId === user?.Username){
permissions |= Permission.Admin permissions |= Permission.Admin
}else{ }else{
if (serverPermissions === null){ if (serverPermissions === null){
api.get(`/servers/${props.server_info.id_}/permissions`).then((event)=>{setServerPermissions(event.data)}) api.get(`/servers/${props.server_info.Id}/permissions`).then((event)=>{setServerPermissions(event.data)})
}else{ }else{
permissions |= serverPermissions permissions |= serverPermissions
} }
if (user){ if (user){
permissions |= user.permissions permissions |= user.Permissions
} }
} }
const name = `${props.server_info.user_id}'s ${props.server_info.image.name} ${props.server_info.image.version} Server` const name = `${props.server_info.OwnerId}'s ${props.server_info.Image.Name} ${props.server_info.Image.Version} Server`
if (props.server_info.ports === null) { if (props.server_info.Ports === null) {
props.server_info.ports = [] props.server_info.Ports = []
} }
return ( return (
<UserInfoContext.Provider value={user? {username: user.username, email: user.email, permissions: permissions}: null}> <UserInfoContext.Provider value={user? {Username: user.Username, Email: user.Email, Permissions: permissions}: null}>
<actionIdentifierContext.Provider value={props.server_info.id_}> <actionIdentifierContext.Provider value={props.server_info.Id}>
<TableRow> <TableRow>
<TableCell>{props.server_info.nickname}</TableCell> <TableCell>{props.server_info.Nickname}</TableCell>
<TableCell>{props.server_info.user_id}</TableCell> <TableCell>{props.server_info.OwnerId}</TableCell>
<TableCell>{props.server_info.image.name}</TableCell> <TableCell>{props.server_info.Image.Name}</TableCell>
<TableCell>{props.server_info.image.version}</TableCell> <TableCell>{props.server_info.Image.Version}</TableCell>
<TableCell>{props.server_info.domain}</TableCell> <TableCell>{props.server_info.Domain}</TableCell>
<TableCell>{props.server_info.ports.map((port, index, array) => { return <Chip label={`${port.number}/${port.protocol}`} /> })}</TableCell> <TableCell>{props.server_info.Ports.map((port, index, array) => { return <Chip label={`${port.Number}/${port.Protocol}`} /> })}</TableCell>
<TableCell> <TableCell>
<ActionGroup actions={actions} identifierSubstring="server_id" /> <ActionGroup actions={actions} identifierSubstring="server_id" />
</TableCell> </TableCell>
@ -74,7 +74,7 @@ export default function ServersBoard() {
properties: { properties: {
image_id: { image_id: {
type: "string", type: "string",
oneOf: images.map((value, index, array) => { return { const: value.id_, title: `${value.name} ${value.version}` } }), oneOf: images.map((value, index, array) => { return { const: value.Id, title: `${value.Name} ${value.Version}` } }),
title: "Image Id" title: "Image Id"
} }
}, },
@ -140,9 +140,9 @@ export default function ServersBoard() {
} }
) )
}}> }}>
<serverActionsContext.Provider value={useActions(api, '/servers/{server_id}')}> <serverActionsContext.Provider value={SERVER_ACTIONS}>
{ {
servers.sort((s1: ServerInfo, s2: ServerInfo) => { return s1.id_ < s2.id_ ? 0 : 1 }).map( servers.sort((s1: ServerInfo, s2: ServerInfo) => { return s1.Id < s2.Id ? 0 : 1 }).map(
(value: ServerInfo, index: number, array) => { (value: ServerInfo, index: number, array) => {
return <ServerItem server_info={value} /> return <ServerItem server_info={value} />
} }

View File

@ -14,9 +14,9 @@ function UserItem(p: { user: User }) {
return ( return (
<TableRow> <TableRow>
<TableCell>{user.username}</TableCell> <TableCell>{user.Username}</TableCell>
<TableCell>{user.email}</TableCell> <TableCell>{user.Email}</TableCell>
<TableCell>{user.permissions.map((value, index, array) => { return <Chip label={value} /> })}</TableCell> <TableCell>{user.Permissions.map((value, index, array) => { return <Chip label={value} /> })}</TableCell>
<TableCell><ActionGroup actions={userActions} identifierSubstring="username" /></TableCell> <TableCell><ActionGroup actions={userActions} identifierSubstring="username" /></TableCell>
</TableRow> </TableRow>
) )
@ -69,7 +69,7 @@ export function UsersPage({ }) {
let userComponents = [] let userComponents = []
for (let user of users) { for (let user of users) {
userComponents.push(<actionIdentifierContext.Provider value={user.username}><UserItem user={user} /></actionIdentifierContext.Provider>) userComponents.push(<actionIdentifierContext.Provider value={user.Username}><UserItem user={user} /></actionIdentifierContext.Provider>)
} }
return <DataTable headers={['Username', 'Email', 'Permissions', 'Actions']} actionInfo={action}> return <DataTable headers={['Username', 'Email', 'Permissions', 'Actions']} actionInfo={action}>