Showing
14 changed files
with
118 additions
and
78 deletions
| ... | @@ -22,7 +22,7 @@ function createWindow () { | ... | @@ -22,7 +22,7 @@ function createWindow () { |
| 22 | })) | 22 | })) |
| 23 | 23 | ||
| 24 | // Open the DevTools. | 24 | // Open the DevTools. |
| 25 | - win.webContents.openDevTools() | 25 | + // win.webContents.openDevTools() |
| 26 | 26 | ||
| 27 | // Emitted when the window is closed. | 27 | // Emitted when the window is closed. |
| 28 | win.on('closed', () => { | 28 | win.on('closed', () => { | ... | ... |
desktop-app/klasFD/functions.js
deleted
100644 → 0
This diff is collapsed. Click to expand it.
desktop-app/klasFD/module.js
deleted
100644 → 0
| 1 | -var functions = require('./functions'); | ||
| 2 | - | ||
| 3 | -exports.getLectureList = function (id, pw, cb) { | ||
| 4 | - functions.login(id, pw) | ||
| 5 | - .then(functions.getLecture) | ||
| 6 | - .then(functions.getLectureLink) | ||
| 7 | - .then(function(res){ | ||
| 8 | - cb(res); | ||
| 9 | - }) | ||
| 10 | - .catch(function(err){ | ||
| 11 | - cb(err); | ||
| 12 | - }) | ||
| 13 | -}; | ||
| 14 | - | ||
| 15 | -exports.getLectureFileLinks = function(lectureLink, cb){ | ||
| 16 | - functions.getClassPageBody(lectureLink) | ||
| 17 | - .then(functions.findFiles) | ||
| 18 | - .then(function(res){ | ||
| 19 | - cb(res); | ||
| 20 | - }) | ||
| 21 | - .catch(function(err){ | ||
| 22 | - cb(err); | ||
| 23 | - }) | ||
| 24 | -}; | ||
| 25 | - | ||
| 26 | -exports.isValidIdPw = function(id, pw, cb){ | ||
| 27 | - functions.login(id, pw) | ||
| 28 | - .then(function(){ | ||
| 29 | - cb(true); | ||
| 30 | - }) | ||
| 31 | - .catch(function(){ | ||
| 32 | - cb(false); | ||
| 33 | - }) | ||
| 34 | -}; | ||
| 35 | - | ||
| 36 | -exports.downloadSelectedFiles = function(selectedChapter, selectedLecture, cb){ | ||
| 37 | - functions.downloadSelectedFiles(selectedChapter, selectedLecture,null) | ||
| 38 | - .then(function(res){ | ||
| 39 | - cb(res); | ||
| 40 | - }) | ||
| 41 | - .catch(function(err){ | ||
| 42 | - cb(err); | ||
| 43 | - }) | ||
| 44 | -}; | ||
| 45 | - | ||
| 46 | -exports.downloadAllFiles = function(selectedFilesArr, selectedLecture, cb){ | ||
| 47 | - functions.downloadAllFiles(selectedFilesArr, selectedLecture,null) | ||
| 48 | - .then(function(res){ | ||
| 49 | - cb(res); | ||
| 50 | - }) | ||
| 51 | - .catch(function(err){ | ||
| 52 | - cb(err); | ||
| 53 | - }) | ||
| 54 | -}; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -3,7 +3,7 @@ | ... | @@ -3,7 +3,7 @@ |
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -let klasFD = require('./klasFD/module'); | 6 | +let klasFD = require('klas-file-downloader'); |
| 7 | 7 | ||
| 8 | let userLectures = []; | 8 | let userLectures = []; |
| 9 | let lectureFiles = []; | 9 | let lectureFiles = []; |
| ... | @@ -116,6 +116,7 @@ $(document).ready(function () { | ... | @@ -116,6 +116,7 @@ $(document).ready(function () { |
| 116 | 116 | ||
| 117 | const lectureIndex = $a.attr('href').substr(1); | 117 | const lectureIndex = $a.attr('href').substr(1); |
| 118 | selectedLecture = userLectures[lectureIndex].lectureName; | 118 | selectedLecture = userLectures[lectureIndex].lectureName; |
| 119 | + | ||
| 119 | renderChapterList(userLectures[lectureIndex]); | 120 | renderChapterList(userLectures[lectureIndex]); |
| 120 | }); | 121 | }); |
| 121 | 122 | ||
| ... | @@ -126,13 +127,26 @@ $(document).ready(function () { | ... | @@ -126,13 +127,26 @@ $(document).ready(function () { |
| 126 | disableAll('강의자료를 다운로드하고 있습니다..'); | 127 | disableAll('강의자료를 다운로드하고 있습니다..'); |
| 127 | klasFD.downloadSelectedFiles(lectureFiles[chapterIndex], selectedLecture, function (res) { | 128 | klasFD.downloadSelectedFiles(lectureFiles[chapterIndex], selectedLecture, function (res) { |
| 128 | ableAll(); | 129 | ableAll(); |
| 129 | - swal({ | 130 | + if(res.code){ |
| 130 | - title: '다운로드 완료', | 131 | + // 에러 |
| 131 | - text: res, | 132 | + swal({ |
| 132 | - type: "success", | 133 | + title: '다운로드 실패', |
| 133 | - confirmButtonText: "OK", | 134 | + text: res.message, |
| 134 | - confirmButtonColor: "#424242", | 135 | + type: "error", |
| 135 | - }); | 136 | + confirmButtonText: "OK", |
| 137 | + confirmButtonColor: "#424242", | ||
| 138 | + }); | ||
| 139 | + } else { | ||
| 140 | + | ||
| 141 | + swal({ | ||
| 142 | + title: '다운로드 완료', | ||
| 143 | + text: res, | ||
| 144 | + type: "success", | ||
| 145 | + confirmButtonText: "OK", | ||
| 146 | + confirmButtonColor: "#424242", | ||
| 147 | + }); | ||
| 148 | + } | ||
| 149 | + | ||
| 136 | }) | 150 | }) |
| 137 | }); | 151 | }); |
| 138 | 152 | ||
| ... | @@ -184,7 +198,6 @@ $(document).ready(function () { | ... | @@ -184,7 +198,6 @@ $(document).ready(function () { |
| 184 | 198 | ||
| 185 | // 사용자의 강의 리스트 렌더 | 199 | // 사용자의 강의 리스트 렌더 |
| 186 | function renderLectureList() { | 200 | function renderLectureList() { |
| 187 | - console.log(userLectures); | ||
| 188 | for (let i in userLectures) { | 201 | for (let i in userLectures) { |
| 189 | $('.lectureCollection') | 202 | $('.lectureCollection') |
| 190 | .append('<a href="#' + i + '" class="collection-item grey-text text-darken-3 my-lecture">' | 203 | .append('<a href="#' + i + '" class="collection-item grey-text text-darken-3 my-lecture">' |
| ... | @@ -194,10 +207,10 @@ $(document).ready(function () { | ... | @@ -194,10 +207,10 @@ $(document).ready(function () { |
| 194 | 207 | ||
| 195 | // 선택한 강의의 챕터 렌더 | 208 | // 선택한 강의의 챕터 렌더 |
| 196 | function renderChapterList(lectureObj) { | 209 | function renderChapterList(lectureObj) { |
| 197 | - console.log(lectureObj); | 210 | + disableAll('강의의 챕터를 불러오는 중입니다...'); |
| 198 | klasFD.getLectureFileLinks(lectureObj, function (fileList) { | 211 | klasFD.getLectureFileLinks(lectureObj, function (fileList) { |
| 212 | + ableAll(); | ||
| 199 | lectureFiles = fileList; | 213 | lectureFiles = fileList; |
| 200 | - console.log(fileList); | ||
| 201 | $('.chapterCollection').empty(); | 214 | $('.chapterCollection').empty(); |
| 202 | if (fileList.length === 0) { | 215 | if (fileList.length === 0) { |
| 203 | $('.chapterCollection') | 216 | $('.chapterCollection') |
| ... | @@ -231,8 +244,8 @@ $(document).ready(function () { | ... | @@ -231,8 +244,8 @@ $(document).ready(function () { |
| 231 | $('.imageWrapper').attr('style', 'height: 300px;'); | 244 | $('.imageWrapper').attr('style', 'height: 300px;'); |
| 232 | $('.listWrapper').hide(); | 245 | $('.listWrapper').hide(); |
| 233 | $('#logout').hide(); | 246 | $('#logout').hide(); |
| 234 | - $('#id').text(''); | 247 | + $('#id').val(''); |
| 235 | - $('#pw').text(''); | 248 | + $('#pw').val(''); |
| 236 | } | 249 | } |
| 237 | 250 | ||
| 238 | function disableAll(text) { | 251 | function disableAll(text) { | ... | ... |
| ... | @@ -5,11 +5,17 @@ | ... | @@ -5,11 +5,17 @@ |
| 5 | "devDependencies": { | 5 | "devDependencies": { |
| 6 | "electron": "^1.6.10", | 6 | "electron": "^1.6.10", |
| 7 | "electron-connect": "^0.6.1", | 7 | "electron-connect": "^0.6.1", |
| 8 | + "electron-installer-dmg": "^0.2.1", | ||
| 8 | "gulp": "^3.9.1" | 9 | "gulp": "^3.9.1" |
| 9 | }, | 10 | }, |
| 10 | "dependencies": { | 11 | "dependencies": { |
| 11 | "electron-connect": "^0.6.1", | 12 | "electron-connect": "^0.6.1", |
| 12 | - "klas-file-downloader": "^0.2.7", | 13 | + "klas-file-downloader": "^1.0.0", |
| 13 | "sweetalert": "^1.1.3" | 14 | "sweetalert": "^1.1.3" |
| 15 | + }, | ||
| 16 | + "scripts": { | ||
| 17 | + "package-mac": "electron-packager . KLAS파일다운로더 --overwrite --platform=darwin --arch=x64 --icon=./public/images/logo_1024.icns prune=true --out=release-builds", | ||
| 18 | + "create-installer-mac": "electron-installer-dmg ./release-builds/KLAS파일다운로더-darwin-x64/KLAS파일다운로더.app KLAS파일다운로더", | ||
| 19 | + "package-windows":"electron-packager . --overwrite --asar=true --platform=win32 --arch=ia32 --icon=./public/images/logo_256.ico --prune=true --out=release-builds --version-string.CompanyName='CE' --version-string.FileDescription=‘KLAS파일다운로더’ --version-string.ProductName=‘KLAS파일다운로더’" | ||
| 14 | } | 20 | } |
| 15 | } | 21 | } | ... | ... |
desktop-app/public/images/logo.png
deleted
100644 → 0
336 KB
No preview for this file type
desktop-app/public/images/logo_256.ico
0 → 100644
No preview for this file type
desktop-app/public/images/logo_256.png
0 → 100644
29.3 KB
| ... | @@ -63,7 +63,7 @@ exports.getLecture = function () { | ... | @@ -63,7 +63,7 @@ exports.getLecture = function () { |
| 63 | }, function (err, res, body) { | 63 | }, function (err, res, body) { |
| 64 | if (err) { | 64 | if (err) { |
| 65 | console.log(err); | 65 | console.log(err); |
| 66 | - reject({code:'PARSING_ERR', message: ' 파싱 중 에러가 발생했어요!'}); | 66 | + reject({code:'CONNECT_ERR', message: ' 페이지 접근 중 에러가 발생했어요!'}); |
| 67 | } else { | 67 | } else { |
| 68 | resolve(body); | 68 | resolve(body); |
| 69 | } | 69 | } |
| ... | @@ -99,7 +99,11 @@ exports.getLectureLink = function (getLectureBody) { | ... | @@ -99,7 +99,11 @@ exports.getLectureLink = function (getLectureBody) { |
| 99 | lectureLinkList[i].link = 'https://klas.khu.ac.kr' + $(this).attr('href') | 99 | lectureLinkList[i].link = 'https://klas.khu.ac.kr' + $(this).attr('href') |
| 100 | }); | 100 | }); |
| 101 | 101 | ||
| 102 | - resolve(lectureLinkList); | 102 | + if(lectureLinkList.length === 0){ |
| 103 | + reject({code:'LOGIN_ERR', message: ' 학번과 비밀번호를 확인해주세요!'}); | ||
| 104 | + } else { | ||
| 105 | + resolve(lectureLinkList); | ||
| 106 | + } | ||
| 103 | 107 | ||
| 104 | }) | 108 | }) |
| 105 | }; | 109 | }; |
| ... | @@ -160,16 +164,18 @@ exports.getClassPageBody = function (lectureLinkObj) { | ... | @@ -160,16 +164,18 @@ exports.getClassPageBody = function (lectureLinkObj) { |
| 160 | 164 | ||
| 161 | return new Promise(function (resolve, reject) { | 165 | return new Promise(function (resolve, reject) { |
| 162 | 166 | ||
| 163 | - let url = lectureLinkObj.link; | 167 | + let pageUrl = lectureLinkObj.link; |
| 164 | 168 | ||
| 165 | let headers = { | 169 | let headers = { |
| 166 | 'Cookie': 'COURSE_MENU_NAME=%uAC15%uC758%uC2E4', | 170 | 'Cookie': 'COURSE_MENU_NAME=%uAC15%uC758%uC2E4', |
| 167 | 'User-Agent': 'request' | 171 | 'User-Agent': 'request' |
| 168 | }; | 172 | }; |
| 169 | 173 | ||
| 174 | + let request = require('request'); | ||
| 175 | + | ||
| 170 | request({ | 176 | request({ |
| 171 | - url: url, | 177 | + url: pageUrl, |
| 172 | - mothod: 'GET', | 178 | + method: 'GET', |
| 173 | jar: j, | 179 | jar: j, |
| 174 | headers: headers, | 180 | headers: headers, |
| 175 | timeout: 3000 | 181 | timeout: 3000 |
| ... | @@ -279,6 +285,7 @@ exports.downloadSelectedFiles = function (selectedFiles, selectLecture, download | ... | @@ -279,6 +285,7 @@ exports.downloadSelectedFiles = function (selectedFiles, selectLecture, download |
| 279 | 285 | ||
| 280 | return new Promise(function (resolve, reject) { | 286 | return new Promise(function (resolve, reject) { |
| 281 | 287 | ||
| 288 | + | ||
| 282 | if (!downloadPath) { | 289 | if (!downloadPath) { |
| 283 | downloadPath = os.homedir() + '/Downloads/'; | 290 | downloadPath = os.homedir() + '/Downloads/'; |
| 284 | } else { | 291 | } else { |
| ... | @@ -296,6 +303,9 @@ exports.downloadSelectedFiles = function (selectedFiles, selectLecture, download | ... | @@ -296,6 +303,9 @@ exports.downloadSelectedFiles = function (selectedFiles, selectLecture, download |
| 296 | downloadPath += selectedFiles.chapter + '/'; | 303 | downloadPath += selectedFiles.chapter + '/'; |
| 297 | 304 | ||
| 298 | let count = 0; | 305 | let count = 0; |
| 306 | + if(selectedFiles.files.length === 0){ | ||
| 307 | + reject({code: 'NO_FILES',message:' 해당 챕터에 해당하는 파일이 없어요!!'}); | ||
| 308 | + } | ||
| 299 | selectedFiles.files.forEach(function (value, index) { | 309 | selectedFiles.files.forEach(function (value, index) { |
| 300 | request = https.get(value.link, function (response) { | 310 | request = https.get(value.link, function (response) { |
| 301 | 311 | ||
| ... | @@ -334,18 +344,32 @@ exports.downloadAllFiles = function (chapterFilesArr, selectLecture, downloadPat | ... | @@ -334,18 +344,32 @@ exports.downloadAllFiles = function (chapterFilesArr, selectLecture, downloadPat |
| 334 | 344 | ||
| 335 | let count = 0; | 345 | let count = 0; |
| 336 | chapterFilesArr.forEach(function (chapterObj, index) { | 346 | chapterFilesArr.forEach(function (chapterObj, index) { |
| 347 | + | ||
| 348 | + | ||
| 337 | var asyncDownloadPath = downloadPath + chapterObj.chapter + '/'; | 349 | var asyncDownloadPath = downloadPath + chapterObj.chapter + '/'; |
| 338 | 350 | ||
| 339 | if (!fs.existsSync(asyncDownloadPath)) | 351 | if (!fs.existsSync(asyncDownloadPath)) |
| 340 | fs.mkdirSync(asyncDownloadPath); | 352 | fs.mkdirSync(asyncDownloadPath); |
| 341 | 353 | ||
| 342 | var subCount = 0; | 354 | var subCount = 0; |
| 355 | + | ||
| 356 | + if(chapterFilesArr.length-1 === count){ | ||
| 357 | + resolve('\n 파일이 ' + downloadPath + ' 에 저장되었어요! 열공 :)'); | ||
| 358 | + } | ||
| 359 | + if(chapterObj.files.length === 0){ | ||
| 360 | + count ++; | ||
| 361 | + return; | ||
| 362 | + } | ||
| 363 | + | ||
| 343 | chapterObj.files.forEach(function (value, index) { | 364 | chapterObj.files.forEach(function (value, index) { |
| 344 | request = https.get(value.link, function (response) { | 365 | request = https.get(value.link, function (response) { |
| 366 | + | ||
| 345 | let file = fs.createWriteStream(asyncDownloadPath + value.fileName); | 367 | let file = fs.createWriteStream(asyncDownloadPath + value.fileName); |
| 346 | response.pipe(file); | 368 | response.pipe(file); |
| 347 | 369 | ||
| 348 | subCount++; | 370 | subCount++; |
| 371 | + | ||
| 372 | + | ||
| 349 | if (subCount === chapterObj.files.length) { | 373 | if (subCount === chapterObj.files.length) { |
| 350 | count++; | 374 | count++; |
| 351 | console.log(' 다운로드중... (' + asyncDownloadPath + ')'); | 375 | console.log(' 다운로드중... (' + asyncDownloadPath + ')'); | ... | ... |
| 1 | var functions = require('./functions'); | 1 | var functions = require('./functions'); |
| 2 | 2 | ||
| 3 | -exports.getLectureList = function (id, pw) { | ||
| 4 | - console.log(id + " " + pw); | ||
| 5 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 3 | +exports.getLectureList = function (id, pw, cb) { | ||
| 4 | + functions.login(id, pw) | ||
| 5 | + .then(functions.getLecture) | ||
| 6 | + .then(functions.getLectureLink) | ||
| 7 | + .then(function(res){ | ||
| 8 | + cb(res); | ||
| 9 | + }) | ||
| 10 | + .catch(function(err){ | ||
| 11 | + cb(err); | ||
| 12 | + }) | ||
| 13 | +}; | ||
| 14 | + | ||
| 15 | +exports.getLectureFileLinks = function(lectureLink, cb){ | ||
| 16 | + functions.getClassPageBody(lectureLink) | ||
| 17 | + .then(functions.findFiles) | ||
| 18 | + .then(function(res){ | ||
| 19 | + cb(res); | ||
| 20 | + }) | ||
| 21 | + .catch(function(err){ | ||
| 22 | + cb(err); | ||
| 23 | + }) | ||
| 24 | +}; | ||
| 25 | + | ||
| 26 | +exports.isValidIdPw = function(id, pw, cb){ | ||
| 27 | + functions.login(id, pw) | ||
| 28 | + .then(function(){ | ||
| 29 | + cb(true); | ||
| 30 | + }) | ||
| 31 | + .catch(function(){ | ||
| 32 | + cb(false); | ||
| 33 | + }) | ||
| 34 | +}; | ||
| 35 | + | ||
| 36 | +exports.downloadSelectedFiles = function(selectedChapter, selectedLecture, cb){ | ||
| 37 | + functions.downloadSelectedFiles(selectedChapter, selectedLecture,null) | ||
| 38 | + .then(function(res){ | ||
| 39 | + cb(res); | ||
| 40 | + }) | ||
| 41 | + .catch(function(err){ | ||
| 42 | + cb(err); | ||
| 43 | + }) | ||
| 44 | +}; | ||
| 45 | + | ||
| 46 | +exports.downloadAllFiles = function(selectedFilesArr, selectedLecture, cb){ | ||
| 47 | + functions.downloadAllFiles(selectedFilesArr, selectedLecture,null) | ||
| 48 | + .then(function(res){ | ||
| 49 | + cb(res); | ||
| 50 | + }) | ||
| 51 | + .catch(function(err){ | ||
| 52 | + cb(err); | ||
| 53 | + }) | ||
| 54 | +}; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | { | 1 | { |
| 2 | "name": "klas-file-downloader", | 2 | "name": "klas-file-downloader", |
| 3 | - "version": "0.1.7", | 3 | + "version": "1.0.0", |
| 4 | "description": "Project that download lecture reference files from Klas", | 4 | "description": "Project that download lecture reference files from Klas", |
| 5 | "main": "module.js", | 5 | "main": "module.js", |
| 6 | "scripts": { | 6 | "scripts": { | ... | ... |
-
Please register or login to post a comment