diff --git a/codedrop.js b/codedrop.js index d6406405f4..a037a3a687 100644 --- a/codedrop.js +++ b/codedrop.js @@ -1,3 +1,4 @@ + function getFileLang(src) { var lang_aliases = /*aliases_placeholder[*/ { diff --git a/filebrowser.js b/filebrowser.js index 112dfd15b3..b5d2502326 100644 --- a/filebrowser.js +++ b/filebrowser.js @@ -1,6 +1,3 @@ -/* - github -*/ // show bookmark on hover sidebarToggle.addEventListener('mouseover', () => { diff --git a/full.html b/full.html index c752f01e97..6dbc7ec37b 100644 --- a/full.html +++ b/full.html @@ -13,25 +13,27 @@ - - + + - + - - - + + + - + + + + - - + + - - - + + @@ -40,15 +42,15 @@ + + - - - +
diff --git a/git/gitauth.js b/git/gitauth.js index 498862d19e..857f91d0aa 100644 --- a/git/gitauth.js +++ b/git/gitauth.js @@ -1,8 +1,5 @@ -/* - github -*/ -// git login +// github login window.onload = async () => { @@ -62,15 +59,17 @@ window.onload = async () => { } + const authURL = 'https://github.com/login/oauth/authorize?client_id=7ede3eed3185e59c042d&scope=repo,user,write:org'; + loginButton.addEventListener('click', () => { if (isMobile) { - window.location.href = 'https://github.com/login/oauth/authorize?client_id=7ede3eed3185e59c042d&scope=repo,user,write:org'; + window.location.href = authURL; } else { - window.open('https://github.com/login/oauth/authorize?client_id=7ede3eed3185e59c042d&scope=repo,user,write:org', 'Login with Github', 'height=575,width=575'); + window.open(authURL, 'Login with Github', 'height=575,width=575'); } @@ -79,35 +78,30 @@ window.onload = async () => { window.addEventListener('message', (event) => { - // if redirected from git auth - if (event.source.location.pathname === '/git/login') { - - // hide intro screen - sidebar.classList.remove('intro'); + // hide intro screen + sidebar.classList.remove('intro'); - // if on safari, refresh header color - if (isSafari) { + // if on safari, refresh header color + if (isSafari) { - document.querySelector('meta[name="theme-color"]').content = '#313744'; + document.querySelector('meta[name="theme-color"]').content = '#313744'; - onNextFrame(() => { + onNextFrame(() => { - document.querySelector('meta[name="theme-color"]').content = '#1a1c24'; + document.querySelector('meta[name="theme-color"]').content = '#1a1c24'; - }); + }); - } + } - // start loading - startLoading(); + // start loading + startLoading(); - const gitCode = event.data; + const gitCode = event.data; - // get git token from Github - getGithubToken(gitCode); + // get git token from Github + getGithubToken(gitCode); - } - }) diff --git a/git/gitlab/gitlab-api.js b/git/gitlab/gitlab-api.js new file mode 100644 index 0000000000..f1ee72129b --- /dev/null +++ b/git/gitlab/gitlab-api.js @@ -0,0 +1,4 @@ +https://gitlab.com/api/v4/projects?access_token=19a48ef34811b9425b6fc1e4c75f1358bdf7f528d151ec5624c46fa61e8b4c03&order_by=updated_at&min_access_level=30 +https://docs.gitlab.com/ee/api/oauth2.html +https://docs.gitlab.com/ee/api/projects.html +https://docs.gitlab.com/ee/api/repository_files.html diff --git a/git/gitlab/gitlab-auth.js b/git/gitlab/gitlab-auth.js new file mode 100644 index 0000000000..4bc70082bd --- /dev/null +++ b/git/gitlab/gitlab-auth.js @@ -0,0 +1,179 @@ + +// gitlab login + +window.onload = async () => { + + gitToken = getStorage('gitToken') ?? ''; + + if (gitToken == 'undefined') { + gitToken = ''; + } + + + // decode URL + linkData = decodeLink(window.location.href); + + // clear URL + window.history.pushState(window.location.origin, 'Codeit', window.location.origin + '/full'); + + + // if treeLoc is in local storage + if (linkData.dir) { + + treeLoc = linkData.dir; + saveTreeLocLS(treeLoc); + + } else { + + treeLoc = getStorage('tree') ? getStorage('tree').split(',') : ['', '', '']; + + // if repo dosen't have a branch (legacy treeLoc) + if (treeLoc[1] && !treeLoc[1].includes(':')) { + + // add default branch to repo + treeLoc[1] += ':main'; + saveTreeLocLS(treeLoc); + + } + + } + + + if (getStorage('loggedUser')) { + + loggedUser = getStorage('loggedUser'); + + try { + + loggedUser = JSON.parse(loggedUser); + + // save logged user in local storage + setStorage('loggedUser', loggedUser.login); + + } catch(e) {} + + } else { + + loggedUser = false; + + } + + + const authURL = 'https://gitlab.com/oauth/authorize?client_id=f3b94ba233943fa82855c1b495f28c02ccaa11cf276b419d6d1798488a4bb7b0&redirect_uri=https://codeit.codes/git/gitlab/oauth&response_type=code&state=1f3b3477&scope=api'; + + loginButton.addEventListener('click', () => { + + if (isMobile) { + + window.location.href = authURL; + + } else { + + window.open(authURL, 'Login with Gitlab', 'height=575,width=575'); + + } + + }) + + + window.addEventListener('message', (event) => { + + // if redirected from git auth + if (event.source.location.pathname === '/git/gitlab/oauth') { + + // hide intro screen + sidebar.classList.remove('intro'); + + // if on safari, refresh header color + if (isSafari) { + + document.querySelector('meta[name="theme-color"]').content = '#313744'; + + onNextFrame(() => { + + document.querySelector('meta[name="theme-color"]').content = '#1a1c24'; + + }); + + } + + // start loading + startLoading(); + + const gitCode = event.data; + + // get git token from Gitlab + getGitlabToken(gitCode); + + } + + }) + + + loadLS(); + + + // if git code exists in link + if (linkData.gitCode) { + + // hide intro screen + sidebar.classList.remove('intro'); + + // if on safari, refresh header color + if (isSafari) { + + document.querySelector('meta[name="theme-color"]').content = '#313744'; + + onNextFrame(() => { + + document.querySelector('meta[name="theme-color"]').content = '#1a1c24'; + + }); + + } + + // start loading + startLoading(); + + const gitCode = linkData.gitCode; + + // get git token from Gitlab + getGitlabToken(gitCode); + + } + +} + +async function getGitlabToken(gitCode) { + + // post to git with clientId, clientSecret and code + const resp = await axios.post('https://gitlab.com/oauth/token?' + + 'client_id=f3b94ba233943fa82855c1b495f28c02ccaa11cf276b419d6d1798488a4bb7b0' + + '&client_secret=1a4098e4770f84f01c94df563201d87b39dae740fe910622c76cd05d8ea30d03' + + '&grant_type=authorization_code&redirect_uri=https://codeit.codes/git/gitlab/oauth' + + '&code=' + gitCode); + + // save git token to localStorage + gitToken = resp.access_token; + saveGitTokenLS(gitToken); + + + // get logged user + loggedUser = await axios.get('https://gitlab.com/api/v4/user', gitToken); + loggedUser = loggedUser.username; + + // save logged user in local storage + setStorage('loggedUser', loggedUser); + + + // render sidebar + renderSidebarHTML(); + +} + + + + + +await axios.post('https://gitlab.com/oauth/token?client_id=&client_secret=&code=&&redirect_uri=https://codeit.codes/git/gitlab/oauth') + diff --git a/homepage/homepage.js b/homepage/homepage.js index 04f71dda57..89d2bd0192 100644 --- a/homepage/homepage.js +++ b/homepage/homepage.js @@ -126,11 +126,11 @@ document.querySelectorAll('.btn.install').forEach(button => { } else { - if (localStorage.getItem('installed')) { + //if (localStorage.getItem('installed')) { button.classList.add('installed'); - } + //} } diff --git a/homepage/privacy.html b/homepage/privacy.html index 61623516ad..d7b1bc3491 100644 --- a/homepage/privacy.html +++ b/homepage/privacy.html @@ -140,7 +140,7 @@Privacy policy
-