mike23415 commited on
Commit
78b921e
·
verified ·
1 Parent(s): 0a9cca4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -18
app.py CHANGED
@@ -163,25 +163,33 @@ def index():
163
 
164
  @app.route("/api/store", methods=["POST"])
165
  def store():
166
- """Store encrypted secret with enhanced features - MODIFIED FOR FRONTEND FILE ENCRYPTION"""
167
  try:
168
- form = request.form
169
- data = form.get("data")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  if not data:
172
  return jsonify({"error": "Data is required"}), 400
173
 
174
- # Parse parameters
175
- ttl = int(form.get("ttl", 300))
176
- view_once = form.get("view_once", "false").lower() == "true"
177
- delay_seconds = int(form.get("delay_seconds", 0))
178
- theme = form.get("theme", "default")
179
- password_hint = form.get("password_hint", "")
180
- has_file = form.get("has_file", "false").lower() == "true" # NEW: File flag from frontend
181
-
182
- # REMOVED: File upload handling (no longer needed)
183
- # The frontend now encrypts files into the data field
184
-
185
  # Generate IDs
186
  secret_id = str(uuid.uuid4())
187
  short_id = generate_short_id()
@@ -190,15 +198,15 @@ def store():
190
  while short_id in SHORT_LINKS:
191
  short_id = generate_short_id()
192
 
193
- # Store secret - SIMPLIFIED STRUCTURE
194
  SECRETS[secret_id] = {
195
- "data": data, # Now contains encrypted message + file data
196
  "expire_at": time.time() + ttl,
197
  "view_once": view_once,
198
  "delay_seconds": delay_seconds,
199
  "theme": theme,
200
  "password_hint": password_hint,
201
- "has_file": has_file, # NEW: Flag to indicate if encrypted data contains file
202
  "created_at": time.time(),
203
  "creator_ip": get_client_ip(request),
204
  "access_count": 0
@@ -218,10 +226,11 @@ def store():
218
  "short_url": f"{base_url}/s/{short_id}",
219
  "qr_code": qr_code,
220
  "expires_at": SECRETS[secret_id]["expire_at"],
221
- "has_file": has_file # Return the file flag
222
  })
223
 
224
  except Exception as e:
 
225
  return jsonify({"error": str(e)}), 500
226
 
227
  @app.route("/api/fetch/<secret_id>")
 
163
 
164
  @app.route("/api/store", methods=["POST"])
165
  def store():
166
+ """Store encrypted secret with enhanced features - FIXED FOR JSON REQUEST"""
167
  try:
168
+ # Check if request is JSON or form data
169
+ if request.is_json:
170
+ # Handle JSON request (from frontend)
171
+ json_data = request.get_json()
172
+ data = json_data.get("data")
173
+ ttl = int(json_data.get("ttl", 300))
174
+ view_once = json_data.get("view_once", False)
175
+ delay_seconds = int(json_data.get("delay_seconds", 0))
176
+ theme = json_data.get("theme", "default")
177
+ password_hint = json_data.get("password_hint", "")
178
+ has_file = json_data.get("has_file", False)
179
+ else:
180
+ # Handle form data (backward compatibility)
181
+ form = request.form
182
+ data = form.get("data")
183
+ ttl = int(form.get("ttl", 300))
184
+ view_once = form.get("view_once", "false").lower() == "true"
185
+ delay_seconds = int(form.get("delay_seconds", 0))
186
+ theme = form.get("theme", "default")
187
+ password_hint = form.get("password_hint", "")
188
+ has_file = form.get("has_file", "false").lower() == "true"
189
 
190
  if not data:
191
  return jsonify({"error": "Data is required"}), 400
192
 
 
 
 
 
 
 
 
 
 
 
 
193
  # Generate IDs
194
  secret_id = str(uuid.uuid4())
195
  short_id = generate_short_id()
 
198
  while short_id in SHORT_LINKS:
199
  short_id = generate_short_id()
200
 
201
+ # Store secret
202
  SECRETS[secret_id] = {
203
+ "data": data, # Contains encrypted message + file data
204
  "expire_at": time.time() + ttl,
205
  "view_once": view_once,
206
  "delay_seconds": delay_seconds,
207
  "theme": theme,
208
  "password_hint": password_hint,
209
+ "has_file": has_file,
210
  "created_at": time.time(),
211
  "creator_ip": get_client_ip(request),
212
  "access_count": 0
 
226
  "short_url": f"{base_url}/s/{short_id}",
227
  "qr_code": qr_code,
228
  "expires_at": SECRETS[secret_id]["expire_at"],
229
+ "has_file": has_file
230
  })
231
 
232
  except Exception as e:
233
+ print(f"Error in store endpoint: {str(e)}") # Add logging
234
  return jsonify({"error": str(e)}), 500
235
 
236
  @app.route("/api/fetch/<secret_id>")