Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
IliasHad
committed
Jul 17, 2019
1 parent
883e00c
commit a9127cd
Showing
8 changed files
with
126 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,91 @@ | ||
|
||
const fetch = require('node-fetch'); | ||
const apiEndpoint = require('./config'); | ||
const vscode = require('vscode'); | ||
const fs = require('fs') | ||
const fetch = require("node-fetch"); | ||
const apiEndpoint = require("./config"); | ||
const vscode = require("vscode"); | ||
const fs = require("fs"); | ||
|
||
import { statusBar, apiKey, fileDuration } from "./extension"; | ||
import { serverIsDown } from "./offline" | ||
import { getJSONFile } from "./dashboard" | ||
import {getApikey} from "./login" | ||
import { serverIsDown } from "./offline"; | ||
import { getJSONFile } from "./dashboard"; | ||
import { getApikey } from "./login"; | ||
let lastSendingData = 0; | ||
|
||
|
||
export function sendData() { | ||
let file = getJSONFile(); | ||
let fileDuration = []; | ||
let data = fs.readFileSync(file); | ||
|
||
// @ts-ignore | ||
fileDuration = JSON.parse(data) | ||
|
||
let url = `${apiEndpoint}duration`; | ||
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
|
||
|
||
console.log(url) | ||
|
||
let body = { | ||
fileDuration, | ||
apiKey | ||
} | ||
async function sendPost() { | ||
|
||
// @ts-ignore | ||
let response = await fetch(url, { | ||
method: 'POST', | ||
// @ts-ignore | ||
body: JSON.stringify(body), | ||
headers: { 'Content-Type': 'application/json' } | ||
|
||
}); | ||
let data = await response.json() | ||
return data; | ||
} | ||
|
||
|
||
sendPost() | ||
|
||
|
||
.then(data => { | ||
console.log(data); | ||
|
||
}) | ||
.catch(err => { | ||
console.log(err) | ||
// serverIsDown(); | ||
}) | ||
|
||
|
||
let file = getJSONFile(); | ||
let fileDuration = []; | ||
let data = fs.readFileSync(file); | ||
|
||
// @ts-ignore | ||
fileDuration = JSON.parse(data); | ||
|
||
let url = `${apiEndpoint}duration`; | ||
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
|
||
console.log(url); | ||
|
||
let body = { | ||
fileDuration, | ||
apiKey | ||
}; | ||
async function sendPost() { | ||
// @ts-ignore | ||
let response = await fetch(url, { | ||
method: "POST", | ||
// @ts-ignore | ||
body: JSON.stringify(body), | ||
headers: { "Content-Type": "application/json" } | ||
}); | ||
let data = await response.json(); | ||
return data; | ||
} | ||
|
||
sendPost() | ||
.then(data => { | ||
console.log(data); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
// serverIsDown(); | ||
}); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// Check API Is Valid | ||
// Check API Is Valid | ||
export function checkApi() { | ||
console.log('CHeck Api') | ||
|
||
let url = `${apiEndpoint}duration/u/${apiKey}` | ||
console.log(url) | ||
|
||
let editors = { | ||
name: "vs_code", | ||
connected_at: new Date().toISOString() | ||
} | ||
let isValid; | ||
// @ts-ignore | ||
fetch(url, { | ||
|
||
method: 'POST', | ||
body: JSON.stringify(editors), | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
.then(response => { | ||
|
||
return response.json() | ||
}) | ||
.then(resData => { | ||
console.log(resData) | ||
if (resData !== undefined) { | ||
|
||
vscode.window.showInformationMessage('Congratulations, Codabits is now active!'); | ||
} | ||
else { | ||
vscode.window.showInformationMessage('Oops, API Key is not valid!'); | ||
|
||
getApikey() | ||
} | ||
}) | ||
|
||
.catch((err) => { | ||
getApikey() | ||
console.log(err) | ||
}) | ||
|
||
return isValid; | ||
} | ||
console.log("CHeck Api"); | ||
|
||
let url = `${apiEndpoint}duration/u/${apiKey}`; | ||
console.log(url); | ||
|
||
let editors = { | ||
name: "vs_code", | ||
connected_at: new Date().toISOString() | ||
}; | ||
let isValid; | ||
// @ts-ignore | ||
fetch(url, { | ||
method: "POST", | ||
body: JSON.stringify(editors), | ||
headers: { "Content-Type": "application/json" } | ||
}) | ||
.then(response => { | ||
return response.json(); | ||
}) | ||
.then(resData => { | ||
console.log(resData); | ||
if (resData !== undefined) { | ||
vscode.window.showInformationMessage( | ||
"Congratulations, Codabits is now active!" | ||
); | ||
} else { | ||
vscode.window.showInformationMessage("Oops, API Key is not valid!"); | ||
|
||
getApikey(); | ||
} | ||
}) | ||
|
||
.catch(err => { | ||
getApikey(); | ||
console.log(err); | ||
}); | ||
|
||
return isValid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.