FEAT: Adiciona botão de download para o modelo do CSV.

This commit is contained in:
tulioperdigao 2025-10-24 17:56:38 -03:00
parent 9355527b66
commit f8874b33b9
5 changed files with 26 additions and 1 deletions

9
app.js
View File

@ -422,7 +422,14 @@ app.get("/", (req, res) => {
return res.json({ jobId });
});
// download endpoint
// download model endpoint
app.get("/download-model", (req, res) => {
const modelPath = path.join(__dirname, "models", "modelo.viabilidade.csv");
if (!fs.existsSync(modelPath)) return res.status(404).send("Modelo não encontrado");
return res.download(modelPath, "modelo.viabilidade.csv");
});
// download result endpoint
app.get("/download/:name", (req, res) => {
const name = req.params.name;
const p = path.join(__dirname, "outputs", name);

View File

@ -0,0 +1 @@
CEP;Numero
1 CEP Numero

View File

@ -44,6 +44,7 @@
<input class="form-control" type="file" id="csvfile" accept=".csv" required />
</div>
<button class="btn btn-primary" type="submit">Enviar CSV</button>
<button type="button" class="btn btn-primary" id="card__button-download">Baixar Modelo</button>
</form>
<div id="uploadResult" class="mt-3"></div>
<div class="progress mt-2" style="height:24px; display:none;" id="progressWrap">

View File

@ -67,3 +67,12 @@ document.getElementById('btnConsultaCep').addEventListener('click', async () =>
el.innerText = 'Erro na consulta';
}
});
// baixar modelo
const modelBtn = document.getElementById('card__button-download');
if (modelBtn) {
modelBtn.addEventListener('click', (e) => {
// inicia download do endpoint que serve o modelo
window.location.href = '/download-model';
});
}

View File

@ -37,6 +37,13 @@ button:hover {
background-color: #298897 !important;
}
#card__button-download {
background-color: transparent !important;
border: 1px solid #31a3b5 !important;
color: #31a3b5 !important;
margin-left: 10px;
}
.progress-bar {
background-color: #31a3b5 !important;
}