-
Notifications
You must be signed in to change notification settings - Fork 477
pfop #164
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
pfop #164
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.qiniu.processing; | ||
|
||
import com.qiniu.common.Config; | ||
import com.qiniu.common.QiniuException; | ||
import com.qiniu.http.Client; | ||
import com.qiniu.http.Response; | ||
import com.qiniu.util.Auth; | ||
import com.qiniu.util.StringMap; | ||
import com.qiniu.util.StringUtils; | ||
|
||
/** | ||
* 触发持久化处理 | ||
* 针对七牛空间文件,触发异步文件处理。如异步视频转码等 | ||
*/ | ||
public class OperationManager { | ||
private final Client client; | ||
private final Auth auth; | ||
|
||
public OperationManager(Auth auth) { | ||
this.auth = auth; | ||
this.client = new Client(); | ||
} | ||
|
||
/** | ||
* 触发 空间 文件 的 pfop 操作 | ||
* | ||
* @param bucket 空间名 | ||
* @param key 文件名 | ||
* @param fops fop指令 | ||
* @return persistentId | ||
* @throws QiniuException 触发失败异常,包含错误响应等信息 | ||
* @link http://developer.qiniu.com/docs/v6/api/reference/fop/pfop/pfop.html | ||
*/ | ||
public String pfop(String bucket, String key, String fops) throws QiniuException { | ||
return pfop(bucket, key, fops, null); | ||
} | ||
|
||
/** | ||
* 触发 空间 文件 的 pfop 操作 | ||
* | ||
* @param bucket 空间名 | ||
* @param key 文件名 | ||
* @param fops fop指令 | ||
* @param params notifyURL、force、pipeline 等参数 | ||
* @return persistentId | ||
* @throws QiniuException 触发失败异常,包含错误响应等信息 | ||
* @link http://developer.qiniu.com/docs/v6/api/reference/fop/pfop/pfop.html | ||
*/ | ||
public String pfop(String bucket, String key, String fops, StringMap params) throws QiniuException { | ||
params = params == null ? new StringMap() : params; | ||
params.put("bucket", bucket).put("key", key).put("fops", fops); | ||
byte[] data = StringUtils.utf8Bytes(params.formString()); | ||
String url = Config.API_HOST + "/pfop/"; | ||
StringMap headers = auth.authorization(url, data, Client.FormMime); | ||
Response response = client.post(url, data, headers, Client.FormMime); | ||
PfopStatus status = response.jsonToObject(PfopStatus.class); | ||
return status.persistentId; | ||
} | ||
|
||
private class PfopStatus { | ||
public String persistentId; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.qiniu.processing; | ||
|
||
import com.qiniu.TestConfig; | ||
import com.qiniu.common.QiniuException; | ||
import com.qiniu.http.Response; | ||
import com.qiniu.util.Auth; | ||
import com.qiniu.util.StringMap; | ||
|
||
import com.qiniu.util.UrlSafeBase64; | ||
import org.junit.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class PfopTest { | ||
private Auth auth = TestConfig.testAuth; | ||
private OperationManager operater = new OperationManager(auth); | ||
|
||
@Test | ||
public void testAvthumb() { | ||
String bucket = "testres"; | ||
String key = "sintel_trailer.mp4"; | ||
|
||
String notifyURL = ""; | ||
boolean force = true; | ||
String pipeline = ""; | ||
StringMap params = new StringMap().putNotEmpty("notifyURL", notifyURL) | ||
.putWhen("force", 1, force).putNotEmpty("pipeline", pipeline); | ||
// CHECKSTYLE:OFF | ||
String fops = "avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/amF2YXNkazptcDRfODVmZWVjY2ItMGZmOS00NTg5LTk3MTMtZDM1ZmYzZGQ4ZjM2"; | ||
// CHECKSTYLE:ON | ||
try { | ||
String id = operater.pfop(bucket, key, fops, params); | ||
assertNotNull(id); | ||
assertNotEquals("", id); | ||
String purl = "http://api.qiniu.com/status/get/prefop?id=" + id; | ||
System.out.println(purl); | ||
} catch (QiniuException e) { | ||
Response res = e.response; | ||
System.out.println(res); | ||
try { | ||
System.out.println(res.bodyString()); | ||
} catch (QiniuException e1) { | ||
e1.printStackTrace(); | ||
} | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testMuAvthumb() { | ||
String bucket = "testres"; | ||
String key = "sintel_trailer.mp4"; | ||
// CHECKSTYLE:OFF | ||
String fops = "avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/amF2YXNkazptcDRfM19mMDNjZjQ4Mi1kMzgxLTQ5NWUtOThiNC04NjZkYTVkMDVlMTY=;avthumb/m3u8/segtime/10/vcodec/libx264/s/480x480|saveas/amF2YXNkazptcDRfNF8wYmQ2NjQxOS04MjZmLTRiZDItYjQ5MS00ZDRmM2Y1ZmQ1Mjk=;avthumb/m3u8/segtime/10/vcodec/libx264/s/720x720|saveas/amF2YXNkazptcDRfN19hMTM1ZmRlNS1hYTNlLTQ3MWItYjdhMi0yNmQ5MWEyZTc5MzM=;avthumb/mp4/vcodec/libx264"; | ||
// CHECKSTYLE:ON | ||
StringMap params = new StringMap().putWhen("force", 1, true); | ||
try { | ||
String id = operater.pfop(bucket, key, fops, params); | ||
assertNotNull(id); | ||
assertNotEquals("", id); | ||
String purl = "http://api.qiniu.com/status/get/prefop?id=" + id; | ||
System.out.println(purl); | ||
} catch (QiniuException e) { | ||
Response res = e.response; | ||
System.out.println(res); | ||
try { | ||
System.out.println(res.bodyString()); | ||
} catch (QiniuException e1) { | ||
e1.printStackTrace(); | ||
} | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testMkzip() { | ||
String bucket = "testres"; | ||
String key = "sintel_trailer.mp4"; | ||
// CHECKSTYLE:OFF | ||
String fops = "mkzip/2/url/aHR0cDovL3Rlc3RyZXMucWluaXVkbi5jb20vZ29nb3BoZXIuanBn/alias/Z29nb3BoZXIuanBn/url/aHR0cDovL3Rlc3RyZXMucWluaXVkbi5jb20vZ29nb3BoZXIuanBn"; | ||
fops += "|saveas/" + UrlSafeBase64.encodeToString("javasdk" + ":" + key + "_" + UUID.randomUUID()); | ||
// CHECKSTYLE:ON | ||
try { | ||
String id = operater.pfop(bucket, key, fops); | ||
assertNotNull(id); | ||
assertNotEquals("", id); | ||
String purl = "http://api.qiniu.com/status/get/prefop?id=" + id; | ||
System.out.println(purl); | ||
} catch (QiniuException e) { | ||
Response res = e.response; | ||
System.out.println(res); | ||
try { | ||
System.out.println(res.bodyString()); | ||
} catch (QiniuException e1) { | ||
e1.printStackTrace(); | ||
} | ||
fail(); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertNotNull (id) 这是什么意思
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是单元测试。。。