From 4f6fa481cff81ead5609688a4b2fe6152a05b701 Mon Sep 17 00:00:00 2001 From: Moneeza Syed <14besemsyed@seecs.edu.pk> Date: Sat, 2 Dec 2023 20:19:14 +0100 Subject: [PATCH] fixed interceptor --- src/components/DialogAddRepositories.vue | 1 - src/components/DialogCommit.vue | 1 - src/components/FileExplorer.vue | 1 - src/plugins/api.js | 37 +++++++++--------------- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/components/DialogAddRepositories.vue b/src/components/DialogAddRepositories.vue index 844b782..321b6f1 100644 --- a/src/components/DialogAddRepositories.vue +++ b/src/components/DialogAddRepositories.vue @@ -268,7 +268,6 @@ export default { */ addRepositories: async function () { this.showLoadingOverlay = true; - debugger; console.log(this.repositoriesSelected) loadAllRepositoryContent( this.repositoriesSelected.map((repo) => ({ diff --git a/src/components/DialogCommit.vue b/src/components/DialogCommit.vue index 71fc654..a3dd782 100644 --- a/src/components/DialogCommit.vue +++ b/src/components/DialogCommit.vue @@ -342,7 +342,6 @@ export default { type: value.fileStatus }); if (!this.errorRequest) { - debugger; createBlobs(value.value) .then((res) => { diff --git a/src/components/FileExplorer.vue b/src/components/FileExplorer.vue index 48570f4..0e34f0c 100644 --- a/src/components/FileExplorer.vue +++ b/src/components/FileExplorer.vue @@ -303,7 +303,6 @@ export default { createNewAdr({ repository }) { let newAdr = store.createNewAdr(repository.repository); // Open the new adr. - debugger; store.openAdrBy(repository.fullName, newAdr.path.split("/").pop()); } } diff --git a/src/plugins/api.js b/src/plugins/api.js index 0267b29..0fe8260 100644 --- a/src/plugins/api.js +++ b/src/plugins/api.js @@ -8,6 +8,8 @@ let repoOwner = ""; let repoName = ""; let branch = ""; +axios.defaults.headers.common['Authorization'] = getHeaders().Authorization; + export function setInfosForApi(currRepoOwner, currRepoName, currBranch) { repoName = currRepoName; repoOwner = currRepoOwner; @@ -21,9 +23,8 @@ export function setInfosForApi(currRepoOwner, currRepoName, currBranch) { * @returns {Promise} the array of emails with attributes 'email', 'primary', 'verified', 'visibility' */ export async function getUserEmail() { - const headers = getHeaders(); return axios - .get(`${BASE_URL_USER}/public_emails`, { headers }) + .get(`${BASE_URL_USER}/public_emails`) .then((response) => response.data) .catch((err) => { console.log(err); @@ -37,8 +38,7 @@ export async function getUserEmail() { * @returns {Promise} the array of informations with attributes 'login', 'name', etc. */ export async function getUserName() { - const headers = getHeaders() - return axios.get(BASE_URL_USER, { headers }) + return axios.get(BASE_URL_USER) .then((response) => response.data) .catch((err) => { console.log(err); @@ -53,7 +53,7 @@ export async function getUserName() { */ export async function getCommitSha() { const headers = getHeaders() - return axios.get(`${BASE_URL_REPO}/${repoOwner}/${repoName}/branches/${branch}`, { headers }) + return axios.get(`${BASE_URL_REPO}/${repoOwner}/${repoName}/branches/${branch}`) .then((response) => response.data) .catch((err) => { console.log(err); @@ -75,7 +75,7 @@ export async function createBlobs(file) { ({ content: file, encoding: "utf-8" - }), { headers: copyHeader }) + })) .then((response) => response.data) .then((body) => body) .catch((err) => { @@ -92,12 +92,11 @@ export async function createBlobs(file) { * @returns {Promise} informations about the newly created tree with attributes 'sha', etc. */ export async function createFileTree(lastCommitSha, folderTree) { - const headers = getHeaders() return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/trees`, { base_tree: lastCommitSha, tree: folderTree - }, { headers }) + }) .then((response) => response.data) .then((body) => body) .catch((err) => { @@ -116,14 +115,13 @@ export async function createFileTree(lastCommitSha, folderTree) { * @returns {Promise} informations about the created commit with attributes 'sha', etc. */ export async function createCommit(commitMessage, authorInfos, lastCommitSha, treeSha) { - const headers = getHeaders() return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/commits`, { message: commitMessage, author: authorInfos, parents: [lastCommitSha], tree: treeSha - }, { headers }) + }) .then((response) => response.data) .then((body) => body) .catch((err) => { @@ -139,11 +137,10 @@ export async function createCommit(commitMessage, authorInfos, lastCommitSha, tr * @returns {Promise} informations about the reference. */ export async function pushToGitHub(newCommitSha) { - const headers = getHeaders() return axios.post(`${BASE_URL_REPO}/${repoOwner}/${repoName}/git/refs/heads/${branch}`, { ref: "refs/heads/" + branch, sha: newCommitSha - }, { headers }) + }) .then((response) => response.data) .then((body) => body) .catch((err) => { @@ -164,7 +161,6 @@ export async function pushToGitHub(newCommitSha) { */ export async function loadRepositoryList(searchText = "", page = 1, perPage = 5) { - try { const userId = localStorage.getItem('user'); @@ -186,9 +182,7 @@ export async function loadRepositoryList(searchText = "", page = 1, perPage = 5) }` }; - const response = await axios.post('https://api.github.com/graphql', body, { - headers: getHeaders() - }); + const response = await axios.post('https://api.github.com/graphql', body); if (!response?.data) { return []; @@ -260,9 +254,8 @@ export async function searchRepositoryList(searchString, maxResults = 2, searchR */ export async function loadFileTreeOfRepository(repoFullName, branch) { - const headers = getHeaders() - return axios.get(`${BASE_URL_REPO}/${repoFullName}/git/trees/${branch}?recursive=1`, { headers }) + return axios.get(`${BASE_URL_REPO}/${repoFullName}/git/trees/${branch}?recursive=1`) .then((response) => response.data) .catch((err) => { console.log(err); @@ -279,9 +272,8 @@ export async function loadFileTreeOfRepository(repoFullName, branch) { * @returns {Promise<{ name : string }[]>} the fetched array of branches */ export async function loadBranchesName(repoName, username) { - const headers = getHeaders() return axios - .get(`${BASE_URL_REPO}/${username}/${repoName}/branches?per_page=999`, { headers }) + .get(`${BASE_URL_REPO}/${username}/${repoName}/branches?per_page=999`) .then((response) => response.data) .catch((err) => { console.log(err); @@ -299,7 +291,6 @@ export async function loadBranchesName(repoName, username) { * @returns {Promise} a promise with the raw content of the specified file */ export async function loadRawFile(repoFullName, branch, filePath) { - const headers = getHeaders() if (typeof branch !== "string" || typeof branch != "string") { console.log( @@ -312,9 +303,7 @@ export async function loadRawFile(repoFullName, branch, filePath) { ); } else { return axios - .get(`${BASE_URL_REPO}/${repoFullName}/contents/${filePath}?ref=${branch}`, { - headers - }) + .get(`${BASE_URL_REPO}/${repoFullName}/contents/${filePath}?ref=${branch}`) .then((response) => response.data) .then((response) => decodeUnicode(response.content)) .catch((err) => {