models.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. remark = "";
  27. enable = true;
  28. expiryTime = 0;
  29. listen = "";
  30. port = 0;
  31. protocol = "";
  32. settings = "";
  33. streamSettings = "";
  34. tag = "";
  35. sniffing = "";
  36. constructor(data) {
  37. if (data == null) {
  38. return;
  39. }
  40. ObjectUtil.cloneProps(this, data);
  41. }
  42. toInbound() {
  43. let settings = {};
  44. if (!ObjectUtil.isEmpty(this.settings)) {
  45. settings = JSON.parse(this.settings);
  46. }
  47. let streamSettings = {};
  48. if (!ObjectUtil.isEmpty(this.streamSettings)) {
  49. streamSettings = JSON.parse(this.streamSettings);
  50. }
  51. let sniffing = {};
  52. if (!ObjectUtil.isEmpty(this.sniffing)) {
  53. sniffing = JSON.parse(this.sniffing);
  54. }
  55. const config = {
  56. port: this.port,
  57. listen: this.listen,
  58. protocol: this.protocol,
  59. settings: settings,
  60. streamSettings: streamSettings,
  61. tag: this.tag,
  62. sniffing: sniffing,
  63. };
  64. return Inbound.fromJson(config);
  65. }
  66. hasLink() {
  67. switch (this.protocol) {
  68. case Protocols.VMESS:
  69. case Protocols.VLESS:
  70. case Protocols.TROJAN:
  71. case Protocols.SHADOWSOCKS:
  72. return true;
  73. default:
  74. return false;
  75. }
  76. }
  77. genLink(address="") {
  78. const inbound = this.toInbound();
  79. return inbound.genLink(address, this.remark);
  80. }
  81. }
  82. class AllSetting {
  83. webListen = "";
  84. webPort = 65432;
  85. webCertFile = "";
  86. webKeyFile = "";
  87. webBasePath = "/";
  88. xrayTemplateConfig = "";
  89. timeLocation = "Asia/Shanghai";
  90. constructor(data) {
  91. if (data == null) {
  92. return
  93. }
  94. ObjectUtil.cloneProps(this, data);
  95. }
  96. equals(other) {
  97. return ObjectUtil.equals(this, other);
  98. }
  99. }