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


TypeScript v4.v4函數代碼示例

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


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

示例1: createVideoChannel

async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) {
  const uuid = uuidv4()
  const url = getVideoChannelActivityPubUrl(uuid)
  // We use the name as uuid
  const actorInstance = buildActorInstance('Group', url, uuid, uuid)

  const actorInstanceCreated = await actorInstance.save({ transaction: t })

  const videoChannelData = {
    name: videoChannelInfo.displayName,
    description: videoChannelInfo.description,
    support: videoChannelInfo.support,
    accountId: account.id,
    actorId: actorInstanceCreated.id
  }

  const videoChannel = VideoChannelModel.build(videoChannelData)

  const options = { transaction: t }
  const videoChannelCreated = await videoChannel.save(options)

  // Do not forget to add Account/Actor information to the created video channel
  videoChannelCreated.Account = account
  videoChannelCreated.Actor = actorInstanceCreated

  // No need to seed this empty video channel to followers
  return videoChannelCreated
}
開發者ID:jiang263,項目名稱:PeerTube,代碼行數:28,代碼來源:video-channel.ts

示例2: function

 router.put('/upload/', function (req, res) {
     let body = req.body;
     if (!body || !body.Filename || !body.Size) {
         return res.send({ Success: false, Error: 'No filename!' });
     }
     let fileid = uuidv4();
     pool.getConnection((err, conn) => {
         if (err) {
             console.log(err);
             return res.status(500).send({Error: 'Could not establish connection to database'});
         } else {
             let q = 'Insert into `filemetadata` (`FileID`, `Filename`, `Owner`, `Size`) VALUES (?, ?, ?, ?);';
             let args = [fileid, body.Filename, res.locals.user.ID, body.Size];
             conn.query(q, args, (qerr, result) => {
                 conn.release();
                 if (qerr) {
                     console.log('Error saving file metadata', qerr);
                     return res.status(500).send({ Error: 'Internal Server Error' });
                 }
                 console.log('Beginning upload of', body.Filename);
                 return res.send({ EndpointID: fileid });
             });
         }
     });
 });
開發者ID:TetuSecurity,項目名稱:Crypt,代碼行數:25,代碼來源:files.ts

示例3: updateMyAvatar

async function updateMyAvatar (req: express.Request, res: express.Response, next: express.NextFunction) {
  const avatarPhysicalFile = req.files['avatarfile'][0]
  const user = res.locals.oauth.token.user
  const actor = user.Account.Actor

  const extension = extname(avatarPhysicalFile.filename)
  const avatarName = uuidv4() + extension
  const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
  await processImage(avatarPhysicalFile, destination, AVATARS_SIZE)

  const avatar = await sequelizeTypescript.transaction(async t => {
    const updatedActor = await updateActorAvatarInstance(actor, avatarName, t)
    await updatedActor.save({ transaction: t })

    await sendUpdateActor(user.Account, t)

    return updatedActor.Avatar
  })

  return res
    .json({
      avatar: avatar.toFormattedJSON()
    })
    .end()
}
開發者ID:quoidautre,項目名稱:PeerTube,代碼行數:25,代碼來源:users.ts

示例4: Error

 return db.findOne({ email, password }).then((user) => {
   if (!user) {
     throw Error("Could not authorize");
   }
   user.token = uuidv4();
   return user.save();
 });
開發者ID:racketometer,項目名稱:backend-application,代碼行數:7,代碼來源:authorize.ts

示例5: authToken

router.post("/edit_user", async ctx => {
  await authToken(ctx, true);
  const {
    uid,
    email,
    note,
    enabled,
    isAdmin,
    isEmailVerified,
    regenerate,
  } = ctx.request.body;
  if (!uid) {
    return raiseApiError(400, "請求格式錯誤");
  }
  const user = await getRepository(User).findOneById(uid);
  if (!user) {
    return raiseApiError(404, "用戶不存在");
  }
  user.email = email || user.email;
  user.note = note || user.note;
  user.enabled = enabled;
  user.isAdmin = isAdmin;
  user.isEmailVerified = isEmailVerified;
  if (regenerate) {
    user.setConnPassword();
    await user.allocConnPort();
    user.vmessUid = uuid();
  }
  await getRepository(User).save(user);
  await writeServerConfig();
  ctx.body = { message: "操作成功" };
});
開發者ID:coderfox,項目名稱:Another-SS-Panel,代碼行數:32,代碼來源:api.ts

示例6: mixin

export function mixin(mixinClass) {
  Object.defineProperty(mixinClass, 'name', {
    value: uuid(),
  });
  Injectable()(mixinClass);
  return mixinClass;
}
開發者ID:SARAVANA1501,項目名稱:nest,代碼行數:7,代碼來源:component.decorator.ts

示例7: generateEmptyPokemon

export function generateEmptyPokemon(pokemon?: Pokemon[]): Pokemon {
    let position: number = 0;
    if (pokemon && pokemon.length > 0) {
        try {
            position = parseInt(pokemon.sort(sortPokes)[pokemon.length - 1].position as any) + 1;
        } catch (e) {
            console.error('Attempted to generate position, but failed.', e);
        }
    }
    const genStatus = () => {
        if (pokemon && pokemon.filter(poke => poke.status === 'Team').length >= 6) return 'Boxed';
        return 'Team';
    };
    return {
        id: uuid(),
        position: position,
        species: '',
        nickname: '',
        status: genStatus(),
        gender: 'genderless',
        level: undefined,
        met: '',
        metLevel: undefined,
        nature: 'None',
        ability: '',
        types: [Types.Normal, Types.Normal],
        egg: false,
    };
}
開發者ID:EmmaRamirez,項目名稱:nuzlocke-generator,代碼行數:29,代碼來源:generateEmptyPokemon.ts

示例8: saveUser

export async function saveUser(req: Request, res: Response, next: NextFunction): Promise<any> {
  let body: User = snakeCase(req.body);
  body.id = uuid();
  
  return await Account
  .findOne({ where: {email: body.email} })
  .then(async account => validateAndCreateUser(body, account, res))
  .catch(err => next(err));
}
開發者ID:KShewengerz,項目名稱:ngx-express-passport-setup,代碼行數:9,代碼來源:user.ts

示例9: constructor

    // CONSTRUCTOR
    // --------------------------------------------------------------------------------------------
    constructor(name: string, tasks: boolean, notices: boolean) {
        this.id = uuid();
        this.name = name;
        this.startTs = Date.now();

        this.tasks = tasks ? [] : undefined;
        this.notices = notices ? [] : undefined;
        this.deferred = [];
    }
開發者ID:herculesinc,項目名稱:nova-base,代碼行數:11,代碼來源:Operation.ts

示例10: uuid

        source.sensors.reduce((acc, sensor) => {
          const id = uuid()
          ids.push(id)

          const sensorWithId = {
            ...sensor,
            visible: true,
            source: source.id,
            id
          }

          return { ...acc, [id]: sensorWithId }
        }, {})
開發者ID:KHP-Informatics,項目名稱:RADAR-frontend,代碼行數:13,代碼來源:sensors.reducer.ts


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