Skip to content

Commit 0a0827f

Browse files
committed
Update oembed.js
1 parent 5942cd6 commit 0a0827f

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

api/oembed.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ export default function handler(request, response) {
33

44
const query = request.query;
55

6-
let json = { "error": "Try adding a URL" };
6+
const isJSON = query.format ? query.format === 'json' : false;
7+
8+
9+
let resp;
10+
11+
if (isJSON) resp = { "error": "Try adding a URL" };
12+
else resp = 'Try adding a <code>?url=</code>.';
13+
714

815
if (query.url) {
916

@@ -13,23 +20,42 @@ export default function handler(request, response) {
1320
url = 'https://dev.codeit.codes';
1421
}
1522

16-
const embedHTML = `<iframe src="`+ url +`/api/link?url=`+ query.url +`&embed=true" width="700" height="480" style="border-radius: 10px;" allow="accelerometer; camera; encrypted-media; display-capture; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write" allowfullscreen="true" allowpaymentrequest="true" loading="lazy" sandbox="allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-same-origin allow-scripts allow-top-navigation-by-user-activation" scrolling="yes" frameborder="0"></iframe></html>`;
23+
url += '/api/link?url=' + query.url + '&oembed=true';
1724

18-
json = {
19-
"type": "rich",
20-
"title": "Codeit",
21-
"width": 700,
22-
"height": 480,
23-
"html": embedHTML,
24-
"version": "1.0",
25-
"cache_age": 3600,
26-
"provider_name": "Codeit",
27-
"provider_url": "https://codeit.codes/"
28-
};
25+
const embedHTML = `<iframe src="`+ url +`" width="700" height="480" style="border-radius: 10px;" allow="accelerometer; camera; encrypted-media; display-capture; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write" allowfullscreen="true" allowpaymentrequest="true" loading="lazy" sandbox="allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-same-origin allow-scripts allow-top-navigation-by-user-activation" scrolling="yes" frameborder="0"></iframe></html>`;
2926

30-
}
3127

32-
response.status(200).json(json);
28+
if (isJSON) {
29+
30+
resp = {
31+
"type": "rich",
32+
"title": "Codeit",
33+
"width": 700,
34+
"height": 480,
35+
"html": embedHTML,
36+
"version": "1.0",
37+
"cache_age": 3600,
38+
"provider_name": "Codeit",
39+
"provider_url": "https://codeit.codes/"
40+
};
41+
42+
} else {
43+
44+
resp = `
45+
<oembed>
46+
<html>`+ embedHTML +`</html>
47+
<width>700</width>
48+
<height>480</height>
49+
</oembed>
50+
`;
51+
52+
}
53+
54+
}
55+
56+
57+
if (isJSON) response.status(200).json(resp);
58+
else response.status(200).html(resp);
3359

3460
}
3561

0 commit comments

Comments
 (0)