Compare commits
7 Commits
feat/termi
...
e184375897
| Author | SHA1 | Date | |
|---|---|---|---|
|
e184375897
|
|||
|
844f1b52e2
|
|||
|
19c51c3665
|
|||
|
85ebd460ed
|
|||
|
50879b4f0e
|
|||
|
6c09923281
|
|||
|
332c408b89
|
@@ -40,7 +40,6 @@ def help():
|
|||||||
"/time": "Get the current time",
|
"/time": "Get the current time",
|
||||||
"/timezone": "Get the current timezone",
|
"/timezone": "Get the current timezone",
|
||||||
"/message": "Get the message from the config",
|
"/message": "Get the message from the config",
|
||||||
"/ip": "Get your IP address",
|
|
||||||
"/project": "Get the current project from git",
|
"/project": "Get the current project from git",
|
||||||
"/version": "Get the current version of the website",
|
"/version": "Get the current version of the website",
|
||||||
"/page_date?url=URL&verbose=BOOL": "Get the last modified date of a webpage (verbose is optional, default false)",
|
"/page_date?url=URL&verbose=BOOL": "Get the last modified date of a webpage (verbose is optional, default false)",
|
||||||
@@ -48,6 +47,8 @@ def help():
|
|||||||
"/playing": "Get the currently playing Spotify track",
|
"/playing": "Get the currently playing Spotify track",
|
||||||
"/status": "Just check if the site is up",
|
"/status": "Just check if the site is up",
|
||||||
"/ping": "Just check if the site is up",
|
"/ping": "Just check if the site is up",
|
||||||
|
"/ip": "Get your IP address",
|
||||||
|
"/headers": "Get your request headers",
|
||||||
"/help": "Get this help message"
|
"/help": "Get this help message"
|
||||||
},
|
},
|
||||||
"base_url": "/api/v1",
|
"base_url": "/api/v1",
|
||||||
@@ -191,6 +192,17 @@ def playing():
|
|||||||
return json_response(request, track_info, HTTP_OK)
|
return json_response(request, track_info, HTTP_OK)
|
||||||
return json_response(request, {"spotify": track_info}, HTTP_OK)
|
return json_response(request, {"spotify": track_info}, HTTP_OK)
|
||||||
|
|
||||||
|
|
||||||
|
@api_bp.route("/headers")
|
||||||
|
def headers():
|
||||||
|
"""Get the request headers."""
|
||||||
|
headers = dict(request.headers)
|
||||||
|
return jsonify({
|
||||||
|
"headers": headers,
|
||||||
|
"ip": getClientIP(request),
|
||||||
|
"status": HTTP_OK
|
||||||
|
})
|
||||||
|
|
||||||
@api_bp.route("/page_date")
|
@api_bp.route("/page_date")
|
||||||
def page_date():
|
def page_date():
|
||||||
url = request.args.get("url")
|
url = request.args.get("url")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from flask import Blueprint, render_template, request, jsonify
|
|||||||
import markdown
|
import markdown
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import re
|
import re
|
||||||
from tools import isCurl, getClientIP, getHandshakeScript
|
from tools import isCLI, getClientIP, getHandshakeScript
|
||||||
|
|
||||||
blog_bp = Blueprint('blog', __name__)
|
blog_bp = Blueprint('blog', __name__)
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ def render_home(handshake_scripts: str | None = None):
|
|||||||
|
|
||||||
@blog_bp.route("/")
|
@blog_bp.route("/")
|
||||||
def index():
|
def index():
|
||||||
if not isCurl(request):
|
if not isCLI(request):
|
||||||
return render_home(handshake_scripts=getHandshakeScript(request.host))
|
return render_home(handshake_scripts=getHandshakeScript(request.host))
|
||||||
|
|
||||||
# Get a list of pages
|
# Get a list of pages
|
||||||
@@ -131,7 +131,7 @@ def index():
|
|||||||
|
|
||||||
@blog_bp.route("/<path:path>")
|
@blog_bp.route("/<path:path>")
|
||||||
def path(path):
|
def path(path):
|
||||||
if not isCurl(request):
|
if not isCLI(request):
|
||||||
return render_page(path, handshake_scripts=getHandshakeScript(request.host))
|
return render_page(path, handshake_scripts=getHandshakeScript(request.host))
|
||||||
|
|
||||||
# Convert md to html
|
# Convert md to html
|
||||||
|
|||||||
@@ -93,30 +93,7 @@ def callback():
|
|||||||
@spotify_bp.route("/currently-playing")
|
@spotify_bp.route("/currently-playing")
|
||||||
def currently_playing():
|
def currently_playing():
|
||||||
"""Public endpoint showing your current track."""
|
"""Public endpoint showing your current track."""
|
||||||
token = refresh_access_token()
|
track = get_spotify_track()
|
||||||
if not token:
|
|
||||||
return json_response(request, {"error": "Failed to refresh access token"}, 500)
|
|
||||||
|
|
||||||
headers = {"Authorization": f"Bearer {token}"}
|
|
||||||
response = requests.get(SPOTIFY_CURRENTLY_PLAYING_URL, headers=headers)
|
|
||||||
|
|
||||||
if response.status_code == 204:
|
|
||||||
return json_response(request, {"message": "Nothing is currently playing."}, 200)
|
|
||||||
elif response.status_code != 200:
|
|
||||||
return json_response(request, {"error": "Spotify API error", "status": response.status_code}, response.status_code)
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
if not data.get("item"):
|
|
||||||
return json_response(request, {"message": "Nothing is currently playing."}, 200)
|
|
||||||
|
|
||||||
|
|
||||||
track = {
|
|
||||||
"song_name": data["item"]["name"],
|
|
||||||
"artist": ", ".join([artist["name"] for artist in data["item"]["artists"]]),
|
|
||||||
"album_name": data["item"]["album"]["name"],
|
|
||||||
"album_art": data["item"]["album"]["images"][0]["url"],
|
|
||||||
"is_playing": data["is_playing"]
|
|
||||||
}
|
|
||||||
return json_response(request, {"spotify":track}, 200)
|
return json_response(request, {"spotify":track}, 200)
|
||||||
|
|
||||||
def get_spotify_track():
|
def get_spotify_track():
|
||||||
@@ -137,12 +114,13 @@ def get_spotify_track():
|
|||||||
if not data.get("item"):
|
if not data.get("item"):
|
||||||
return {"error": "Nothing is currently playing."}
|
return {"error": "Nothing is currently playing."}
|
||||||
|
|
||||||
|
|
||||||
track = {
|
track = {
|
||||||
"song_name": data["item"]["name"],
|
"song_name": data["item"]["name"],
|
||||||
"artist": ", ".join([artist["name"] for artist in data["item"]["artists"]]),
|
"artist": ", ".join([artist["name"] for artist in data["item"]["artists"]]),
|
||||||
"album_name": data["item"]["album"]["name"],
|
"album_name": data["item"]["album"]["name"],
|
||||||
"album_art": data["item"]["album"]["images"][0]["url"],
|
"album_art": data["item"]["album"]["images"][0]["url"],
|
||||||
"is_playing": data["is_playing"]
|
"is_playing": data["is_playing"],
|
||||||
|
"progress_ms": data.get("progress_ms",0),
|
||||||
|
"duration_ms": data["item"].get("duration_ms",1)
|
||||||
}
|
}
|
||||||
return track
|
return track
|
||||||
7
curl.py
7
curl.py
@@ -123,4 +123,9 @@ def curl_response(request):
|
|||||||
if os.path.exists(f"templates/{path}.html"):
|
if os.path.exists(f"templates/{path}.html"):
|
||||||
return render_template(f"{path}.html")
|
return render_template(f"{path}.html")
|
||||||
|
|
||||||
return error_response(request)
|
# Return curl error page
|
||||||
|
error = {
|
||||||
|
"code": 404,
|
||||||
|
"message": "The requested resource was not found on this server."
|
||||||
|
}
|
||||||
|
return render_template("error.ascii",header=get_header(),error=error), 404, {'Content-Type': 'text/plain; charset=utf-8'}
|
||||||
@@ -23,6 +23,12 @@
|
|||||||
"url": "https://code.visualstudio.com/",
|
"url": "https://code.visualstudio.com/",
|
||||||
"description": "Source-code editor developed by Microsoft"
|
"description": "Source-code editor developed by Microsoft"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Vesktop",
|
||||||
|
"type": "Desktop Applications",
|
||||||
|
"url": "https://vesktop.dev/",
|
||||||
|
"description": "Vesktop is a customizable and privacy friendly Discord desktop app!"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Zellij",
|
"name": "Zellij",
|
||||||
"type": "Terminal Tools",
|
"type": "Terminal Tools",
|
||||||
|
|||||||
10
server.py
10
server.py
@@ -26,7 +26,7 @@ from blueprints.api import api_bp
|
|||||||
from blueprints.podcast import podcast_bp
|
from blueprints.podcast import podcast_bp
|
||||||
from blueprints.acme import acme_bp
|
from blueprints.acme import acme_bp
|
||||||
from blueprints.spotify import spotify_bp
|
from blueprints.spotify import spotify_bp
|
||||||
from tools import isCurl, isCrawler, getAddress, getFilePath, error_response, getClientIP, json_response, getHandshakeScript, get_tools_data
|
from tools import isCLI, isCrawler, getAddress, getFilePath, error_response, getClientIP, json_response, getHandshakeScript, get_tools_data
|
||||||
from curl import curl_response
|
from curl import curl_response
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@@ -244,7 +244,7 @@ def index():
|
|||||||
# Always load if load is in the query string
|
# Always load if load is in the query string
|
||||||
if request.args.get("load"):
|
if request.args.get("load"):
|
||||||
loaded = False
|
loaded = False
|
||||||
if isCurl(request):
|
if isCLI(request):
|
||||||
return curl_response(request)
|
return curl_response(request)
|
||||||
|
|
||||||
if not loaded and not isCrawler(request):
|
if not loaded and not isCrawler(request):
|
||||||
@@ -397,7 +397,7 @@ def index():
|
|||||||
# region Donate
|
# region Donate
|
||||||
@app.route("/donate")
|
@app.route("/donate")
|
||||||
def donate():
|
def donate():
|
||||||
if isCurl(request):
|
if isCLI(request):
|
||||||
return curl_response(request)
|
return curl_response(request)
|
||||||
|
|
||||||
coinList = os.listdir(".well-known/wallets")
|
coinList = os.listdir(".well-known/wallets")
|
||||||
@@ -687,7 +687,7 @@ def resume_pdf():
|
|||||||
|
|
||||||
@app.route("/tools")
|
@app.route("/tools")
|
||||||
def tools():
|
def tools():
|
||||||
if isCurl(request):
|
if isCLI(request):
|
||||||
return curl_response(request)
|
return curl_response(request)
|
||||||
return render_template("tools.html", tools=get_tools_data())
|
return render_template("tools.html", tools=get_tools_data())
|
||||||
|
|
||||||
@@ -704,7 +704,7 @@ def catch_all(path: str):
|
|||||||
return error_response(request, message="Restricted route", code=403)
|
return error_response(request, message="Restricted route", code=403)
|
||||||
|
|
||||||
# If curl request, return curl response
|
# If curl request, return curl response
|
||||||
if isCurl(request):
|
if isCLI(request):
|
||||||
return curl_response(request)
|
return curl_response(request)
|
||||||
|
|
||||||
if path in REDIRECT_ROUTES:
|
if path in REDIRECT_ROUTES:
|
||||||
|
|||||||
9
templates/error.ascii
Normal file
9
templates/error.ascii
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{{header}}
|
||||||
|
[1;36m───────────────────────────────────────────────[0m
|
||||||
|
[1;31m ERROR: {{ error.code }} [0m
|
||||||
|
[1;36m────────────[0m
|
||||||
|
|
||||||
|
[1;31m{{ error.message }}[0m
|
||||||
|
|
||||||
|
If you believe this is an error, please contact me via my socials listed at /contact
|
||||||
|
|
||||||
@@ -294,7 +294,7 @@ Check them out here!</blockquote><img class="img-fluid" src="/assets/img/pfront.
|
|||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M10 18C14.4183 18 18 14.4183 18 10C18 5.58172 14.4183 2 10 2C5.58172 2 2 5.58172 2 10C2 14.4183 5.58172 18 10 18ZM11 6C11 5.44772 10.5523 5 10 5C9.44771 5 9 5.44772 9 6V10C9 10.2652 9.10536 10.5196 9.29289 10.7071L12.1213 13.5355C12.5118 13.9261 13.145 13.9261 13.5355 13.5355C13.9261 13.145 13.9261 12.5118 13.5355 12.1213L11 9.58579V6Z" fill="currentColor"></path>
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M10 18C14.4183 18 18 14.4183 18 10C18 5.58172 14.4183 2 10 2C5.58172 2 2 5.58172 2 10C2 14.4183 5.58172 18 10 18ZM11 6C11 5.44772 10.5523 5 10 5C9.44771 5 9 5.44772 9 6V10C9 10.2652 9.10536 10.5196 9.29289 10.7071L12.1213 13.5355C12.5118 13.9261 13.145 13.9261 13.5355 13.5355C13.9261 13.145 13.9261 12.5118 13.5355 12.1213L11 9.58579V6Z" fill="currentColor"></path>
|
||||||
</svg><span style="margin-left: 10px;font-family: 'Anonymous Pro', monospace;">{{time|safe}}</span></div><!-- Pop-out button for mobile -->
|
</svg><span style="margin-left: 10px;font-family: 'Anonymous Pro', monospace;">{{time|safe}}</span></div><!-- Pop-out button for mobile -->
|
||||||
<button id="spotify-toggle" style="
|
<button id="spotify-toggle" style="
|
||||||
display: none;
|
display: block;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
right: 20px;
|
right: 20px;
|
||||||
@@ -305,6 +305,8 @@ Check them out here!</blockquote><img class="img-fluid" src="/assets/img/pfront.
|
|||||||
background: none;
|
background: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
transition: transform 0.5s ease;
|
||||||
|
transform: translateX(200%); /* start hidden off-screen *
|
||||||
">
|
">
|
||||||
<img src="/assets/img/external/spotify.png" alt="Spotify" style="
|
<img src="/assets/img/external/spotify.png" alt="Spotify" style="
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -360,6 +362,21 @@ Check them out here!</blockquote><img class="img-fluid" src="/assets/img/pfront.
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
"></div>
|
"></div>
|
||||||
|
<!-- Progress Bar -->
|
||||||
|
<div style="
|
||||||
|
margin-top: 6px;
|
||||||
|
height: 4px;
|
||||||
|
background: #333;
|
||||||
|
border-radius: 2px;
|
||||||
|
overflow: hidden;
|
||||||
|
">
|
||||||
|
<div id="spotify-progress" style="
|
||||||
|
width: 0%;
|
||||||
|
height: 100%;
|
||||||
|
background: #1DB954;
|
||||||
|
transition: width 1s linear;
|
||||||
|
"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -374,16 +391,17 @@ function isMobile() {
|
|||||||
function updateVisibility() {
|
function updateVisibility() {
|
||||||
if(isMobile()){
|
if(isMobile()){
|
||||||
widget.style.transform = 'translateX(120%)'; // hidden off-screen
|
widget.style.transform = 'translateX(120%)'; // hidden off-screen
|
||||||
toggleBtn.style.display = 'block';
|
toggleBtn.style.transform = 'translateX(0)'; // visible
|
||||||
} else {
|
} else {
|
||||||
widget.style.transform = 'translateX(0)'; // visible
|
widget.style.transform = 'translateX(0)'; // visible
|
||||||
toggleBtn.style.display = 'none';
|
toggleBtn.style.transform = 'translateX(200%)'; // hidden off-screen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle widget slide in/out on mobile
|
// Toggle widget slide in/out on mobile
|
||||||
toggleBtn.addEventListener('click', (e) => {
|
toggleBtn.addEventListener('click', (e) => {
|
||||||
widget.style.transform = 'translateX(0)'; // slide in
|
widget.style.transform = 'translateX(0)'; // slide in
|
||||||
|
toggleBtn.style.transform = 'translateX(200%)'; // hide button
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -392,6 +410,7 @@ document.addEventListener('click', (e) => {
|
|||||||
if(isMobile()){
|
if(isMobile()){
|
||||||
if(!widget.contains(e.target) && e.target !== toggleBtn){
|
if(!widget.contains(e.target) && e.target !== toggleBtn){
|
||||||
widget.style.transform = 'translateX(120%)'; // slide out
|
widget.style.transform = 'translateX(120%)'; // slide out
|
||||||
|
toggleBtn.style.transform = 'translateX(0)'; // show button
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -401,6 +420,15 @@ widget.addEventListener('click', (e) => {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Variable to track progress bar animation
|
||||||
|
let progressInterval = null;
|
||||||
|
let progressSpeed = 0;
|
||||||
|
let lastUpdateTime = Date.now();
|
||||||
|
let currentProgress = 0;
|
||||||
|
let targetProgress = 0;
|
||||||
|
let trackDuration = 0;
|
||||||
|
let currentTrackId = null;
|
||||||
|
|
||||||
// --- Spotify fetch ---
|
// --- Spotify fetch ---
|
||||||
async function updateSpotifyWidget() {
|
async function updateSpotifyWidget() {
|
||||||
try {
|
try {
|
||||||
@@ -419,6 +447,11 @@ async function updateSpotifyWidget() {
|
|||||||
document.getElementById('spotify-song').textContent = 'Not Playing';
|
document.getElementById('spotify-song').textContent = 'Not Playing';
|
||||||
document.getElementById('spotify-artist').textContent = '';
|
document.getElementById('spotify-artist').textContent = '';
|
||||||
document.getElementById('spotify-album').textContent = '';
|
document.getElementById('spotify-album').textContent = '';
|
||||||
|
document.getElementById('spotify-progress').style.width = '0%';
|
||||||
|
clearInterval(progressInterval);
|
||||||
|
progressInterval = null;
|
||||||
|
currentProgress = 0;
|
||||||
|
currentTrackId = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,14 +461,53 @@ async function updateSpotifyWidget() {
|
|||||||
if (!document.getElementById('spotify-song').textContent) {
|
if (!document.getElementById('spotify-song').textContent) {
|
||||||
firstLoad = true;
|
firstLoad = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if track has changed (new song started)
|
||||||
|
const trackId = track.song_name + track.artist; // Simple track identifier
|
||||||
|
const isNewTrack = currentTrackId !== null && currentTrackId !== trackId;
|
||||||
|
|
||||||
|
if (isNewTrack) {
|
||||||
|
// Reset progress bar instantly for new track
|
||||||
|
currentProgress = 0;
|
||||||
|
document.getElementById('spotify-progress').style.transition = 'none';
|
||||||
|
document.getElementById('spotify-progress').style.width = '0%';
|
||||||
|
// Force reflow to apply the instant reset
|
||||||
|
document.getElementById('spotify-progress').offsetHeight;
|
||||||
|
// Re-enable transition
|
||||||
|
document.getElementById('spotify-progress').style.transition = 'width 0.1s linear';
|
||||||
|
}
|
||||||
|
|
||||||
|
currentTrackId = trackId;
|
||||||
|
|
||||||
|
|
||||||
document.getElementById('spotify-album-art').src = track.album_art;
|
document.getElementById('spotify-album-art').src = track.album_art;
|
||||||
document.getElementById('spotify-song').textContent = track.song_name;
|
document.getElementById('spotify-song').textContent = track.song_name;
|
||||||
document.getElementById('spotify-artist').textContent = track.artist;
|
document.getElementById('spotify-artist').textContent = track.artist;
|
||||||
document.getElementById('spotify-album').textContent = track.album_name;
|
document.getElementById('spotify-album').textContent = track.album_name;
|
||||||
|
|
||||||
|
// Update progress bar
|
||||||
|
if (track.is_playing) {
|
||||||
|
currentProgress = (track.progress_ms / track.duration_ms) * 100;
|
||||||
|
trackDuration = track.duration_ms;
|
||||||
|
lastUpdateTime = Date.now();
|
||||||
|
|
||||||
|
document.getElementById('spotify-progress').style.width = currentProgress + '%';
|
||||||
|
|
||||||
|
// Clear existing interval
|
||||||
|
if (progressInterval) {
|
||||||
|
clearInterval(progressInterval);
|
||||||
|
}
|
||||||
|
// Start interval to animate progress bar
|
||||||
|
progressInterval = setInterval(animateProgressBar, 100);
|
||||||
|
} else {
|
||||||
|
document.getElementById('spotify-progress').style.width = currentProgress + '%';
|
||||||
|
clearInterval(progressInterval);
|
||||||
|
progressInterval = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If first load and desktop, slide in the widget
|
||||||
if (firstLoad) {
|
if (firstLoad) {
|
||||||
widget.style.transform = 'translateX(0)'; // slide in on first load
|
updateVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -443,6 +515,30 @@ async function updateSpotifyWidget() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Animate progress bar
|
||||||
|
function animateProgressBar() {
|
||||||
|
if (trackDuration === 0) return;
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
const elapsed = now - lastUpdateTime;
|
||||||
|
lastUpdateTime = now;
|
||||||
|
|
||||||
|
// Calculate progress increment based on elapsed time
|
||||||
|
const progressIncrement = (elapsed / trackDuration) * 100;
|
||||||
|
currentProgress += progressIncrement;
|
||||||
|
|
||||||
|
if (currentProgress >= 100) {
|
||||||
|
currentProgress = 100;
|
||||||
|
document.getElementById('spotify-progress').style.width = '100%';
|
||||||
|
clearInterval(progressInterval);
|
||||||
|
progressInterval = null;
|
||||||
|
// Refresh API when progress reaches 100%
|
||||||
|
setTimeout(updateSpotifyWidget, 500);
|
||||||
|
} else {
|
||||||
|
document.getElementById('spotify-progress').style.width = currentProgress + '%';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for Spotify API to have responded before initial display
|
// Wait for Spotify API to have responded before initial display
|
||||||
updateSpotifyWidget();
|
updateSpotifyWidget();
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,15 @@ GET http://127.0.0.1:5000/api/v1/ip
|
|||||||
HTTP 200
|
HTTP 200
|
||||||
[Asserts]
|
[Asserts]
|
||||||
jsonpath "$.ip" == "127.0.0.1"
|
jsonpath "$.ip" == "127.0.0.1"
|
||||||
|
|
||||||
GET http://127.0.0.1:5000/api/v1/time
|
GET http://127.0.0.1:5000/api/v1/time
|
||||||
HTTP 200
|
HTTP 200
|
||||||
GET http://127.0.0.1:5000/api/v1/timezone
|
GET http://127.0.0.1:5000/api/v1/timezone
|
||||||
HTTP 200
|
HTTP 200
|
||||||
|
[Asserts]
|
||||||
|
jsonpath "$.timezone" >= 10
|
||||||
|
jsonpath "$.timezone" <= 12
|
||||||
|
|
||||||
GET http://127.0.0.1:5000/api/v1/message
|
GET http://127.0.0.1:5000/api/v1/message
|
||||||
HTTP 200
|
HTTP 200
|
||||||
GET http://127.0.0.1:5000/api/v1/project
|
GET http://127.0.0.1:5000/api/v1/project
|
||||||
@@ -17,4 +22,7 @@ HTTP 200
|
|||||||
GET http://127.0.0.1:5000/api/v1/tools
|
GET http://127.0.0.1:5000/api/v1/tools
|
||||||
HTTP 200
|
HTTP 200
|
||||||
[Asserts]
|
[Asserts]
|
||||||
jsonpath "$.tools" count > 5
|
jsonpath "$.tools" count > 5
|
||||||
|
|
||||||
|
GET http://127.0.0.1:5000/api/v1/playing
|
||||||
|
HTTP 200
|
||||||
13
tools.py
13
tools.py
@@ -27,6 +27,13 @@ CRAWLERS = [
|
|||||||
"Twitterbot"
|
"Twitterbot"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
CLI_AGENTS = [
|
||||||
|
"curl",
|
||||||
|
"hurl",
|
||||||
|
"xh",
|
||||||
|
"Posting"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def getClientIP(request: Request) -> str:
|
def getClientIP(request: Request) -> str:
|
||||||
"""
|
"""
|
||||||
@@ -75,7 +82,7 @@ def getGitCommit() -> str:
|
|||||||
return "failed to get version"
|
return "failed to get version"
|
||||||
|
|
||||||
|
|
||||||
def isCurl(request: Request) -> bool:
|
def isCLI(request: Request) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if the request is from curl or hurl.
|
Check if the request is from curl or hurl.
|
||||||
|
|
||||||
@@ -87,7 +94,7 @@ def isCurl(request: Request) -> bool:
|
|||||||
"""
|
"""
|
||||||
if request.headers and request.headers.get("User-Agent"):
|
if request.headers and request.headers.get("User-Agent"):
|
||||||
user_agent = request.headers.get("User-Agent", "")
|
user_agent = request.headers.get("User-Agent", "")
|
||||||
return "curl" in user_agent or "hurl" in user_agent
|
return any(agent in user_agent for agent in CLI_AGENTS)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -221,7 +228,7 @@ def error_response(
|
|||||||
Returns:
|
Returns:
|
||||||
Union[Tuple[Dict, int], object]: The JSON or HTML response
|
Union[Tuple[Dict, int], object]: The JSON or HTML response
|
||||||
"""
|
"""
|
||||||
if force_json or isCurl(request):
|
if force_json or isCLI(request):
|
||||||
return json_response(request, message, code)
|
return json_response(request, message, code)
|
||||||
|
|
||||||
# Check if <error code>.html exists in templates
|
# Check if <error code>.html exists in templates
|
||||||
|
|||||||
Reference in New Issue
Block a user