Update app.py
Browse files
app.py
CHANGED
@@ -241,7 +241,7 @@ def store():
|
|
241 |
"id": secret_id,
|
242 |
"short_id": short_id,
|
243 |
"short_url": f"{base_url}/s/{short_id}",
|
244 |
-
"qr_code": qr_code,
|
245 |
"expires_at": SECRETS[secret_id]["expire_at"],
|
246 |
"has_file": file_data is not None
|
247 |
})
|
@@ -251,7 +251,7 @@ def store():
|
|
251 |
|
252 |
@app.route("/api/fetch/<secret_id>")
|
253 |
def fetch(secret_id):
|
254 |
-
"""Fetch and decrypt secret with analytics"""
|
255 |
try:
|
256 |
# Check if it's a short link
|
257 |
if secret_id in SHORT_LINKS:
|
@@ -272,11 +272,16 @@ def fetch(secret_id):
|
|
272 |
del SHORT_LINKS[short_id]
|
273 |
return jsonify({"error": "Secret has expired"}), 410
|
274 |
|
275 |
-
#
|
276 |
-
|
277 |
|
278 |
-
#
|
279 |
-
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
# Prepare response
|
282 |
response = {
|
@@ -287,14 +292,14 @@ def fetch(secret_id):
|
|
287 |
"access_count": secret["access_count"]
|
288 |
}
|
289 |
|
290 |
-
# Include file data if present
|
291 |
if secret.get("file_data"):
|
292 |
response["file_data"] = secret["file_data"]
|
293 |
response["file_type"] = secret.get("file_type", "unknown")
|
294 |
response["file_name"] = secret.get("file_name", "unknown")
|
295 |
|
296 |
-
# Handle view-once deletion
|
297 |
-
if secret["view_once"]:
|
298 |
# Delete the secret
|
299 |
del SECRETS[secret_id]
|
300 |
|
@@ -311,12 +316,20 @@ def fetch(secret_id):
|
|
311 |
|
312 |
@app.route("/api/analytics/<secret_id>")
|
313 |
def get_analytics(secret_id):
|
314 |
-
"""Get analytics for a specific secret"""
|
315 |
try:
|
|
|
|
|
|
|
316 |
# Verify secret exists or existed
|
317 |
if secret_id not in SECRETS and secret_id not in ANALYTICS:
|
318 |
return jsonify({"error": "Secret not found"}), 404
|
319 |
|
|
|
|
|
|
|
|
|
|
|
320 |
analytics_data = ANALYTICS.get(secret_id, [])
|
321 |
|
322 |
# Format analytics for frontend
|
@@ -379,11 +392,19 @@ def list_secrets():
|
|
379 |
|
380 |
@app.route("/api/delete/<secret_id>", methods=["DELETE"])
|
381 |
def delete_secret(secret_id):
|
382 |
-
"""Manually delete a secret"""
|
383 |
try:
|
|
|
|
|
|
|
384 |
if secret_id not in SECRETS:
|
385 |
return jsonify({"error": "Secret not found"}), 404
|
386 |
|
|
|
|
|
|
|
|
|
|
|
387 |
# Delete secret
|
388 |
del SECRETS[secret_id]
|
389 |
|
@@ -518,6 +539,7 @@ if __name__ == "__main__":
|
|
518 |
print(" β
Self-destruct messages")
|
519 |
print(" β
Multiple themes")
|
520 |
print(" β
Password hints")
|
|
|
521 |
print("π Server running on http://0.0.0.0:7860")
|
522 |
|
523 |
app.run(host="0.0.0.0", port=7860, debug=True)
|
|
|
241 |
"id": secret_id,
|
242 |
"short_id": short_id,
|
243 |
"short_url": f"{base_url}/s/{short_id}",
|
244 |
+
"qr_code": qr_code,
|
245 |
"expires_at": SECRETS[secret_id]["expire_at"],
|
246 |
"has_file": file_data is not None
|
247 |
})
|
|
|
251 |
|
252 |
@app.route("/api/fetch/<secret_id>")
|
253 |
def fetch(secret_id):
|
254 |
+
"""Fetch and decrypt secret with analytics - MODIFIED TO HANDLE verify_only"""
|
255 |
try:
|
256 |
# Check if it's a short link
|
257 |
if secret_id in SHORT_LINKS:
|
|
|
272 |
del SHORT_LINKS[short_id]
|
273 |
return jsonify({"error": "Secret has expired"}), 410
|
274 |
|
275 |
+
# CHECK FOR verify_only PARAMETER
|
276 |
+
verify_only = request.args.get('verify_only', 'false').lower() == 'true'
|
277 |
|
278 |
+
# Only record access and increment count if NOT verify_only
|
279 |
+
if not verify_only:
|
280 |
+
# Record access analytics
|
281 |
+
analytics_entry = record_access(secret_id, request)
|
282 |
+
|
283 |
+
# Increment access count
|
284 |
+
secret["access_count"] += 1
|
285 |
|
286 |
# Prepare response
|
287 |
response = {
|
|
|
292 |
"access_count": secret["access_count"]
|
293 |
}
|
294 |
|
295 |
+
# Include file data if present
|
296 |
if secret.get("file_data"):
|
297 |
response["file_data"] = secret["file_data"]
|
298 |
response["file_type"] = secret.get("file_type", "unknown")
|
299 |
response["file_name"] = secret.get("file_name", "unknown")
|
300 |
|
301 |
+
# Handle view-once deletion (only if not verify_only)
|
302 |
+
if secret["view_once"] and not verify_only:
|
303 |
# Delete the secret
|
304 |
del SECRETS[secret_id]
|
305 |
|
|
|
316 |
|
317 |
@app.route("/api/analytics/<secret_id>")
|
318 |
def get_analytics(secret_id):
|
319 |
+
"""Get analytics for a specific secret - MODIFIED TO HANDLE verify_only"""
|
320 |
try:
|
321 |
+
# CHECK FOR verify_only PARAMETER
|
322 |
+
verify_only = request.args.get('verify_only', 'false').lower() == 'true'
|
323 |
+
|
324 |
# Verify secret exists or existed
|
325 |
if secret_id not in SECRETS and secret_id not in ANALYTICS:
|
326 |
return jsonify({"error": "Secret not found"}), 404
|
327 |
|
328 |
+
# Only record access if NOT verify_only
|
329 |
+
if not verify_only:
|
330 |
+
# Record access analytics for the analytics request itself
|
331 |
+
record_access(secret_id, request)
|
332 |
+
|
333 |
analytics_data = ANALYTICS.get(secret_id, [])
|
334 |
|
335 |
# Format analytics for frontend
|
|
|
392 |
|
393 |
@app.route("/api/delete/<secret_id>", methods=["DELETE"])
|
394 |
def delete_secret(secret_id):
|
395 |
+
"""Manually delete a secret - MODIFIED TO HANDLE verify_only"""
|
396 |
try:
|
397 |
+
# CHECK FOR verify_only PARAMETER
|
398 |
+
verify_only = request.args.get('verify_only', 'false').lower() == 'true'
|
399 |
+
|
400 |
if secret_id not in SECRETS:
|
401 |
return jsonify({"error": "Secret not found"}), 404
|
402 |
|
403 |
+
# Only record access if NOT verify_only
|
404 |
+
if not verify_only:
|
405 |
+
# Record access analytics for the delete request
|
406 |
+
record_access(secret_id, request)
|
407 |
+
|
408 |
# Delete secret
|
409 |
del SECRETS[secret_id]
|
410 |
|
|
|
539 |
print(" β
Self-destruct messages")
|
540 |
print(" β
Multiple themes")
|
541 |
print(" β
Password hints")
|
542 |
+
print(" β
verify_only parameter support")
|
543 |
print("π Server running on http://0.0.0.0:7860")
|
544 |
|
545 |
app.run(host="0.0.0.0", port=7860, debug=True)
|