-
Notifications
You must be signed in to change notification settings - Fork 7
/
NFTDataItem.cs
158 lines (155 loc) · 5.13 KB
/
NFTDataItem.cs
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
namespace VEDriversLite.NFT.Dto
{
/// <summary>
/// Type of the content
/// </summary>
public enum DataItemType
{
/// <summary>
/// Image file, file .bmp, .jpg, .jpeg, .gif, .png, jfif
/// </summary>
Image,
/// <summary>
/// Audio or Video file, file .wav, .ogg, .mp3, .mp4, .avi, .mov
/// </summary>
AVMedia,
/// <summary>
/// PDF file, file .pdf
/// </summary>
PDF,
/// <summary>
/// Simple text, file .txt
/// </summary>
Text,
/// <summary>
/// Text file with Markdown formating, file .md
/// </summary>
Markdown,
/// <summary>
/// Mermaid graph, file .mmd
/// </summary>
Mermaid,
/// <summary>
/// HTML file, file .html
/// </summary>
HTML,
/// <summary>
/// Json file, file .json
/// </summary>
JSON,
/// <summary>
/// 3d model in STL, file .stl
/// </summary>
Model3dSTL,
/// <summary>
/// Another NFT
/// </summary>
NFT,
/// <summary>
/// Blazor WASM App
/// </summary>
BlazorApp = 5000,
/// <summary>
/// Standard HTML + JS app
/// </summary>
HTMLApp = 5001
}
/// <summary>
/// Type of the storage where the data are stored. Usually it is IPFS.
/// </summary>
public enum DataItemStorageType
{
/// <summary>
/// IPFS storage
/// </summary>
IPFS,
/// <summary>
/// Common url
/// </summary>
Url,
/// <summary>
/// Local storage
/// </summary>
Local,
/// <summary>
/// Neblio blockchain NTP1
/// </summary>
NeblioNTP1
}
/// <summary>
/// Item in the NFT gallery. It is usually some image with tags
/// </summary>
public class NFTDataItem
{
/// <summary>
/// Type of the item
/// </summary>
public DataItemType Type { get; set; } = DataItemType.Image;
/// <summary>
/// Hash of the transaction
/// </summary>
public string Hash { get; set; } = string.Empty;
/// <summary>
/// Type of the storage where the data are stored. Usually it is IPFS.
/// </summary>
public DataItemStorageType Storage { get; set; } = DataItemStorageType.IPFS;
/// <summary>
/// Parsed tags from the TagsList
/// </summary>
public List<string> TagsList { get; set; } = new List<string>();
/// <summary>
/// Loaded data as byte array
/// </summary>
[JsonIgnore]
public byte[] Data { get; set; } = new byte[0];
/// <summary>
/// Loaded data as Base64 string
/// </summary>
[JsonIgnore]
public string Base64Data { get; set; } = string.Empty;
/// <summary>
/// Display flag for UI
/// </summary>
public bool IsMain { get; set; } = false;
public static DataItemType GetItemType(string filename)
{
var type = DataItemType.Image;
if (!string.IsNullOrEmpty(filename))
{
if (filename.ToLower().Contains(".bmp") ||
filename.ToLower().Contains(".jpg") ||
filename.ToLower().Contains(".jpeg") ||
filename.ToLower().Contains(".png") ||
filename.ToLower().Contains(".gif") ||
filename.ToLower().Contains(".jfif"))
type = DataItemType.Image;
else if (filename.ToLower().Contains(".mp3") ||
filename.ToLower().Contains(".wav") ||
filename.ToLower().Contains(".ogg") ||
filename.ToLower().Contains(".mp4") ||
filename.ToLower().Contains(".avi") ||
filename.ToLower().Contains(".mov"))
type = DataItemType.AVMedia;
else if (filename.ToLower().Contains(".pdf"))
type = DataItemType.PDF;
else if (filename.ToLower().Contains(".stl"))
type = DataItemType.Model3dSTL;
else if (filename.ToLower().Contains(".md"))
type = DataItemType.Markdown;
else if (filename.ToLower().Contains(".mmd"))
type = DataItemType.Mermaid;
else if (filename.ToLower().Contains(".html"))
type = DataItemType.HTML;
else if (filename.ToLower().Contains(".txt"))
type = DataItemType.Text;
else if (filename.ToLower().Contains(".json"))
type = DataItemType.JSON;
}
return type;
}
}
}