Skip to content

Commit 7763a6a

Browse files
committed
add fop
1 parent fa9e97e commit 7763a6a

File tree

5 files changed

+132
-6
lines changed

5 files changed

+132
-6
lines changed

src/Qiniu/Processing/Operation.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
namespace Qiniu\Processing;
3+
4+
final class Operation
5+
{
6+
public static function buildOp($cmd, $first_arg, array $args)
7+
{
8+
$op = array($cmd);
9+
if (!empty($first_arg)) {
10+
array_push($op, $first_arg);
11+
}
12+
foreach ($args as $key => $value) {
13+
array_push($op, "$key/$value");
14+
}
15+
return implode('/', $op);
16+
}
17+
18+
public static function pipeCmd($cmds)
19+
{
20+
return implode('|', $cmds);
21+
}
22+
23+
public static function saveas($op, $bucket, $key)
24+
{
25+
return self::pipeCmd(array($op, 'saveas/' . \Qiniu\entry($bucket, $key)));
26+
}
27+
}
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
namespace Qiniu\Processing;
3+
4+
use Qiniu\Config;
5+
use Qiniu\Http\Client;
6+
use Qiniu\Http\Error;
7+
8+
final class PersistentFop
9+
{
10+
private $auth;
11+
private $bucket;
12+
private $pipeline;
13+
private $notify_url;
14+
15+
public function __construct($auth, $bucket, $pipeline = null, $notify_url = null)
16+
{
17+
$this->auth = $auth;
18+
$this->bucket = $bucket;
19+
$this->pipeline = $pipeline;
20+
$this->notify_url = $notify_url;
21+
}
22+
23+
public function execute($key, array $fops, $force = false)
24+
{
25+
$ops = implode(';', $fops);
26+
$params = array('bucket' => $this->bucket, 'key' => $key, 'fops' => $ops);
27+
if (!empty($this->pipeline)) {
28+
$params['pipeline'] = $this->pipeline;
29+
}
30+
if (!empty($this->notify_url)){
31+
$params['notifyURL'] = $this->notify_url;
32+
}
33+
if ($force) {
34+
$params['force'] = 1;
35+
}
36+
$data = http_build_query($params);
37+
$url = Config::API_HOST . '/pfop/';
38+
$headers = $this->auth->authorization($url, $data, 'application/x-www-form-urlencoded');
39+
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
40+
$response = Client::post($url, $data, $headers);
41+
if ($response->statusCode != 200) {
42+
return array(null, new Error($url, $response));
43+
}
44+
$r = $response->json();
45+
$id = $r['persistentId'];
46+
return array($id, null);
47+
}
48+
49+
public static function status($id)
50+
{
51+
$url = Config::API_HOST . "/status/get/prefop?id=$id";
52+
$response = Client::get($url);
53+
if ($response->statusCode != 200) {
54+
return array(null, new Error($url, $response));
55+
}
56+
return array($response->json(), null);
57+
}
58+
}

src/Qiniu/Processing/Pfop.php

-6
This file was deleted.

tests/Qiniu/Tests/DownloadTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace Qiniu\Tests;
3+
4+
use Qiniu\Http\Client;
5+
6+
class DownloadTest extends \PHPUnit_Framework_TestCase
7+
{
8+
public function test()
9+
{
10+
global $testAuth;
11+
$base_url = 'http://private-res.qiniudn.com/gogopher.jpg';
12+
$private_url = $testAuth->privateDownloadUrl($base_url);
13+
$response = Client::get($private_url);
14+
$this->assertEquals(200, $response->statusCode);
15+
}
16+
17+
public function testFop()
18+
{
19+
global $testAuth;
20+
$base_url = 'http://private-res.qiniudn.com/gogopher.jpg?exif';
21+
$private_url = $testAuth->privateDownloadUrl($base_url);
22+
$response = Client::get($private_url);
23+
$this->assertEquals(200, $response->statusCode);
24+
}
25+
}

tests/Qiniu/Tests/PfopTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
namespace Qiniu\Tests;
3+
4+
use Qiniu\Processing\Operation;
5+
use Qiniu\Processing\PersistentFop;
6+
7+
class PfopTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function test()
10+
{
11+
global $testAuth;
12+
$pfop = new PersistentFop($testAuth, 'testres', 'sdktest');
13+
$op = Operation::saveas('avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240', 'phpsdk', 'pfoptest');
14+
$ops = array();
15+
array_push($ops, $op);
16+
list($id, $error) = $pfop->execute('sintel_trailer.mp4', $ops, true);
17+
$this->assertNull($error);
18+
list($status, $error) = PersistentFop::status($id);
19+
$this->assertNotNull($status);
20+
$this->assertNull($error);
21+
}
22+
}

0 commit comments

Comments
 (0)