1
1
import 'package:discord_api/src/models/discord_image_format.dart' ;
2
2
3
3
class DiscordCdnHelper {
4
+ static final instance = DiscordCdnHelper ._();
5
+ DiscordCdnHelper ._();
6
+
4
7
static final cndUrl = Uri (scheme: "https" , host: "cdn.discordapp.com" );
5
8
6
9
/// Available formats : PNG, JPEG, WebP, GIF
7
- static final formatList1 = [
10
+ static const formatList1 = [
8
11
DiscordImageFormat .png,
9
12
DiscordImageFormat .jpeg,
10
13
DiscordImageFormat .webp,
11
14
DiscordImageFormat .gif,
12
15
];
13
16
14
17
/// Available formats : PNG, JPEG, WebP
15
- static final formatList2 = [
18
+ static const formatList2 = [
16
19
DiscordImageFormat .png,
17
20
DiscordImageFormat .jpeg,
18
21
DiscordImageFormat .webp,
19
22
];
20
23
21
24
/// Available formats : PNG, Lottie
22
- static final formatList3 = [
25
+ static const formatList3 = [
23
26
DiscordImageFormat .png,
24
27
DiscordImageFormat .lottie,
25
28
];
@@ -28,6 +31,8 @@ class DiscordCdnHelper {
28
31
///
29
32
/// The size is only valid if it's a power of 2,
30
33
/// between 16 and 4096.
34
+ ///
35
+ /// **NOTE**: Apparently, 160 also is a valid size, even though it doesn't meet the requirements.
31
36
bool isValidSize (int x) {
32
37
return (x >= 16 ) && (x <= 4096 ) && ((x & (x - 1 )) == 0 );
33
38
}
@@ -40,7 +45,7 @@ class DiscordCdnHelper {
40
45
/// Returns the CDN URL for a given path, as an URI.
41
46
///
42
47
/// Probably shouldn't be used, as specialized functions exists.
43
- Uri getUrl (String path) => cndUrl.replace (pathSegments : path. split ( '/' ) );
48
+ Uri getUrl (String path) => cndUrl.resolve ( path);
44
49
45
50
/// Tries to create the right URL slug for an emoji, given its emoji_id, in a given format
46
51
/// (defaults to PNG), with a given size (defaults to 128).
0 commit comments