File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ namespace devanewbot . Api . v0 . Controllers ;
2
+
3
+ using System . IO ;
4
+ using System . IO . Compression ;
5
+ using System . Linq ;
6
+ using System . Net . Http ;
7
+ using System . Net . Mime ;
8
+ using System . Threading . Tasks ;
9
+ using Microsoft . AspNetCore . Mvc ;
10
+ using SlackNet ;
11
+
12
+ [ Route ( "/api/v0/emoji" ) ]
13
+ public class EmojiController : Controller
14
+ {
15
+ protected ISlackApiClient Client { get ; }
16
+
17
+ protected IHttpClientFactory HttpClientFactory { get ; }
18
+
19
+
20
+ public EmojiController ( ISlackApiClient client , IHttpClientFactory httpClientFactory )
21
+ {
22
+ Client = client ;
23
+ HttpClientFactory = httpClientFactory ;
24
+ }
25
+
26
+ [ HttpGet ( "export" ) ]
27
+ public async Task < IActionResult > Export ( )
28
+ {
29
+ var emojis = await Client . Emoji . List ( ) ;
30
+ using var memoryStream = new MemoryStream ( ) ;
31
+ using var archive = new ZipArchive ( memoryStream ) ;
32
+ using var httpClient = HttpClientFactory . CreateClient ( ) ;
33
+ foreach ( var emoji in emojis . Where ( e => ! e . Value . StartsWith ( "alias:" ) ) )
34
+ {
35
+ var response = await httpClient . GetStreamAsync ( emoji . Value ) ;
36
+ var entry = archive . CreateEntry ( $ "{ emoji . Key } .png") ;
37
+ var entryStream = entry . Open ( ) ;
38
+ await response . CopyToAsync ( entryStream ) ;
39
+ }
40
+
41
+ return File ( memoryStream , "application/zip" , "emoji.zip" ) ;
42
+ }
43
+ }
Original file line number Diff line number Diff line change 33
33
var configuration = builder . Configuration ;
34
34
35
35
builder . Services
36
+ . AddHttpClient ( )
36
37
. AddSingleton < Slack > ( )
37
38
. AddSingleton < Client > ( )
38
39
. AddTransient < InviteService > ( )
You can’t perform that action at this time.
0 commit comments