Fix node asset cache busting

This commit is contained in:
cyph3rasi
2026-03-07 20:32:30 -08:00
parent 588307d21e
commit 2acebc15a5
6 changed files with 45 additions and 6 deletions
+6
View File
@@ -65,6 +65,12 @@ export async function PATCH(req: NextRequest) {
if (data.faviconData !== undefined) {
updateData.faviconData = data.faviconData;
}
if (data.logoUrl === '') {
updateData.logoData = null;
}
if (data.faviconUrl === '') {
updateData.faviconData = null;
}
[node] = await db.update(nodes)
.set(updateData)
+10 -4
View File
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';
import { db, nodes } from '@/db';
import { eq } from 'drizzle-orm';
import { requireAdmin } from '@/lib/auth/admin';
import { getVersionedNodeAssetUrl } from '@/lib/node/assets';
// Logo constraints
const MAX_LOGO_SIZE = 2 * 1024 * 1024; // 2MB
@@ -112,9 +113,14 @@ export async function POST(req: NextRequest) {
}
// Update the appropriate field
const updateData = isLogo
? { logoData: dataUrl, logoUrl: `/api/node/logo`, updatedAt: new Date() }
: { faviconData: dataUrl, faviconUrl: `/api/node/favicon`, updatedAt: new Date() };
const updatedAt = new Date();
const assetUrl = isLogo
? getVersionedNodeAssetUrl('/api/node/logo', updatedAt)
: getVersionedNodeAssetUrl('/api/node/favicon', updatedAt);
const updateData = isLogo
? { logoData: dataUrl, logoUrl: assetUrl, updatedAt }
: { faviconData: dataUrl, faviconUrl: assetUrl, updatedAt };
await db.update(nodes)
.set(updateData)
@@ -122,7 +128,7 @@ export async function POST(req: NextRequest) {
return NextResponse.json({
success: true,
url: isLogo ? '/api/node/logo' : '/api/node/favicon',
url: assetUrl,
type,
size: file.size,
});
+3 -1
View File
@@ -48,7 +48,9 @@ export async function GET() {
status: 200,
headers: {
'Content-Type': mimeType,
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
'Cache-Control': 'no-store, max-age=0',
Pragma: 'no-cache',
Expires: '0',
'Content-Length': buffer.length.toString(),
},
});
+3 -1
View File
@@ -48,7 +48,9 @@ export async function GET() {
status: 200,
headers: {
'Content-Type': mimeType,
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
'Cache-Control': 'no-store, max-age=0',
Pragma: 'no-cache',
Expires: '0',
'Content-Length': buffer.length.toString(),
},
});
+10
View File
@@ -3,6 +3,7 @@ import { db } from '@/db';
import { nodes, users } from '@/db';
import { eq, inArray } from 'drizzle-orm';
import { getNodePublicKey } from '@/lib/swarm/node-keys';
import { getVersionedNodeAssetUrl } from '@/lib/node/assets';
export async function GET() {
try {
@@ -58,8 +59,17 @@ export async function GET() {
});
}
const logoUrl = node.logoData
? getVersionedNodeAssetUrl('/api/node/logo', node.updatedAt)
: node.logoUrl;
const faviconUrl = node.faviconData
? getVersionedNodeAssetUrl('/api/node/favicon', node.updatedAt)
: node.faviconUrl;
return NextResponse.json({
...node,
logoUrl,
faviconUrl,
publicKey, // Always include the public key
admins,
// Don't expose the secret keys
+13
View File
@@ -0,0 +1,13 @@
export function getNodeAssetVersion(updatedAt: Date | string | null | undefined): string {
if (!updatedAt) {
return Date.now().toString();
}
const timestamp = new Date(updatedAt).getTime();
return Number.isNaN(timestamp) ? Date.now().toString() : timestamp.toString();
}
export function getVersionedNodeAssetUrl(path: string, updatedAt: Date | string | null | undefined): string {
const version = getNodeAssetVersion(updatedAt);
return `${path}?v=${encodeURIComponent(version)}`;
}