将文件管理的http请求改为websocket
This commit is contained in:
parent
2a6e8e78c0
commit
aee328fb82
|
@ -1483,6 +1483,42 @@ export default class ClientConnection {
|
||||||
}
|
}
|
||||||
this.ws = null;
|
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 {
|
export interface NotifyMessage {
|
||||||
|
|
|
@ -624,41 +624,25 @@ export default defineComponent({
|
||||||
label: $t.t("operator"),
|
label: $t.t("operator"),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const _request_list_files = async (path: string) => {
|
const _request_list_files = async (path: string) => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
let client = GlobalData.getInstance().getCurrentClient();
|
let client = GlobalData.getInstance().getCurrentClient();
|
||||||
if (client) {
|
if (client) {
|
||||||
let url = new URL(client.url);
|
let file_list = await GlobalData.getInstance()
|
||||||
url.port =
|
.getCurrentClient()
|
||||||
GlobalData.getInstance().applicationConfig?.httpserver_port ??
|
?.getFileListFileManager(path);
|
||||||
HttpProtocol.DefaultHttpPort.toString();
|
return file_list;
|
||||||
url.pathname = HttpProtocol.RequestPathListFile;
|
|
||||||
url.protocol = "http:";
|
|
||||||
url.searchParams.append("path", path);
|
|
||||||
return await api.get(url.toString());
|
|
||||||
}
|
}
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const _show_files = (response: any) => {
|
const _show_files = (response: any) => {
|
||||||
if (response) {
|
if (response) {
|
||||||
if (response.status == 200) {
|
if (response.success) {
|
||||||
interface IRsponseData {
|
|
||||||
files: FileEntity[];
|
|
||||||
free: number;
|
|
||||||
}
|
|
||||||
let file_entitys: FileEntity[] = [];
|
let file_entitys: FileEntity[] = [];
|
||||||
let free = 0;
|
let free = 0;
|
||||||
|
file_entitys = response.files;
|
||||||
if (Array.isArray(response.data)) {
|
free = response.free;
|
||||||
file_entitys = response.data as FileEntity[];
|
|
||||||
} else {
|
|
||||||
const resposne_data = response.data as IRsponseData;
|
|
||||||
file_entitys = resposne_data.files;
|
|
||||||
free = resposne_data.free;
|
|
||||||
}
|
|
||||||
free_space.value = free;
|
free_space.value = free;
|
||||||
if (Array.isArray(file_entitys)) {
|
if (Array.isArray(file_entitys)) {
|
||||||
directory_count.value = 0;
|
directory_count.value = 0;
|
||||||
|
@ -703,6 +687,7 @@ export default defineComponent({
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const refresh_file_list_async = async () => {
|
const refresh_file_list_async = async () => {
|
||||||
const response = await _request_list_files(path.value);
|
const response = await _request_list_files(path.value);
|
||||||
_show_files(response);
|
_show_files(response);
|
||||||
|
@ -923,8 +908,6 @@ export default defineComponent({
|
||||||
resolve_value = null;
|
resolve_value = null;
|
||||||
},
|
},
|
||||||
async onCreateNewFolder() {
|
async onCreateNewFolder() {
|
||||||
let url = GlobalData.getInstance().createCurrentRequestUrl();
|
|
||||||
if (url) {
|
|
||||||
$q.dialog({
|
$q.dialog({
|
||||||
title: $t.t("create folder"),
|
title: $t.t("create folder"),
|
||||||
message: $t.t("input folder name") + ":",
|
message: $t.t("input folder name") + ":",
|
||||||
|
@ -945,14 +928,9 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
persistent: true,
|
persistent: true,
|
||||||
}).onOk(async (data: string) => {
|
}).onOk(async (data: string) => {
|
||||||
if (url) {
|
const response = await GlobalData.getInstance()
|
||||||
url.pathname = HttpProtocol.RequestPathCreateDirectory;
|
.getCurrentClient()
|
||||||
let response = (
|
?.CreateDirectoryFileManager(path.value, data);
|
||||||
await api.post(url.toString(), {
|
|
||||||
base_dir: path.value,
|
|
||||||
dir_name: data,
|
|
||||||
})
|
|
||||||
).data as NormalResult;
|
|
||||||
if (response && response.success) {
|
if (response && response.success) {
|
||||||
refresh_file_list();
|
refresh_file_list();
|
||||||
$q.notify({
|
$q.notify({
|
||||||
|
@ -968,30 +946,21 @@ export default defineComponent({
|
||||||
$t.t("create folder") +
|
$t.t("create folder") +
|
||||||
$t.t("fail") +
|
$t.t("fail") +
|
||||||
"!" +
|
"!" +
|
||||||
(response ? response.message : ""),
|
(response ? response.error_message : ""),
|
||||||
position: "top",
|
position: "top",
|
||||||
timeout: 1500,
|
timeout: 1500,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
selectFile,
|
selectFile,
|
||||||
async deleteFile(file: FileEntity) {
|
async deleteFile(file: FileEntity) {
|
||||||
let url = GlobalData.getInstance().createCurrentRequestUrl();
|
|
||||||
if (url) {
|
|
||||||
url.pathname = HttpProtocol.RequestPathDeleteFile;
|
|
||||||
let response = null;
|
let response = null;
|
||||||
try {
|
try {
|
||||||
response = (
|
response = await GlobalData.getInstance()
|
||||||
await api.delete(url.toString(), {
|
.getCurrentClient()
|
||||||
data: {
|
?.DeleteFileManager(path.value, file.name);
|
||||||
base_dir: path.value,
|
|
||||||
file_name: file.name,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
).data as NormalResult;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
@ -1010,16 +979,13 @@ export default defineComponent({
|
||||||
$t.t("delete file") +
|
$t.t("delete file") +
|
||||||
$t.t("fail") +
|
$t.t("fail") +
|
||||||
"!" +
|
"!" +
|
||||||
(response ? response.message : ""),
|
(response ? response.error_message : ""),
|
||||||
position: "top",
|
position: "top",
|
||||||
timeout: 1500,
|
timeout: 1500,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
renameFile(file: FileEntity) {
|
renameFile(file: FileEntity) {
|
||||||
let url = GlobalData.getInstance().createCurrentRequestUrl();
|
|
||||||
if (url) {
|
|
||||||
$q.dialog({
|
$q.dialog({
|
||||||
title: $t.t("rename"),
|
title: $t.t("rename"),
|
||||||
message: $t.t("input new file name") + ":",
|
message: $t.t("input new file name") + ":",
|
||||||
|
@ -1043,20 +1009,9 @@ export default defineComponent({
|
||||||
if (data == file.name) {
|
if (data == file.name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (url) {
|
let response = await GlobalData.getInstance()
|
||||||
url.pathname = HttpProtocol.RequestPathRenameFile;
|
.getCurrentClient()
|
||||||
url.searchParams.append(
|
?.RenameFileManager(path.value, file.name, data);
|
||||||
"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;
|
|
||||||
if (response && response.success) {
|
if (response && response.success) {
|
||||||
refresh_file_list();
|
refresh_file_list();
|
||||||
$q.notify({
|
$q.notify({
|
||||||
|
@ -1072,14 +1027,12 @@ export default defineComponent({
|
||||||
$t.t("file rename") +
|
$t.t("file rename") +
|
||||||
$t.t("fail") +
|
$t.t("fail") +
|
||||||
"!" +
|
"!" +
|
||||||
(response ? response.message : ""),
|
(response ? response.error_message : ""),
|
||||||
position: "top",
|
position: "top",
|
||||||
timeout: 1500,
|
timeout: 1500,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
},
|
},
|
||||||
copyStringToClipboard(value: string) {
|
copyStringToClipboard(value: string) {
|
||||||
copyToClipboard(value);
|
copyToClipboard(value);
|
||||||
|
@ -1171,12 +1124,10 @@ export default defineComponent({
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response && response.data && response.data.is_support) {
|
if (response && response.data && response.data.is_support) {
|
||||||
} else {
|
} else {
|
||||||
onError(file);
|
onError(file);
|
||||||
}
|
}
|
||||||
console.log(response);
|
|
||||||
} else {
|
} else {
|
||||||
throw "";
|
throw "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -521,7 +521,19 @@ export namespace Protocol {
|
||||||
public static get kSaveBlendingConfig() {
|
public static get kSaveBlendingConfig() {
|
||||||
return Commands.PROTOCOL_PREFIX + "SaveBlendingConfig";
|
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([
|
static _all_commands = new Set([
|
||||||
Commands.kUnKnowCommand,
|
Commands.kUnKnowCommand,
|
||||||
Commands.kSearchDevice,
|
Commands.kSearchDevice,
|
||||||
|
@ -652,6 +664,10 @@ export namespace Protocol {
|
||||||
Commands.kSaveBlendingConfig,
|
Commands.kSaveBlendingConfig,
|
||||||
Commands.kRpcSetMagicWallGridState,
|
Commands.kRpcSetMagicWallGridState,
|
||||||
Commands.kRpcGetMagicWallGridState,
|
Commands.kRpcGetMagicWallGridState,
|
||||||
|
Commands.kRpcFileManagerGetFileList,
|
||||||
|
Commands.kRpcFileManagerRename,
|
||||||
|
Commands.kRpcFileManagerDelete,
|
||||||
|
Commands.kRpcFileManagerCreateDirectory,
|
||||||
]);
|
]);
|
||||||
public static get AllCommands() {
|
public static get AllCommands() {
|
||||||
return this._all_commands;
|
return this._all_commands;
|
||||||
|
@ -3438,4 +3454,91 @@ export namespace Protocol {
|
||||||
}
|
}
|
||||||
name = "";
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -505,6 +505,7 @@
|
||||||
<q-item v-else>
|
<q-item v-else>
|
||||||
<q-item-section avatar style="margin-right: 0px; padding-right: 0px">
|
<q-item-section avatar style="margin-right: 0px; padding-right: 0px">
|
||||||
<q-btn
|
<q-btn
|
||||||
|
flat
|
||||||
@click="isfullbtn()"
|
@click="isfullbtn()"
|
||||||
:icon="isfull ? 'fullscreen_exit' : 'fullscreen'"
|
:icon="isfull ? 'fullscreen_exit' : 'fullscreen'"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue