models.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. class User {
  2. username = "";
  3. password = "";
  4. }
  5. class Msg {
  6. success = false;
  7. msg = "";
  8. obj = null;
  9. constructor(success, msg, obj) {
  10. if (success != null) {
  11. this.success = success;
  12. }
  13. if (msg != null) {
  14. this.msg = msg;
  15. }
  16. if (obj != null) {
  17. this.obj = obj;
  18. }
  19. }
  20. }
  21. class DBInbound {
  22. id = 0;
  23. userId = 0;
  24. up = 0;
  25. down = 0;
  26. total = 0;
  27. remark = "";
  28. enable = true;
  29. expiryTime = 0;
  30. listen = "";
  31. port = 0;
  32. protocol = "";
  33. settings = "";
  34. streamSettings = "";
  35. tag = "";
  36. sniffing = "";
  37. constructor(data) {
  38. if (data == null) {
  39. return;
  40. }
  41. ObjectUtil.cloneProps(this, data);
  42. }
  43. get totalGB() {
  44. return toFixed(this.total / ONE_GB, 2);
  45. }
  46. set totalGB(gb) {
  47. this.total = toFixed(gb * ONE_GB, 0);
  48. }
  49. toInbound() {
  50. let settings = {};
  51. if (!ObjectUtil.isEmpty(this.settings)) {
  52. settings = JSON.parse(this.settings);
  53. }
  54. let streamSettings = {};
  55. if (!ObjectUtil.isEmpty(this.streamSettings)) {
  56. streamSettings = JSON.parse(this.streamSettings);
  57. }
  58. let sniffing = {};
  59. if (!ObjectUtil.isEmpty(this.sniffing)) {
  60. sniffing = JSON.parse(this.sniffing);
  61. }
  62. const config = {
  63. port: this.port,
  64. listen: this.listen,
  65. protocol: this.protocol,
  66. settings: settings,
  67. streamSettings: streamSettings,
  68. tag: this.tag,
  69. sniffing: sniffing,
  70. };
  71. return Inbound.fromJson(config);
  72. }
  73. hasLink() {
  74. switch (this.protocol) {
  75. case Protocols.VMESS:
  76. case Protocols.VLESS:
  77. case Protocols.TROJAN:
  78. case Protocols.SHADOWSOCKS:
  79. return true;
  80. default:
  81. return false;
  82. }
  83. }
  84. genLink(address = "") {
  85. const inbound = this.toInbound();
  86. return inbound.genLink(address, this.remark);
  87. }
  88. }
  89. class AllSetting {
  90. webListen = "";
  91. webPort = 54321;
  92. webCertFile = "";
  93. webKeyFile = "";
  94. webBasePath = "/";
  95. xrayTemplateConfig = "";
  96. timeLocation = "Asia/Shanghai";
  97. constructor(data) {
  98. if (data == null) {
  99. return
  100. }
  101. ObjectUtil.cloneProps(this, data);
  102. }
  103. equals(other) {
  104. return ObjectUtil.equals(this, other);
  105. }
  106. }