diff --git a/cli.js b/cli.js index 24675a4..5e65bad 100644 --- a/cli.js +++ b/cli.js @@ -99,11 +99,10 @@ async function interactive() { } (async () => { - let noFlag = true; - - updateNotifier({ pkg: utils.pkg }).notify(); + updateNotifier({ pkg: utils.pkg, updateCheckInterval: 1000 * 60 * 60 * 3 }).notify({ + isGlobal: true, + }); await doTask(cli.input[0]); - process.exit(); })(); diff --git a/package-lock.json b/package-lock.json index b00bcdd..3916f3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "e-kreta-cli", - "version": "0.0.4", + "version": "0.0.5", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -233,6 +233,15 @@ "widest-line": "^3.1.0" }, "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, "type-fest": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", @@ -290,9 +299,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.0.0.tgz", + "integrity": "sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==", "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -564,9 +573,9 @@ } }, "fuse.js": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-3.6.1.tgz", - "integrity": "sha512-hT9yh/tiinkmirKrlv4KWOjztdoZo1mx9Qh4KvWqC7isoXwdUY3PNWUxceF4/qO9R6riA2C29jdTOeQOIROjgw==" + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-5.1.0.tgz", + "integrity": "sha512-R8nPr9tQx0HdjRJsqkESimL7o/2Xe0/Lw0cMBrBjkAKAJFq6D6u/o3obteqxkvOJNEgS4xPP78dxoNMaCWNoGg==" }, "get-stream": { "version": "4.1.0", @@ -710,6 +719,17 @@ "string-width": "^4.1.0", "strip-ansi": "^6.0.0", "through": "^2.3.6" + }, + "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "inquirer-autocomplete-prompt": { @@ -1079,9 +1099,9 @@ } }, "mkdirp": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.3.tgz", - "integrity": "sha512-6uCP4Qc0sWsgMLy1EOqqS/3rjDHOEnsStVr/4vtAIK2Y5i2kA7lFFejYrpIyiN9w0pYf4ckeCYT9f1r1P9KX5g==" + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" }, "mute-stream": { "version": "0.0.8", @@ -1145,6 +1165,17 @@ "mute-stream": "0.0.8", "strip-ansi": "^6.0.0", "wcwidth": "^1.0.1" + }, + "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "os-tmpdir": { @@ -1624,6 +1655,17 @@ "pupa": "^2.0.1", "semver-diff": "^3.1.1", "xdg-basedir": "^4.0.0" + }, + "dependencies": { + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + } } }, "uri-js": { diff --git a/package.json b/package.json index 868a52a..d6510c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "e-kreta-cli", - "version": "0.0.4", + "version": "0.0.5", "description": "Check your electronic diary - from right inside your terminal.", "main": "cli.js", "scripts": {}, @@ -12,14 +12,14 @@ "author": "Milan Szekely (https://szekelymilan.eu)", "license": "MIT", "dependencies": { - "chalk": "^3.0.0", + "chalk": "^4.0.0", "configstore": "^5.0.1", - "fuse.js": "^3.6.1", + "fuse.js": "^5.1.0", "inquirer": "^7.1.0", "inquirer-autocomplete-prompt": "^1.0.2", "js-base64": "^2.5.2", "meow": "^6.1.0", - "mkdirp": "^1.0.3", + "mkdirp": "^1.0.4", "ora": "^4.0.3", "request": "^2.88.2", "request-promise-native": "^1.0.8", diff --git a/src/assignments.js b/src/assignments.js index dc4c441..26ce1e5 100644 --- a/src/assignments.js +++ b/src/assignments.js @@ -4,9 +4,9 @@ const fs = require('fs'); const mkdirp = require('mkdirp'); const path = require('path'); const ora = require('ora'); -const request = require('request-promise-native'); const utils = require('./utils'); +const request = utils.request; module.exports = async directory => { const spinner = ora('Downloading...').start(); @@ -17,9 +17,12 @@ module.exports = async directory => { mkdirp.sync(directory); const lessons = JSON.parse( - await request.get(`https://${utils.conf.get('institute')}.e-kreta.hu/mapi/api/v1/Lesson`, { - auth: { bearer: accessToken }, - }), + await request.get( + `https://${utils.conf.get('institute')}.e-kreta.hu/mapi/api/v1/Lesson?fromDate=1970-01-01`, + { + auth: { bearer: accessToken }, + }, + ), ); const wasAssignment = {}; diff --git a/src/averages.js b/src/averages.js index afbbdf9..4e08517 100644 --- a/src/averages.js +++ b/src/averages.js @@ -1,8 +1,8 @@ const { bold, red, green, white, gray } = require('chalk'); const configstore = require('configstore'); -const request = require('request-promise-native'); const utils = require('./utils'); +const request = utils.request; module.exports = async () => { try { diff --git a/src/messages.js b/src/messages.js index 5b16319..a5c1c4a 100644 --- a/src/messages.js +++ b/src/messages.js @@ -4,9 +4,9 @@ const fs = require('fs'); const mkdirp = require('mkdirp'); const path = require('path'); const ora = require('ora'); -const request = require('request-promise-native'); const utils = require('./utils'); +const request = utils.request; module.exports = async directory => { const spinner = ora('Downloading...').start(); diff --git a/src/utils.js b/src/utils.js index e9cc511..79905bb 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,24 +1,29 @@ const { Base64 } = require('js-base64'); const { bold, red } = require('chalk'); const configstore = require('configstore'); -const request = require('request-promise-native'); +const request = require('request-promise-native').defaults({ + headers: { 'User-Agent': 'Kreta.Ellenorzo/2.9.11.2020033003 (Android; 0.0)' }, +}); exports.pkg = require('../package.json'); exports.conf = new configstore(exports.pkg.name); +exports.request = request; exports.getInstitutes = async () => { - const response = await request.get('https://kretaglobalmobileapi.ekreta.hu/api/v1/Institute', { - headers: { apiKey: '7856d350-1fda-45f5-822d-e1a2f3f1acf0' }, - }); - return JSON.parse(response); + return JSON.parse( + await request.get('https://kretaglobalmobileapi.ekreta.hu/api/v1/Institute', { + headers: { apiKey: '7856d350-1fda-45f5-822d-e1a2f3f1acf0' }, + }), + ); }; async function loginUtil(institute, username, password) { try { - const response = await request.post(`https://${institute}.e-kreta.hu/idp/api/v1/Token`, { - body: `institute_code=${institute}&userName=${username}&password=${password}&grant_type=password&client_id=919e0c1c-76a2-4646-a2fb-7085bbbf3c56`, - }); - return JSON.parse(response); + return JSON.parse( + await request.post(`https://${institute}.e-kreta.hu/idp/api/v1/Token`, { + body: `institute_code=${institute}&userName=${username}&password=${password}&grant_type=password&client_id=919e0c1c-76a2-4646-a2fb-7085bbbf3c56`, + }), + ); } catch (e) { return e.statusCode || -1; }