mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
migrate to Protobuf ES
This commit is contained in:
parent
68e22d22bf
commit
fd55f4fb7f
133 changed files with 1745 additions and 1621 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_BanFromServer_ext, Command_BanFromServerSchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function banFromServer(minutes: number, userName?: string, address?: string, reason?: string,
|
||||
visibleReason?: string, clientid?: string, removeMessages?: number): void {
|
||||
BackendService.sendModeratorCommand('Command_BanFromServer', {
|
||||
BackendService.sendModeratorCommand(Command_BanFromServer_ext, create(Command_BanFromServerSchema, {
|
||||
minutes, userName, address, reason, visibleReason, clientid, removeMessages
|
||||
}, {
|
||||
}), {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.banFromServer(userName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import {
|
||||
Command_ForceActivateUser_ext, Command_ForceActivateUserSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function forceActivateUser(usernameToActivate: string, moderatorName: string): void {
|
||||
BackendService.sendModeratorCommand('Command_ForceActivateUser', { usernameToActivate, moderatorName }, {
|
||||
const cmd = create(Command_ForceActivateUserSchema, { usernameToActivate, moderatorName });
|
||||
BackendService.sendModeratorCommand(Command_ForceActivateUser_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.forceActivateUser(usernameToActivate, moderatorName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_GetAdminNotes_ext, Command_GetAdminNotesSchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_GetAdminNotes_ext } from 'generated/proto/response_get_admin_notes_pb';
|
||||
|
||||
export function getAdminNotes(userName: string): void {
|
||||
BackendService.sendModeratorCommand('Command_GetAdminNotes', { userName }, {
|
||||
responseName: 'Response_GetAdminNotes',
|
||||
BackendService.sendModeratorCommand(Command_GetAdminNotes_ext, create(Command_GetAdminNotesSchema, { userName }), {
|
||||
responseExt: Response_GetAdminNotes_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.getAdminNotes(userName, response.notes);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_GetBanHistory_ext, Command_GetBanHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_BanHistory_ext } from 'generated/proto/response_ban_history_pb';
|
||||
|
||||
export function getBanHistory(userName: string): void {
|
||||
BackendService.sendModeratorCommand('Command_GetBanHistory', { userName }, {
|
||||
responseName: 'Response_BanHistory',
|
||||
BackendService.sendModeratorCommand(Command_GetBanHistory_ext, create(Command_GetBanHistorySchema, { userName }), {
|
||||
responseExt: Response_BanHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.banHistory(userName, response.banList);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_GetWarnHistory_ext, Command_GetWarnHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_WarnHistory_ext } from 'generated/proto/response_warn_history_pb';
|
||||
|
||||
export function getWarnHistory(userName: string): void {
|
||||
BackendService.sendModeratorCommand('Command_GetWarnHistory', { userName }, {
|
||||
responseName: 'Response_WarnHistory',
|
||||
BackendService.sendModeratorCommand(Command_GetWarnHistory_ext, create(Command_GetWarnHistorySchema, { userName }), {
|
||||
responseExt: Response_WarnHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnHistory(userName, response.warnList);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_GetWarnList_ext, Command_GetWarnListSchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_WarnList_ext } from 'generated/proto/response_warn_list_pb';
|
||||
|
||||
export function getWarnList(modName: string, userName: string, userClientid: string): void {
|
||||
BackendService.sendModeratorCommand('Command_GetWarnList', { modName, userName, userClientid }, {
|
||||
responseName: 'Response_WarnList',
|
||||
BackendService.sendModeratorCommand(Command_GetWarnList_ext, create(Command_GetWarnListSchema, { modName, userName, userClientid }), {
|
||||
responseExt: Response_WarnList_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnListOptions(response.warning);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import {
|
||||
Command_GrantReplayAccess_ext, Command_GrantReplayAccessSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function grantReplayAccess(replayId: number, moderatorName: string): void {
|
||||
BackendService.sendModeratorCommand('Command_GrantReplayAccess', { replayId, moderatorName }, {
|
||||
BackendService.sendModeratorCommand(Command_GrantReplayAccess_ext, create(Command_GrantReplayAccessSchema, { replayId, moderatorName }), {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.grantReplayAccess(replayId, moderatorName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -22,6 +22,23 @@ vi.mock('../../persistence', () => ({
|
|||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import {
|
||||
Command_BanFromServer_ext,
|
||||
Command_ForceActivateUser_ext,
|
||||
Command_GetAdminNotes_ext,
|
||||
Command_GetBanHistory_ext,
|
||||
Command_GetWarnHistory_ext,
|
||||
Command_GetWarnList_ext,
|
||||
Command_GrantReplayAccess_ext,
|
||||
Command_UpdateAdminNotes_ext,
|
||||
Command_ViewLogHistory_ext,
|
||||
Command_WarnUser_ext,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
import { Response_GetAdminNotes_ext } from 'generated/proto/response_get_admin_notes_pb';
|
||||
import { Response_BanHistory_ext } from 'generated/proto/response_ban_history_pb';
|
||||
import { Response_WarnHistory_ext } from 'generated/proto/response_warn_history_pb';
|
||||
import { Response_WarnList_ext } from 'generated/proto/response_warn_list_pb';
|
||||
import { Response_ViewLogHistory_ext } from 'generated/proto/response_viewlog_history_pb';
|
||||
import { banFromServer } from './banFromServer';
|
||||
import { forceActivateUser } from './forceActivateUser';
|
||||
import { getAdminNotes } from './getAdminNotes';
|
||||
|
|
@ -34,7 +51,8 @@ import { viewLogHistory } from './viewLogHistory';
|
|||
import { warnUser } from './warnUser';
|
||||
|
||||
const { getLastSendOpts, invokeOnSuccess } = makeCallbackHelpers(
|
||||
BackendService.sendModeratorCommand as vi.Mock
|
||||
BackendService.sendModeratorCommand as vi.Mock,
|
||||
2
|
||||
);
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
|
@ -47,7 +65,7 @@ describe('banFromServer', () => {
|
|||
it('calls sendModeratorCommand with Command_BanFromServer', () => {
|
||||
banFromServer(30, 'alice', '1.2.3.4', 'reason', 'visible', 'cid', 1);
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
'Command_BanFromServer',
|
||||
Command_BanFromServer_ext,
|
||||
expect.objectContaining({ minutes: 30, userName: 'alice' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -67,7 +85,7 @@ describe('forceActivateUser', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_ForceActivateUser', () => {
|
||||
forceActivateUser('alice', 'mod1');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith('Command_ForceActivateUser', expect.any(Object), expect.any(Object));
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(Command_ForceActivateUser_ext, expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.forceActivateUser', () => {
|
||||
|
|
@ -85,16 +103,16 @@ describe('getAdminNotes', () => {
|
|||
it('calls sendModeratorCommand with Command_GetAdminNotes', () => {
|
||||
getAdminNotes('alice');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
'Command_GetAdminNotes',
|
||||
Command_GetAdminNotes_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseName: 'Response_GetAdminNotes' })
|
||||
expect.objectContaining({ responseExt: Response_GetAdminNotes_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.getAdminNotes with notes', () => {
|
||||
getAdminNotes('alice');
|
||||
const resp = { notes: 'some notes' };
|
||||
invokeOnSuccess(resp, { responseCode: 0, '.Response_GetAdminNotes.ext': resp });
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(ModeratorPersistence.getAdminNotes).toHaveBeenCalledWith('alice', 'some notes');
|
||||
});
|
||||
});
|
||||
|
|
@ -107,16 +125,16 @@ describe('getBanHistory', () => {
|
|||
it('calls sendModeratorCommand with Command_GetBanHistory', () => {
|
||||
getBanHistory('alice');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
'Command_GetBanHistory',
|
||||
Command_GetBanHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseName: 'Response_BanHistory' })
|
||||
expect.objectContaining({ responseExt: Response_BanHistory_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.banHistory with banList', () => {
|
||||
getBanHistory('alice');
|
||||
const resp = { banList: [{ id: 1 }] };
|
||||
invokeOnSuccess(resp, { responseCode: 0, '.Response_BanHistory.ext': resp });
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(ModeratorPersistence.banHistory).toHaveBeenCalledWith('alice', [{ id: 1 }]);
|
||||
});
|
||||
});
|
||||
|
|
@ -129,16 +147,16 @@ describe('getWarnHistory', () => {
|
|||
it('calls sendModeratorCommand with Command_GetWarnHistory', () => {
|
||||
getWarnHistory('alice');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
'Command_GetWarnHistory',
|
||||
Command_GetWarnHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseName: 'Response_WarnHistory' })
|
||||
expect.objectContaining({ responseExt: Response_WarnHistory_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.warnHistory with warnList', () => {
|
||||
getWarnHistory('alice');
|
||||
const resp = { warnList: [{ id: 2 }] };
|
||||
invokeOnSuccess(resp, { responseCode: 0, '.Response_WarnHistory.ext': resp });
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(ModeratorPersistence.warnHistory).toHaveBeenCalledWith('alice', [{ id: 2 }]);
|
||||
});
|
||||
});
|
||||
|
|
@ -151,16 +169,16 @@ describe('getWarnList', () => {
|
|||
it('calls sendModeratorCommand with Command_GetWarnList', () => {
|
||||
getWarnList('mod1', 'alice', 'US');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
'Command_GetWarnList',
|
||||
Command_GetWarnList_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseName: 'Response_WarnList' })
|
||||
expect.objectContaining({ responseExt: Response_WarnList_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.warnListOptions with warning', () => {
|
||||
getWarnList('mod1', 'alice', 'US');
|
||||
const resp = { warning: ['w1', 'w2'] };
|
||||
invokeOnSuccess(resp, { responseCode: 0, '.Response_WarnList.ext': resp });
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(ModeratorPersistence.warnListOptions).toHaveBeenCalledWith(['w1', 'w2']);
|
||||
});
|
||||
});
|
||||
|
|
@ -172,7 +190,7 @@ describe('grantReplayAccess', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_GrantReplayAccess', () => {
|
||||
grantReplayAccess(10, 'mod1');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith('Command_GrantReplayAccess', expect.any(Object), expect.any(Object));
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(Command_GrantReplayAccess_ext, expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.grantReplayAccess', () => {
|
||||
|
|
@ -189,7 +207,7 @@ describe('updateAdminNotes', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_UpdateAdminNotes', () => {
|
||||
updateAdminNotes('alice', 'new notes');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith('Command_UpdateAdminNotes', expect.any(Object), expect.any(Object));
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(Command_UpdateAdminNotes_ext, expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.updateAdminNotes', () => {
|
||||
|
|
@ -205,18 +223,18 @@ describe('updateAdminNotes', () => {
|
|||
describe('viewLogHistory', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_ViewLogHistory', () => {
|
||||
viewLogHistory({ filters: 'all' } as any);
|
||||
viewLogHistory({ dateRange: 7 } as any);
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
'Command_ViewLogHistory',
|
||||
Command_ViewLogHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseName: 'Response_ViewLogHistory' })
|
||||
expect.objectContaining({ responseExt: Response_ViewLogHistory_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.viewLogs with logMessage', () => {
|
||||
viewLogHistory({ filters: 'all' } as any);
|
||||
viewLogHistory({ dateRange: 7 } as any);
|
||||
const resp = { logMessage: ['log1'] };
|
||||
invokeOnSuccess(resp, { responseCode: 0, '.Response_ViewLogHistory.ext': resp });
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(ModeratorPersistence.viewLogs).toHaveBeenCalledWith(['log1']);
|
||||
});
|
||||
});
|
||||
|
|
@ -228,7 +246,7 @@ describe('warnUser', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_WarnUser', () => {
|
||||
warnUser('alice', 'bad behavior', 'cid');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith('Command_WarnUser', expect.any(Object), expect.any(Object));
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(Command_WarnUser_ext, expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.warnUser', () => {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import {
|
||||
Command_UpdateAdminNotes_ext, Command_UpdateAdminNotesSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function updateAdminNotes(userName: string, notes: string): void {
|
||||
BackendService.sendModeratorCommand('Command_UpdateAdminNotes', { userName, notes }, {
|
||||
BackendService.sendModeratorCommand(Command_UpdateAdminNotes_ext, create(Command_UpdateAdminNotesSchema, { userName, notes }), {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.updateAdminNotes(userName, notes);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_ViewLogHistory_ext, Command_ViewLogHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_ViewLogHistory_ext } from 'generated/proto/response_viewlog_history_pb';
|
||||
import { LogFilters } from 'types';
|
||||
|
||||
export function viewLogHistory(filters: LogFilters): void {
|
||||
BackendService.sendModeratorCommand('Command_ViewLogHistory', filters, {
|
||||
responseName: 'Response_ViewLogHistory',
|
||||
BackendService.sendModeratorCommand(Command_ViewLogHistory_ext, create(Command_ViewLogHistorySchema, filters), {
|
||||
responseExt: Response_ViewLogHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.viewLogs(response.logMessage);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import { Command_WarnUser_ext, Command_WarnUserSchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function warnUser(userName: string, reason: string, clientid?: string, removeMessages?: number): void {
|
||||
BackendService.sendModeratorCommand('Command_WarnUser', { userName, reason, clientid, removeMessages }, {
|
||||
const cmd = create(Command_WarnUserSchema, { userName, reason, clientid, removeMessages });
|
||||
BackendService.sendModeratorCommand(Command_WarnUser_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.warnUser(userName);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue