Ejemplo n.º 1
0
    expand (url, cb) {
        if (!url && !this.shortenUrl) {
            throw 'You need to pass a url or have a shorten url';
        }
        let _url = url || this.shortenUrl;

        let apiExpandUrl = API_URL + 'v3/expand',
            params = querystring({
                shortUrl: _url,
                access_token: this.token,
                format: 'txt'
            }),
            that = this;

        this.request(apiExpandUrl + params, (err, res) => {
            if (!err && res.statusCode === 200) {
                that.shortenUrl = res.body;
                if (cb && typeof cb === 'function') {
                    cb();
                } else {
                    return that.shortenUrl;
                }
            } else {
                throw `Error on Bitly short() call, ${err}`;
            }
        }).on('error', (err) => {
            throw `Error on Bitly short() call, ${err}`;
        });
    }
Ejemplo n.º 2
0
    short (url, cb) {
        let apiShortUrl = API_URL + 'v3/shorten',
            params = querystring({
                uri: url,
                access_token: this.token,
                format: 'txt'
            }),
            that = this;

        this.request(apiShortUrl + params, (err, res) => {
            if (!err && res.statusCode === 200) {
                that.shortenUrl = res.body;
                if (cb && typeof cb === 'function') {
                    cb();
                } else {
                    return that.shortenUrl;
                }
            } else {
                throw `Error on Bitly short() call, ${err}`;
            }
        }).on('error', (err) => {
            throw `Error on Bitly short() call, ${err}`;
        });
    }
${l.config.TAKE_TIME}: ${e.debug_info.cost_time_ms||''}`}})}catch(a){}this.props.setWidget({ready:!0,height:n,wxaData:f,jumpUrl:k,jumpQuery:m}),this.setWidgetOffset(),d.toService({command:'APPSERVICE_ON_EVENT',data:{eventName:'onCanvasInsert',data:{query:{wxOpenId:h,widgetData:encodeURIComponent(g),wxParamData:encodeURIComponent(j)},width:o,height:Math.ceil(n)}}})}).catch((a)=>{this.props.setWidget({ready:!0,errmsg:{group:l.config.WIDGET_NETWORK_ERROR,type:'error',msg:l.config.WIDGET_GET_SEARCH_RESULT_ERROR.format(a)}})})}}render(){const a=this.props,b={height:a.height,width:a.width,position:'absolute'};return c.createElement('div',{className:'webview',ref:(a)=>this.container=a,style:b})}}module.exports=s((a)=>{var b=Math.floor;const c=a.toolbar.deviceInfo,d=a.project.current,g=d.compileType,h=e.getWidgetOffset(g,c);let{width:i,height:j}=h;const k=a.simulator.widget||{};g==f.search&&k.height&&(j=k.height);const l=d.condiction[g]||{},m=l.list[l.current]||{},n=a.toolbar.network.list[a.toolbar.network.current]||'wifi';return{compileCommand:a.simulator.compileCommand,device:c,deviceScale:a.toolbar.deviceScale,ua:c.ua||'',id:2e4,project:a.project.current,compileType:g,width:b(i),height:b(j),ready:k.ready,jumpUrl:k.jumpUrl||'',jumpQuery:k.jumpQuery||{},tapCallback:k.tapCallback,networkType:n,condiction:m}},(a)=>({setConfirmInfo:e.bindActionCreators(m.setConfirmInfo,a),setWidget:e.bindActionCreators(g.setWidget,a),widgetJumpToWeapp:e.bindActionCreators(g.widgetJumpToWeapp,a)}))(u)}(require('lazyload'),require);
Ejemplo n.º 4
0
}(jQuery),function(e){"use strict";function a(a){return console.log("Waiting "+a+" ms to retry"),void 0===e.wait?e.Deferred(function(r){setTimeout(e.bind(r.resolve,r),a)}).promise():e.wait(a)}function r(a){var r="";return a&&(r=e.param(a)),""!==r&&(r="?"+r),r}function s(e){var a=null;return e&&(a=JSON.stringify(e)),a}e.appnet.core.makeUrl=function(e){var a="",r=0;for(r=0;e.length>r;r+=1)e[r]&&(a+=e[r]);return a},e.appnet.core.call=function(t,n,p,o){var i={contentType:"application/json",dataType:"json",type:n,url:t+r(p)},l=e.appnet.userToken;l||(l=e.appnet.appToken),l&&(i.headers={Authorization:"Bearer "+l}),o&&(i.data=s(o));var u=e.ajax(i);return u.fail(function(r){var s;if(s="undefined"!=typeof exports?r.status:r.statusCode(),429===s){var t;t="undefined"!=typeof exports?parseInt(r.headers["retry-after"],10):parseInt(r.getRequestHeader("Retry-After"),10);var n=a(1e3*t);return n.then(function(){return e.ajax(i)})}if("undefined"!=typeof exports)throw r;return r})}}(jQuery),function(e){"use strict";function a(e){r(e.stream_types),s(e.base,e.endpoints),p()}function r(a){var r=0;for(r=0;a.length>r;r+=1)e.appnet[a[r]]={}}function s(a,r){var s=0;for(s=0;r.length>s;s+=1){var t=e.appnet[r[s].group];t?n(a,t,r[s]):(console.log("Invalid group: "+r[s].group),console.dir(r[s]))}}function t(a,r){var s=null,t=null;a.end.url.length>0&&(s=a.end.url[0]),a.end.url.length>1&&(t=a.end.url[1]);var n=e.appnet.core.makeUrl([a.base,s,a.first,t,a.second]),p={};return a.list&&(p.ids=a.list.join(",")),p=e.extend({},p,r),e.appnet.core.call(n,a.end.method,p,a.data)}function n(e,a,r){0===r.url_params.length&&0===r.data_params.length&&0===r.array_params.length?a[r.name]=function(a){return t({base:e,end:r},a)}:1===r.url_params.length&&0===r.data_params.length&&0===r.array_params.length?a[r.name]=function(a,s){return t({base:e,end:r,first:a},s)}:2===r.url_params.length&&0===r.data_params.length&&0===r.array_params.length?a[r.name]=function(a,s,n){return t({base:e,end:r,first:a,second:s},n)}:0===r.url_params.length&&1===r.data_params.length&&0===r.array_params.length?a[r.name]=function(a,s){return t({base:e,end:r,data:a},s)}:1===r.url_params.length&&1===r.data_params.length&&0===r.array_params.length?a[r.name]=function(a,s,n){return t({base:e,end:r,first:a,data:s},n)}:2===r.url_params.length&&1===r.data_params.length&&0===r.array_params.length?a[r.name]=function(a,s,n,p){return t({base:e,end:r,first:a,second:s,data:n},p)}:0===r.url_params.length&&0===r.data_params.length&&1===r.array_params.length?a[r.name]=function(a,s){return t({base:e,end:r,list:a},s)}:1===r.url_params.length&&0===r.data_params.length&&1===r.array_params.length?a[r.name]=function(a,s,n){return t({base:e,end:r,first:a,list:s},n)}:2===r.url_params.length&&0===r.data_params.length&&1===r.array_params.length?a[r.name]=function(a,s,n,p){return t({base:e,end:r,first:a,second:s,list:n},p)}:0===r.url_params.length&&1===r.data_params.length&&1===r.array_params.length?a[r.name]=function(a,s,n){return t({base:e,end:r,data:a,list:s},n)}:1===r.url_params.length&&1===r.data_params.length&&1===r.array_params.length?a[r.name]=function(a,s,n,p){return t({base:e,end:r,first:a,data:s,list:n},p)}:2===r.url_params.length&&1===r.data_params.length&&1===r.array_params.length?a[r.name]=function(a,s,n,p,o){return t({base:e,end:r,first:a,second:s,data:n,list:p},o)}:console.log("Skipping "+r.group+"."+r.name)}function p(){e.appnet.all={},o("getSubscriptions",e.appnet.channel.getUserSubscribed),i("getMessages",e.appnet.message.getChannel),i("getUserPosts",e.appnet.post.getUser),i("getFollowing",e.appnet.user.getFollowing),i("getFollowers",e.appnet.user.getFollowers),u("getChannelList",e.appnet.channel.getList),u("getUserList",e.appnet.user.getList)}function o(a,r){e.appnet.all[a]=l(r)}function i(a,r){e.appnet.all[a]=function(e,a){var s=function(a){return r(e,a)};return l(s)(a)}}function l(a){return function(r){function s(n){if(void 0!==e.wait&&(n=JSON.parse(""+n)),t=t.concat(n.data),n.meta.more){r.before_id=n.meta.min_id;var p=a(r);return p.then(s)}var o={};return n.meta.max_id&&(o.max_id=n.meta.max_id),{data:t,meta:o}}r||(r={}),r.count=200;var t=[],n=a(r);return n.then(s)}}function u(a,r){e.appnet.all[a]=function(a,s){function t(i){if(void 0!==e.wait&&(i=JSON.parse(""+i)),o=o.concat(i.data),n+=200,p=n+(n+200>a.length?a.length:200),a.length>n){var l=r(a.slice(n,p),s);return l.then(t)}return{data:o}}var n=0,p=n+(200>a.length?a.length:200),o=[],i=r(a.slice(n,p),s);return i.then(t)}}a(e.appnet.endpoints)}(jQuery),function(e){"use strict";e.appnet.note.find=function(e,a){var r=null,s=0;if(a)for(s=0;a.length>s;s+=1)if(a[s].type===e){r=a[s].value;break}return r}}(jQuery),function(e){"use strict";function a(a,r){var s=require("mime"),t={type:a,content:{file:r,content_type:s.lookup(r)}};return e.ajax({url:e.appnet.endpoints.base+"files",type:"POST",dataType:"multipart",data:t,headers:{Authorization:"Bearer "+e.appnet.userToken}})}var r=function(){};r.prototype.send=function(){var r,s=this,t=this.parseLinks||this.parseMarkdownLinks,n={annotations:[],entities:{parse_links:!!t,parse_markdown_links:!!this.parseMarkdownLinks}};if("undefined"!=typeof exports){var p=require("q"),o=[];if(this.photo){var i=a("com.github.duerig.appnetjs.photo",this.photo);o.push(i.then(function(e){var a=e.data;return a&&n.annotations.push({type:"net.app.core.oembed",value:{"+net.app.core.file":{file_id:a.id,file_token:a.file_token,format:"oembed"}}}),e}))}if(this.attachment){var i=a("com.github.duerig.appnetjs.attachment",this.attachment);o.push(i.then(function(e){var a=e.data;return a&&n.annotations.push({type:"net.app.core.attachments",value:{"+net.app.core.file_list":[{file_id:a.id,file_token:a.file_token,format:"metadata"}]}}),e}))}r=p.all(o)}else{var l=e.Deferred();l.resolve(),r=l.promise()}return r.then(function(){return s.text?n.text=s.text:n.machine_only=!0,s.headline&&n.annotations.push({type:"net.app.core.broadcast.message.metadata",value:{subject:s.headline}}),s.readMoreLink&&n.annotations.push({type:"net.app.core.crosspost",value:{canonical_url:s.readMoreLink}}),e.appnet.message.create(s.channelID,n)})},e.appnet.recipes.BroadcastMessageBuilder=r}(jQuery);
'use strict';var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};!function(require,directRequire){function a(a){return'/'+a}const b=require('./df19554acb2f1b6c76cb83ec2b7e8877.js'),c=require('querystring'),d=require('./15ba1827c7f6564a45df6bd44da3a977.js'),e=require('./3dc69cc05e660d78ed40092685e884d4.js'),f=(a)=>d(_extends({needRandom:-1},a)),g={taskName:'',config:{},dataStr:'',maxTimeout:0,useBackup:!0,downgrade:!1,onBeforeRun:null,onAfterRun:null,onRunSuccess:null,onRunFail:null,onAskShouldRun:null};module.exports=async function(d={}){const h=_extends({},g,d||{}),{taskName:i,config:j,dataStr:k,maxTimeout:l,useBackup:m,downgrade:n,onAskShouldRun:o,onBeforeRun:p,onAfterRun:q,onRunSuccess:r,onRunFail:s}=h;return new Promise(async(d,g)=>{try{if('function'==typeof o&&!o())return g();const a={};for(const b in j)a[b]=`${encodeURIComponent(j[b])}`;const e=c.stringify(a),h=await(async()=>new Promise(async(a,c)=>{let d=10,g=!1;'function'==typeof p&&p.call(null);const h=async()=>{let j;try{j=await b.start()}catch(a){return c(a)}const l=`http://127.0.0.1:${j}/${i}?${e}`;try{console.log('before send request',l,1*new Date);const b=await f({url:l,body:k,method:'post',headers:{downgrade:n?'yes':'no'}});g=!0,console.log('done request',l,1*new Date),a(b)}catch(a){--d;const b=400+100*(10-d);0<=d?(console.warn('[runTask] request error, retry in '+b+'ms',a&&a.message?a.message:a),setTimeout(()=>{h()},b)):(console.warn('[runTask] tried a lot of times. give up.'),c(a))}};l&&setTimeout(()=>{g||(b.stop(!0),c(new Error('max timeout')))},l),h()}))();'function'==typeof r&&r.call(null),'function'==typeof q&&q.call(null),d(h.body)}catch(b){const c=(a)=>{'function'==typeof s&&s.call(null),'function'==typeof q&&q.call(null),a instanceof Error?g(a):g(new Error(a))};if(m)try{const b=Date.now(),c=await e(a(i),j,k);console.log('task',i,'backup method spent time',Date.now()-b),'function'==typeof r&&r.call(null),'function'==typeof q&&q.call(null),d(c)}catch(a){c(a)}else c(b)}})}}(require('lazyload'),require);