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


TypeScript ms.default函數代碼示例

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


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

示例1: default

export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'limit' parameter
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
	if (limitErr) return rej('invalid limit param');

	// Get 'offset' parameter
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
	if (offsetErr) return rej('invalid offset param');

	// ID list of the user itself and other users who the user follows
	const followingIds = await getFriendIds(me._id);

	// ミュートしているユーザーを取得
	const mutedUserIds = (await Mute.find({
		muterId: me._id
	})).map(m => m.muteeId);

	const users = await User
		.find({
			_id: {
				$nin: followingIds.concat(mutedUserIds)
			},
			isLocked: false,
			$or: [{
				lastUsedAt: {
					$gte: new Date(Date.now() - ms('7days'))
				}
			}, {
				host: null
			}]
		}, {
			limit: limit,
			skip: offset,
			sort: {
				followersCount: -1
			}
		});

	// Serialize
	res(await Promise.all(users.map(async user =>
		await pack(user, me, { detail: true }))));
});
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:42,代碼來源:recommendation.ts

示例2: ms

import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note';
import User, { ILocalUser, IUser } from '../../../../models/user';
import DriveFile, { IDriveFile } from '../../../../models/drive-file';
import create from '../../../../services/note/create';
import { IApp } from '../../../../models/app';
import getParams from '../../get-params';

export const meta = {
	desc: {
		ja: '投稿します。'
	},

	requireCredential: true,

	limit: {
		duration: ms('1hour'),
		max: 300,
		minInterval: ms('1second')
	},

	kind: 'note-write',

	params: {
		visibility: $.str.optional.or(['public', 'home', 'followers', 'specified', 'private']).note({
			default: 'public',
			desc: {
				ja: '投稿の公開範囲'
			}
		}),

		visibleUserIds: $.arr($.type(ID)).optional.unique().min(1).note({
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:31,代碼來源:create.ts

示例3: require

import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
const ms = require('ms');
import User, { pack, ILocalUser } from '../../../../models/user';
import Following from '../../../../models/following';
import deleteFollowing from '../../../../services/following/delete';

export const meta = {
	desc: {
		ja: '指定したユーザーのフォローを解除します。',
		en: 'Unfollow a user.'
	},

	limit: {
		duration: ms('1hour'),
		max: 100
	},

	requireCredential: true,

	kind: 'following-write'
};

export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	const follower = user;

	// Get 'userId' parameter
	const [userId, userIdErr] = $.type(ID).get(params.userId);
	if (userIdErr) return rej('invalid userId param');

	// Check if the followee is yourself
	if (user._id.equals(userId)) {
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:31,代碼來源:delete.ts

示例4: ms

import * as sdk from 'botpress/sdk'
import { validate } from 'joi'
import ms from 'ms'

import ConfusionEngine from './confusion-engine'
import ScopedEngine from './engine'
import { EngineByBot } from './typings'
import { EntityDefCreateSchema, IntentDefCreateSchema } from './validation'
import _ from 'lodash'

const SYNC_INTERVAL_MS = ms('15s')

export default async (bp: typeof sdk, nlus: EngineByBot) => {
  const router = bp.http.createRouterForBot('nlu')

  const syncByBots: { [key: string]: NodeJS.Timer } = {}

  const scheduleSyncNLU = (botId: string) => {
    if (syncByBots[botId]) {
      clearTimeout(syncByBots[botId])
      delete syncByBots[botId]
    }

    syncByBots[botId] = setTimeout(() => {
      delete syncByBots[botId]
      const botEngine = nlus[botId] as ScopedEngine
      syncNLU(botEngine, false)
    }, SYNC_INTERVAL_MS)
  }

  const syncNLU = async (botEngine: ScopedEngine, confusionMode: boolean = false): Promise<string> => {
開發者ID:alexsandrocruz,項目名稱:botpress,代碼行數:31,代碼來源:api.ts

示例5: default

export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'limit' parameter
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
	if (limitErr) return rej('invalid limit param');

	// Get 'offset' parameter
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
	if (offsetErr) return rej('invalid offset param');

	// Get 'reply' parameter
	const [reply, replyErr] = $.bool.optional.get(params.reply);
	if (replyErr) return rej('invalid reply param');

	// Get 'renote' parameter
	const [renote, renoteErr] = $.bool.optional.get(params.renote);
	if (renoteErr) return rej('invalid renote param');

	// Get 'media' parameter
	const [media, mediaErr] = $.bool.optional.get(params.media);
	if (mediaErr) return rej('invalid media param');

	// Get 'poll' parameter
	const [poll, pollErr] = $.bool.optional.get(params.poll);
	if (pollErr) return rej('invalid poll param');

	const query = {
		_id: { $gte: new Date(Date.now() - ms('1days')) },
		renoteCount: { $gt: 0 },
		'_user.host': null
	} as any;

	if (reply != undefined) {
		query.replyId = reply ? { $exists: true, $ne: null } : null;
	}

	if (renote != undefined) {
		query.renoteId = renote ? { $exists: true, $ne: null } : null;
	}

	if (media != undefined) {
		query.mediaIds = media ? { $exists: true, $ne: null } : null;
	}

	if (poll != undefined) {
		query.poll = poll ? { $exists: true, $ne: null } : null;
	}

	// Issue query
	const notes = await Note
		.find(query, {
			limit: limit,
			skip: offset,
			sort: {
				renoteCount: -1,
				_id: -1
			}
		});

	// Serialize
	res(await Promise.all(notes.map(async note =>
		await pack(note, user, { detail: true }))));
});
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:62,代碼來源:trend.ts

示例6: Promise

        return new Promise(async (resolve, reject) => {
            const payload = {
                value:
                {
                    user: {
                        displayName: user.displayName,
                        email: user.email,
                        name: user.name,
                        tenant: user.tenant
                    },
                    scopes: user.scopes
                }
            };

            let options = { issuer: this.issuer.value, expiresIn: this.tokenExpiration.value };

            try {
                let jwtToken = this.createToken(payload, options);
                let renewToken = this.createToken({}, options);

                let expiresIn;
                if (typeof this.tokenExpiration.value === 'string') {
                    const milliseconds = ms(this.tokenExpiration.value);
                    expiresIn = Math.floor(milliseconds / 1000);
                }
                else {
                    expiresIn = this.tokenExpiration.value;
                }
                // token payload contains iat (absolute expiration date in sec)
                resolve({ expiresIn, token: jwtToken, renewToken: renewToken });
            }
            catch (err) {
                reject({ error: err, message: "Error when creating new token for user :" + user.name + " - " + (err.message || err) });
            }
        });
開發者ID:workfel,項目名稱:vulcain-corejs,代碼行數:35,代碼來源:tokenService.ts

示例7: ms

export const groupEntriesByTime = (entries: MonitoringStats[], timeInterval: string) => {
  if (!entries || !entries.length) {
    return
  }

  const timeInMs = ms(timeInterval)
  let groupTime = entries[0].ts

  return _.groupBy(entries, entry => {
    return entry.ts - groupTime <= timeInMs ? groupTime : (groupTime = entry.ts)
  }) as MonitoringGroupInterval
}
開發者ID:alexsandrocruz,項目名稱:botpress,代碼行數:12,代碼來源:monitoring.ts

示例8: getOrCreateRecentConversation

  async getOrCreateRecentConversation(botId: string, userId: string, { originatesFromUserMessage = false } = {}) {
    // TODO: Lifetime config by bot
    const config = await this.bp.config.getModuleConfigForBot('channel-web', botId)

    const recentCondition = this.knex.date.isAfter(
      'last_heard_on',
      moment()
        .subtract(ms(config.recentConversationLifetime), 'ms')
        .toDate()
    )

    const conversation = await this.knex('web_conversations')
      .select('id')
      .whereNotNull('last_heard_on')
      .andWhere({ userId, botId })
      .andWhere(recentCondition)
      .orderBy('last_heard_on', 'desc')
      .limit(1)
      .then()
      .get(0)

    return conversation ? conversation.id : this.createConversation(botId, userId, { originatesFromUserMessage })
  }
開發者ID:seffalabdelaziz,項目名稱:botpress,代碼行數:23,代碼來源:db.ts


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