Skip to content

Commit

Permalink
Deactivate Netlify functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanasa committed Aug 22, 2023
1 parent 257fd15 commit c810df6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 92 deletions.
97 changes: 51 additions & 46 deletions netlify/functions/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,59 @@ const BASE_URLS = [
];

exports.handler = async (event, context) => {
const query = event.queryStringParameters;
const url = decodeURIComponent(query.url || '');
if (
!url ||
BASE_URLS.every(
(baseUrl) =>
!url.startsWith(baseUrl) ||
url.startsWith(`${baseUrl}/api`) ||
url.includes('.', baseUrl.length),
)
) {
return {
statusCode: 400,
body: 'Invalid embed link',
};
}
const format = query.format;
const defaultWidth = 800;
const width = +query.maxwidth || defaultWidth;
let height = +query.maxheight || 500;
try {
const match = /[?&]lines=([0-9]+)/.exec(url);
if (match) {
const [, lineCount] = match;
// height = Math.min(120 + lineCount * 24, height);
height = Math.min(145 + lineCount * 28, height);
}
} catch (err) {
console.error(err);
}
// const query = event.queryStringParameters;
// const url = decodeURIComponent(query.url || '');
// if (
// !url ||
// BASE_URLS.every(
// (baseUrl) =>
// !url.startsWith(baseUrl) ||
// url.startsWith(`${baseUrl}/api`) ||
// url.includes('.', baseUrl.length),
// )
// ) {
// return {
// statusCode: 400,
// body: 'Invalid embed link',
// };
// }
// const format = query.format;
// const defaultWidth = 800;
// const width = +query.maxwidth || defaultWidth;
// let height = +query.maxheight || 500;
// try {
// const match = /[?&]lines=([0-9]+)/.exec(url);
// if (match) {
// const [, lineCount] = match;
// // height = Math.min(120 + lineCount * 24, height);
// height = Math.min(145 + lineCount * 28, height);
// }
// } catch (err) {
// console.error(err);
// }

// const result = {
// version: '1.0',
// provider_name: 'Embed Motoko',
// provider_url: 'https://embed.motoko.org',
// type: 'rich',
// width,
// height,
// html: `<iframe src="${encodeXML(
// url,
// )}" width="${width}" height="${height}" style="border:0" />`,
// };
// return {
// statusCode: 200,
// body: format === 'xml' ? getXML(result) : JSON.stringify(result),
// headers: {
// 'Content-Type': format === 'xml' ? 'text/xml' : 'application/json',
// },
// };

const result = {
version: '1.0',
provider_name: 'Embed Motoko',
provider_url: 'https://embed.motoko.org',
type: 'rich',
width,
height,
html: `<iframe src="${encodeXML(
url,
)}" width="${width}" height="${height}" style="border:0" />`,
};
return {
statusCode: 200,
body: format === 'xml' ? getXML(result) : JSON.stringify(result),
headers: {
'Content-Type': format === 'xml' ? 'text/xml' : 'application/json',
},
statusCode: 400,
body: 'Maintenance in progress. Please check back soon.',
};
};

Expand Down
97 changes: 51 additions & 46 deletions netlify/functions/onebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,59 @@ const BASE_URLS = [
];

exports.handler = async (event, context) => {
const query = event.queryStringParameters;
const url = decodeURIComponent(query.url || '');
if (
!url ||
BASE_URLS.every(
(baseUrl) =>
!url.startsWith(baseUrl) ||
url.startsWith(`${baseUrl}/api`) ||
url.includes('.', baseUrl.length),
)
) {
return {
statusCode: 400,
body: 'Invalid embed link',
};
}
const format = query.format;
const defaultWidth = 695; // DFINITY Dev Forum iframe width
const width = +query.maxwidth || defaultWidth;
let height = +query.maxheight || 500;
try {
const match = /[?&]lines=([0-9]+)/.exec(url);
if (match) {
const [, lineCount] = match;
height = Math.min(120 + lineCount * 24, height);
// height = Math.min(140 + lineCount * 28, height);
}
} catch (err) {
console.error(err);
}
// const query = event.queryStringParameters;
// const url = decodeURIComponent(query.url || '');
// if (
// !url ||
// BASE_URLS.every(
// (baseUrl) =>
// !url.startsWith(baseUrl) ||
// url.startsWith(`${baseUrl}/api`) ||
// url.includes('.', baseUrl.length),
// )
// ) {
// return {
// statusCode: 400,
// body: 'Invalid embed link',
// };
// }
// const format = query.format;
// const defaultWidth = 695; // DFINITY Dev Forum iframe width
// const width = +query.maxwidth || defaultWidth;
// let height = +query.maxheight || 500;
// try {
// const match = /[?&]lines=([0-9]+)/.exec(url);
// if (match) {
// const [, lineCount] = match;
// height = Math.min(120 + lineCount * 24, height);
// // height = Math.min(140 + lineCount * 28, height);
// }
// } catch (err) {
// console.error(err);
// }

// const result = {
// version: '1.0',
// provider_name: 'Embed Motoko',
// provider_url: 'https://embed.motoko.org',
// type: 'rich',
// width,
// height,
// html: `<iframe src="${encodeXML(
// url,
// )}" width="${width}" height="${height}" style="border:0" />`,
// };
// return {
// statusCode: 200,
// body: format === 'xml' ? getXML(result) : JSON.stringify(result),
// headers: {
// 'Content-Type': format === 'xml' ? 'text/xml' : 'application/json',
// },
// };

const result = {
version: '1.0',
provider_name: 'Embed Motoko',
provider_url: 'https://embed.motoko.org',
type: 'rich',
width,
height,
html: `<iframe src="${encodeXML(
url,
)}" width="${width}" height="${height}" style="border:0" />`,
};
return {
statusCode: 200,
body: format === 'xml' ? getXML(result) : JSON.stringify(result),
headers: {
'Content-Type': format === 'xml' ? 'text/xml' : 'application/json',
},
statusCode: 400,
body: 'Maintenance in progress. Please check back soon.',
};
};

Expand Down

0 comments on commit c810df6

Please sign in to comment.