Spaces:
Building
Building
Update utils.py
Browse files
utils.py
CHANGED
@@ -123,4 +123,39 @@ def is_safe_path(path: str, base_path: str) -> bool:
|
|
123 |
target = os.path.abspath(os.path.join(base, path))
|
124 |
|
125 |
# Check if target is under base
|
126 |
-
return target.startswith(base)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
target = os.path.abspath(os.path.join(base, path))
|
124 |
|
125 |
# Check if target is under base
|
126 |
+
return target.startswith(base)
|
127 |
+
|
128 |
+
def get_current_timestamp() -> str:
|
129 |
+
"""
|
130 |
+
Get current UTC timestamp in ISO format with Z suffix
|
131 |
+
Returns: "2025-01-10T12:00:00.123Z"
|
132 |
+
"""
|
133 |
+
return datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z')
|
134 |
+
|
135 |
+
def normalize_timestamp(timestamp: Optional[str]) -> str:
|
136 |
+
"""
|
137 |
+
Normalize timestamp string for consistent comparison
|
138 |
+
Handles various formats:
|
139 |
+
- "2025-01-10T12:00:00Z"
|
140 |
+
- "2025-01-10T12:00:00.000Z"
|
141 |
+
- "2025-01-10T12:00:00+00:00"
|
142 |
+
- "2025-01-10 12:00:00+00:00"
|
143 |
+
"""
|
144 |
+
if not timestamp:
|
145 |
+
return ""
|
146 |
+
|
147 |
+
# Normalize various formats
|
148 |
+
normalized = timestamp.replace(' ', 'T') # Space to T
|
149 |
+
normalized = normalized.replace('+00:00', 'Z') # UTC timezone
|
150 |
+
|
151 |
+
# Remove milliseconds if present for comparison
|
152 |
+
if '.' in normalized and normalized.endswith('Z'):
|
153 |
+
normalized = normalized.split('.')[0] + 'Z'
|
154 |
+
|
155 |
+
return normalized
|
156 |
+
|
157 |
+
def timestamps_equal(ts1: Optional[str], ts2: Optional[str]) -> bool:
|
158 |
+
"""
|
159 |
+
Compare two timestamps regardless of format differences
|
160 |
+
"""
|
161 |
+
return normalize_timestamp(ts1) == normalize_timestamp(ts2)
|