-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
110 lines (82 loc) · 2.82 KB
/
Copy pathProgram.cs
File metadata and controls
110 lines (82 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using FotoPrint.Services;
using System.IO.Compression;
using Microsoft.Extensions.Logging;
var builder = WebApplication.CreateBuilder(args);
/* =========================
* LOGGING CONFIGURATION
* ========================= */
// Remove logs padrão (Debug, EventLog, etc.)
builder.Logging.ClearProviders();
// Adiciona log no console (ideal para executável local)
builder.Logging.AddConsole();
// Define nível mínimo de log
builder.Logging.SetMinimumLevel(LogLevel.Information);
/* =========================
* SERVICES
* ========================= */
builder.Services.AddRazorPages();
builder.Services.AddSingleton<ConfigService>();
builder.Services.AddSingleton<FileService>();
builder.Services.AddSingleton<PrintSchedulerService>();
builder.Services.AddSingleton<AdminConfigService>();
builder.Services.AddServerSideBlazor()
.AddHubOptions(options =>
{
options.ClientTimeoutInterval = TimeSpan.FromSeconds(120);
options.HandshakeTimeout = TimeSpan.FromSeconds(30);
options.KeepAliveInterval = TimeSpan.FromSeconds(15);
options.MaximumReceiveMessageSize = 10 * 1024 * 1024;
});
/* =========================
* HOST CONFIG
* ========================= */
// Ouvir em todas interfaces na porta 5000
builder.WebHost.UseUrls("http://0.0.0.0:5000");
var app = builder.Build();
/* =========================
* PIPELINE
* ========================= */
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
// Log de startup
var logger = app.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("FotoPrint iniciado com sucesso.");
app.UseStaticFiles();
app.UseRouting();
/* =========================
* ENDPOINTS
* ========================= */
// Endpoint para baixar ZIP do Backup
app.MapGet("/download-zip", (IWebHostEnvironment env, ILogger<Program> log) =>
{
try
{
log.LogInformation("Solicitação de download de backup.");
var backupDir = Path.Combine(env.WebRootPath, "Backup");
if (!Directory.Exists(backupDir))
{
log.LogWarning("Diretório de backup não encontrado.");
return Results.NotFound();
}
var tempZip = Path.Combine(
Path.GetTempPath(),
$"backup_{DateTime.UtcNow:yyyyMMdd_HHmmss}.zip");
if (File.Exists(tempZip))
File.Delete(tempZip);
ZipFile.CreateFromDirectory(backupDir, tempZip);
var bytes = File.ReadAllBytes(tempZip);
File.Delete(tempZip);
log.LogInformation("Backup ZIP gerado com sucesso.");
return Results.File(bytes, "application/zip", "backup_fotos.zip");
}
catch (Exception ex)
{
log.LogError(ex, "Erro ao gerar ZIP de backup.");
return Results.Problem("Erro ao gerar backup.");
}
});
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();