feat: Move getGitCommit from api to tools
All checks were successful
Build Docker / BuildImage (push) Successful in 1m4s

This commit is contained in:
2025-10-11 18:51:22 +11:00
parent 258061c64d
commit bfc1f0839a
3 changed files with 24 additions and 23 deletions

View File

@@ -4,7 +4,7 @@ import datetime
import requests import requests
from mail import sendEmail from mail import sendEmail
from sol import create_transaction from sol import create_transaction
from tools import getClientIP from tools import getClientIP, getGitCommit
api_bp = Blueprint('api', __name__) api_bp = Blueprint('api', __name__)
@@ -18,26 +18,6 @@ if 'time-zone' not in ncConfig:
ncConfig['time-zone'] = 10 ncConfig['time-zone'] = 10
def getGitCommit():
# if .git exists, get the latest commit hash
if os.path.isdir(".git"):
git_dir = ".git"
head_ref = ""
with open(os.path.join(git_dir, "HEAD")) as file:
head_ref = file.read().strip()
if head_ref.startswith("ref: "):
head_ref = head_ref[5:]
with open(os.path.join(git_dir, head_ref)) as file:
return file.read().strip()
else:
return head_ref
# Check if env SOURCE_COMMIT is set
if "SOURCE_COMMIT" in os.environ:
return os.environ["SOURCE_COMMIT"]
return "failed to get version"
@api_bp.route("/") @api_bp.route("/")
@api_bp.route("/help") @api_bp.route("/help")
def help_get(): def help_get():

View File

@@ -22,10 +22,10 @@ from PIL import Image
from blueprints.now import now_bp from blueprints.now import now_bp
from blueprints.blog import blog_bp from blueprints.blog import blog_bp
from blueprints.wellknown import wk_bp from blueprints.wellknown import wk_bp
from blueprints.api import api_bp, getGitCommit 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 tools import isCurl, isCrawler, getAddress, getFilePath, error_response, getClientIP, json_response from tools import isCurl, isCrawler, getAddress, getFilePath, error_response, getClientIP, json_response, getGitCommit
app = Flask(__name__) app = Flask(__name__)
CORS(app) CORS(app)

View File

@@ -10,6 +10,27 @@ def getClientIP(request):
ip = request.remote_addr ip = request.remote_addr
return ip return ip
def getGitCommit():
# if .git exists, get the latest commit hash
if os.path.isdir(".git"):
git_dir = ".git"
head_ref = ""
with open(os.path.join(git_dir, "HEAD")) as file:
head_ref = file.read().strip()
if head_ref.startswith("ref: "):
head_ref = head_ref[5:]
with open(os.path.join(git_dir, head_ref)) as file:
return file.read().strip()
else:
return head_ref
# Check if env SOURCE_COMMIT is set
if "SOURCE_COMMIT" in os.environ:
return os.environ["SOURCE_COMMIT"]
return "failed to get version"
def isCurl(request: Request) -> bool: def isCurl(request: Request) -> bool:
""" """
Check if the request is from curl Check if the request is from curl