Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nx/blocks/loc/project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const getHtml = async (path, html) => {
};

const str = html || await fetchHtml(path);
if (!str) return null;
return PARSER.parseFromString(collapseInnerTextSpaces(str), 'text/html');
};

Expand Down
36 changes: 35 additions & 1 deletion nx/blocks/snapshot-admin/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,19 @@ function formatResources(name, resources) {
}));
}

function pathnameAllowedForSnapshot(pathname) {
if (pathname.endsWith('.html')
|| pathname.endsWith('.json')
|| pathname.endsWith('.svg')) return true;
const basename = pathname.slice(pathname.lastIndexOf('/') + 1);
return !/\.[^./]+$/.test(basename);
}

function filterPaths(hrefs) {
return hrefs.reduce((acc, href) => {
try {
const { pathname } = new URL(href);
if (!pathnameAllowedForSnapshot(pathname)) return acc;
acc.push(pathname.endsWith('.html') ? pathname.replace('.html', '') : pathname);
} catch {
// do nothing
Expand Down Expand Up @@ -189,9 +198,34 @@ export function appendHtmlUnlessExtension(pathname) {
return /\.[^./]+$/.test(basename) ? pathname : `${pathname}.html`;
}

async function directDaCopy(url) {
const srcResp = await daFetch(`${DA_ORIGIN}/source${url.source}`);
if (!srcResp.ok) {
url.status = 'error';
return;
}
const data = await srcResp.arrayBuffer();
let type = srcResp.headers.get('content-type')?.split(';')[0]?.trim() || '';
if (!type || type === 'text/plain') {
type = url.destination.includes('.json') ? 'application/json' : 'application/octet-stream';
}
const blob = new Blob([data], { type });
const body = new FormData();
body.append('data', blob);
const resp = await daFetch(`${DA_ORIGIN}/source${url.destination}`, {
method: 'POST',
body,
});
url.status = resp.ok ? 'success' : 'error';
}

export async function copyManifest(name, resources, direction, mode = 'merge') {
const copyUrl = async (url) => {
if (mode === 'overwrite' || !url.source.endsWith('.html')) {
if (!url.source.endsWith('.html')) {
await directDaCopy(url);
return;
}
if (mode === 'overwrite') {
await overwriteCopy(url, `Snapshot ${direction}`);
} else {
const labels = (direction === 'fork')
Expand Down
Loading