82 lines
1.8 KiB
TypeScript
82 lines
1.8 KiB
TypeScript
import type { HttpContext } from '@adonisjs/core/http'
|
|
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
export default class IosLicenseController {
|
|
/* ================= LIST ================= */
|
|
|
|
async getIos() {
|
|
return fs.readdirSync('storage/ios')
|
|
}
|
|
|
|
async getLicense() {
|
|
return fs.readdirSync('storage/license')
|
|
}
|
|
|
|
/* ================= UPLOAD ================= */
|
|
|
|
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)
|
|
}
|
|
}
|