import createAxios from '@/utils/request'

// 设备文件根目录查询
export function getDeviceRootPath(nDid) {
    return createAxios({
        url: '/cs-device-boot/deviceFile/askDeviceRootPath?nDid=' + nDid,
        method: 'POST'
    })
}

// 设备文件-目录信息询问
export function getFileServiceFileOrDir(data) {
    return createAxios({
        url: `cs-device-boot/deviceFile/askDeviceFileOrDir?nDid=${data.nDid}&name=${data.name}&type=${data.type}`,
        method: 'POST'
    })
}
// 监测设备-目录信息询问
export function listDir(data) {
    return createAxios({
        url: `/zl-event-boot/file/listDir`,
        method: 'POST',
        data: data
    })
}
// 下载文件
export function downloadFileFromFrontr(data: any) {
    return createAxios({
        url: `/zl-event-boot/file/downloadFileFromFront`,
        method: 'POST',
        data: data,
        responseType: 'blob'
    })
}
// 删除文件
export function deleteCld(data: any) {
    return createAxios({
        url: `/zl-event-boot/file/delete`,
        method: 'POST',
        data: data
    })
}
// 新建文件
export function mkdir(data: any) {
    return createAxios({
        url: `/zl-event-boot/file/mkdir`,
        method: 'POST',
        data: data
    })
}
//  上传文件
export function uploadFileToFront(obj: any) {
    let form = new FormData()
    form.append('file', obj.file)
    form.append('devId', obj.devId)
    form.append('dirPath', obj.dirPath)
    return createAxios({
        url: `/zl-event-boot/file/uploadFileToFront`,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}
//设备文件下载
export function downLoadDeviceFile(data) {
    return createAxios({
        url: `/cs-device-boot/deviceFile/downloadFile?nDid=${data.nDid}&name=${data.name}&fileCheck=${data.fileCheck}&size=${data.size}`,
        method: 'POST'
    })
}

//获取下载文件的文件路径地址
export function downLoadDeviceFilePath(obj) {
    let form = new FormData()
    form.append('name', obj.name)
    form.append('nDid', obj.nDid)
    return createAxios({
        url: `/cs-device-boot/deviceFile/getDownloadFilePath`,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}
//设备重启
export function reStartDevice(data) {
    return createAxios({
        url: `/cs-device-boot/EquipmentDelivery/rebootDevice?nDid=${data.nDid}`,
        method: 'POST'
    })
}

//上传文件至设备
export function uploadDeviceFile(data) {
    let form = new FormData()
    form.append('file', data.file)
    form.append('filePath', data.filePath)
    form.append('id', data.id)
    return createAxios({
        url: `/access-boot/analyzeModel/uploadDevFile`,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

//新建文件夹目录
export function addDeviceDir(data) {
    let form = new FormData()
    form.append('nDid', data.nDid)
    form.append('path', data.path)
    return createAxios({
        url: `/access-boot/askDeviceData/createFolder`,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

//删除文件/文件夹
export function delDeviceDir(data) {
    let form = new FormData()
    form.append('nDid', data.nDid)
    form.append('path', data.path)
    return createAxios({
        url: `/access-boot/askDeviceData/deleteFolder`,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}
