當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript acm.default方法代碼示例

本文整理匯總了TypeScript中acm.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript acm.default方法的具體用法?TypeScript acm.default怎麽用?TypeScript acm.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在acm的用法示例。


在下文中一共展示了acm.default方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

export default function (collection: string, cb: Function = () => {}) {
    var url, env = process.env;

    function send_back(err, conn, collection, cb) {
        if (err) {
            cb(err);
        } else {
            cb(null, conn.collection(collection));
        }
    }

    if (connection) {
        send_back(connection_err, connection, collection, cb);
    } else {
        log.info('connecting to mongodb');
        url = !env.MONGO_HOST ? config('mongo.url') :
            'mongodb://' + env.MONGO_HOST + ':27017/' + env.MONGO_COLLECTION;

        MongoClient.connect(url, (err, db) => {
            connection = db;
            connection_err = err;

            if (err) {
                log.error('error connecting to mongo', err);
            } else {
                log.info('connected to mongodb');
            }

            send_back(connection_err, connection, collection, cb);
        });
    }
}
開發者ID:consumr-project,項目名稱:cp,代碼行數:32,代碼來源:mongo.ts

示例2: if

app.use((err: any, req, res, next) => {
    log.error('catching request handler error', err);

    if (!res.headersSent) {
        if (err instanceof HttpError || (isFinite(err.code) && err.name)) {
            log.debug('sending back %s(%s)', err.name, err.code);
            res.status(err.code);
        } else if (err.code === 'ETIMEDOUT' || err.type === 'entity.too.large') {
            log.debug('sending back Request Timeout(408)');
            res.status(RequestTimeoutError.code);
        } else {
            log.debug('sending back generic 500');
            res.status(500);
        }
    } else {
        log.debug('headers already sent. no updates to response');
    }

    res.render('index', {
        err,
        cp_url: config('cp_url'),
        debugging: CLIENT_DEBUG_INFO,
        lang: normalize_i18n(req.query.lang),
    });
});
開發者ID:consumr-project,項目名稱:cp,代碼行數:25,代碼來源:main.ts

示例3: generate_body

function generate_body(template: EMAIL, payload: PAYLOAD, lang: string) {
    var data = {
        body: '',
        payload: payload,
        images: ASSETS.images,
        styles: ASSETS.styles,
        i18n: pick_i18n(lang),
        config: {
            url: config('cp.url'),
        }
    };

    data.body = TEMPLATES[template](data);
    return TEMPLATES.base(data);
}
開發者ID:consumr-project,項目名稱:cp,代碼行數:15,代碼來源:email.ts

示例4: config

import * as imgur from 'imgur';
import * as config from 'acm';

const IMGUR_ALBUM_ID = config('files.avatars.imgur.album_id');
const IMGUR_CLIENT_ID = config('files.avatars.imgur.client_id');
const IMGUR_PASSWORD = config('files.avatars.imgur.password');
const IMGUR_USERNAME = config('files.avatars.imgur.username');

export namespace Model {
    export interface Base {
        id?: string;
        link?: string;
    }

    export interface ImgurImage extends Base {
        id: string;
        link: string;
    }
}

export namespace Payload {
    export interface Base {
        base64?: string;
    }

    export class ImgurImage implements Base {
        base64: string;

        constructor(base64: string) {
            this.base64 = base64;
        }
開發者ID:consumr-project,項目名稱:cp,代碼行數:31,代碼來源:upload.ts

示例5: add

import { BadGatewayError, ERR_MSG_EXTERNAL_ERROR } from '../errors';
import * as config from 'acm';

import Trello = require('trello');

const TRELLO_KEY = config('trello.key');
const TRELLO_TOKEN = config('trello.token');
const TRELLO_LIST_ID = config('trello.list_id');
const TRELLO_BOARD_ID = config('trello.board_id');

export const trello = new Trello(TRELLO_KEY, TRELLO_TOKEN);

export namespace card {
    export function add(name: string, desc: string) {
        return trello.addCard(name, desc, TRELLO_LIST_ID)
            .then(errw);
    }

    export function get(id: string) {
        return trello.getCard(TRELLO_BOARD_ID, id)
            .then(errw);
    }

    export function del(id: string) {
        return trello.deleteCard(id)
            .then(errw);
    }
}

function errw(ack) {
    if (typeof ack === 'string') {
開發者ID:consumr-project,項目名稱:cp,代碼行數:31,代碼來源:trello.ts

示例6: get_event_and_act_upon_message

    InternalServerError, ERR_MSG_MISSING_FIELDS } from '../errors';

import Message, { CATEGORY, NOTIFICATION, OTYPE } from '../notification/message';
import { save, find, purge, update, purge_signature } from '../repository/notification';
import { head } from 'lodash';
import connect from '../device/mongo';

export const router = Router();

router.use((req, res, next) => {
    // 5 minute caching
    res.setHeader('Cache-Control', `private, max-age=${minutes(5) / 1000}`);
    next();
});

connect(config('mongo.collections.notifications'), (err, coll) => {
    function get_event_and_act_upon_message(id: string, action: Function, processor: (ev: EventMessage) => Message) {
        // XXX check this isn't our own event
        return new Promise<Message | DeleteWriteOpResultObject>((resolve, reject) =>
            Event.findById(id)
                .then((ev: EventMessage) => {
                    var msg = processor(ev);
                    msg.sign();

                    action(coll, action === purge_signature ? msg.signature : msg)
                        .then(ack => resolve(msg))
                        .catch(err => reject(new InternalServerError(err.message)));
                })
                .catch(err => reject(new InternalServerError(err.message))));
    }
開發者ID:consumr-project,項目名稱:cp,代碼行數:30,代碼來源:notification.ts

示例7: recaptcha

import * as config from 'acm';
import * as request from 'request';
import { try_func } from '../utilities';
import { BadRequestError, BadGatewayError,
    ERR_MSG_PARSING_ERROR } from '../errors';

const GOOGLE_RECAPTCHA_ENDPOINT = config('google.recaptcha.endpoint');
const GOOGLE_RECAPTCHA_SECRET = config('google.recaptcha.secret');

export function recaptcha(response: string, remoteip: string) {
    return new Promise<boolean>((resolve, reject) => {
        request({
            method: 'POST',
            uri: GOOGLE_RECAPTCHA_ENDPOINT,
            formData: { response, remoteip,
                secret: GOOGLE_RECAPTCHA_SECRET }
        }, (err, res, body) => {
            var [ parse_err, check ] = try_func(() => JSON.parse(body));

            if (err) {
                reject(err);
            } else if (parse_err) {
                reject(new BadGatewayError(ERR_MSG_PARSING_ERROR('google')));
            } else if (!check.success) {
                reject(new BadRequestError('failed to verify recaptcha'));
            } else {
                resolve(true);
            }
        });
    });
}
開發者ID:consumr-project,項目名稱:cp,代碼行數:31,代碼來源:recaptcha.ts

示例8: LinkDefinition

import db_connect, { DbmsDevice } from '../device/dbms';
import es_connect, { ElasticsearchDevice } from '../device/elasticsearch';
import { get, elasticsearch } from '../search/updater';
import { UpdaterAck, LinkConfiguration, LinkDefinition } from '../river/sync';
import { Duration } from '../lang';
import { logger } from '../log';
import { nonce } from '../crypto';
import * as config from 'acm';
import * as toes from '../toe';

const log = logger(__filename);
const models: LinkDefinition[] = config('river.models').map((def: LinkConfiguration) =>
    new LinkDefinition(
        def.name,
        def.fields,
        def.query_file,
        def.soft_delete,
        def.primary_key,
        def.label));

export function run(since: Duration, identity: string, counter: number): Promise<UpdaterAck[]> {
    var db: DbmsDevice;
    var es: ElasticsearchDevice;

    try {
        db = db_connect();
        es = es_connect();

        models.map(model => log.info('river model entry', model));

        return Promise.all(models.map(model => get(db, model, { since })
開發者ID:consumr-project,項目名稱:cp,代碼行數:31,代碼來源:river.ts

示例9: do_log

function do_log() {
    if (config('logging.enable.sql')) {
        return log.debug.apply(log, arguments);
    }
}
開發者ID:consumr-project,項目名稱:cp,代碼行數:5,代碼來源:dbms.ts

示例10: config

 })).catch(err => res.render('index', {
     unfurled: OG,
     cp_url: config('cp_url'),
     debugging: CLIENT_DEBUG_INFO,
     lang: normalize_i18n(req.query.lang),
 }));
開發者ID:consumr-project,項目名稱:cp,代碼行數:6,代碼來源:main.ts


注:本文中的acm.default方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。