Skip to content

Commit 5864559

Browse files
authored
Merge pull request #116 from codeitcodes/dev
Dev
2 parents 3f768e5 + b963f75 commit 5864559

File tree

12 files changed

+106
-40
lines changed

12 files changed

+106
-40
lines changed

api-link-parser.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ function decodeLink(url) {
2323
const isGithub = url.startsWith('https://github.com/');
2424
if (isGithub) url = url.slice('https://github.com/'.length);
2525

26+
// if link is a Git URL
27+
if (isGithub && url.endsWith('.git')) {
28+
29+
// slice .git ending
30+
url = url.slice(0, -('.git'.length));
31+
32+
}
33+
2634

2735
let baseURL = 'https://codeit.codes';
2836
if (isDev) baseURL = 'https://dev.codeit.codes';
@@ -106,7 +114,7 @@ function decodeLink(url) {
106114
} else {
107115

108116
// show codeit link
109-
linkData.redirect = baseURL;
117+
linkData.redirect = baseURL + '/full';
110118
linkData.redirectText = 'Open Codeit';
111119

112120
}
@@ -144,6 +152,8 @@ function decodeLink(url) {
144152

145153
}
146154

155+
if (isEmbed) resp += '&embed=true';
156+
147157

148158
return resp;
149159

api/link.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ const html = `
9292
9393
const isDev = (window.location.hostname === 'dev.codeit.codes');
9494
95-
if (link && !link.startsWith('https://cde.run')
96-
&& !link.startsWith('https://dev.cde.run')) {
95+
if (link && link.startsWith('https:/github.com')) {
9796
98-
if (!isDev) link = 'https://cde.run/' + link;
99-
else link = 'https://dev.cde.run/' + link;
97+
link = link.replace('https:/github.com', 'https://github.com');
10098
10199
}
102100
103-
if (link && link.startsWith('https:/github.com')) {
101+
if (link && !link.startsWith('https://cde.run')
102+
&& !link.startsWith('https://dev.cde.run')) {
104103
105-
link = link.replace('https:/github.com', 'https://github.com');
104+
if (!isDev) link = 'https://cde.run/' + link;
105+
else link = 'https://dev.cde.run/' + link;
106106
107107
}
108108

api/oembed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function handler(request, response) {
1515

1616
html = `
1717
<oembed>
18-
<html><iframe src="`+ url +`/api/link?url=`+ query.url +`&embed=true" width="700" height="480"></html>
18+
<html><iframe src="`+ url +`/api/link?url=`+ query.url +`&embed=true" width="700" height="480"></iframe></html>
1919
<width>700</width>
2020
<height>480</height>
2121
</oembed>

filebrowser.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ async function renderSidebarHTML() {
176176
// show title
177177
sidebarLogo.innerText = 'Repositories';
178178

179+
// hide branch button
180+
sidebarBranch.classList.remove('visible');
181+
179182

180183
// scroll to start of title
181184
sidebarLogo.scrollTo(0, 0);
@@ -206,6 +209,9 @@ async function renderSidebarHTML() {
206209
// change sidebar title
207210
sidebarLogo.innerText = 'Repositories';
208211

212+
// hide branch button
213+
sidebarBranch.classList.remove('visible');
214+
209215
// scroll to start of repo name
210216
sidebarLogo.scrollTo(0, 0);
211217
scrolledSidebarTitle();
@@ -413,6 +419,9 @@ async function renderSidebarHTML() {
413419
// show title
414420
sidebarLogo.innerText = 'Repositories';
415421

422+
// hide branch button
423+
sidebarBranch.classList.remove('visible');
424+
416425
// scroll to start of repo name
417426
sidebarLogo.scrollTo(0, 0);
418427
sidebarLogo.classList.add('notransition');
@@ -567,9 +576,6 @@ async function renderSidebarHTML() {
567576
// change header options
568577
header.classList.add('out-of-repo');
569578

570-
// hide branch button
571-
sidebarBranch.classList.remove('visible');
572-
573579

574580
// get rendered repos
575581
let renderedRepos = {};
@@ -642,7 +648,9 @@ async function renderSidebarHTML() {
642648
const modRepo = modifiedRepos[modRepoName];
643649

644650
// if repo isn't rendered
645-
if (!renderedRepos[modRepoName]) {
651+
// and user has push access in repo
652+
if (!renderedRepos[modRepoName]
653+
&& modRepo.pushAccess) {
646654

647655
// render repo
648656

@@ -1260,7 +1268,7 @@ async function renderBranchMenuHTML(renderAll) {
12601268
// check if repository object exists
12611269

12621270
const fullName = user + '/' + repoName;
1263-
const repoObj = modifiedRepos[fullName];
1271+
let repoObj = modifiedRepos[fullName];
12641272

12651273
let branchResp;
12661274

@@ -1329,16 +1337,20 @@ async function renderBranchMenuHTML(renderAll) {
13291337
// if selected branch is not defined
13301338
if (!selectedBranch) {
13311339

1340+
repoObj = modifiedRepos[fullName];
1341+
13321342
// if default branch isn't fetched yet
13331343
if (!repoObj.selBranch) {
1334-
1344+
13351345
// await fetch
13361346
await repoPromise;
1337-
1347+
1348+
repoObj = modifiedRepos[fullName];
1349+
13381350
}
13391351

13401352
// add branch to tree
1341-
treeLoc[1] = repo.split(':')[0] + ':' + repoObj.selBranch;
1353+
treeLoc[1] = repo + ':' + repoObj.selBranch;
13421354
saveTreeLocLS(treeLoc);
13431355

13441356
// update selected branch

full.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<link rel="canonical" href="https://codeit.codes/">
3939
<meta name="next-head-count" content="24">
4040
<meta name="robots" content="all">
41-
<script nonce>if (top != window && !document.referrer.startsWith(window.location.origin)) { top.location.href = window.location.href }</script>
4241
<script defer data-domain="codeit.codes" src="https://plausible.io/js/plausible.js"></script>
4342

4443
<link rel="shortcut icon" href="/icons/android-app-512.png">

git/gitauth.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,4 @@ async function getGithubToken(gitCode) {
134134
renderSidebarHTML();
135135

136136
}
137+

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<link rel="canonical" href="https://codeit.codes/">
4040
<meta name="next-head-count" content="24">
4141
<meta name="robots" content="all">
42-
<script nonce>if (top != window) { top.location.href = 'https://codeit.codes/' }</script>
42+
<script nonce>if (top !== window) { top.location.href = 'https://codeit.codes/' }</script>
4343
<script defer data-domain="codeit.codes" src="https://plausible.io/js/plausible.js"></script>
4444

4545
<link rel="shortcut icon" href="/icons/android-app-512.png">

links.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ function decodeLink(url) {
104104

105105
}
106106

107+
if (link.get('embed')) {
108+
109+
linkData.embed = true;
110+
111+
}
112+
107113

108114

109115
// legacy link type

live-view/live-view.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// setup live view
33
async function setupLiveView() {
44

5+
// if link is embed
6+
if (linkData.embed) {
7+
body.classList.add('embed');
8+
}
9+
510
// if URL has a file
611
if (linkData.file) {
712

@@ -832,6 +837,15 @@ async function renderLiveViewHTML(file) {
832837
}
833838

834839

840+
// if service worker isn't installed yet
841+
if (workerInstallPromise) {
842+
843+
// wait until finished installing
844+
await workerInstallPromise;
845+
846+
}
847+
848+
835849
liveView.innerHTML = '<iframe src="'+ livePath +'" name="' + file.name + '" title="' + file.name + '" class="live-frame" 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>';
836850

837851

service-worker.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,11 @@ const FILES_TO_CACHE = [
5353

5454
];
5555

56-
self.addEventListener('install', (evt) => {
57-
58-
// precache static resources
59-
evt.waitUntil(
60-
caches.open(WORKER_NAME).then((cache) => {
61-
return cache.addAll(FILES_TO_CACHE);
62-
})
63-
);
64-
65-
self.skipWaiting();
66-
67-
});
68-
6956
self.addEventListener('activate', (evt) => {
70-
57+
58+
self.clients.claim();
59+
60+
7161
// remove previous cached data from disk
7262
evt.waitUntil(
7363
caches.keys().then((keyList) => {
@@ -78,13 +68,20 @@ self.addEventListener('activate', (evt) => {
7868
}));
7969
})
8070
);
71+
72+
// precache static resources
73+
evt.waitUntil(
74+
caches.open(WORKER_NAME).then((cache) => {
75+
return cache.addAll(FILES_TO_CACHE);
76+
})
77+
);
8178

82-
self.clients.claim();
79+
self.skipWaiting();
8380

8481

8582
// send reload request to client
86-
workerChannel.postMessage({
83+
/*workerChannel.postMessage({
8784
type: 'reload'
88-
});
85+
});*/
8986

9087
});

0 commit comments

Comments
 (0)