本文整理匯總了TypeScript中levelup.LevelUp.put方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript LevelUp.put方法的具體用法?TypeScript LevelUp.put怎麽用?TypeScript LevelUp.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類levelup.LevelUp
的用法示例。
在下文中一共展示了LevelUp.put方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: enqueueFile
public async enqueueFile(
filepath: string,
filetype: FileJobType
): Promise<boolean> {
try {
const tag = new Tag(filepath);
const jobType = filetype;
const jobStatus = FileJobStatus.Pending;
const filePayload: FilePayload = {
jobStatus,
jobType
};
await this.files.put(filepath, filePayload);
const fileJobPayload: FileJobPayload = {
filepath,
jobType
};
const jobId = await this.queue.pushPromise(fileJobPayload);
logger.debug('File enqueued with jobId: %s', jobId);
await tag.addTag('Yellow');
return true;
} catch (err) {
logger.error('Error in enqueue\n%s', prettyPrint(err));
return false;
}
}
示例2: addKeys
async addKeys(params: {
name: string;
keys: Wallet.KeyImport[];
encryptionKey: string;
}) {
const { name, keys, encryptionKey } = params;
const ops = keys.map(key => {
let { pubKey } = key;
pubKey =
pubKey || new bitcoreLib.PrivateKey(key.privKey).publicKey.toString();
let payload = {};
if (pubKey && key.privKey && encryptionKey) {
const encKey = Encryption.encryptPrivateKey(
JSON.stringify(key),
Buffer.from(pubKey, 'hex'),
Buffer.from(encryptionKey, 'hex')
);
payload = { encKey, pubKey };
}
return {
type: 'put',
key: `key|${name}|${key.address}`,
value: JSON.stringify(payload)
};
});
if (ops.length > 1) {
return this.db.batch(ops);
} else {
this.db.put(ops[0].key, ops[0].value);
}
}
示例3: handler
public async handler(_: string, payload: any): Promise<void> {
try {
const { filepath, jobType } = payload;
logger.info('Starting work for %s', filepath);
const tag = new Tag(filepath);
const currentValue = await this.files.get(filepath);
const { jobStatus } = currentValue;
logger.debug('Work type: %s', FileJobType[jobType]);
try {
const handled =
jobStatus === FileJobStatus.Pending && existsSync(filepath)
? this.handleFile(filepath, jobType) && true
: false;
currentValue.jobStatus = handled
? FileJobStatus.Complete
: FileJobStatus.Unhandled;
await tag.removeTag('Red');
await tag.removeTag('Yellow');
await tag.addTag('Green');
} catch (err) {
logger.error(err);
currentValue.jobStatus = FileJobStatus.Error;
await tag.removeTag('Green');
await tag.removeTag('Yellow');
await tag.addTag('Red');
} finally {
this.files.put(filepath, currentValue);
}
} catch (err) {
logger.error(err);
}
}
示例4: saveWallet
async saveWallet(params) {
const { wallet } = params;
return this.db.put(`wallet|${wallet.name}`, JSON.stringify(wallet));
}