FileResponse.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Net;
  2. using System.Text.Json;
  3. using System.Text.Json.Serialization;
  4. namespace NexusMods.Responses {
  5. /*
  6. {
  7. "category_id": 7,
  8. "category_name": "ARCHIVED",
  9. "changelog_html": "Added: Infinite Logs toggle",
  10. "content_preview_link": "https://file-metadata.nexusmods.com/file/nexus-files-s3-meta/5165/46/SOTFModMenu-v2.0.0-46-2-0-0-1679156402.rar.json",
  11. "description": "",
  12. "external_virus_scan_url": "https://www.virustotal.com/gui/file/982036f24b1d3eaf05bf59607a779378fdd1677d0b69029d0f5f50602bee2518/detection/f-982036f24b1d3eaf05bf59607a779378fdd1677d0b69029d0f5f50602bee2518-1679156408",
  13. "file_id": 117,
  14. "file_name": "SOTFModMenu-v2.0.0-46-2-0-0-1679156402.rar",
  15. "id": [
  16. 117,
  17. 5165
  18. ],
  19. "is_primary": false,
  20. "mod_version": "2.0.0",
  21. "name": "SOTFModMenu-v2.0.0",
  22. "size": 246,
  23. "size_in_bytes": 252382,
  24. "size_kb": 246,
  25. "uid": 22183506083957,
  26. "uploaded_time": "2023-03-18T16:20:02.000+00:00",
  27. "uploaded_timestamp": 1679156402,
  28. "version": "2.0.0"
  29. }
  30. */
  31. public class FileResponse {
  32. public int category_id { get; set; }
  33. public string category_name { get; set; }
  34. public string changelog_html { get; set; }
  35. public Uri? content_preview_link { get; set; }
  36. private Preview _prev;
  37. public Preview content_preview {
  38. get {
  39. if (this.content_preview == null && this.content_preview_link != null) {
  40. WebRequest? webRequest = null;
  41. WebResponse? response = null;
  42. try {
  43. webRequest = WebRequest.Create(this.content_preview_link);
  44. webRequest.Method = "GET";
  45. using (response = webRequest.GetResponse()) {
  46. response.Close();
  47. }
  48. } finally {
  49. response?.Dispose();
  50. }
  51. webRequest = null;
  52. response = null;
  53. StreamReader? streamReader = null;
  54. string? responseData;
  55. try {
  56. using (streamReader = new StreamReader(response.GetResponseStream())) {
  57. responseData = streamReader.ReadToEnd();
  58. streamReader.Close();
  59. }
  60. } finally {
  61. streamReader?.Dispose();
  62. }
  63. streamReader = null;
  64. this._prev = JsonSerializer.Deserialize<Preview>(responseData);
  65. }
  66. return this._prev;
  67. }
  68. }
  69. public string description { get; set; }
  70. public Uri external_virus_scan_url { get; set; }
  71. public int file_id { get; set; }
  72. public string file_name { get; set; }
  73. public int[] id { get; set; }
  74. public bool is_primary { get; set; }
  75. public Version mod_version { get; set; }
  76. public string name { get; set; }
  77. public long size { get; set; }
  78. public long size_in_bytes { get; set; }
  79. public long size_kb { get; set; }
  80. public long uid { get; set; }
  81. public DateTime uploaded_time { get; set; }
  82. public int uploaded_timestamp { get; set; }
  83. public Version version { get; set; }
  84. }
  85. }