update upload function

This commit is contained in:
Mohamed Nouffer
2021-09-13 12:46:52 +05:30
parent dae426eefa
commit 77cef6d5e9
3 changed files with 114 additions and 93 deletions

View File

@ -16,9 +16,8 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors(corsOptions)); app.use(cors(corsOptions));
function callInitFileMover(re) { function callLoadInitializeData(projectid, construction_id, username, sheetname, filename){
https.get('https://natnats.mobilous.com/loadInitializeData?projectid=23&construction_id=1&username=1&sheetname=dataSheet&filename=ini_データ入力シート.xlsx', (resp) => {
https.get('https://natnats.mobilous.com/iniFileMover', (resp) => {
let data = ''; let data = '';
// A chunk of data has been received. // A chunk of data has been received.
@ -26,6 +25,36 @@ https.get('https://natnats.mobilous.com/iniFileMover', (resp) => {
data += chunk; data += chunk;
}); });
// The whole response has been received. Print out the result.
resp.on('end', () => {
if(data !== 'no match'){
resdata = JSON.parse(data);
console.log(resdata);
}
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
function callInitFileMover(re) {
https.get('https://natnats.mobilous.com/iniFileMover', (resp) => {
let data = '';
// A chunk of data has been received.
resp.on('data', (chunk) => {
//debug
data = "{
"construction_id": 3,
"file_name": "ini_データ入力シート.xlsx",
"file_type": "dataSheet"
}"
data += chunk;
});
// The whole response has been received. Print out the result. // The whole response has been received. Print out the result.
resp.on('end', () => { resp.on('end', () => {
if(data !== 'no match'){ if(data !== 'no match'){
@ -55,6 +84,8 @@ var upload = multer({ storage: storage }).single('file')
app.post('/upload', function(req, res, next) { app.post('/upload', function(req, res, next) {
console.log(req.body.email);
upload(req, res, function(err) { upload(req, res, function(err) {
if (err instanceof multer.MulterError) { if (err instanceof multer.MulterError) {
return res.status(500).json(err) return res.status(500).json(err)

View File

@ -28,11 +28,11 @@ const TheContent = () => {
async function fetchSession() { async function fetchSession() {
//setSsoSession('{ "expiration": 468, "client_address": "111.223.144.163", "protocol": "urn:oasis:names:tc:SAML:2.0:protocol", "identity_provider": "https://sso.ts.bizside.biz/idp/shibboleth", "authn_instant": "2021-09-03T08:26:41.248Z", "authncontext_class": "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport", "attributes": [ { "name": "mail", "values": [ "akira.miyata@mobilous.com" ] } ] }') setSsoSession('{ "expiration": 468, "client_address": "111.223.144.163", "protocol": "urn:oasis:names:tc:SAML:2.0:protocol", "identity_provider": "https://sso.ts.bizside.biz/idp/shibboleth", "authn_instant": "2021-09-03T08:26:41.248Z", "authncontext_class": "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport", "attributes": [ { "name": "mail", "values": [ "akira.miyata@mobilous.com" ] } ] }')
const result = await axios('https://fsbsso.sumasen.net/Shibboleth.sso/Session'); // const result = await axios('https://fsbsso.sumasen.net/Shibboleth.sso/Session');
if(JSON.stringify(SsoSession) !== JSON.stringify(result.data)) { // if(JSON.stringify(SsoSession) !== JSON.stringify(result.data)) {
setSsoSession(result.data); // setSsoSession(result.data);
} // }
} }
useEffect(() => { useEffect(() => {
@ -93,47 +93,47 @@ const TheContent = () => {
function get_token_from_storage_or_cookie() { function get_token_from_storage_or_cookie() {
//return true; //return true;
const cookies = new Cookies(); // const cookies = new Cookies();
const shib = cookies.get('_shibsession_64656661756c7468747470733a2f2f66736273736f2e73756d6173656e2e6e65742f73686962626f6c657468') // const shib = cookies.get('_shibsession_64656661756c7468747470733a2f2f66736273736f2e73756d6173656e2e6e65742f73686962626f6c657468')
if (shib !== undefined) { // if (shib !== undefined) {
fetchSession().then(() => { // fetchSession().then(() => {
if (SsoSession !== null) { // if (SsoSession !== null) {
console.log(shib); // console.log(shib);
fetchUser().then(() => { // fetchUser().then(() => {
if(UserId === ''){ // if(UserId === ''){
let id = Math.floor(100000 + Math.random() * 900000) // let id = Math.floor(100000 + Math.random() * 900000)
setUserId(id); // setUserId(id);
} // }
const _firstname = UserData.firstname; // const _firstname = UserData.firstname;
const _lastname = UserData.lastname; // const _lastname = UserData.lastname;
const _email = UserData.email; // const _email = UserData.email;
const _empcode = UserData.employee_code; // const _empcode = UserData.employee_code;
const json_str = `[ // const json_str = `[
{ // {
"mailadress": "${_email}", // "mailadress": "${_email}",
"name": "${_lastname} ${_firstname}", // "name": "${_lastname} ${_firstname}",
"jsessionid": ${UserId}, // "jsessionid": ${UserId},
"_idp_session": "", // "_idp_session": "",
"_opensaml_key": "_shibsession_64656661756c7468747470733a2f2f66736273736f2e73756d6173656e2e6e65742f73686962626f6c657468", // "_opensaml_key": "_shibsession_64656661756c7468747470733a2f2f66736273736f2e73756d6173656e2e6e65742f73686962626f6c657468",
"_opensaml_value": "${shib}" // "_opensaml_value": "${shib}"
} // }
]`; // ]`;
//const json_str = '[{"jsessonid": "' + UserId + '" , "name": "' + _firstname + ' ' +_lastname+ '", "mailadress":" ' + _email + '", "empcode": "' + _empcode + '"}]'; // //const json_str = '[{"jsessonid": "' + UserId + '" , "name": "' + _firstname + ' ' +_lastname+ '", "mailadress":" ' + _email + '", "empcode": "' + _empcode + '"}]';
if(_empcode !== null && _empcode !== undefined){ // if(_empcode !== null && _empcode !== undefined){
if(isCSVPath()){ // if(isCSVPath()){
postUserData(json_str); // postUserData(json_str);
} // }
} // }
return true; // return true;
}); // });
} // }
}); // });
} else { // } else {
return null; // return null;
} // }
} }
@ -151,7 +151,7 @@ const TheContent = () => {
render = { render = {
props => props =>
get_token_from_storage_or_cookie() !== null ? get_token_from_storage_or_cookie() !== null ?
( <route.component {...props} userid={UserId}/> ( <route.component {...props} userid={UserId} email={"test@test.com"}/>
) : ( <Redirect to = { ) : ( <Redirect to = {
{ pathname: "/sso" } { pathname: "/sso" }
} }

View File

@ -1,4 +1,4 @@
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import axios from 'axios'; import axios from 'axios';
import { import {
CCol, CCol,
@ -15,7 +15,7 @@ import {
import CIcon from '@coreui/icons-react' import CIcon from '@coreui/icons-react'
function Uploader() { function Uploader(props) {
const [file, setFile] = useState(null); const [file, setFile] = useState(null);
@ -26,6 +26,7 @@ function Uploader() {
function onClickHandler(e) { function onClickHandler(e) {
const data = new FormData() const data = new FormData()
data.append('file', file); data.append('file', file);
data.append('email', props.email);
const chk = file.name.trim(); const chk = file.name.trim();
const collator = new Intl.Collator('ja'); const collator = new Intl.Collator('ja');
const order1 = collator.compare('ini_工程内検査票.xlsx', chk); const order1 = collator.compare('ini_工程内検査票.xlsx', chk);
@ -50,38 +51,27 @@ function Uploader() {
} }
return ( < return (
div > <div>
< <CCard >
CCard > <CCardHeader>
< アップロード
CCardHeader > </CCardHeader>
アップロード < <CCardBody >
/CCardHeader> < <CFormGroup row>
CCardBody > <CCol md = "3">
< <CLabel htmlFor = "date-input" > アップロードするファイルを選んでください < /CLabel>
CFormGroup row > </CCol >
< <CCol xs = "12"md = "9" >
CCol md = "3" > <CInputFile type = "file"onChange = { onChangeHandler } id = "file-input" name = "file-input" / >
< </CCol>
CLabel htmlFor = "date-input" > アップロードするファイルを選んでください < /CLabel> < / </CFormGroup >
CCol > <
CCol xs = "12"
md = "9" >
<
CInputFile type = "file"
onChange = { onChangeHandler }
id = "file-input"
name = "file-input" / >
<
/CCol> < /
CFormGroup >
<CCardFooter > <CCardFooter >
<CButton type = "submit" <CButton type = "submit"
onClick = { onClickHandler } onClick = { onClickHandler }
size = "sm" size = "sm"
color = "primary" > < CIcon name = "cil-scrubber" / > アップロード < /CButton> < / color = "primary" > < CIcon name = "cil-scrubber" / > アップロード </CButton>
CCardFooter> </CCardFooter>
</CCardBody> </CCardBody>
</CCard> </CCard>
</div> </div>