检查索引的http请求改为websocket

This commit is contained in:
miao 2023-02-14 08:50:40 +08:00 committed by fangxiang
parent e4827b4fe6
commit 5a1dba7a8f
4 changed files with 572 additions and 538 deletions

View File

@ -117,7 +117,7 @@ export default defineComponent({
console.log(e);
}
EventBus.getInstance().on(EventNamesDefine.CheckDebug, () => {
EventBus.getInstance().on(EventNamesDefine.CheckDebug2, () => {
const to_normal_url = () => {
const p1 = window.location.href.indexOf("?debug");
const p2 = window.location.href.indexOf("#");

View File

@ -1519,6 +1519,15 @@ export default class ClientConnection {
console.error(e);
}
}
public async CheckModeIndex(mode_index:number) {
try {
return await this.doRpc<Protocol.RpcCheckModeIndexResponseEntity>(
new Protocol.RpcCheckModeIndexRequestEntity(mode_index)
);
} catch (e) {
console.error(e);
}
}
}
export interface NotifyMessage {

View File

@ -457,13 +457,17 @@ export default defineComponent({
resolve($t.t("Please type 0~65535"));
} else {
try {
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (!url) {
url = new URL(window.location.hostname);
}
url.pathname = HttpProtocol.RequestCheckModeIndex;
url.searchParams.append("index", index.value.toString());
let response = (await api.get(url.toString())).data as boolean;
// let url = GlobalData.getInstance().createCurrentRequestUrl();
// if (!url) {
// url = new URL(window.location.hostname);
// }
// url.pathname = HttpProtocol.RequestCheckModeIndex;
// url.searchParams.append("index", index.value.toString());
// let response = (await api.get(url.toString())).data as boolean;
// console.log(url)
let response= (await GlobalData.getInstance().getCurrentClient()?.CheckModeIndex(index.value))?.success as boolean;
// let response:boolean;
// console.log(res)
if (typeof response != "boolean") {
try {
response = JSON.parse(response);

View File

@ -534,6 +534,9 @@ export namespace Protocol {
public static get kRpcFileManagerCreateDirectory() {
return Commands.PROTOCOL_PREFIX + "RpcFileManagerCreateDirectory";
}
public static get kRpcCheckModeIndex() {
return Commands.PROTOCOL_PREFIX + "RpcCheckModeIndex";
}
static _all_commands = new Set([
Commands.kUnKnowCommand,
Commands.kSearchDevice,
@ -668,6 +671,7 @@ export namespace Protocol {
Commands.kRpcFileManagerRename,
Commands.kRpcFileManagerDelete,
Commands.kRpcFileManagerCreateDirectory,
Commands.kRpcCheckModeIndex,
]);
public static get AllCommands() {
return this._all_commands;
@ -3541,4 +3545,21 @@ export namespace Protocol {
error_message=""
error_code=0;
}
export class RpcCheckModeIndexRequestEntity extends PacketEntity{
constructor(mode_index:number,rpc_id = 0) {
super();
super.command = Commands.kRpcCheckModeIndex;
super.flag = PacketEntity.FLAG_REQUEST;
this.mode_index=mode_index
}
mode_index = 0;
}
export class RpcCheckModeIndexResponseEntity extends PacketEntity{
constructor() {
super();
super.flag = PacketEntity.FLAG_RESPONSE;
}
success = false;
}
}