feat: Add api endpoint
All checks were successful
Build Docker / Build Image (push) Successful in 20s
All checks were successful
Build Docker / Build Image (push) Successful in 20s
This commit is contained in:
parent
5e6af2bcc8
commit
30c723cebb
@ -22,4 +22,5 @@ docker run -d \
|
||||
| max_price | Maximum price to pay for a domain (in HNS) | 5 |
|
||||
| max_gifts_per_interval | Maximum number of gifts to send per interval | 24 |
|
||||
| interval | Interval to send gifts (in seconds) | 86400 (24 hours) |
|
||||
| discord_webhook | Discord webhook to send notifications to | None |
|
||||
| discord_webhook | Discord webhook to send notifications to | None |
|
||||
| api_key | API key for api gifts | None |
|
34
main.py
34
main.py
@ -75,6 +75,40 @@ def submit():
|
||||
else:
|
||||
return render_template('error.html',error=status,address=address)
|
||||
|
||||
@app.route('/api', methods=['POST'])
|
||||
def api():
|
||||
# Get from params
|
||||
params = request.args
|
||||
name = params['name']
|
||||
email = params['email']
|
||||
key = params['key']
|
||||
|
||||
if key != os.getenv('api_key'):
|
||||
return jsonify({'error': 'Invalid API key', 'success': False})
|
||||
|
||||
if 'X-REAL-IP' in request.headers:
|
||||
ip = request.headers['X-REAL-IP']
|
||||
|
||||
if 'X-Real-Ip' in request.headers:
|
||||
ip = request.headers['X-Real-Ip']
|
||||
|
||||
# Validate email
|
||||
try:
|
||||
emailinfo = validate_email(email, check_deliverability=False)
|
||||
email = emailinfo.normalized
|
||||
except EmailNotValidError as e:
|
||||
return jsonify({'error': 'Invalid email address', 'success': False})
|
||||
|
||||
|
||||
status = gift.gift(name, email, "api", ip)
|
||||
print(status,flush=True)
|
||||
|
||||
if status == True:
|
||||
return jsonify({'success': True})
|
||||
else:
|
||||
return jsonify({'error': status, 'success': False})
|
||||
|
||||
|
||||
# Special routes
|
||||
@app.route('/.well-known/wallets/<token>')
|
||||
def send_wallet(token):
|
||||
|
Loading…
Reference in New Issue
Block a user