Skip to content

Commit

Permalink
feat: Add fake_node method to ProxyNode model
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Aug 19, 2024
1 parent c1fed29 commit 4ea6791
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def get_user_and_nodes(self, request):
node_list = node_list.filter(country=location)

if node_list.count() == 0:
return None, HttpResponseBadRequest("no active nodes for you")

return user, [m.ProxyNode.fake_node("当前没有可用节点")]
return user, node_list


Expand Down
8 changes: 8 additions & 0 deletions apps/proxy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ def have_oc_users(self) -> bool:
occupancies_query = UserProxyNodeOccupancy.get_node_occupancies(self)
return occupancies_query.count() > 0

@classmethod
def fake_node(cls, name):
node = cls(name=name, node_type=cls.NODE_TYPE_SS, server="0.0.0.0")
SSConfig(method="aes-256-gcm", proxy_node=node)
# here is the magic, set cached_property to False
node.enable_relay = False
return node

def get_node_users(self):
# 1. if node is not enable, return empty list
if not self.enable:
Expand Down

0 comments on commit 4ea6791

Please sign in to comment.