Skip to content

Commit 04dba27

Browse files
DevDev
authored andcommitted
a ver si funciona
1 parent e038ed9 commit 04dba27

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

.github/workflows/auto-index.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- 'public/1/**'
77
branches:
88
- main
9+
workflow_dispatch: # Permite ejecutarlo manualmente desde GitHub
910

1011
jobs:
1112
update-index:

astro.config.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { defineConfig } from 'astro/config';
2+
import cloudflare from '@astrojs/cloudflare';
23

34
export default defineConfig({
4-
output: 'static',
5-
// Eliminamos el adaptador de Cloudflare para que sea 100% estático
6-
// Cloudflare Pages servirá la carpeta dist/ automáticamente.
5+
output: 'server',
6+
adapter: cloudflare({
7+
platformProxy: {
8+
enabled: true,
9+
},
10+
}),
711
});

src/pages/api/files.json.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import type { APIRoute } from 'astro';
22
import fileIndex from '../../data/file-index.json';
33

4-
export const prerender = true;
4+
export const GET: APIRoute = ({ response }) => {
5+
// Evitar caché agresiva en la API
6+
response.headers.set('Cache-Control', 'no-cache, no-store, must-revalidate');
7+
response.headers.set('Pragma', 'no-cache');
8+
response.headers.set('Expires', '0');
59

6-
export const GET: APIRoute = () => {
710
return new Response(JSON.stringify({
811
success: true,
912
count: fileIndex.length,

src/pages/index.astro

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
---
2-
import fileIndex from '../data/file-index.json';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
34
import UploadModal from '../components/UploadModal.astro';
45
5-
export const prerender = true;
6-
7-
// Ya no filtramos en el servidor, solo pasamos el índice al cliente
8-
const allItems = fileIndex;
6+
// Configuramos la respuesta para que no se cachee de forma agresiva
7+
Astro.response.headers.set('Cache-Control', 'no-cache, no-store, must-revalidate');
8+
Astro.response.headers.set('Pragma', 'no-cache');
9+
Astro.response.headers.set('Expires', '0');
10+
11+
// Leemos el índice directamente del sistema de archivos en cada petición
12+
const indexPath = path.join(process.cwd(), 'src/data/file-index.json');
13+
let allItems = [];
14+
try {
15+
const fileContent = fs.readFileSync(indexPath, 'utf-8');
16+
allItems = JSON.parse(fileContent);
17+
} catch (e) {
18+
console.error("Error leyendo file-index.json:", e);
19+
}
920
1021
function formatBytes(bytes: number): string {
1122
if (bytes === 0) return '0 Bytes';

0 commit comments

Comments
 (0)