Skip to content

Feature/pfop #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/README.gist.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,19 @@ PutExtra是上传时的可选信息,默认为null
### 云处理

<a云处理使用说明\>

#### pfop
`pfop`的作用是对已存在七牛服务器上的文件做持久化的fop,具体见[api文档](http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html)

```{javascript}
// 原型
func pfop(bucketName, keyName, fops, opts, callback);

// 例子
@gist(../test/io.test.js#pfop)

```

#### 查看图像信息

```{javascript}
Expand Down
17 changes: 17 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,23 @@ qiniu.rsf.listPrefix(bucketname, prefix, marker, limit, function(err, ret) {
### 云处理

<a云处理使用说明\>

#### pfop
`pfop`的作用是对已存在七牛服务器上的文件做持久化的fop,具体见[api文档](http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html)

```{javascript}
// 原型
func pfop(bucketName, keyName, fops, opts, callback);

// 例子
// pfop
qiniu.fop.pfop(TEST_BUCKET, keys[0], 'avinfo', {notifyUrl: 'www.test.com', force: true}, function(err, ret) {
ret.should.have.keys('persistentId');
done();
});

```

#### 查看图像信息

```{javascript}
Expand Down
28 changes: 28 additions & 0 deletions qiniu/fop.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
var util = require('./util');
var rpc = require('./rpc');

var querystring = require('querystring');

exports.ImageView = ImageView;
exports.ImageInfo = ImageInfo;
exports.Exif = Exif;
exports.pfop = pfop;

function ImageView(mode, width, height, quality, format) {
this.mode = mode || 1;
Expand Down Expand Up @@ -49,3 +53,27 @@ Exif.prototype.makeRequest = function(url) {
}


function pfop(bucket, key, fops, opts, onret) {

opts = opts || {};

param = {
bucket: bucket,
key: key,
fops: fops
};
if (opts.notifyURL) {
param.notifyURL = opts.notifyURL;
} else {
param.notifyURL = 'www.test.com';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么这里填了一个不存在的网址? 填空字符串不行么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为服务端会对notifyURL做简单的检测

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不填,没有这一项 不行?

}
if (opts.force) {
param.force = 1;
}

var uri = 'http://api.qiniu.com/pfop/';
var body = querystring.stringify(param);
var auth = util.generateAccessToken(uri, body);
rpc.postWithForm(uri, body, auth, onret);
}

6 changes: 6 additions & 0 deletions qiniu/rs.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ PutPolicy.prototype.getFlags = function(putPolicy) {
if (this.endUser != null) {
flags['endUser'] = this.endUser;
}
if (this.persistentOps != null) {
flags['persistentOps'] = this.persistentOps;
}
if (this.persistentNotifyUrl != null) {
flags['persistentNotifyUrl'] = this.persistentNotifyUrl;
}
flags['deadline'] = this.expires + Math.floor(Date.now() / 1000);
return flags;
}
Expand Down
12 changes: 12 additions & 0 deletions test/io.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ describe('test start step1:', function() {
});
});
});

describe('pfop', function() {
it('do pfop', function(done) {
// @gist pfop
// pfop
qiniu.fop.pfop(TEST_BUCKET, keys[0], 'avinfo', {notifyURL: 'www.test.com'}, function(err, ret) {
ret.should.have.keys('persistentId');
done();
});
// @endgist
})
});
});