54 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
		
		
			
		
	
	
			54 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
|   | import json | ||
|  | import os | ||
|  | from logging import getLogger | ||
|  | 
 | ||
|  | import requests | ||
|  | from flask import request, send_file | ||
|  | from nc_http.core import Response | ||
|  | from nc_http.core.request.func import get_client_ip, get_request_json | ||
|  | 
 | ||
|  | import config | ||
|  | from api.blueprint import root | ||
|  | from commons import meta | ||
|  | from tasks import once | ||
|  | 
 | ||
|  | LOGGER = getLogger('root') | ||
|  | 
 | ||
|  | 
 | ||
|  | @root.route('') | ||
|  | def root_check(): | ||
|  |     # 测试服务是否启动 | ||
|  |     return 'ok' | ||
|  | 
 | ||
|  | 
 | ||
|  | @root.route('/ip') | ||
|  | def get_ip(): | ||
|  |     # 获取客户端 ip | ||
|  |     ip = get_client_ip(request) | ||
|  |     return Response(ip) | ||
|  | 
 | ||
|  | 
 | ||
|  | @root.route('/debug/c', methods=['POST']) | ||
|  | def test_es(): | ||
|  |     data = get_request_json() | ||
|  |     url = "{}/one-map-data/_search".format(config.ES_HOSTS) | ||
|  |     headers = {'Content-Type': 'application/json'} | ||
|  |     result = requests.post(url, json.dumps(data), headers=headers) | ||
|  |     return Response(json.loads(result.content)) | ||
|  | 
 | ||
|  | 
 | ||
|  | @root.route('/debug/run_once/<string:task_name>', methods=['GET']) | ||
|  | def run_once_task(task_name): | ||
|  |     if not config.DEBUG: | ||
|  |         raise meta.NO_CONTENT | ||
|  | 
 | ||
|  |     task = getattr(once, task_name) | ||
|  | 
 | ||
|  |     return Response(task()) | ||
|  | 
 | ||
|  | 
 | ||
|  | @root.route('/logs', methods=['GET']) | ||
|  | def download_log_file(): | ||
|  |     log_file = os.path.join(config.LOG_DIR, 'app.log') | ||
|  |     return send_file(log_file, as_attachment=True, download_name='geological-map-api.log', mimetype='text/plain') |