vsmdvic commited on
Commit
5f35ed2
·
verified ·
1 Parent(s): a322166

Upload 20 files

Browse files
Files changed (2) hide show
  1. app.py +22 -1
  2. static/elev-dashboard.html +12 -4
app.py CHANGED
@@ -31,6 +31,8 @@ def get_drive_token():
31
  now = time.time()
32
  if _drive_token and now < _drive_token_exp - 60:
33
  return _drive_token
 
 
34
  private_key = DRIVE_SA["private_key"]
35
  claim = {
36
  "iss": DRIVE_SA["client_email"],
@@ -44,11 +46,30 @@ def get_drive_token():
44
  "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
45
  "assertion": signed,
46
  }, timeout=15)
47
- r.raise_for_status()
 
48
  _drive_token = r.json()["access_token"]
49
  _drive_token_exp = now + 3600
 
50
  return _drive_token
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  def drive_headers():
53
  return {"Authorization": f"Bearer {get_drive_token()}"}
54
 
 
31
  now = time.time()
32
  if _drive_token and now < _drive_token_exp - 60:
33
  return _drive_token
34
+ if pyjwt is None:
35
+ raise RuntimeError("PyJWT nu este instalat! Adaugă PyJWT==2.8.0 in requirements.txt")
36
  private_key = DRIVE_SA["private_key"]
37
  claim = {
38
  "iss": DRIVE_SA["client_email"],
 
46
  "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
47
  "assertion": signed,
48
  }, timeout=15)
49
+ if r.status_code != 200:
50
+ raise RuntimeError(f"OAuth2 error {r.status_code}: {r.text}")
51
  _drive_token = r.json()["access_token"]
52
  _drive_token_exp = now + 3600
53
+ print(f"[DRIVE TOKEN] OK — obtinut token nou")
54
  return _drive_token
55
 
56
+ @app.route("/drive/test", methods=["GET"])
57
+ def drive_test():
58
+ """Endpoint de diagnostic — verifica conexiunea Drive"""
59
+ try:
60
+ token = get_drive_token()
61
+ r = requests.get(
62
+ f"https://www.googleapis.com/drive/v3/files/{DRIVE_FOLDER_ID}",
63
+ params={"fields": "id,name"},
64
+ headers={"Authorization": f"Bearer {token}"},
65
+ timeout=10
66
+ )
67
+ return jsonify({"ok": True, "token_ok": True, "folder": r.json(), "status": r.status_code})
68
+ except Exception as e:
69
+ import traceback
70
+ return jsonify({"ok": False, "error": str(e), "trace": traceback.format_exc()}), 500
71
+
72
+
73
  def drive_headers():
74
  return {"Authorization": f"Bearer {get_drive_token()}"}
75
 
static/elev-dashboard.html CHANGED
@@ -275,10 +275,16 @@ async function uploadFile(file) {
275
  }
276
  };
277
  xhr.onload = () => {
278
- if (xhr.status === 200) resolve(JSON.parse(xhr.responseText));
279
- else reject(new Error('Upload eșuat: ' + xhr.status));
 
 
 
 
 
 
280
  };
281
- xhr.onerror = () => reject(new Error('Eroare rețea'));
282
  xhr.send(formData);
283
  });
284
 
@@ -302,7 +308,9 @@ async function uploadFile(file) {
302
  await loadFiles();
303
  } catch(e) {
304
  progWrap.classList.remove('show');
305
- showError('err-upload','err-009');
 
 
306
  }
307
  }
308
 
 
275
  }
276
  };
277
  xhr.onload = () => {
278
+ if (xhr.status === 200) {
279
+ try { resolve(JSON.parse(xhr.responseText)); }
280
+ catch(e) { reject(new Error('Răspuns invalid de la server')); }
281
+ } else {
282
+ let errMsg = `HTTP ${xhr.status}`;
283
+ try { const d = JSON.parse(xhr.responseText); errMsg = d.error || errMsg; } catch(e) {}
284
+ reject(new Error(errMsg));
285
+ }
286
  };
287
+ xhr.onerror = () => reject(new Error('Eroare rețea — serverul nu răspunde'));
288
  xhr.send(formData);
289
  });
290
 
 
308
  await loadFiles();
309
  } catch(e) {
310
  progWrap.classList.remove('show');
311
+ const msg = e.message || 'Eroare necunoscută';
312
+ showError('err-upload', 'err-009', `Upload eșuat: ${msg}`);
313
+ console.error('[UPLOAD ERROR]', e);
314
  }
315
  }
316