Skip to content

Commit 890b985

Browse files
authored
Merge pull request #166 from codeitcodes/dev
2 parents 128c8d0 + 9941c8a commit 890b985

File tree

6 files changed

+76
-39
lines changed

6 files changed

+76
-39
lines changed

api/_cors.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
export default async function handler(request, response) {
3+
4+
const https = require('https');
5+
6+
console.log(request);
7+
8+
const {status, data} = await getRequest(decodeURIComponent(request.query.url));
9+
10+
response.status(status).send(data);
11+
12+
13+
function getRequest(url) {
14+
15+
return new Promise(resolve => {
16+
17+
const req = https.get(url, (resp) => {
18+
19+
let data = '';
20+
21+
resp.on('data', (chunk) => {
22+
23+
data += chunk;
24+
25+
});
26+
27+
resp.on('end', () => {
28+
29+
resolve({status: resp.statusCode, data: data});
30+
31+
});
32+
33+
});
34+
35+
});
36+
37+
}
38+
39+
}

api/oembed.js

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

44
const query = request.query;
55

6-
let html = 'Try adding a <code>?url=</code>.';
6+
let json = { "error": "Try adding a URL" };
77

88
if (query.url) {
99

@@ -13,17 +13,23 @@ export default function handler(request, response) {
1313
url = 'https://dev.codeit.codes';
1414
}
1515

16-
html = `
17-
<oembed>
18-
<html><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>
19-
<width>700</width>
20-
<height>480</height>
21-
</oembed>
22-
`;
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>`;
17+
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+
};
2329

2430
}
2531

26-
response.status(200).send(html);
32+
response.status(200).json(json);
2733

2834
}
2935

full.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,9 @@ body:not(.mobile) .sidebar .header .title .branch-icon:active {
15041504
height: 50px;
15051505
width: 233px;
15061506
font-weight: 500;
1507+
}
1508+
1509+
body.mobile .sidebar .button {
15071510
transition: .1s var(--ease-function);
15081511
transition-property: background, color;
15091512
}

git/gitauth.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ async function getGithubToken(gitCode) {
143143

144144
// post through CORS proxy to git with clientId, clientSecret and code
145145
const resp = await axios.post('https://scepter-cors2.herokuapp.com/' +
146-
'https://github.com/login/oauth/access_token?' +
147-
'client_id=7ede3eed3185e59c042d' +
148-
'&client_secret=c1934d5aab1c957800ea8e84ce6a24dda6d68f45' +
149-
'&code=' + gitCode);
146+
'https://github.com/login/oauth/access_token?' +
147+
'client_id=7ede3eed3185e59c042d' +
148+
'&client_secret=c1934d5aab1c957800ea8e84ce6a24dda6d68f45' +
149+
'&code=' + gitCode);
150150

151151
// save git token to localStorage
152152
gitToken = resp.access_token;

git/gitlab/gitlab-auth.js

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,30 @@ window.onload = async () => {
7878

7979
window.addEventListener('message', (event) => {
8080

81-
// if redirected from git auth
82-
if (event.source.location.pathname === '/git/gitlab/oauth') {
83-
84-
// hide intro screen
85-
sidebar.classList.remove('intro');
81+
// hide intro screen
82+
sidebar.classList.remove('intro');
8683

87-
// if on safari, refresh header color
88-
if (isSafari) {
84+
// if on safari, refresh header color
85+
if (isSafari) {
8986

90-
document.querySelector('meta[name="theme-color"]').content = '#313744';
87+
document.querySelector('meta[name="theme-color"]').content = '#313744';
9188

92-
onNextFrame(() => {
89+
onNextFrame(() => {
9390

94-
document.querySelector('meta[name="theme-color"]').content = '#1a1c24';
91+
document.querySelector('meta[name="theme-color"]').content = '#1a1c24';
9592

96-
});
93+
});
9794

98-
}
95+
}
9996

100-
// start loading
101-
startLoading();
97+
// start loading
98+
startLoading();
10299

103-
const gitCode = event.data;
100+
const gitCode = event.data;
104101

105-
// get git token from Gitlab
106-
getGitlabToken(gitCode);
102+
// get git token from Gitlab
103+
getGitlabToken(gitCode);
107104

108-
}
109-
110105
})
111106

112107

@@ -171,9 +166,3 @@ async function getGitlabToken(gitCode) {
171166

172167
}
173168

174-
175-
176-
177-
178-
await axios.post('https://gitlab.com/oauth/token?client_id=&client_secret=&code=&&redirect_uri=https://codeit.codes/git/gitlab/oauth')
179-

worker/client-channel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
// update worker name when updating worker
7-
const WORKER_NAME = 'codeit-worker-v527';
7+
const WORKER_NAME = 'codeit-worker-v531';
88

99

1010
// internal paths

0 commit comments

Comments
 (0)