성준영

데스크탑 앱 버전 1

node_modules/
release-builds/
desktop-app/KLAS파일다운로더.dmg
\ No newline at end of file
......
......@@ -22,7 +22,7 @@ function createWindow () {
}))
// Open the DevTools.
win.webContents.openDevTools()
// win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
......
This diff is collapsed. Click to expand it.
var functions = require('./functions');
exports.getLectureList = function (id, pw, cb) {
functions.login(id, pw)
.then(functions.getLecture)
.then(functions.getLectureLink)
.then(function(res){
cb(res);
})
.catch(function(err){
cb(err);
})
};
exports.getLectureFileLinks = function(lectureLink, cb){
functions.getClassPageBody(lectureLink)
.then(functions.findFiles)
.then(function(res){
cb(res);
})
.catch(function(err){
cb(err);
})
};
exports.isValidIdPw = function(id, pw, cb){
functions.login(id, pw)
.then(function(){
cb(true);
})
.catch(function(){
cb(false);
})
};
exports.downloadSelectedFiles = function(selectedChapter, selectedLecture, cb){
functions.downloadSelectedFiles(selectedChapter, selectedLecture,null)
.then(function(res){
cb(res);
})
.catch(function(err){
cb(err);
})
};
exports.downloadAllFiles = function(selectedFilesArr, selectedLecture, cb){
functions.downloadAllFiles(selectedFilesArr, selectedLecture,null)
.then(function(res){
cb(res);
})
.catch(function(err){
cb(err);
})
};
\ No newline at end of file
......@@ -3,7 +3,7 @@
*/
let klasFD = require('./klasFD/module');
let klasFD = require('klas-file-downloader');
let userLectures = [];
let lectureFiles = [];
......@@ -116,6 +116,7 @@ $(document).ready(function () {
const lectureIndex = $a.attr('href').substr(1);
selectedLecture = userLectures[lectureIndex].lectureName;
renderChapterList(userLectures[lectureIndex]);
});
......@@ -126,13 +127,26 @@ $(document).ready(function () {
disableAll('강의자료를 다운로드하고 있습니다..');
klasFD.downloadSelectedFiles(lectureFiles[chapterIndex], selectedLecture, function (res) {
ableAll();
swal({
title: '다운로드 완료',
text: res,
type: "success",
confirmButtonText: "OK",
confirmButtonColor: "#424242",
});
if(res.code){
// 에러
swal({
title: '다운로드 실패',
text: res.message,
type: "error",
confirmButtonText: "OK",
confirmButtonColor: "#424242",
});
} else {
swal({
title: '다운로드 완료',
text: res,
type: "success",
confirmButtonText: "OK",
confirmButtonColor: "#424242",
});
}
})
});
......@@ -184,7 +198,6 @@ $(document).ready(function () {
// 사용자의 강의 리스트 렌더
function renderLectureList() {
console.log(userLectures);
for (let i in userLectures) {
$('.lectureCollection')
.append('<a href="#' + i + '" class="collection-item grey-text text-darken-3 my-lecture">'
......@@ -194,10 +207,10 @@ $(document).ready(function () {
// 선택한 강의의 챕터 렌더
function renderChapterList(lectureObj) {
console.log(lectureObj);
disableAll('강의의 챕터를 불러오는 중입니다...');
klasFD.getLectureFileLinks(lectureObj, function (fileList) {
ableAll();
lectureFiles = fileList;
console.log(fileList);
$('.chapterCollection').empty();
if (fileList.length === 0) {
$('.chapterCollection')
......@@ -231,8 +244,8 @@ $(document).ready(function () {
$('.imageWrapper').attr('style', 'height: 300px;');
$('.listWrapper').hide();
$('#logout').hide();
$('#id').text('');
$('#pw').text('');
$('#id').val('');
$('#pw').val('');
}
function disableAll(text) {
......
......@@ -5,11 +5,17 @@
"devDependencies": {
"electron": "^1.6.10",
"electron-connect": "^0.6.1",
"electron-installer-dmg": "^0.2.1",
"gulp": "^3.9.1"
},
"dependencies": {
"electron-connect": "^0.6.1",
"klas-file-downloader": "^0.2.7",
"klas-file-downloader": "^1.0.0",
"sweetalert": "^1.1.3"
},
"scripts": {
"package-mac": "electron-packager . KLAS파일다운로더 --overwrite --platform=darwin --arch=x64 --icon=./public/images/logo_1024.icns prune=true --out=release-builds",
"create-installer-mac": "electron-installer-dmg ./release-builds/KLAS파일다운로더-darwin-x64/KLAS파일다운로더.app KLAS파일다운로더",
"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파일다운로더’"
}
}
......

397 KB | W: | H:

92.3 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
......@@ -63,7 +63,7 @@ exports.getLecture = function () {
}, function (err, res, body) {
if (err) {
console.log(err);
reject({code:'PARSING_ERR', message: ' 파싱 중 에러가 발생했어요!'});
reject({code:'CONNECT_ERR', message: ' 페이지 접근 중 에러가 발생했어요!'});
} else {
resolve(body);
}
......@@ -99,7 +99,11 @@ exports.getLectureLink = function (getLectureBody) {
lectureLinkList[i].link = 'https://klas.khu.ac.kr' + $(this).attr('href')
});
resolve(lectureLinkList);
if(lectureLinkList.length === 0){
reject({code:'LOGIN_ERR', message: ' 학번과 비밀번호를 확인해주세요!'});
} else {
resolve(lectureLinkList);
}
})
};
......@@ -160,16 +164,18 @@ exports.getClassPageBody = function (lectureLinkObj) {
return new Promise(function (resolve, reject) {
let url = lectureLinkObj.link;
let pageUrl = lectureLinkObj.link;
let headers = {
'Cookie': 'COURSE_MENU_NAME=%uAC15%uC758%uC2E4',
'User-Agent': 'request'
};
let request = require('request');
request({
url: url,
mothod: 'GET',
url: pageUrl,
method: 'GET',
jar: j,
headers: headers,
timeout: 3000
......@@ -279,6 +285,7 @@ exports.downloadSelectedFiles = function (selectedFiles, selectLecture, download
return new Promise(function (resolve, reject) {
if (!downloadPath) {
downloadPath = os.homedir() + '/Downloads/';
} else {
......@@ -296,6 +303,9 @@ exports.downloadSelectedFiles = function (selectedFiles, selectLecture, download
downloadPath += selectedFiles.chapter + '/';
let count = 0;
if(selectedFiles.files.length === 0){
reject({code: 'NO_FILES',message:' 해당 챕터에 해당하는 파일이 없어요!!'});
}
selectedFiles.files.forEach(function (value, index) {
request = https.get(value.link, function (response) {
......@@ -334,18 +344,32 @@ exports.downloadAllFiles = function (chapterFilesArr, selectLecture, downloadPat
let count = 0;
chapterFilesArr.forEach(function (chapterObj, index) {
var asyncDownloadPath = downloadPath + chapterObj.chapter + '/';
if (!fs.existsSync(asyncDownloadPath))
fs.mkdirSync(asyncDownloadPath);
var subCount = 0;
if(chapterFilesArr.length-1 === count){
resolve('\n 파일이 ' + downloadPath + ' 에 저장되었어요! 열공 :)');
}
if(chapterObj.files.length === 0){
count ++;
return;
}
chapterObj.files.forEach(function (value, index) {
request = https.get(value.link, function (response) {
let file = fs.createWriteStream(asyncDownloadPath + value.fileName);
response.pipe(file);
subCount++;
if (subCount === chapterObj.files.length) {
count++;
console.log(' 다운로드중... (' + asyncDownloadPath + ')');
......
var functions = require('./functions');
exports.getLectureList = function (id, pw) {
console.log(id + " " + pw);
}
\ No newline at end of file
exports.getLectureList = function (id, pw, cb) {
functions.login(id, pw)
.then(functions.getLecture)
.then(functions.getLectureLink)
.then(function(res){
cb(res);
})
.catch(function(err){
cb(err);
})
};
exports.getLectureFileLinks = function(lectureLink, cb){
functions.getClassPageBody(lectureLink)
.then(functions.findFiles)
.then(function(res){
cb(res);
})
.catch(function(err){
cb(err);
})
};
exports.isValidIdPw = function(id, pw, cb){
functions.login(id, pw)
.then(function(){
cb(true);
})
.catch(function(){
cb(false);
})
};
exports.downloadSelectedFiles = function(selectedChapter, selectedLecture, cb){
functions.downloadSelectedFiles(selectedChapter, selectedLecture,null)
.then(function(res){
cb(res);
})
.catch(function(err){
cb(err);
})
};
exports.downloadAllFiles = function(selectedFilesArr, selectedLecture, cb){
functions.downloadAllFiles(selectedFilesArr, selectedLecture,null)
.then(function(res){
cb(res);
})
.catch(function(err){
cb(err);
})
};
\ No newline at end of file
......
{
"name": "klas-file-downloader",
"version": "0.1.7",
"version": "1.0.0",
"description": "Project that download lecture reference files from Klas",
"main": "module.js",
"scripts": {
......