Skip to content

Commit

Permalink
Update API version
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Jun 21, 2023
1 parent 9345a24 commit 10762ae
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 102 deletions.
4 changes: 4 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}",
"pathMappings": [
{
"url": "webpack://tgstation-server-control-panel/src/components/views/Admin",
"path": "${workspaceFolder}/src/components/views/Admin"
},
{
"url": "webpack://tgstation-server-control-panel/src/components/views/Instance",
"path": "${workspaceFolder}/src/components/views/Instance"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tgstation-server-control-panel",
"version": "4.21.3",
"tgs_api_version": "9.10.2",
"tgs_api_version": "9.11.0",
"private": true,
"homepage": "https://tgstation.github.io/tgstation-server-control-panel",
"repository": "github:tgstation/tgstation-server-control-panel",
Expand Down Expand Up @@ -124,7 +124,8 @@
"patch": "yarn patch-package"
},
"schema_gen": {
"type": "version"
"type": "url",
"value": "http://localhost:5000/swagger/v1/swagger.json"
},
"schema_gen_example_version": {
"desc": "Fetches a tgs api version from github using the tag name. References the \"tgs_api_version\" field in package.json.",
Expand Down
112 changes: 104 additions & 8 deletions src/ApiClient/AdminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import type {
AdministrationResponse,
ErrorMessageResponse,
LogFileResponse,
PaginatedLogFileResponse
PaginatedLogFileResponse,
ServerUpdateResponse
} from "./generatedcode/generated";
import { DownloadedLog } from "./models/DownloadedLog";
import InternalError, { ErrorCode, GenericErrors } from "./models/InternalComms/InternalError";
import InternalStatus, { StatusCode } from "./models/InternalComms/InternalStatus";
import ServerClient from "./ServerClient";
import TransferClient, { DownloadErrors } from "./TransferClient";
import TransferClient, { DownloadErrors, UploadErrors } from "./TransferClient";
import configOptions from "./util/config";

interface IEvents {
Expand All @@ -28,7 +29,8 @@ export type UpdateErrors =
| ErrorCode.ADMIN_WATCHDOG_UNAVAIL
| ErrorCode.ADMIN_VERSION_NOT_FOUND
| ErrorCode.ADMIN_GITHUB_RATE
| ErrorCode.ADMIN_GITHUB_ERROR;
| ErrorCode.ADMIN_GITHUB_ERROR
| UploadErrors;

export type LogsErrors = GenericErrors | ErrorCode.ADMIN_LOGS_IO_ERROR;

Expand Down Expand Up @@ -190,7 +192,9 @@ export default new (class AdminClient extends ApiClient<IEvents> {
}
}

public async updateServer(newVersion: string): Promise<InternalStatus<null, UpdateErrors>> {
public async updateServer(
newVersion: string
): Promise<InternalStatus<ServerUpdateResponse, UpdateErrors>> {
await ServerClient.wait4Init();

let response;
Expand All @@ -209,7 +213,7 @@ export default new (class AdminClient extends ApiClient<IEvents> {
case 202: {
return new InternalStatus({
code: StatusCode.OK,
payload: null
payload: response.data as ServerUpdateResponse
});
}
case 410: {
Expand All @@ -236,7 +240,7 @@ export default new (class AdminClient extends ApiClient<IEvents> {
}
case 424: {
const errorMessage = response.data as ErrorMessageResponse;
return new InternalStatus<null, ErrorCode.ADMIN_GITHUB_RATE>({
return new InternalStatus<ServerUpdateResponse, ErrorCode.ADMIN_GITHUB_RATE>({
code: StatusCode.ERROR,
error: new InternalError(
ErrorCode.ADMIN_GITHUB_RATE,
Expand All @@ -247,7 +251,7 @@ export default new (class AdminClient extends ApiClient<IEvents> {
}
case 429: {
const errorMessage = response.data as ErrorMessageResponse;
return new InternalStatus<null, ErrorCode.ADMIN_GITHUB_ERROR>({
return new InternalStatus<ServerUpdateResponse, ErrorCode.ADMIN_GITHUB_ERROR>({
code: StatusCode.ERROR,
error: new InternalError(
ErrorCode.ADMIN_GITHUB_ERROR,
Expand All @@ -257,7 +261,99 @@ export default new (class AdminClient extends ApiClient<IEvents> {
});
}
default: {
return new InternalStatus<null, ErrorCode.UNHANDLED_RESPONSE>({
return new InternalStatus<ServerUpdateResponse, ErrorCode.UNHANDLED_RESPONSE>({
code: StatusCode.ERROR,
error: new InternalError(
ErrorCode.UNHANDLED_RESPONSE,
{ axiosResponse: response },
response
)
});
}
}
}

public async uploadVersion(
newVersion: string,
file: ArrayBuffer
): Promise<InternalStatus<ServerUpdateResponse, UpdateErrors>> {
await ServerClient.wait4Init();

let response;
try {
response = await ServerClient.apiClient!.administration.administrationControllerUpdate({
newVersion,
uploadZip: true
});
} catch (stat) {
return new InternalStatus({
code: StatusCode.ERROR,
error: stat as InternalError<UpdateErrors>
});
}

switch (response.status) {
case 202: {
const payload = response.data as ServerUpdateResponse;
const upload = await TransferClient.Upload(payload.fileTicket, file);
if (upload.code === StatusCode.OK) {
return new InternalStatus({
code: StatusCode.OK,
payload
});
}

return new InternalStatus<ServerUpdateResponse, UpdateErrors>({
code: StatusCode.ERROR,
error: upload.error
});
}
case 410: {
const errorMessage = response.data as ErrorMessageResponse;
return new InternalStatus({
code: StatusCode.ERROR,
error: new InternalError(
ErrorCode.ADMIN_VERSION_NOT_FOUND,
{ errorMessage },
response
)
});
}
case 422: {
const errorMessage = response.data as ErrorMessageResponse;
return new InternalStatus({
code: StatusCode.ERROR,
error: new InternalError(
ErrorCode.ADMIN_WATCHDOG_UNAVAIL,
{ errorMessage },
response
)
});
}
case 424: {
const errorMessage = response.data as ErrorMessageResponse;
return new InternalStatus<ServerUpdateResponse, ErrorCode.ADMIN_GITHUB_RATE>({
code: StatusCode.ERROR,
error: new InternalError(
ErrorCode.ADMIN_GITHUB_RATE,
{ errorMessage },
response
)
});
}
case 429: {
const errorMessage = response.data as ErrorMessageResponse;
return new InternalStatus<ServerUpdateResponse, ErrorCode.ADMIN_GITHUB_ERROR>({
code: StatusCode.ERROR,
error: new InternalError(
ErrorCode.ADMIN_GITHUB_ERROR,
{ errorMessage },
response
)
});
}
default: {
return new InternalStatus<ServerUpdateResponse, ErrorCode.UNHANDLED_RESPONSE>({
code: StatusCode.ERROR,
error: new InternalError(
ErrorCode.UNHANDLED_RESPONSE,
Expand Down
Loading

0 comments on commit 10762ae

Please sign in to comment.