ATC_SIMPLE/BACKEND/app/controllers/ios_license_controller.ts

73 lines
1.7 KiB
TypeScript

import fs from 'node:fs'
import path from 'node:path'
interface FileInfo {
name: string
fileSize: number
dateModify: number
}
export default class IosLicenseController {
/* ================= HELPER ================= */
private getBinFiles(dir: string): FileInfo[] {
if (!fs.existsSync(dir)) return []
return fs
.readdirSync(dir)
.filter((file) => file.toLowerCase().endsWith('.bin'))
.map((file) => {
const fullPath = path.join(dir, file)
const stat = fs.statSync(fullPath)
return {
name: file,
fileSize: stat.size,
dateModify: stat.mtime.getTime(),
}
})
.sort((a, b) => b.dateModify - a.dateModify)
}
private getLicFiles(dir: string): FileInfo[] {
if (!fs.existsSync(dir)) return []
return fs
.readdirSync(dir)
.filter((file) => file.toLowerCase().endsWith('.lic'))
.map((file) => {
const fullPath = path.join(dir, file)
const stat = fs.statSync(fullPath)
return {
name: file,
fileSize: stat.size,
dateModify: stat.mtime.getTime(),
}
})
.sort((a, b) => b.dateModify - a.dateModify)
}
/* ================= IOS ================= */
async getIos() {
const smbPath = '/ipsteamSMB/IOS/i'
const localPath = 'storage/i'
const targetPath = fs.existsSync(smbPath) ? smbPath : localPath
return this.getBinFiles(targetPath)
}
/* ================= LICENSE ================= */
async getLicense() {
const smbPath = '/ipsteamSMB/IOS/License'
const localPath = 'storage/License'
const targetPath = fs.existsSync(smbPath) ? smbPath : localPath
return this.getLicFiles(targetPath)
}
}