Spaces:
Sleeping
Sleeping
Commit
·
c8fb59f
1
Parent(s):
356ac4f
Updated files
Browse files- app.py +21 -7
- data/active_sessions.json +3 -3
- new.py +0 -0
- src/static/js/main.js +6 -2
app.py
CHANGED
@@ -92,24 +92,38 @@ security = HTTPBearer(auto_error=False)
|
|
92 |
# Settings for Hugging Face Spaces: use /tmp dirs
|
93 |
class Settings:
|
94 |
def __init__(self):
|
|
|
|
|
|
|
95 |
self.server = type('ServerSettings', (), {
|
96 |
-
'debug':
|
97 |
-
'host': '
|
98 |
-
'port': int(
|
99 |
})()
|
100 |
self.security = type('SecuritySettings', (), {
|
101 |
'cors_origins': ["*"],
|
102 |
'cors_methods': ["*"],
|
103 |
'cors_headers': ["*"]
|
104 |
})()
|
|
|
105 |
def get_static_dir(self):
|
106 |
-
|
|
|
|
|
|
|
107 |
def get_templates_dir(self):
|
108 |
-
|
|
|
|
|
109 |
def get_upload_dir(self):
|
110 |
-
|
|
|
|
|
|
|
111 |
def get_logs_dir(self):
|
112 |
-
|
|
|
|
|
113 |
|
114 |
settings = Settings()
|
115 |
|
|
|
92 |
# Settings for Hugging Face Spaces: use /tmp dirs
|
93 |
class Settings:
|
94 |
def __init__(self):
|
95 |
+
# Detect if running in Hugging Face Spaces (PORT is set and not a typical local port)
|
96 |
+
port_env = os.environ.get('PORT')
|
97 |
+
self.is_spaces = port_env is not None and port_env not in ['8000', '5000', '8080']
|
98 |
self.server = type('ServerSettings', (), {
|
99 |
+
'debug': not self.is_spaces,
|
100 |
+
'host': '127.0.0.1',
|
101 |
+
'port': int(port_env) if port_env else 8000 # Default to 8000 for local
|
102 |
})()
|
103 |
self.security = type('SecuritySettings', (), {
|
104 |
'cors_origins': ["*"],
|
105 |
'cors_methods': ["*"],
|
106 |
'cors_headers': ["*"]
|
107 |
})()
|
108 |
+
|
109 |
def get_static_dir(self):
|
110 |
+
if self.is_spaces:
|
111 |
+
return "/tmp/researchmate/static"
|
112 |
+
return "src/static"
|
113 |
+
|
114 |
def get_templates_dir(self):
|
115 |
+
# Templates can remain in src for both
|
116 |
+
return "src/templates"
|
117 |
+
|
118 |
def get_upload_dir(self):
|
119 |
+
if self.is_spaces:
|
120 |
+
return "/tmp/researchmate/uploads"
|
121 |
+
return "uploads"
|
122 |
+
|
123 |
def get_logs_dir(self):
|
124 |
+
if self.is_spaces:
|
125 |
+
return "/tmp/researchmate/logs"
|
126 |
+
return "logs"
|
127 |
|
128 |
settings = Settings()
|
129 |
|
data/active_sessions.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
{
|
2 |
"admin_user": {
|
3 |
-
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
|
4 |
-
"created_at": "2025-07-15T18:
|
5 |
-
"last_activity": "2025-07-15T18:
|
6 |
}
|
7 |
}
|
|
|
1 |
{
|
2 |
"admin_user": {
|
3 |
+
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYWRtaW5fdXNlciIsInVzZXJuYW1lIjoiYWRtaW4iLCJleHAiOjE3NTI2MTQwMzZ9.ymVeZ3z0Qiap57XjE2u8II_EXexLH49oM3shT7lXfJ0",
|
4 |
+
"created_at": "2025-07-15T18:43:56.569611",
|
5 |
+
"last_activity": "2025-07-15T18:43:58.764999"
|
6 |
}
|
7 |
}
|
new.py
ADDED
File without changes
|
src/static/js/main.js
CHANGED
@@ -21,8 +21,12 @@ function setAuthToken(token) {
|
|
21 |
localStorage.setItem('authToken', token);
|
22 |
localStorage.setItem('tokenTimestamp', Date.now().toString());
|
23 |
|
24 |
-
// Set cookie with
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
// Reset activity tracking
|
28 |
lastActivityTime = Date.now();
|
|
|
21 |
localStorage.setItem('authToken', token);
|
22 |
localStorage.setItem('tokenTimestamp', Date.now().toString());
|
23 |
|
24 |
+
// Set cookie with Secure flag only if using HTTPS
|
25 |
+
let cookie = `authToken=${token}; path=/; SameSite=Strict`;
|
26 |
+
if (location.protocol === 'https:') {
|
27 |
+
cookie += '; Secure';
|
28 |
+
}
|
29 |
+
document.cookie = cookie;
|
30 |
|
31 |
// Reset activity tracking
|
32 |
lastActivityTime = Date.now();
|