Преглед на файлове

青龙助手工具类测试

shawenguan преди 1 година
родител
ревизия
1041aabbf1
променени са 4 файла, в които са добавени 416 реда и са изтрити 0 реда
  1. 18 0
      Scripts/jhsh/test.js
  2. 301 0
      Scripts/util/QLTools.js
  3. 0 0
      Scripts/util/QLTools.min.js
  4. 97 0
      test.js

Файловите разлики са ограничени, защото са твърде много
+ 18 - 0
Scripts/jhsh/test.js


+ 301 - 0
Scripts/util/QLTools.js

@@ -0,0 +1,301 @@
+
+function QLTools(url, clientId, clientSecret) {
+    return new (class {
+        constructor(url, clientId, clientSecret) {
+            this.isEnableLog = true;
+            this.logSeparator = '\n██'
+            this.url = url;
+            this.clientId = clientId;
+            this.clientSecret = clientSecret;
+            this.auth = null;
+        }
+
+        log(message) {
+            if (this.isEnableLog) console.log(`${this.logSeparator}${message}`);
+        }
+
+        isSurge() {
+            return typeof $httpClient != "undefined";
+        }
+
+        isQuanX() {
+            return typeof $task != "undefined";
+        }
+
+        isLoon() {
+            return typeof $loon != "undefined";
+        }
+
+        isJSBox() {
+            return typeof $app != "undefined" && typeof $http != "undefined";
+        }
+
+        isStash() {
+            return 'undefined' !== typeof $environment && $environment['stash-version'];
+        }
+
+        isNode() {
+            return typeof require == "function" && !this.isJSBox();
+        }
+
+        get(options, callback = () => { }) {
+            if (this.isQuanX()) {
+                if (typeof options == "string") options = {
+                    url: options
+                }
+                options["method"] = "GET"
+                $task.fetch(options).then(response => {
+                    callback(null, this.adapterStatus(response), response.body)
+                }, reason => callback(reason.error, null, null))
+            }
+            if (this.isSurge() || this.isLoon() || this.isStash()) $httpClient.get(options, (error, response, body) => {
+                callback(error, this.adapterStatus(response), body)
+            })
+            if (this.isNode()) {
+                this.node.request(options, (error, response, body) => {
+                    callback(error, this.adapterStatus(response), body)
+                })
+            }
+            if (this.isJSBox()) {
+                if (typeof options == "string") options = {
+                    url: options
+                }
+                options["header"] = options["headers"]
+                options["handler"] = function (resp) {
+                    let error = resp.error
+                    if (error) error = JSON.stringify(resp.error)
+                    let body = resp.data
+                    if (typeof body == "object") body = JSON.stringify(resp.data)
+                    callback(error, this.adapterStatus(resp.response), body)
+                }
+                $http.get(options)
+            }
+        }
+
+        post(options, callback = () => { }) {
+            if (this.isQuanX()) {
+                if (typeof options == "string") options = {
+                    url: options
+                }
+                options["method"] = "POST"
+                $task.fetch(options).then(response => {
+                    callback(null, this.adapterStatus(response), response.body)
+                }, reason => callback(reason.error, null, null))
+            }
+            if (this.isSurge() || this.isLoon() || this.isStash()) {
+                $httpClient.post(options, (error, response, body) => {
+                    callback(error, this.adapterStatus(response), body)
+                })
+            }
+            if (this.isNode()) {
+                this.node.request.post(options, (error, response, body) => {
+                    callback(error, this.adapterStatus(response), body)
+                })
+            }
+            if (this.isJSBox()) {
+                if (typeof options == "string") options = {
+                    url: options
+                }
+                options["header"] = options["headers"]
+                options["handler"] = function (resp) {
+                    let error = resp.error
+                    if (error) error = JSON.stringify(resp.error)
+                    let body = resp.data
+                    if (typeof body == "object") body = JSON.stringify(resp.data)
+                    callback(error, this.adapterStatus(resp.response), body)
+                }
+                $http.post(options)
+            }
+        }
+
+        put(options, callback = () => { }) {
+            if (this.isQuanX()) {
+                // no test
+                if (typeof options == "string") options = {
+                    url: options
+                }
+                options["method"] = "PUT"
+                $task.fetch(options).then(response => {
+                    callback(null, this.adapterStatus(response), response.body)
+                }, reason => callback(reason.error, null, null))
+            }
+            if (this.isSurge() || this.isLoon() || this.isStash()) {
+                options.method = "PUT"
+                $httpClient.put(options, (error, response, body) => {
+                    callback(error, this.adapterStatus(response), body)
+                })
+            }
+            if (this.isNode()) {
+                options.method = "PUT"
+                this.node.request.put(options, (error, response, body) => {
+                    callback(error, this.adapterStatus(response), body)
+                })
+            }
+        }
+
+        delete(options, callback = () => { }) {
+            if (this.isQuanX()) {
+                // no test
+                if (typeof options == "string") options = {
+                    url: options
+                }
+                options["method"] = "DELETE"
+                $task.fetch(options).then(response => {
+                    callback(null, this.adapterStatus(response), response.body)
+                }, reason => callback(reason.error, null, null))
+            }
+            if (this.isSurge() || this.isLoon() || this.isStash()) {
+                options.method = "DELETE"
+                $httpClient.put(options, (error, response, body) => {
+                    callback(error, this.adapterStatus(response), body)
+                })
+            }
+            if (this.isNode()) {
+                options.method = "DELETE"
+                this.node.request.put(options, (error, response, body) => {
+                    callback(error, this.adapterStatus(response), body)
+                })
+            }
+        }
+
+        setAuth(auth){
+            this.auth = auth;
+        }
+
+
+        async login(){
+            let result = await this.getToken();
+            if(!result){
+                return false;
+            }
+            if(result.code == 200){
+                let data = result.data;
+                this.auth = `${data.token_type} ${data.token}`;
+                return true;
+            }
+            return false;
+        }
+
+        async getToken(){
+            let url = `${this.url}/open/auth/token?client_id=${this.clientId}&client_secret=${this.clientSecret}`;
+            let options = {
+                url: url,
+            };
+            return new Promise(resolve => {
+                this.get(options, async (error, response, data) => {
+                    try {
+                        let result = JSON.parse(data);
+                        resolve(result);
+                    } catch (error) {
+                        this.log(error);
+                    } finally {
+                        resolve();
+                    }
+                });
+            });
+        }
+
+
+        async callApi(reqType, optName1, optName2=null , params=null){
+            let url = `${this.url}/open/${optName1}`;
+            if(optName2 && optName2.length > 0){
+                url += `/${optName2}`;
+            }
+            let body = '';
+            if(params){
+                body = JSON.stringify(params);
+            }
+            let options = {
+                url: url,
+                headers: {
+                    'Authorization': this.auth,
+                    'Content-Type': `application/json`,
+                    'Accept': `application/json`,
+                },
+                body: body,
+            };
+            return new Promise(resolve => {
+                let func = this['reqType'];
+                if(!func){
+                    resolve();
+                    return;
+                }
+                func.call(this, options, async (error, response, data) => {
+                    try {
+                        let result = JSON.parse(data);
+                        resolve(result);
+                    } catch (error) {
+                        this.log(error);
+                    } finally {
+                        resolve();
+                    }
+                });
+            });
+        }
+
+        async getEnvs(){
+            return this.callApi('get', 'envs');
+        }
+
+        async getEnvById(id){
+            return this.callApi('get', 'envs', id);
+        }
+
+        async deleteEnvs(ids){
+            return this.callApi('delete', 'envs', '', ids);
+        }
+
+        async addEnvs(envsList){
+            return this.callApi('post', 'envs', '', envsList);
+        }
+
+        async updateEnv(envObj){
+            return this.callApi('put', 'envs', '', envObj);
+        }
+
+        async getCrons(){
+            return this.callApi('get', 'crons');
+        }
+
+        async getCronById(id){
+            return this.callApi('get', 'crons', id);
+        }
+
+        async deleteCrons(ids){
+            return this.callApi('delete', 'crons', '', ids);
+        }
+
+        async addCron(cronObj){
+            return this.callApi('post', 'crons', '', cronObj);
+        }
+
+        async updateCron(cronObj){
+            return this.callApi('put', 'crons', '', cronObj);
+        }
+
+        async runCrons(ids){
+            return this.callApi('put', 'crons', 'run', ids);
+        }
+
+        async stopCrons(ids){
+            return this.callApi('put', 'crons', 'stop', ids);
+        }
+
+        async enableCrons(ids){
+            return this.callApi('put', 'crons', 'enable', ids);
+        }
+
+        async disableCrons(ids){
+            return this.callApi('put', 'crons', 'disable', ids);
+        }
+
+        async getCronDetail(id){
+            return this.callApi('get', 'crons', id);
+        }
+
+        async getCronLog(id){
+            return this.callApi('get', 'crons', `${id}/log`);
+        }
+
+    })(url, clientId, clientSecret);
+}

Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
Scripts/util/QLTools.min.js


+ 97 - 0
test.js

@@ -0,0 +1,97 @@
+function FindProxyForURL(url, host) {
+    host = host.toLowerCase();
+    url = url.toLowerCase();
+    if (dnsDomainIs(host, 'test.com')) {
+        return 'PROXY 123.123.123.123:8080';
+    } else if (dnsDomainIs(host, 'yunbusiness.ccb.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'piaocmb.o2o.cmbchina.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'icbc.opapp.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'piaorush.o2o.cmbchina.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'piao-json-cdn.o2o.cmbchina.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'fpwx.o2o.cmbchina.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'ccpay.cib.com.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'psbc.huajifen.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'gdecard.jiahuaming.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'mall.abchina.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'm.ujia007.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'creditcardapp.bankcomm.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'mall.creditcard.gzcb.com.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'vtravel.link2shops.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'uop.amexpressnetwork.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'mapi-seckill.bestpay.com.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'piaorush.o2o.cmbchina.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'piao-json-cdn.o2o.cmbchina.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'fpwx.o2o.cmbchina.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'm.client.10010.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'aaph.nbcb.com.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'api.shoppingm.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'wzapi.oywanhao.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'hemi.lianhaikeji.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'static.lianhaikeji.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'hz.qyfw168.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'appsmall.rtmap.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'www.mcearnmore.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'm.mallcoo.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'mall.nbcb.com.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'delivery.aeonbuy.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'g.qll-times.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'api.jifenfu.net')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'h5.schengle.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'bnb.rongdatamall.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'chuxinget.fpsd.unionpay.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'marketing.bulk-delivery.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'wypwfw.xsy365.com.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'fw.qyfw168.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, '94828.activity-35.m.duiba.com.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'aaph.nbcb.com.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'market-web.ofpay.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'service.jifenfu.net')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'vip.octharbour.com')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'crm.scpgroup.com.cn')) {
+        return 'PROXY 106.52.252.45:25010';
+    } else if (dnsDomainIs(host, 'mtp.creditcard.ecitic.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'rushbuy.creditcard.ecitic.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'wx.abchina.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'mrp.creditcard.hxb.com.cn')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'api.m.jd.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'prodev.m.jd.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'promotion.waimai.meituan.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'activitymanual.epaynfc.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'ebusiness.bzh001.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'yx.all-pay.cn')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'w.all-pay.cn')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'icbc.rellux.com.cn')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'ilike-cloud-mapi.zmaxfilm.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'coin.abchina.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'ldp.creditcard.ecitic.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'wxapi.m.taopiaopiao.com')) { return 'PROXY 106.52.252.45:25010'; } else if (dnsDomainIs(host, 'hbp-prod.fenlekeji.com')) { return 'PROXY 106.52.252.45:25010'; } else { return 'DIRECT'; }
+}

Някои файлове не бяха показани, защото твърде много файлове са промени