Skip to content

Commit

Permalink
failsafe on big course imports
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Aug 16, 2023
1 parent a5c3170 commit fe93dd5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
31 changes: 20 additions & 11 deletions api/apps/haxcms/convert/elmslnToSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,33 @@ export default async function handler(req, res) {
site = await resolveSiteData(base);
// use legit prop or just pull off the url
siteName = (site.metadata && site.metadata.site && site.metadata.site.name) ? site.metadata.site.name : parseURL.pathname.split('/').pop();
// note location includes base path of site bc of nature of how system builds base URIs
let __fetchOptions = {
method: "GET",
};
// test for aanda elms as "basic auth" is required to bypass azure
// and defer to app level permissions handling
if (url.includes('.aanda.psu.edu') || url.includes('.ed.science.psu.edu')) {
let buff = Buffer.from(process.env.ELMSLN_VERCEL_SERVICE_AUTH).toString('base64');
__fetchOptions.headers = {'Authorization': 'Basic ' + buff};
}
var elapsed;
var all = 0;
for await (const item of site.items) {
// note location includes base path of site bc of nature of how system builds base URIs
let __fetchOptions = {
method: "GET",
};
// test for aanda elms as "basic auth" is required to bypass azure
// and defer to app level permissions handling
if (url.includes('.aanda.psu.edu') || url.includes('.ed.science.psu.edu')) {
let buff = Buffer.from(process.env.ELMSLN_VERCEL_SERVICE_AUTH).toString('base64');
__fetchOptions.headers = {'Authorization': 'Basic ' + buff};
elapsed = process.hrtime()[1] / 100000000;
if (all < 55) {
item.contents = await fetch(`http://${process.env.VERCEL_URL}/api/services/website/cacheAddress?q=${base}/${item.location.replace(`/${siteName}/`,'')}`, __fetchOptions).then((d) => d.ok ? d.json() : '').then((r) => r.data);
}
else {
item.contents = `<p>get source from <a href="${base}/${item.location.replace(`/${siteName}/`,'')}" target="_blank">${base}/${item.location.replace(`/${siteName}/`,'')}</a></p>`;
}
item.contents = await fetch(`${base}/${item.location.replace(`/${siteName}/`,'')}`,__fetchOptions).then((d) => d.ok ? d.text(): '');
console.log(item.contents);
if (item.metadata && item.metadata.files) {
for await (const file of item.metadata.files) {
downloads[file.url] = `${base}/${file.url}`;
}
}
elapsed = process.hrtime()[1] / 100000000;
all = all+elapsed;
}
}
res = stdResponse(res, {
Expand Down
12 changes: 11 additions & 1 deletion api/services/website/cacheAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ export default async function handler(req, res) {
}
let content;
try {
content = await fetch(req.query.q).then((d) => d.ok ? d.text(): '');
// note location includes base path of site bc of nature of how system builds base URIs
let __fetchOptions = {
method: "GET",
};
// test for aanda elms as "basic auth" is required to bypass azure
// and defer to app level permissions handling
if (req.query.q.includes('.aanda.psu.edu') || req.query.q.includes('.ed.science.psu.edu')) {
let buff = Buffer.from(process.env.ELMSLN_VERCEL_SERVICE_AUTH).toString('base64');
__fetchOptions.headers = {'Authorization': 'Basic ' + buff};
}
content = await fetch(req.query.q, __fetchOptions).then((d) => d.ok ? d.text(): '');
}
catch {
content = '';
Expand Down
6 changes: 3 additions & 3 deletions elements/app-hax/app-hax.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Window size: ${window.innerWidth}x${window.innerHeight}
icon: "hax:hax2022",
tags: ["Sites", "Administration", "change"],
eventName: "super-daemon-run-program",
path: "hax/action/goToSite",
path: "HAX/action/goToSite",
value: {
name: "Go to site",
program: async (input, values) => {
Expand Down Expand Up @@ -323,9 +323,9 @@ Window size: ${window.innerWidth}x${window.innerHeight}
eventName: "super-daemon-element-method",
context: [
"*",
"hax/action/goToSite/" + site.metadata.site.name,
"HAX/action/goToSite/" + site.metadata.site.name,
],
path: "hax/action/goToSite/" + site.metadata.site.name,
path: "HAX/action/goToSite/" + site.metadata.site.name,
});
}
});
Expand Down

1 comment on commit fe93dd5

@vercel
Copy link

@vercel vercel bot commented on fe93dd5 Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.