Ignore:
Timestamp:
Aug 30, 2019 7:54:52 AM (6 years ago)
Author:
anonymous
Message:

add bin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/testa-single-bookmark/js/remotex.js

    r36 r41  
    77    }
    88
    9     make_url_params( arrayx ){
     9    make_url_params0( arrayx ){
    1010        let params = new URLSearchParams();
    1111        arrayx.reduce(function(acc, element, index, array) {
     
    1313            return acc;
    1414        }, params)
    15         return params;
     15        return params.toString();
     16    }
     17
     18    make_url_params( arrayx , num ){
     19        let params = new URLSearchParams();
     20        for(let i=0; i<num; i++ ){
     21            params.append(arrayx[i][0], arrayx[i][1])
     22        }
     23        const pa = params.toString()
     24        return pa
    1625    }
    1726
    1827    async get_filelist_from_remote( num, part, func ) {
    19         console.log("remotex get_filelist_from_remote num=" + num + " part=" + part )
    2028        let param_array = [['cmd', 'get_filelistx'], ['num', num ], ['part', part ]]
    21         await this.fetchx( this.filename , param_array, func )
     29        await this.fetchx( this.filename , param_array, 3, func )
    2230    }
    2331
    2432    async update_filelist( num, part, func ) {
    25         console.log("remotex update_filelist num=" + num + " part=" + part )
    2633        let param_array = [['cmd', 'update_filelistx'], ['num', num ], ['part', part ]]
    27         await this.fetchx( this.filename , param_array, func )
     34        await this.fetchx( this.filename , param_array, 3, func )
    2835    }
    2936
    3037    async get_content(num, part, path , func) {
    31         console.log("remotex get_content num=" + num + " part=" + part )
    32         console.log("part=" + part)
    3338        let param_array = [['cmd', 'get_content'], ['num', num ], ['part', part ], ['path', path]]
    34         await this.fetchx( this.filename , param_array, func )
     39        await this.fetchx( this.filename , param_array, 4, func )
    3540    }
    3641
    3742    async get_output_url(num, func) {
    38 console.log("get_output_url")
    39         console.log("remotex get_output_url num=" + num )
    4043        let param_array = [['cmd', 'get_output_url'], ['num', num ] ]
    41         await this.fetchx( this.filename , param_array, func )
     44        await this.fetchx( this.filename , param_array, 2, func )
    4245    }
    4346
    44     async fetchx( filename, param_array, func) {
    45 console.log("fetchx func" + func)
    46         let params = this.make_url_params( param_array )
     47    async fetchx( filename, param_array, num, func) {
     48        let params = this.make_url_params( param_array , num )
    4749        fetch(`${filename}?${params}`)
    48             .then((response) => response.text())
    49             .then((text) => { console.log(func) ; if( func !== undefined ){func(text)} else { console.log("func=undefined")} })
    50             .catch((error) => console.log(error));
     50            .then((response) => { return response.text() })
     51            .then((text) => { func(text) })
     52            .catch((error) => console.log("error=" + error));
    5153    }
    5254
     
    5456        if( Globalx[part].key_indicate_file === true ){
    5557            let textarea = $( Globalx[part].textarea_sel )
    56             upload_content(Globalx.num, part, Globalx[part].key, textarea.val())
     58            this.upload_content(Globalx.num, part, Globalx[part].key, textarea.val())
    5759        }
     60    }
     61
     62    async build( cmd, num, part, path, content, func = null ) {
     63        await this.upload_file( cmd, num, part, path, content, func = null )
     64    }
     65
     66    async upload_file(cmd, num, part, path, content, func = null) {
     67        let form = document.createElement('form')
     68        let req_cmd = document.createElement('input')
     69        let req_num = document.createElement('input')
     70        let req_part = document.createElement('input')
     71        let req_path = document.createElement('input')
     72        let req_content = document.createElement('input')
     73
     74        document.body.appendChild(form)
     75
     76        req_cmd.type = 'hidden'
     77        req_cmd.name = 'cmd'
     78        req_cmd.value = cmd
     79       
     80        req_num.type = 'hidden'
     81        req_num.name = 'num'
     82        req_num.value = num + ''
     83       
     84        req_part.type = 'hidden'
     85        req_part.name = 'part'
     86        req_part.value = part
     87       
     88        req_path.type = 'hidden'
     89        req_path.name = 'path'
     90        req_path.value = path
     91       
     92        req_content.type = 'hidden'
     93        req_content.name = 'mytext'
     94        req_content.value = content
     95       
     96        form.appendChild(req_cmd)
     97        form.appendChild(req_num)
     98        form.appendChild(req_part)
     99        form.appendChild(req_path)
     100        form.appendChild(req_content)
     101       
     102        // FormDataオブジェクトを作成する
     103        var form_data = new FormData(form);
     104console.log("remotex.js filename=" + this.filename )
     105        fetch( this.filename , {
     106            method: 'POST',
     107            mode: 'same-origin', /* 'no-cors' 'cors' 'same-origin' */
     108            body: form_data
     109        })
     110            .then((response) => {
     111                return response.text()
     112            })
     113            .then((data) => {console.log( "data=" + data)
     114                             if( func !== null ){
     115                                 func(data)
     116                             }
     117                            })
     118            .catch((error) => {console.log("error=" + error)})
    58119    }
    59120
     
    64125        let req_cmd = document.createElement('input');
    65126        let req_num = document.createElement('input');
     127        let req_part = document.createElement('input');
    66128
    67129        document.body.appendChild(form);
     
    82144        req_num.value = num + '';
    83145       
     146        req_part.type = 'hidden';
     147        req_part.name = 'part';
     148        req_part.value = part;
     149       
    84150        form.appendChild(req_content);
    85151        form.appendChild(req_path);
    86152        form.appendChild(req_cmd);
    87153        form.appendChild(req_num);
     154        form.appendChild(req_part);
    88155       
    89156        // FormDataオブジェクトを作成する
    90157        var form_data = new FormData(form);
    91 
    92         fetch('php/content.php', {
     158console.log("remotex.js filename=" + this.filename )
     159        fetch( this.filename , {
    93160            method: 'POST',
    94161            mode: 'same-origin', /* 'no-cors' 'cors' 'same-origin' */
    95162            body: form_data
    96163        })
    97             .then((response) => response.text())
    98             .then((data) => console.log(data))
    99             .catch((error) => console.log(error));
     164            .then((response) => { return response.text()})
     165            .then((data) => {console.log( "data=" + data)})
     166            .catch((error) => {console.log("error=" + error)});
    100167    }
    101168
Note: See TracChangeset for help on using the changeset viewer.