models.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. export namespace main {
  2. export class AttachLink {
  3. title: string;
  4. href: string;
  5. static createFrom(source: any = {}) {
  6. return new AttachLink(source);
  7. }
  8. constructor(source: any = {}) {
  9. if ('string' === typeof source) source = JSON.parse(source);
  10. this.title = source["title"];
  11. this.href = source["href"];
  12. }
  13. }
  14. export class ResultItem {
  15. no: number;
  16. href: string;
  17. listTitle: string;
  18. listPubishTime: string;
  19. title: string;
  20. publishUnit: string;
  21. publishTime: string;
  22. content: string;
  23. contentHtml: string;
  24. attachLinks: AttachLink[];
  25. attachJson: string;
  26. static createFrom(source: any = {}) {
  27. return new ResultItem(source);
  28. }
  29. constructor(source: any = {}) {
  30. if ('string' === typeof source) source = JSON.parse(source);
  31. this.no = source["no"];
  32. this.href = source["href"];
  33. this.listTitle = source["listTitle"];
  34. this.listPubishTime = source["listPubishTime"];
  35. this.title = source["title"];
  36. this.publishUnit = source["publishUnit"];
  37. this.publishTime = source["publishTime"];
  38. this.content = source["content"];
  39. this.contentHtml = source["contentHtml"];
  40. this.attachLinks = this.convertValues(source["attachLinks"], AttachLink);
  41. this.attachJson = source["attachJson"];
  42. }
  43. convertValues(a: any, classs: any, asMap: boolean = false): any {
  44. if (!a) {
  45. return a;
  46. }
  47. if (a.slice && a.map) {
  48. return (a as any[]).map(elem => this.convertValues(elem, classs));
  49. } else if ("object" === typeof a) {
  50. if (asMap) {
  51. for (const key of Object.keys(a)) {
  52. a[key] = new classs(a[key]);
  53. }
  54. return a;
  55. }
  56. return new classs(a);
  57. }
  58. return a;
  59. }
  60. }
  61. export class SpiderConfig {
  62. site: string;
  63. channel: string;
  64. author: string;
  65. url: string;
  66. code: string;
  67. listItemCss: string;
  68. listLinkCss: string;
  69. listPublishTimeCss: string;
  70. listNextPageCss: string;
  71. titleCss: string;
  72. publishUnitCss: string;
  73. publishTimeCss: string;
  74. contentCss: string;
  75. attachCss: string;
  76. listJs: string;
  77. contentJs: string;
  78. attachJs: string;
  79. static createFrom(source: any = {}) {
  80. return new SpiderConfig(source);
  81. }
  82. constructor(source: any = {}) {
  83. if ('string' === typeof source) source = JSON.parse(source);
  84. this.site = source["site"];
  85. this.channel = source["channel"];
  86. this.author = source["author"];
  87. this.url = source["url"];
  88. this.code = source["code"];
  89. this.listItemCss = source["listItemCss"];
  90. this.listLinkCss = source["listLinkCss"];
  91. this.listPublishTimeCss = source["listPublishTimeCss"];
  92. this.listNextPageCss = source["listNextPageCss"];
  93. this.titleCss = source["titleCss"];
  94. this.publishUnitCss = source["publishUnitCss"];
  95. this.publishTimeCss = source["publishTimeCss"];
  96. this.contentCss = source["contentCss"];
  97. this.attachCss = source["attachCss"];
  98. this.listJs = source["listJs"];
  99. this.contentJs = source["contentJs"];
  100. this.attachJs = source["attachJs"];
  101. }
  102. }
  103. }