441 unmodified lines
Expand all
recordCid: string,
options?: {
forceRewriteHtml?: boolean;
skipInvalidation?: boolean;
forceDownload?: boolean;
}
): Promise<void> {
const forceRewriteHtml = options?.forceRewriteHtml === true;
const forceDownload = options?.forceDownload === true;
logger.info(`Processing site ${did}/${rkey}`, {
recordCid,
forceRewriteHtml,
forceDownload,
});
if (!record.root?.entries) {
logger.error('Invalid record structure');
// Find new or changed files
for (const file of newFiles) {
const shouldForceRewrite = forceRewriteHtml && isHtmlFile(file.path);
if (oldFileCids[file.path] !== file.cid || shouldForceRewrite) {
if (forceDownload || oldFileCids[file.path] !== file.cid || shouldForceRewrite) {
filesToDownload.push(file);
}
}
// Backfill settings if a record exists for this rkey
const settingsRecord = await fetchSettingsRecord(did, rkey, pdsEndpoint);
if (settingsRecord) {
await handleSettingsUpdate(did, rkey, settingsRecord.record, settingsRecord.cid);
await handleSettingsUpdate(did, rkey, settingsRecord.record, settingsRecord.cid, {
skipInvalidation: options?.skipInvalidation,
});
}
// Notify hosting-service to invalidate its local caches
// (skip for revalidate/backfill since hosting-service already has the files locally)
/**
* Handle settings create/update event
*/
export async function handleSettingsUpdate(did: string, rkey: string, settings: WispSettings, recordCid: string): Promise<void> {
export async function handleSettingsUpdate(
did: string,
rkey: string,
settings: WispSettings,
recordCid: string,
options?: { skipInvalidation?: boolean }
): Promise<void> {
logger.info(`Updating settings for ${did}/${rkey}`);
await upsertSiteSettingsCache(did, rkey, recordCid, {
directoryListing: settings.directoryListing,
headers: settings.headers,
});
// Notify hosting-service to invalidate its local caches (redirect rules depend on settings)
if (!options?.skipInvalidation) {
await publishCacheInvalidation(did, rkey, 'settings');
await publishCacheInvalidation(did, rkey, 'settings');
}
}
/**
* Handle settings delete event