diff --git a/BACKEND/app/controllers/ios_license_controller.ts b/BACKEND/app/controllers/ios_license_controller.ts index 8009e9e..1df8375 100644 --- a/BACKEND/app/controllers/ios_license_controller.ts +++ b/BACKEND/app/controllers/ios_license_controller.ts @@ -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) } } diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index fcf202f..c524dd1 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -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('#')) { diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index 716933f..04ef700 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -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