Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
D_Team_Khuloud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
toror33
2020-06-09 01:11:05 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9043186a434ec4dd4b2ec37db971de5467e5217f
9043186a
1 parent
f9f0f066
연락처 업로드
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
4 deletions
backend/package-lock.json
backend/package.json
backend/routes/contact.js
backend/routes/modules/config.js
backend/package-lock.json
View file @
9043186
This diff is collapsed. Click to expand it.
backend/package.json
View file @
9043186
...
...
@@ -17,9 +17,11 @@
"http-errors"
:
"~1.6.3"
,
"moment"
:
"^2.26.0"
,
"morgan"
:
"~1.9.1"
,
"multer"
:
"^1.4.2"
,
"mysql"
:
"^2.18.1"
,
"passport"
:
"^0.4.1"
,
"pug"
:
"^3.0.0"
,
"request"
:
"^2.88.2"
"request"
:
"^2.88.2"
,
"xlsx"
:
"^0.16.2"
}
}
...
...
backend/routes/contact.js
View file @
9043186
var
express
=
require
(
'express'
);
var
router
=
express
.
Router
();
const
XLSX
=
require
(
'xlsx'
);
var
multer
=
require
(
'multer'
);
var
fs
=
require
(
'fs'
);
// var pool = require('./../routes/modules/database');
//파일 저장위치와 파일이름 설정
var
storage
=
multer
.
diskStorage
({
destination
:
function
(
req
,
file
,
cb
)
{
cb
(
null
,
'public/upload'
);
},
//파일이름 설정
filename
:
function
(
req
,
file
,
cb
)
{
cb
(
null
,
file
.
originalname
);
}
})
//파일 업로드 모듈
var
upload
=
multer
({
storage
:
storage
})
// 연락처 백업, 삭제, 검색
/*
...
...
@@ -7,8 +25,62 @@ contact_upload : 연락처 파일 업로드 모듈
input : 사용자가 연락처를 저장해놓은 csv 혹은 xlsx 파일
output : 연락처 저장 성공 여부
*/
router
.
get
(
'/contact_upload'
,
function
(
req
,
res
,
next
)
{
console
.
log
(
"login"
);
router
.
post
(
'/contact_upload'
,
upload
.
single
(
'file'
),
function
(
req
,
res
,
next
)
{
// console.log(req);
var
user_id
=
req
.
query
.
id
;
var
file
=
req
.
file
;
var
workbook
=
XLSX
.
readFile
(
'public/upload/contact.xlsx'
);
var
firstWSheetName
=
workbook
.
SheetNames
[
0
];
var
firstWSheet
=
workbook
.
Sheets
[
firstWSheetName
];
var
name
=
[];
var
phone
=
[];
var
email
=
[];
var
added_date
=
[];
var
length
=
firstWSheet
[
'!ref'
][
4
];
var
temp
=
""
;
var
sqlquery
=
"insert into contact(user_id,name,email,phone,added_date) values"
;
for
(
var
i
=
1
;
i
<
length
;
i
++
)
{
for
(
var
j
=
0
;
j
<
4
;
j
++
)
{
if
(
j
==
0
){
temp
=
"A"
+
(
i
+
1
);
name
.
push
(
firstWSheet
[
temp
].
v
);
sqlquery
+=
' ("'
+
user_id
+
'","'
+
name
[
i
-
1
];
}
else
if
(
j
==
1
){
temp
=
"B"
+
(
i
+
1
);
phone
.
push
(
firstWSheet
[
temp
].
v
);
sqlquery
+=
'","'
+
phone
[
i
-
1
];
}
else
if
(
j
==
2
){
temp
=
"C"
+
(
i
+
1
);
email
.
push
(
firstWSheet
[
temp
].
v
);
sqlquery
+=
'","'
+
email
[
i
-
1
];
}
else
if
(
j
==
3
){
temp
=
"D"
+
(
i
+
1
);
added_date
.
push
(
firstWSheet
[
temp
].
v
);
sqlquery
+=
'","'
+
added_date
[
i
-
1
]
+
'"),'
;
}
}
}
sqlquery
=
sqlquery
.
substring
(
0
,
sqlquery
.
length
-
1
);
connection
.
query
(
sqlquery
,
function
(
err
,
rows
)
{
if
(
err
)
{
console
.
log
(
"upload contact failed"
);
throw
err
;
}
else
{
console
.
log
(
rows
);
var
filename
=
'public/upload/contact.xlsx'
;
fs
.
unlink
(
filename
,
function
(
err
)
{
if
(
err
)
throw
err
;
console
.
log
(
'file deleted'
);
})
res
.
status
(
200
).
send
(
'upload'
);
}
});
});
/*
...
...
backend/routes/modules/config.js
View file @
9043186
...
...
@@ -7,4 +7,4 @@ connection = mysql.createConnection({
password
:
'password1234'
,
database
:
'khuloud'
,
connectionLimit
:
30
});
\ No newline at end of file
});
...
...
Please
register
or
login
to post a comment