How to use the qiniu.js.bucket function in qiniu

To help you get started, we’ve selected a few qiniu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cody1991 / learn / waiting / ES2015 / filmy / src / models / qiniu-bucket.js View on Github external
import qiniu from 'qiniu.js';
import crypto from 'crypto-browserify';

const qiniuBucketUrl = 'ohjhqmsxe.bkt.clouddn.com';

const filmyBucket = qiniu.bucket('filmy', {
	url: (qiniuBucketUrl ? qiniuBucketUrl : `${location.protocol}//${localtion.host}`)
});

console.log(filmyBucket);

function getKeys(password) {
	return filmyBucket.getFile(`secret-${password}.json`)
		.then(body => JSON.parse(body));
}

filmyBucket.fetchPutToken = function(password, keys = null, returnBody = null) {
	return (keys ? Promise.resolve(keys) : getKeys(password))
		.then(keys => {
			const options = {
				scope: 'filmy',
				deadline: Math.floor(Date.now() / 1000) + 3600,