feat: enforce Europe/Istanbul timezone, fix PWA image proxy, add Monday weekly login sync, and standardize English routes
This commit is contained in:
parent
56274f479b
commit
93f0bcb7a1
16 changed files with 851 additions and 175 deletions
|
|
@ -435,6 +435,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
const isWrong = q.status === 'wrong';
|
||||
const studentClass = isWrong ? 'answer-student-wrong' : 'answer-student-empty';
|
||||
const studentText = isWrong ? q.studentAnswer : t('exams.emptyAnswerText');
|
||||
const imgSrc = toProxiedImageUrl(q.imageUrl);
|
||||
|
||||
html += `
|
||||
<div class="question-card">
|
||||
|
|
@ -453,10 +454,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
</div>
|
||||
|
||||
${
|
||||
q.imageUrl
|
||||
imgSrc
|
||||
? `
|
||||
<div class="question-img-wrapper" title="${escapeHtml(t('exams.zoomHint'))}">
|
||||
<img src="${escapeHtml(q.imageUrl)}" alt="Soru ${q.questionNumber}" class="question-img" loading="lazy" />
|
||||
<img src="${escapeHtml(imgSrc)}" alt="Soru ${q.questionNumber}" class="question-img" loading="lazy" />
|
||||
</div>
|
||||
`
|
||||
: `<div class="text-muted small">${escapeHtml(t('exams.noImage'))}</div>`
|
||||
|
|
@ -503,8 +504,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Utility: Escape HTML
|
||||
// Utility: Proxy Portal Images & Escape HTML
|
||||
// ----------------------------------------------------
|
||||
function toProxiedImageUrl(rawUrl) {
|
||||
if (!rawUrl) return '';
|
||||
if (rawUrl.startsWith('/api/image-proxy?url=')) return rawUrl;
|
||||
if (rawUrl.includes('ozelbursakulturokullari.com')) {
|
||||
return `/api/image-proxy?url=${encodeURIComponent(rawUrl)}`;
|
||||
}
|
||||
return rawUrl;
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
if (!str) return '';
|
||||
return str
|
||||
|
|
|
|||
60
public/sw.js
60
public/sw.js
|
|
@ -1,4 +1,4 @@
|
|||
const CACHE_NAME = 'bekultur-v3';
|
||||
const CACHE_NAME = 'bekultur-v4';
|
||||
|
||||
const STATIC_ASSETS = [
|
||||
'/',
|
||||
|
|
@ -57,19 +57,52 @@ self.addEventListener('fetch', (event) => {
|
|||
|
||||
const url = new URL(req.url);
|
||||
|
||||
// Allow caching question images from panel.ozelbursakulturokullari.com
|
||||
const isQuestionImage =
|
||||
url.origin.includes('ozelbursakulturokullari.com') &&
|
||||
(url.pathname.endsWith('.png') || url.pathname.endsWith('.jpg') || url.pathname.endsWith('.jpeg') || url.pathname.includes('/soru/'));
|
||||
// Check if this is an E-Kültür portal image (either direct or via same-origin proxy)
|
||||
const isDirectPortalAsset =
|
||||
url.hostname === 'ozelbursakulturokullari.com' ||
|
||||
url.hostname.endsWith('.ozelbursakulturokullari.com');
|
||||
|
||||
// Ignore cross-origin external analytics or fonts
|
||||
if (url.origin !== self.location.origin && !isQuestionImage) {
|
||||
const isProxiedImage =
|
||||
url.origin === self.location.origin &&
|
||||
url.pathname === '/api/image-proxy';
|
||||
|
||||
// Ignore unrelated cross-origin requests
|
||||
if (url.origin !== self.location.origin && !isDirectPortalAsset) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Static Assets & Question Images -> Cache-First
|
||||
// 1. Portal Images (Direct or Proxied) -> Route via /api/image-proxy, Cache Verified 200 OK Images
|
||||
if (isDirectPortalAsset || isProxiedImage) {
|
||||
const proxyUrl = isDirectPortalAsset
|
||||
? `${self.location.origin}/api/image-proxy?url=${encodeURIComponent(req.url)}`
|
||||
: req.url;
|
||||
const proxyReq = new Request(proxyUrl, { credentials: 'same-origin' });
|
||||
|
||||
event.respondWith(
|
||||
caches.match(proxyReq).then((cachedResponse) => {
|
||||
if (cachedResponse && cachedResponse.status === 200) {
|
||||
return cachedResponse;
|
||||
}
|
||||
return fetch(proxyReq)
|
||||
.then((networkResponse) => {
|
||||
if (networkResponse && networkResponse.ok && networkResponse.status === 200) {
|
||||
const clone = networkResponse.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(proxyReq, clone));
|
||||
}
|
||||
return networkResponse;
|
||||
})
|
||||
.catch(async () => {
|
||||
const fallback = await caches.match(proxyReq);
|
||||
if (fallback) return fallback;
|
||||
return new Response('', { status: 404, statusText: 'Image unavailable offline' });
|
||||
});
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Local Static Assets -> Cache-First (only caching verified 200 OK responses)
|
||||
const isStatic =
|
||||
isQuestionImage ||
|
||||
url.pathname.startsWith('/css/') ||
|
||||
url.pathname.startsWith('/js/') ||
|
||||
url.pathname.startsWith('/icons/') ||
|
||||
|
|
@ -81,25 +114,22 @@ self.addEventListener('fetch', (event) => {
|
|||
if (isStatic) {
|
||||
event.respondWith(
|
||||
caches.match(req).then((cachedResponse) => {
|
||||
if (cachedResponse) {
|
||||
if (cachedResponse && cachedResponse.status === 200) {
|
||||
return cachedResponse;
|
||||
}
|
||||
return fetch(req).then((networkResponse) => {
|
||||
if (networkResponse && (networkResponse.status === 200 || networkResponse.type === 'opaque')) {
|
||||
if (networkResponse && networkResponse.ok && networkResponse.status === 200) {
|
||||
const clone = networkResponse.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(req, clone));
|
||||
}
|
||||
return networkResponse;
|
||||
}).catch(() => {
|
||||
// If question image fails offline and not cached, return empty placeholder
|
||||
return new Response('', { status: 404, statusText: 'Not found offline' });
|
||||
});
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Navigation Pages & API GETs -> Network-First with Cache Fallback
|
||||
// 3. Navigation Pages & API GETs -> Network-First with Cache Fallback
|
||||
event.respondWith(
|
||||
fetch(req)
|
||||
.then((networkResponse) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue