Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result page loading #41

Merged
merged 2 commits into from
Mar 19, 2024
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
97 changes: 68 additions & 29 deletions ai/src/main/ts/list-result-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ const targetRootFolder = '1AQUeaAGTFiwLtgyZif7Wfgj4mCU7v731';
const colorRegex = /-color(\d)\.\w{3,5}$/;
const shipNameRegex = /^(\w+_)?(.*)$/;

const missing = [
'1wHRKjZ9k1mGQqeVl2Nfa3WbiQmKcvLRi', // Interstellar Confluence Cruiser
'1D1yEy3vOcbIx64u2b3ZxEqunk8aT56eo', // Intercultural Research Voyager
'18SWHIV8c4rn9wk5lbZWMvbINiHr32kJo', // Intergalactic Research Ambassador
'1BoOeJNoHaLeFeA6RbHQz8w0uiAivEOSl', // Interstellar Harmony Explorer
'1jDxVe5cLe2r9dyzTn4dKkNVih8U_3c8N', // Leisure Interstellar Starliner
'1FUNPU6rkpU21hq6vdDKOZGRIURxwNVM0', // Planetary Observer
'1HyFQ_I9kZlC0W6-_TDqV-mqX614Fom1b', // Cultural Research Pulsar
'1YGKkm7GhvftuuT6FDIOmLAajojvHQfiG', // Leisure Confluence Starcruiser
'1kyBiq-ArPrDQ2cjO9NgTtBBxUsowrj52', // Observant Pathfinder
'1NzR34CBsWNQLvzsrMDHX--q-oNysABqZ', // Planetary Observer Pathfinder
'1LJwV1hnr5tDZo3Y9J0umcvQXyFG0E7bI', // TerraObservant Explorer
'18Vkp9NJrZWApEJ2MiXqzg_FauQ9HWrh2', // Stellar Recreation Voyager
];


async function list(): Promise<void> {
const focusResponse = await fetch('https://astrocraft.innovationlab.cx/focus/query-index.json');
const focuses = await focusResponse.json();
Expand All @@ -33,16 +49,17 @@ async function list(): Promise<void> {
supportsAllDrives: true,
includeItemsFromAllDrives: true,
});
if(shipResponse.data.files?.length === 1) {
if(missing.indexOf(shipFolder.id || '') >= 0 && shipResponse.data.files?.length === 1) {
const filesResponse = await service.files.list({
pageSize: 1000,
q: `'${(shipResponse.data.files || [])[0].id}' in parents and trashed=false`,
fields: 'nextPageToken, files(id, name, md5Checksum)',
spaces: 'drive',
supportsAllDrives: true,
includeItemsFromAllDrives: true,
});
const files = filesResponse.data.files
?.map((file) => {
?.map((file: any) => {
const match = file.name?.match(colorRegex);
if(!match) {
return null;
Expand Down Expand Up @@ -70,40 +87,62 @@ async function list(): Promise<void> {
supportsAllDrives: true,
includeItemsFromAllDrives: true,
});
let shipFolder;
if (folderList.data.files?.length !== 0) {
await service.files.update({
fileId: (folderList.data.files || [])[0].id || undefined,
const existingFiles = await service.files.list({
q: `trashed != true and '${(folderList.data.files || [])[0].id}' in parents`,
fields: 'nextPageToken, files(id, name, md5Checksum)',
spaces: 'drive',
supportsAllDrives: true,
includeItemsFromAllDrives: true,
});
if(existingFiles.data.files?.every((existingFile) => files.some((file) => file?.name === existingFile?.name && file?.md5Checksum === existingFile.md5Checksum))) {
shipFolder = (folderList.data.files || [])[0];
} else {
await service.files.update({
fileId: (folderList.data.files || [])[0].id || undefined,
supportsAllDrives: true,
requestBody : {
trashed: true,
},
});
}
}
const copyFiles = !shipFolder;
if(!shipFolder) {
shipFolder = (await service.files.create({
requestBody : {
trashed: true,
name: shipName,
mimeType: 'application/vnd.google-apps.folder',
parents: [targetRootFolder],
},
});
supportsAllDrives: true,
})).data;
}
const shipFolder = await service.files.create({
requestBody : {
name: shipName,
mimeType: 'application/vnd.google-apps.folder',
parents: [targetRootFolder],
},
supportsAllDrives: true,
});
queryIndex += `${focus.path};`
for(let file of files || []) {
await service.files.copy({
fileId: (file || {}).id || undefined,
supportsAllDrives: true,
requestBody: {
parents: [shipFolder.data.id || '']
}});
console.log('preview', `/configurations/images/${shipName?.toLowerCase().replaceAll(' ', '-')}/${file?.name?.toLowerCase().replaceAll(' ', '-')}`)
await fetch(`https://admin.hlx.page/preview/netcentric/edge-delivery-solari/main/configurations/images/${shipName?.toLowerCase().replaceAll(' ', '-')}/${file?.name?.toLowerCase().replaceAll(' ', '-')}`,
{ method: 'POST' });
console.log('publish')
const publishResponse = await fetch(`https://admin.hlx.page/live/netcentric/edge-delivery-solari/main/configurations/images/${shipName?.toLowerCase().replaceAll(' ', '-')}/${file?.name?.toLowerCase().replaceAll(' ', '-')}`,
{ method: 'POST' });
const publishData = await publishResponse.json();
const response = await fetch(publishData.live.url, {redirect: 'manual'});
queryIndex += `https://astrocraft.innovationlab.cx${response.headers.get('location')};`;
if(copyFiles) {
await service.files.copy({
fileId: (file || {}).id || undefined,
supportsAllDrives: true,
requestBody: {
parents: [shipFolder.id || '']
}});
}
const relativePath = `netcentric/edge-delivery-solari/main/configurations/images/${shipName?.toLowerCase().replaceAll(' ', '-')}/${file?.name?.toLowerCase().replaceAll(' ', '-')}`;
try {
console.log('preview', `/configurations/images/${relativePath}`)
await fetch(`https://admin.hlx.page/preview/${relativePath}`,
{ method: 'POST' });
console.log('publish')
const publishResponse = await fetch(`https://admin.hlx.page/live/${relativePath}`,
{ method: 'POST' });
const publishData = await publishResponse.json();
const response = await fetch(publishData.live.url, {redirect: 'manual'});
queryIndex += `https://astrocraft.innovationlab.cx${response.headers.get('location')};`;
} catch (e) {
console.error('ERROR publishing', relativePath, e);
}
};
queryIndex += '\n';
}
Expand Down
5 changes: 2 additions & 3 deletions scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,9 @@ function buildBlock(blockName, content) {
* @param {Element} block The block element
*/
async function loadBlock(block) {
const status = block.dataset.blockStatus;
if (status !== 'loading' && status !== 'loaded') {
const { blockName, status } = block.dataset;
if (blockName && status !== 'loading' && status !== 'loaded') {
block.dataset.blockStatus = 'loading';
const { blockName } = block.dataset;
try {
const cssLoaded = loadCSS(`${window.hlx.codeBasePath}/blocks/${blockName}/${blockName}.css`);
const decorationComplete = new Promise((resolve) => {
Expand Down
9 changes: 1 addition & 8 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,7 @@ async function prepareSpecification() {
const isEngineFocus = !isShipFocus && isTemplate('engine-focus');
const isConfigurationResult = !isShipFocus && !isEngineFocus && isTemplate('configuration-result');
try {
const configurationsPromise = isConfigurationResult && fetch('https://main--edge-delivery-solari--netcentric.hlx.page/configurations.json', {
mode: 'no-cors',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
},
});
const configurationsPromise = isConfigurationResult && fetch('/configurations.json', { cache: 'no-cache' });

if (!isShipFocus && !isEngineFocus && !isConfigurationResult) {
return;
Expand Down
Loading