Skip to content

Commit ad2fc48

Browse files
authored
Add support for custom pre-functions in transformation (wasm/remote). (#162)
1 parent e1b3632 commit ad2fc48

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cloudinary-core/src/main/java/com/cloudinary/Transformation.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,4 +893,13 @@ public T variables(Expression... variables) {
893893
public T customFunction(CustomFunction action) {
894894
return param("custom_function", action.toString());
895895
}
896+
897+
/**
898+
* Set a custom pre-function, such as a call to a lambda function or a web-assembly function.
899+
* @param action The custom action to perform, see {@link CustomFunction}.
900+
* @return The transformation for chaining
901+
*/
902+
public T customPreFunction(CustomFunction action) {
903+
return param("custom_function", "pre:" + action.toString());
904+
}
896905
}

cloudinary-core/src/test/java/com/cloudinary/test/CloudinaryTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,13 @@ public void testCustomFunction(){
11631163
new Transformation().customFunction(remote("https://df34ra4a.execute-api.us-west-2.amazonaws.com/default/cloudinaryFunction")).generate());
11641164
}
11651165

1166+
@Test
1167+
public void testCustomPreFunction(){
1168+
assertEquals("fn_pre:wasm:blur_wasm", new Transformation().customPreFunction(wasm("blur_wasm")).generate());
1169+
assertEquals("fn_pre:remote:aHR0cHM6Ly9kZjM0cmE0YS5leGVjdXRlLWFwaS51cy13ZXN0LTIuYW1hem9uYXdzLmNvbS9kZWZhdWx0L2Nsb3VkaW5hcnlGdW5jdGlvbg==",
1170+
new Transformation().customPreFunction(remote("https://df34ra4a.execute-api.us-west-2.amazonaws.com/default/cloudinaryFunction")).generate());
1171+
}
1172+
11661173
public static Map<String, String> getUrlParameters(URI uri) throws UnsupportedEncodingException {
11671174
Map<String, String> params = new HashMap<String, String>();
11681175
for (String param : uri.getRawQuery().split("&")) {

0 commit comments

Comments
 (0)