Skip to content

Commit

Permalink
add text_traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
wang.wangqiang committed Apr 26, 2024
1 parent 4405e89 commit fe66cef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cli_creator/text/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
from .import views

urlpatterns = [
path('duplicates',views.duplicates, name='duplicates'),
path('duplicates',views.duplicates, name='duplicates'),
path('traversal',views.traversal, name='traversal'),
]
25 changes: 25 additions & 0 deletions cli_creator/text/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,29 @@ def duplicates(request):

else:
return Response({'message': 'Only POST requests are allowed'}, status=400)

@api_view(['GET', 'POST'])
def traversal(request):
if request.method == 'POST':
data = request.data # 获取 JSON 格式的数据
text = data.get('text')
str = data.get('str')
result = ''
for line in text.splitlines():
for i in str.splitlines():
replaced_line = line.replace('$', i)
result += replaced_line + '\n'

data = {
'result': 'Success',
'message': result
}
current_date = datetime.now().strftime("%Y-%m-%d")
log_info = "text_traversal"
save_cli_logs(ip_address="127.0.0.1", time=current_date, info=log_info)
return Response(data)


else:
return Response({'message': 'Only POST requests are allowed'}, status=400)

0 comments on commit fe66cef

Please sign in to comment.