将文件管理的http请求改为websocket

This commit is contained in:
miao 2023-02-12 15:58:54 +08:00
parent 2a6e8e78c0
commit aee328fb82
4 changed files with 1437 additions and 1346 deletions

View File

@ -1483,6 +1483,42 @@ export default class ClientConnection {
}
this.ws = null;
}
public async getFileListFileManager(dir_path:string) {
try {
return await this.doRpc<Protocol.RpcFileManagerGetFileListResponse>(
new Protocol.RpcFileManagerGetFileListRequest(dir_path)
);
} catch (e) {
console.error(e);
}
}
public async RenameFileManager(base_dir:string,file_name:string,new_file_name:string) {
try {
return await this.doRpc<Protocol.RpcFileManagerRenameResponse>(
new Protocol.RpcFileManagerRenameRequest(base_dir,file_name,new_file_name)
);
} catch (e) {
console.error(e);
}
}
public async DeleteFileManager(base_dir:string,file_name:string) {
try {
return await this.doRpc<Protocol.RpcFileManagerDeleteResponse>(
new Protocol.RpcFileManagerDeleteRequest(base_dir,file_name)
);
} catch (e) {
console.error(e);
}
}
public async CreateDirectoryFileManager(base_dir:string,dir_name:string) {
try {
return await this.doRpc<Protocol.RpcFileManagerCreateDirectoryResponse>(
new Protocol.RpcFileManagerCreateDirectoryRequest(base_dir,dir_name)
);
} catch (e) {
console.error(e);
}
}
}
export interface NotifyMessage {

View File

@ -624,41 +624,25 @@ export default defineComponent({
label: $t.t("operator"),
},
];
const _request_list_files = async (path: string) => {
loading.value = true;
let client = GlobalData.getInstance().getCurrentClient();
if (client) {
let url = new URL(client.url);
url.port =
GlobalData.getInstance().applicationConfig?.httpserver_port ??
HttpProtocol.DefaultHttpPort.toString();
url.pathname = HttpProtocol.RequestPathListFile;
url.protocol = "http:";
url.searchParams.append("path", path);
return await api.get(url.toString());
let file_list = await GlobalData.getInstance()
.getCurrentClient()
?.getFileListFileManager(path);
return file_list;
}
loading.value = false;
return null;
};
const _show_files = (response: any) => {
if (response) {
if (response.status == 200) {
interface IRsponseData {
files: FileEntity[];
free: number;
}
if (response.success) {
let file_entitys: FileEntity[] = [];
let free = 0;
if (Array.isArray(response.data)) {
file_entitys = response.data as FileEntity[];
} else {
const resposne_data = response.data as IRsponseData;
file_entitys = resposne_data.files;
free = resposne_data.free;
}
file_entitys = response.files;
free = response.free;
free_space.value = free;
if (Array.isArray(file_entitys)) {
directory_count.value = 0;
@ -703,6 +687,7 @@ export default defineComponent({
loading.value = false;
};
const refresh_file_list_async = async () => {
const response = await _request_list_files(path.value);
_show_files(response);
@ -923,8 +908,6 @@ export default defineComponent({
resolve_value = null;
},
async onCreateNewFolder() {
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (url) {
$q.dialog({
title: $t.t("create folder"),
message: $t.t("input folder name") + ":",
@ -945,14 +928,9 @@ export default defineComponent({
},
persistent: true,
}).onOk(async (data: string) => {
if (url) {
url.pathname = HttpProtocol.RequestPathCreateDirectory;
let response = (
await api.post(url.toString(), {
base_dir: path.value,
dir_name: data,
})
).data as NormalResult;
const response = await GlobalData.getInstance()
.getCurrentClient()
?.CreateDirectoryFileManager(path.value, data);
if (response && response.success) {
refresh_file_list();
$q.notify({
@ -968,30 +946,21 @@ export default defineComponent({
$t.t("create folder") +
$t.t("fail") +
"!" +
(response ? response.message : ""),
(response ? response.error_message : ""),
position: "top",
timeout: 1500,
});
}
}
});
}
},
selectFile,
async deleteFile(file: FileEntity) {
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (url) {
url.pathname = HttpProtocol.RequestPathDeleteFile;
let response = null;
try {
response = (
await api.delete(url.toString(), {
data: {
base_dir: path.value,
file_name: file.name,
},
})
).data as NormalResult;
response = await GlobalData.getInstance()
.getCurrentClient()
?.DeleteFileManager(path.value, file.name);
} catch (e) {
console.log(e);
}
@ -1010,16 +979,13 @@ export default defineComponent({
$t.t("delete file") +
$t.t("fail") +
"!" +
(response ? response.message : ""),
(response ? response.error_message : ""),
position: "top",
timeout: 1500,
});
}
}
},
renameFile(file: FileEntity) {
let url = GlobalData.getInstance().createCurrentRequestUrl();
if (url) {
$q.dialog({
title: $t.t("rename"),
message: $t.t("input new file name") + ":",
@ -1043,20 +1009,9 @@ export default defineComponent({
if (data == file.name) {
return;
}
if (url) {
url.pathname = HttpProtocol.RequestPathRenameFile;
url.searchParams.append(
"type",
HttpProtocol.RequestPathRenameFile
);
let response = (
await api.put(url.toString(), {
base_dir: path.value,
file_name: file.name,
new_file_name: data,
})
).data as NormalResult;
let response = await GlobalData.getInstance()
.getCurrentClient()
?.RenameFileManager(path.value, file.name, data);
if (response && response.success) {
refresh_file_list();
$q.notify({
@ -1072,14 +1027,12 @@ export default defineComponent({
$t.t("file rename") +
$t.t("fail") +
"!" +
(response ? response.message : ""),
(response ? response.error_message : ""),
position: "top",
timeout: 1500,
});
}
}
});
}
},
copyStringToClipboard(value: string) {
copyToClipboard(value);
@ -1171,12 +1124,10 @@ export default defineComponent({
"Content-Type": "multipart/form-data",
},
});
if (response && response.data && response.data.is_support) {
} else {
onError(file);
}
console.log(response);
} else {
throw "";
}

View File

@ -521,7 +521,19 @@ export namespace Protocol {
public static get kSaveBlendingConfig() {
return Commands.PROTOCOL_PREFIX + "SaveBlendingConfig";
}
public static get kRpcFileManagerGetFileList() {
return Commands.PROTOCOL_PREFIX + "RpcFileManagerGetFileList";
}
public static get kRpcFileManagerRename() {
return Commands.PROTOCOL_PREFIX + "RpcFileManagerRename";
}
public static get kRpcFileManagerDelete() {
return Commands.PROTOCOL_PREFIX + "RpcFileManagerDelete";
}
public static get kRpcFileManagerCreateDirectory() {
return Commands.PROTOCOL_PREFIX + "RpcFileManagerCreateDirectory";
}
static _all_commands = new Set([
Commands.kUnKnowCommand,
Commands.kSearchDevice,
@ -652,6 +664,10 @@ export namespace Protocol {
Commands.kSaveBlendingConfig,
Commands.kRpcSetMagicWallGridState,
Commands.kRpcGetMagicWallGridState,
Commands.kRpcFileManagerGetFileList,
Commands.kRpcFileManagerRename,
Commands.kRpcFileManagerDelete,
Commands.kRpcFileManagerCreateDirectory,
]);
public static get AllCommands() {
return this._all_commands;
@ -3438,4 +3454,91 @@ export namespace Protocol {
}
name = "";
}
export class RpcFileManagerGetFileListRequest extends PacketEntity{
dir_path:string=""
constructor(dir_path:string,rpc_id = 0) {
super();
super.command = Commands.kRpcFileManagerGetFileList;
super.flag = PacketEntity.FLAG_REQUEST;
super.rpc_id = rpc_id;
this.dir_path=dir_path
}
}
export class RpcFileManagerGetFileListResponse extends PacketEntity{
constructor() {
super();
super.flag = PacketEntity.FLAG_RESPONSE;
}
error_code=0;
success = false;
error_message=""
free=0;
files:FileEntry[]=[]
}
export class RpcFileManagerRenameRequest extends PacketEntity{
constructor(base_dir:string,file_name:string,new_file_name:string,rpc_id = 0) {
super();
super.command = Commands.kRpcFileManagerRename;
super.flag = PacketEntity.FLAG_REQUEST;
super.rpc_id = rpc_id;
this.base_dir=base_dir
this.file_name=file_name
this.new_file_name=new_file_name
}
base_dir=""
file_name=""
new_file_name=""
}
export class RpcFileManagerRenameResponse extends PacketEntity{
constructor() {
super();
super.flag = PacketEntity.FLAG_RESPONSE;
}
success = false;
error_code=0;
error_message=""
}
export class RpcFileManagerDeleteRequest extends PacketEntity{
constructor(base_dir:string,file_name:string,rpc_id = 0) {
super();
super.command = Commands.kRpcFileManagerDelete;
super.flag = PacketEntity.FLAG_REQUEST;
super.rpc_id = rpc_id;
this.base_dir=base_dir
this.file_name=file_name
}
base_dir=""
file_name=""
}
export class RpcFileManagerDeleteResponse extends PacketEntity{
constructor() {
super();
super.flag = PacketEntity.FLAG_RESPONSE;
}
success = false;
delete_count=""
error_code=0;
error_message=""
}
export class RpcFileManagerCreateDirectoryRequest extends PacketEntity{
constructor(base_dir:string,dir_name:string,rpc_id = 0) {
super();
super.command = Commands.kRpcFileManagerCreateDirectory;
super.flag = PacketEntity.FLAG_REQUEST;
super.rpc_id = rpc_id;
this.base_dir=base_dir
this.dir_name=dir_name
}
base_dir=""
dir_name=""
}
export class RpcFileManagerCreateDirectoryResponse extends PacketEntity{
constructor() {
super();
super.flag = PacketEntity.FLAG_RESPONSE;
}
success = false;
error_message=""
error_code=0;
}
}

View File

@ -505,6 +505,7 @@
<q-item v-else>
<q-item-section avatar style="margin-right: 0px; padding-right: 0px">
<q-btn
flat
@click="isfullbtn()"
:icon="isfull ? 'fullscreen_exit' : 'fullscreen'"
/>