Skip to content

Commit

Permalink
Merge branch 'haxtheweb:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zdodson21 authored Jun 24, 2024
2 parents d547fb9 + 5c16c9d commit 075cca7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
55 changes: 29 additions & 26 deletions api/apps/haxcms/aiChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,39 @@ export default async function handler(req, res) {
else {
body = stdPostBody(req);
}
if (body.question && body.type && body.site.file) {
// get URL bits for validating and forming calls
let url = '';
url = body.site.file.replace('/site.json', '');
// handle trailing slash
if (url.endsWith('/')) {
url = url.slice(0, -1);
}
try {
var parseURL = new URL(url);
// verify we have a path / host
if (parseURL.pathname && parseURL.host) {
// support for iam vs oer
if (parseURL.host) {
// specific to our instances but iam is going to block access when querying for the site content
// iam is the authoring domain while oer is the openly available one which if printing
// and rendering the content appropriately, this is the way to do it
parseURL.host = parseURL.host.replace('iam.', 'oer.');
// either need a context OR a site file to know which to request
if (body.question && ((body.site && body.site.file) || body.context)) {
if (body.site && body.site.file) {
// get URL bits for validating and forming calls
let url = '';
url = body.site.file.replace('/site.json', '');
// handle trailing slash
if (url.endsWith('/')) {
url = url.slice(0, -1);
}
try {
var parseURL = new URL(url);
// verify we have a path / host
if (parseURL.pathname && parseURL.host) {
// support for iam vs oer
if (parseURL.host) {
// specific to our instances but iam is going to block access when querying for the site content
// iam is the authoring domain while oer is the openly available one which if printing
// and rendering the content appropriately, this is the way to do it
parseURL.host = parseURL.host.replace('iam.', 'oer.');
}
const base = `${parseURL.protocol}//${parseURL.host}${parseURL.pathname}`;
const siteManifest = await resolveSiteData(base);
context = siteManifest.metadata.site.name;
}
const base = `${parseURL.protocol}//${parseURL.host}${parseURL.pathname}`;
const siteManifest = await resolveSiteData(base);
context = siteManifest.metadata.site.name;
}
// support definition in post
if (body.context) {
context = body.context;
catch(e) {
console.warn('invalid url');
}
}
catch(e) {
console.warn('invalid url');
// support definition in post
if (body.context) {
context = body.context;
}
// hard code to switch context on the fly
//context = "haxcellence";
Expand Down
2 changes: 1 addition & 1 deletion elements/haxcms-elements/demo/wc-registry.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wc-registry.json

Large diffs are not rendered by default.

0 comments on commit 075cca7

Please sign in to comment.