-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (48 loc) · 1.64 KB
/
Copy pathProgram.cs
File metadata and controls
59 lines (48 loc) · 1.64 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
using a2g.TelegramStickerViewer;
using a2g.TelegramStickerViewer.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMemoryCache();
builder.Services.AddSingleton<TelegramClientFactory>();
builder.Services.AddSingleton<StickerSetService>();
var app = builder.Build();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapGet("/api/health", () => Results.Ok(new { ok = true }));
app.MapPost("/api/telegram/login", async (
TelegramClientFactory factory,
CancellationToken ct) =>
{
var user = await factory.LoginIfNeededAsync(ct);
return Results.Ok(new
{
id = user.id,
username = user.username,
firstName = user.first_name,
lastName = user.last_name
});
});
app.MapGet("/api/sticker-sets/{shortName}", async (
string shortName,
StickerSetService stickerService,
CancellationToken ct) =>
{
if (string.IsNullOrWhiteSpace(shortName))
return Results.BadRequest(new { error = "Sticker set short name is required." });
var result = await stickerService.GetStickerSetAsync(shortName, ct);
return result is null
? Results.NotFound(new { error = "Sticker set not found." })
: Results.Ok(result);
});
app.MapGet("/api/stickers/file/{fileId}", async (
string fileId,
StickerSetService stickerService,
HttpContext httpContext,
CancellationToken ct) =>
{
var file = await stickerService.GetFileStreamAsync(fileId, ct);
if (file is null)
return Results.NotFound();
httpContext.Response.Headers.CacheControl = "public,max-age=3600";
return Results.Stream(file.Stream, file.ContentType, file.FileName);
});
app.Run();