本文整理匯總了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
}
示例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 });
});
}
});
});
示例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()
}
示例4: Error
return db.findOne({ email, password }).then((user) => {
if (!user) {
throw Error("Could not authorize");
}
user.token = uuidv4();
return user.save();
});
示例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: "操作成功" };
});
示例6: mixin
export function mixin(mixinClass) {
Object.defineProperty(mixinClass, 'name', {
value: uuid(),
});
Injectable()(mixinClass);
return mixinClass;
}
示例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,
};
}
示例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));
}
示例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 = [];
}
示例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 }
}, {})