Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to TGS HTTP API 9.11.0 #147

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion 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
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