|
|
|
@ -2,7 +2,7 @@ import type { RequestHandler } from './$types';
|
|
|
|
import { getDb } from '$lib/server/db';
|
|
|
|
import { getDb } from '$lib/server/db';
|
|
|
|
import { sha256Hex } from '$lib/server/crypto';
|
|
|
|
import { sha256Hex } from '$lib/server/crypto';
|
|
|
|
import { icsHorizonMonths } from '$lib/server/env';
|
|
|
|
import { icsHorizonMonths } from '$lib/server/env';
|
|
|
|
import { buildIcsCalendar } from '$lib/server/ics';
|
|
|
|
import { buildIcsCalendar, checkIcsRateLimit } from '$lib/server/ics';
|
|
|
|
import { toIsoSqlUTC, ymdUTC, addMonthsUTC } from '$lib/server/datetime';
|
|
|
|
import { toIsoSqlUTC, ymdUTC, addMonthsUTC } from '$lib/server/datetime';
|
|
|
|
|
|
|
|
|
|
|
|
export const GET: RequestHandler = async ({ params, request }) => {
|
|
|
|
export const GET: RequestHandler = async ({ params, request }) => {
|
|
|
|
@ -29,10 +29,14 @@ export const GET: RequestHandler = async ({ params, request }) => {
|
|
|
|
.prepare(`SELECT COALESCE(active,1) as active, COALESCE(archived,0) as archived, COALESCE(is_community,0) as is_community FROM groups WHERE id = ?`)
|
|
|
|
.prepare(`SELECT COALESCE(active,1) as active, COALESCE(archived,0) as archived, COALESCE(is_community,0) as is_community FROM groups WHERE id = ?`)
|
|
|
|
.get(row.group_id) as any;
|
|
|
|
.get(row.group_id) as any;
|
|
|
|
if (!gRow || Number(gRow.active || 0) !== 1 || Number(gRow.archived || 0) === 1 || Number(gRow.is_community || 0) === 1) {
|
|
|
|
if (!gRow || Number(gRow.active || 0) !== 1 || Number(gRow.archived || 0) === 1 || Number(gRow.is_community || 0) === 1) {
|
|
|
|
db.prepare(`UPDATE calendar_tokens SET last_used_at = ? WHERE id = ?`).run(toIsoSqlUTC(), row.id);
|
|
|
|
|
|
|
|
return new Response('Gone', { status: 410 });
|
|
|
|
return new Response('Gone', { status: 410 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rl = checkIcsRateLimit(tokenHash);
|
|
|
|
|
|
|
|
if (!rl.ok) {
|
|
|
|
|
|
|
|
return new Response('Too Many Requests', { status: 429, headers: { 'Retry-After': String(rl.retryAfterSec || 60) } });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const today = new Date();
|
|
|
|
const today = new Date();
|
|
|
|
const startYmd = ymdUTC(today);
|
|
|
|
const startYmd = ymdUTC(today);
|
|
|
|
const endYmd = ymdUTC(addMonthsUTC(today, icsHorizonMonths));
|
|
|
|
const endYmd = ymdUTC(addMonthsUTC(today, icsHorizonMonths));
|
|
|
|
@ -59,13 +63,11 @@ export const GET: RequestHandler = async ({ params, request }) => {
|
|
|
|
prefix: 'T'
|
|
|
|
prefix: 'T'
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
const { body, etag } = await buildIcsCalendar('Tareas sin responsable (grupo)', events);
|
|
|
|
const { body, etag } = await buildIcsCalendar('Wtask.org Tareas – Grupo', events);
|
|
|
|
|
|
|
|
|
|
|
|
// 304 si ETag coincide
|
|
|
|
// 304 si ETag coincide
|
|
|
|
const inm = request.headers.get('if-none-match');
|
|
|
|
const inm = request.headers.get('if-none-match');
|
|
|
|
if (inm && inm === etag) {
|
|
|
|
if (inm && inm === etag) {
|
|
|
|
// Actualizar last_used_at aunque sea 304
|
|
|
|
|
|
|
|
db.prepare(`UPDATE calendar_tokens SET last_used_at = ? WHERE id = ?`).run(toIsoSqlUTC(), row.id);
|
|
|
|
|
|
|
|
return new Response(null, { status: 304, headers: { ETag: etag, 'Cache-Control': 'public, max-age=300' } });
|
|
|
|
return new Response(null, { status: 304, headers: { ETag: etag, 'Cache-Control': 'public, max-age=300' } });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|