handling spaces better
This commit is contained in:
parent
8a630e7ba3
commit
3c2073614f
@ -194,29 +194,37 @@ def article_content_endpoint():
|
||||
if not file_path:
|
||||
return jsonify({"error": "Missing 'path' parameter"}), 400
|
||||
|
||||
# URL decode the file path to handle spaces and special characters properly
|
||||
import urllib.parse
|
||||
|
||||
decoded_file_path = urllib.parse.unquote(file_path)
|
||||
|
||||
# Validate that the file exists and is within our article directory
|
||||
# We'll ensure the file path is safe by checking it's under ARTICLE_DIR
|
||||
file_path = os.path.abspath(file_path)
|
||||
try:
|
||||
decoded_file_path = os.path.abspath(decoded_file_path)
|
||||
article_dir = os.path.abspath(ARTICLE_DIR)
|
||||
|
||||
if not file_path.startswith(article_dir):
|
||||
if not decoded_file_path.startswith(article_dir):
|
||||
return jsonify(
|
||||
{"error": "Invalid file path - must be within article directory"}
|
||||
), 400
|
||||
|
||||
if not os.path.exists(file_path):
|
||||
if not os.path.exists(decoded_file_path):
|
||||
return jsonify({"error": "Article file not found"}), 404
|
||||
except Exception as e:
|
||||
return jsonify({"error": f"Path validation failed: {str(e)}"}), 400
|
||||
|
||||
# Read the content of the article file
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
with open(decoded_file_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
# Get basic info about the article
|
||||
outlet = os.path.basename(os.path.dirname(file_path))
|
||||
filename = os.path.basename(file_path)
|
||||
outlet = os.path.basename(os.path.dirname(decoded_file_path))
|
||||
filename = os.path.basename(decoded_file_path)
|
||||
|
||||
response_data = {
|
||||
"path": file_path,
|
||||
"path": decoded_file_path,
|
||||
"name": filename,
|
||||
"outlet": outlet,
|
||||
"content": content,
|
||||
|
||||
@ -13,4 +13,4 @@ if __name__ == "__main__":
|
||||
if "ARTICLE_DIR" not in os.environ:
|
||||
print("Warning: ARTICLE_DIR environment variable not set. Using default path.")
|
||||
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
app.run(host="0.0.0.0", port=5008, debug=True)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user