maintain (code): cleanup

This commit is contained in:
Mickael KERJEAN 2018-09-12 03:02:28 +10:00
parent 4907c9b0d0
commit 1077165e3d
6 changed files with 41 additions and 9 deletions

View file

@ -111,6 +111,7 @@ export const onUpload = function(path, e){
return Promise.resolve(files);
})
.then((files) => {
console.log("== FILES: " + files.length)
const processes = files.map((file) => {
file.path = Path.join(path, file.path);
if(file.type === 'file'){
@ -132,14 +133,23 @@ export const onUpload = function(path, e){
let current_process = null;
if(processes.length === 0) return Promise.resolve();
for(let i=0; i<processes.length; i++){
if(processes[i].parent === null || PRIOR_STATUS[processes[i].parent] === true){
var i;
for(i=0; i<processes.length; i++){
if(processes[i].parent === null){
// init: getting started with creation of files/folders
current_process = processes[i];
processes.splice(i, 1);
break;
}else if(PRIOR_STATUS[processes[i].parent] === true){
// running: make sure we've created the parent before attempting the entire filesystem
current_process = processes[i];
processes.splice(i, 1);
break;
}
}
console.log(" p:"+processes.length+" ::"+i)
if(current_process){
return current_process.fn(id)
.then(() => {
@ -159,12 +169,15 @@ export const onUpload = function(path, e){
requestAnimationFrame(() => {
done();
});
}, 100);
}, 1000);
});
}
}
}
if(files.length > 5){
notify.send('Uploading '+files.length+' files', 'info');
}
Promise.all(Array.apply(null, Array(MAX_POOL_SIZE)).map((process,index) => {
return runner();
})).then(() => {

View file

@ -97,8 +97,9 @@ export class FilesPage extends React.Component {
onRefresh(path = this.state.path){
this._cleanupListeners();
console.log("- refresh filespage");
const observer = Files.ls(path).subscribe((res) => {
console.log("- refresh filespage: " + res.status);
if(res.status === 'ok'){
let files = res.results;
files = files.map((file) => {

View file

@ -8,6 +8,9 @@ import (
//"github.com/pkg/browser"
//"io/ioutil"
"strconv"
// "os"
// "os/signal"
// "syscall"
)
var APP_URL string
@ -19,6 +22,14 @@ func main() {
router.Init(&app)
APP_URL = "http://" + app.Config.General.Host + ":" + strconv.Itoa(app.Config.General.Port)
// c := make(chan os.Signal)
// signal.Notify(c, os.Interrupt, syscall.SIGTERM)
// go func() {
// <-c
// log.Println("KILLED HERE WITH OS")
// os.Exit(1)
// }()
// systray.Run(setupSysTray(&app), func() {
// srv.Shutdown(context.TODO())
// })

View file

@ -7,6 +7,7 @@ import (
"golang.org/x/crypto/ssh"
"io"
"os"
"log"
"strings"
)
@ -109,6 +110,7 @@ func (b Sftp) Home() (string, error) {
func (b Sftp) Ls(path string) ([]os.FileInfo, error) {
files, err := b.SFTPClient.ReadDir(path)
log.Println("HERE:", err)
return files, b.err(err)
}
@ -173,6 +175,7 @@ func (b Sftp) Touch(path string) error {
func (b Sftp) Save(path string, file io.Reader) error {
remoteFile, err := b.SFTPClient.OpenFile(path, os.O_WRONLY|os.O_CREATE)
//log.Println("HERE: ", err)
if err != nil {
return b.err(err)
}

View file

@ -36,9 +36,13 @@ func Init(a *App) *http.Server {
Handler: r,
}
go func() {
log.Println("ICI")
if err := srv.ListenAndServe(); err != nil {
log.Fatal(err)
log.Fatal("SERVER START ERROR ", err)
return
}
log.Println("SERVER START OK")
}()
log.Println("HERE")
return srv
}

View file

@ -62,11 +62,11 @@ func extractBody(req *http.Request) (map[string]string, error) {
}
byt, err := ioutil.ReadAll(req.Body)
if err != nil {
return nil, err
return body, err
}
if err := json.Unmarshal(byt, &body); err != nil {
return nil, err
}
return body, err
}
return body, nil
}