Update folder get ios
This commit is contained in:
parent
429c570688
commit
5afc8701ab
|
|
@ -1,81 +1,39 @@
|
|||
import type { HttpContext } from '@adonisjs/core/http'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
export default class IosLicenseController {
|
||||
/* ================= LIST ================= */
|
||||
/* ================= HELPER ================= */
|
||||
|
||||
private getBinFiles(dir: string): string[] {
|
||||
if (!fs.existsSync(dir)) return []
|
||||
|
||||
return fs.readdirSync(dir).filter((file) => file.toLowerCase().endsWith('.bin'))
|
||||
}
|
||||
|
||||
private getLicFiles(dir: string): string[] {
|
||||
if (!fs.existsSync(dir)) return []
|
||||
|
||||
return fs.readdirSync(dir).filter((file) => file.toLowerCase().endsWith('.lic'))
|
||||
}
|
||||
|
||||
/* ================= IOS ================= */
|
||||
|
||||
async getIos() {
|
||||
return fs.readdirSync('storage/ios')
|
||||
const smbPath = '/ipsteamSMB/IOS/i'
|
||||
const localPath = 'storage/ios'
|
||||
|
||||
const targetPath = fs.existsSync(smbPath) ? smbPath : localPath
|
||||
|
||||
return this.getBinFiles(targetPath)
|
||||
}
|
||||
|
||||
/* ================= LICENSE ================= */
|
||||
|
||||
async getLicense() {
|
||||
return fs.readdirSync('storage/license')
|
||||
}
|
||||
const smbPath = '/ipsteamSMB/IOS/License'
|
||||
const localPath = 'storage/license'
|
||||
|
||||
/* ================= UPLOAD ================= */
|
||||
const targetPath = fs.existsSync(smbPath) ? smbPath : localPath
|
||||
|
||||
async uploadIos({ request, response }: HttpContext) {
|
||||
const file = request.file('file', {
|
||||
size: '4gb',
|
||||
extnames: ['bin', 'img', 'tar'],
|
||||
})
|
||||
|
||||
if (!file) {
|
||||
return response.badRequest('File is required')
|
||||
}
|
||||
|
||||
await file.move('storage/ios', {
|
||||
name: file.clientName,
|
||||
overwrite: true,
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
filename: file.clientName,
|
||||
}
|
||||
}
|
||||
|
||||
async uploadLicense({ request, response }: HttpContext) {
|
||||
const file = request.file('file', {
|
||||
size: '100mb',
|
||||
extnames: ['lic', 'txt'],
|
||||
})
|
||||
|
||||
if (!file) {
|
||||
return response.badRequest('File is required')
|
||||
}
|
||||
|
||||
await file.move('storage/license', {
|
||||
name: file.clientName,
|
||||
overwrite: true,
|
||||
})
|
||||
|
||||
return {
|
||||
success: true,
|
||||
filename: file.clientName,
|
||||
}
|
||||
}
|
||||
|
||||
/* ================= DOWNLOAD ================= */
|
||||
|
||||
async downloadIos({ params, response }: HttpContext) {
|
||||
const filePath = path.join('storage/ios', params.filename)
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return response.notFound('File not found')
|
||||
}
|
||||
|
||||
return response.download(filePath)
|
||||
}
|
||||
|
||||
async downloadLicense({ params, response }: HttpContext) {
|
||||
const filePath = path.join('storage/license', params.filename)
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return response.notFound('File not found')
|
||||
}
|
||||
|
||||
return response.download(filePath)
|
||||
return this.getLicFiles(targetPath)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1166,7 +1166,7 @@ export default class LineConnection {
|
|||
},
|
||||
{
|
||||
expect: 'rommon',
|
||||
send: `TFTP_FILE=ios/${nameIos}`,
|
||||
send: `TFTP_FILE=i/${nameIos}`,
|
||||
delay: '1',
|
||||
repeat: '1',
|
||||
note: '',
|
||||
|
|
@ -1372,7 +1372,7 @@ export default class LineConnection {
|
|||
},
|
||||
{
|
||||
expect: '',
|
||||
send: this.listDeviceIos?.includes(nameIos) ? '' : `ios/${nameIos}`,
|
||||
send: this.listDeviceIos?.includes(nameIos) ? '' : `i/${nameIos}`,
|
||||
delay: '1',
|
||||
repeat: '1',
|
||||
note: '',
|
||||
|
|
@ -1554,7 +1554,7 @@ export default class LineConnection {
|
|||
await this.writeCommand(`copy flash: tftp:\r\n`)
|
||||
await this.writeCommand(`${fileName}\r\n`)
|
||||
await this.writeCommand(`${server}\r\n`)
|
||||
await this.writeCommand(`ios/${fileName}\r\n`)
|
||||
await this.writeCommand(`i/${fileName}\r\n`)
|
||||
await sleep(5000)
|
||||
while (true) {
|
||||
if (this.outputBuffer.includes('#')) {
|
||||
|
|
|
|||
|
|
@ -669,8 +669,8 @@ export class WebSocketIo {
|
|||
stationId,
|
||||
[lineId],
|
||||
async (lineCon) => {
|
||||
await lineCon.backupIos(iosName)
|
||||
if (isReboot) {
|
||||
await lineCon.backupIos(iosName)
|
||||
if (!outletNumber || outletNumber < 0) return
|
||||
if (!station) return
|
||||
const apcIp = (station as any)[`${apcName}_ip`] as string
|
||||
|
|
|
|||
Loading…
Reference in New Issue