Skip to content
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

added parameters #63

Merged
merged 24 commits into from
Sep 10, 2024
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
4 changes: 3 additions & 1 deletion .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
3.1.x
5.0.x
6.0.x
7.0.x
8.0.x
- name: Build Release
run: dotnet build Imagekit.sln -c Release /p:ContinuousIntegrationBuild=true

Expand All @@ -57,7 +59,7 @@ jobs:
run: dotnet pack Imagekit.sln -c Release --no-build --output ${{ env.NUGET_OUTPUT_PATH }}

- name: 'Upload Artifact'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ${{ env.ATTRIBUTE_NAME }}
path: ${{ env.NUGET_OUTPUT_PATH }}
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.0.0]

### Breaking changes

**Overlay syntax update**
* In version 5.0.0, we've removed the old overlay syntax parameters for transformations, such as `oi`, `ot`, `obg`, and [more](https://docs.imagekit.io/features/image-transformations/overlay). These parameters are deprecated and will start returning errors when used in URLs. Please migrate to the new layers syntax that supports overlay nesting, provides better positional control, and allows more transformations at the layer level. You can start with [examples](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#examples) to learn quickly.
* You can migrate to the new layers syntax using the `raw` transformation parameter.

### Added
- Parameters `EffectShadow` and `EffectGradient` for url generation.
- Upload options
- `transformation` for applying `pre` and `post` transformations.
- `checks` to perform server-side validations before file uploads.
- `isPublished` determines whether the file should be uploaded as published.
- Update parameter
- `publish` to configure the publication status of a file and its versions.

## [4.0.1]
### Fixed
- https://github.com/imagekit-developer/imagekit-dotnet/issues/50
Expand Down
41 changes: 15 additions & 26 deletions ImageKitSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,6 @@ static void Main(string[] args)
Rotation(90).
Blur(10).
Named("some_name").
OverlayX(35).
OverlayY(35).
OverlayFocus("bottom").
OverlayHeight(20).
OverlayHeight(20).
OverlayImage("/folder/file_name.jpg"). // leading slash case
OverlayImageTrim(false).
OverlayImageAspectRatio("4:3").
OverlayImageBackground("0F0F0F").
OverlayImageBorder("10_0F0F0F").
OverlayImageDpr(2).
OverlayImageQuality(50).
OverlayImageCropping("force").
OverlayText("two words").
OverlayTextFontSize(20).
OverlayTextFontFamily("Open Sans").
OverlayTextColor("00FFFF").
OverlayTextTransparency(5).
OverlayTextTypography("b").
OverlayBackground("00AAFF55").
OverlayTextEncoded("b3ZlcmxheSBtYWRlIGVhc3k%3D").
OverlayTextWidth(50).
OverlayTextBackground("00AAFF55").
OverlayTextPadding(40).
OverlayTextInnerAlignment("left").
OverlayRadius(10).
Progressive(true).
Lossless(true).
Trim(5).
Expand All @@ -78,6 +52,8 @@ static void Main(string[] args)
EffectUsm("2-2-0.8-0.024").
EffectContrast(true).
EffectGray().
EffectShadow().
EffectGradient().
Original().
Raw("h-200,w-300,l-image,i-logo.png,l-end");

Expand Down Expand Up @@ -153,6 +129,18 @@ static void Main(string[] args)
maxTags = 5,
minConfidence = 95
};
TransformationObject transformationObject = new TransformationObject
{
type = "transformation",
value = "w-100"
};
List<PostTransformation> postTransformations = new List<PostTransformation>();
postTransformations.Add(transformationObject);
UploadTransformation uploadTransformation = new UploadTransformation
{
pre = "l-text,i-Imagekit,fs-50,l-end",
post = postTransformations,
};
ext.Add(bck1);
ext.Add(autoTags);
ob.extensions = ext;
Expand All @@ -164,6 +152,7 @@ static void Main(string[] args)
ob.overwriteAITags = true;
ob.overwriteTags = true;
ob.overwriteCustomMetadata = true;
ob.transformation= uploadTransformation;
Result resp2 = imagekit.Upload(ob);

// Get Base64
Expand Down
34 changes: 5 additions & 29 deletions Imagekit.UnitTests/ImageKitTestCasesNonAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,6 @@ public void UrlValidation()
Rotation(90).
Blur(10).
Named("some_name").
OverlayX(35).
OverlayY(35).
OverlayFocus("bottom").
OverlayHeight(20).
OverlayHeight(20).
OverlayImage("/folder/file.jpg"). // leading slash case
OverlayImageTrim(false).
OverlayImageAspectRatio("4:3").
OverlayImageBackground("0F0F0F").
OverlayImageBorder("10_0F0F0F").
OverlayImageDpr(2).
OverlayImageQuality(50).
OverlayImageCropping("force").
OverlayText("two words").
OverlayTextFontSize(20).
OverlayTextFontFamily("Open Sans").
OverlayTextColor("00FFFF").
OverlayTextTransparency(5).
OverlayTextTypography("b").
OverlayBackground("00AAFF55").
OverlayTextEncoded("b3ZlcmxheSBtYWRlIGVhc3k%3D").
OverlayTextWidth(50).
OverlayTextBackground("00AAFF55").
OverlayTextPadding(40).
OverlayTextInnerAlignment("left").
OverlayRadius(10).
Progressive(true).
Lossless(true).
Trim(5).
Expand All @@ -94,13 +68,15 @@ public void UrlValidation()
EffectUsm("2-2-0.8-0.024").
EffectContrast(true).
EffectGray().
EffectShadow("bl-15").
EffectGradient("from-lightskyblue_to-mintcream").
Original().
Raw("h-200,w-300,l-image,i-logo.png,l-end")
Raw("l-text,i-Imagekit,fs-50,l-end")
;

string imageURL = imagekit.Url(trans).Path(path).TransformationPosition("query").Generate();

Assert.Equal("https://endpoint_url.io/default-image.jpg?tr=w-400%2Ch-300%2Car-4-3%2Cq-40%2Cc-force%2Ccm-extract%2Cfo-left%2Cf-jpeg%2Cbg-A94D34%2Cb-5-A94D34%2Crt-90%2Cbl-10%2Cn-some_name%2Cox-35%2Coy-35%2Cofo-bottom%2Coh-20%2Coi-folder%40%40file.jpg%2Coit-false%2Coiar-4%3A3%2Coibg-0F0F0F%2Coib-10_0F0F0F%2Coidpr-2%2Coiq-50%2Coic-force%2Cot-two%20words%2Cots-20%2Cotf-Open%20Sans%2Cotc-00FFFF%2Coa-5%2Cott-b%2Cobg-00AAFF55%2Cote-b3ZlcmxheSBtYWRlIGVhc3k%253D%2Cotw-50%2Cotbg-00AAFF55%2Cotp-40%2Cotia-left%2Cor-10%2Cpr-true%2Clo-true%2Ct-5%2Cmd-true%2Ccp-true%2Cdi-folder%40%40file.jpg%2Cdpr-3%2Ce-sharpen-10%2Ce-usm-2-2-0.8-0.024%2Ce-contrast-true%2Ce-grayscale-true%2Corig-true%2Ch-200%2Cw-300%2Cl-image%2Ci-logo.png%2Cl-end", imageURL);
Assert.Equal("https://endpoint_url.io/default-image.jpg?tr=w-400%2Ch-300%2Car-4-3%2Cq-40%2Cc-force%2Ccm-extract%2Cfo-left%2Cf-jpeg%2Cbg-A94D34%2Cb-5-A94D34%2Crt-90%2Cbl-10%2Cn-some_name%2Cpr-true%2Clo-true%2Ct-5%2Cmd-true%2Ccp-true%2Cdi-folder%40%40file.jpg%2Cdpr-3%2Ce-sharpen-10%2Ce-usm-2-2-0.8-0.024%2Ce-contrast-true%2Ce-grayscale-true%2Ce-shadow-bl-15%2Ce-gradient-from-lightskyblue_to-mintcream%2Corig-true%2Cl-text%2Ci-Imagekit%2Cfs-50%2Cl-end", imageURL);
}


Expand Down Expand Up @@ -128,7 +104,7 @@ public void UrlValidation1()

[Fact]
public void GetFileRequest_DefaultNonAsync()
{
{
GetFileListRequest ob = new GetFileListRequest
{
Limit = 10,
Expand Down
19 changes: 9 additions & 10 deletions Imagekit.UnitTests/Imagekit.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0;netcoreapp3.1;net461</TargetFrameworks>
<TargetFrameworks>net7.0;net5.0;net6.0;netcoreapp3.1</TargetFrameworks>
<LangVersion>8</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
Expand All @@ -25,27 +25,29 @@
<WarningLevel>5</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp3.1|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0|AnyCPU'">
<NoWarn>1701;1702;NU5125;NU5048;</NoWarn>
<WarningLevel>5</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netcoreapp3.1|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0|AnyCPU'">
<NoWarn>1701;1702;NU5125;NU5048;</NoWarn>
<WarningLevel>5</WarningLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp2.1|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp3.1|AnyCPU'">
<NoWarn>1701;1702;NU5125;NU5048;</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netcoreapp2.1|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netcoreapp3.1|AnyCPU'">
<NoWarn>1701;1702;NU5125;NU5048;</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net461|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp2.1|AnyCPU'">
<NoWarn>1701;1702;NU5125;NU5048;</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net461|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netcoreapp2.1|AnyCPU'">
<NoWarn>1701;1702;NU5125;NU5048;</NoWarn>
</PropertyGroup>

Expand All @@ -64,9 +66,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="16.6.1" Condition="$(TargetFramework.StartsWith('net4')) AND '$(OS)' == 'Unix'" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Imagekit\Imagekit.csproj" />
</ItemGroup>
Expand Down
43 changes: 42 additions & 1 deletion Imagekit.UnitTests/Upload/UploadTestCasesAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ public void UploadFile_Default()
name = "remove-bg",
options = new options() { add_shadow = true, bg_color = "green" }
};
TransformationObject transformationObject = new TransformationObject
{
value = "w-100"
};
List<PostTransformation> postTransformations = new List<PostTransformation>();
postTransformations.Add(transformationObject);
UploadTransformation uploadTransformation = new UploadTransformation
{
pre = "l-text,i-Imagekit,fs-50,l-end",
post = postTransformations,
};
model1.Add(bck);
ob.webhookUrl = "https://webhook.site/c78d617f-33bc-40d9-9e61-608999721e2e";
ob.useUniqueFileName = true;
Expand All @@ -192,12 +203,14 @@ public void UploadFile_Default()
ob.overwriteAITags = true;
ob.overwriteTags = true;
ob.overwriteCustomMetadata = true;
ob.transformation = uploadTransformation;
ob.checks = "'request.folder' : '/dummy-folder'";
ob.isPublished = true;
Hashtable model = new Hashtable
{
{ "price", 2000 }
};
ob.customMetadata = model;

var responseObj = TestHelpers.ImagekitResponseFaker.Generate();
var httpResponse = new HttpResponseMessage
{
Expand Down Expand Up @@ -381,6 +394,34 @@ public void UpdateFile_Default()
Assert.Equal(responseObj1, response.Raw);
}

[Fact]
public void UpdateFile_Publish_Status()
{
FileUpdateRequest ob = new FileUpdateRequest
{
fileId = "file-Id",

};
PublishStatus publishStatus = new PublishStatus
{
isPublished = false
};
ob.publish = publishStatus;
var responseObj = TestHelpers.ImagekitResponseFaker.Generate();
var httpResponse = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(JsonConvert.SerializeObject(responseObj))
};
var httpClient = TestHelpers.GetTestHttpClient(httpResponse);

var restClient = new RestClient(GOOD_PUBLICKEY, GOOD_URLENDPOINT, httpClient);

var response = (Result)restClient.UpdateFileDetailAsync(ob).Result;
var responseObj1 = JsonConvert.SerializeObject(responseObj);
Assert.Equal(responseObj1, response.Raw);
}


}
}
Expand Down
31 changes: 31 additions & 0 deletions Imagekit.UnitTests/Upload/UploadTestCasesNonAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ public void UploadFile_DefaultNonAsync()
ob.overwriteAITags = false;
ob.overwriteTags = false;
ob.overwriteCustomMetadata = true;
ob.checks = "'request.folder' : '/dummy-folder'";
ob.isPublished = true;
Hashtable model = new Hashtable
{
{ "price", 2000 }
Expand Down Expand Up @@ -381,6 +383,35 @@ public void UpdateFile_Default()
var responseObj1 = JsonConvert.SerializeObject(responseObj);
Assert.Equal(responseObj1, response.Raw);
}

[Fact]
public void UpdateFile_Publish_Status()
{
FileUpdateRequest ob = new FileUpdateRequest
{
fileId = "file-Id",

};
PublishStatus publishStatus = new PublishStatus
{
isPublished = false
};
ob.publish = publishStatus;

var responseObj = TestHelpers.ImagekitResponseFaker.Generate();
var httpResponse = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(JsonConvert.SerializeObject(responseObj))
};
var httpClient = TestHelpers.GetTestHttpClient(httpResponse);

var restClient = new RestClient(GOOD_PUBLICKEY, GOOD_URLENDPOINT, httpClient);

var response = (Result)restClient.UpdateFileDetail(ob);
var responseObj1 = JsonConvert.SerializeObject(responseObj);
Assert.Equal(responseObj1, response.Raw);
}

}
}
Expand Down
23 changes: 23 additions & 0 deletions Imagekit/Helper/MultipartFormDataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using global::Imagekit.Models;
using global::Imagekit.Util;
using Newtonsoft.Json;
using System.Collections.Generic;

public static class MultipartFormDataModel
{
Expand Down Expand Up @@ -105,6 +106,22 @@ public static MultipartFormDataContent Build(FileCreateRequest fileCreateRequest
formdata.Add(new StringContent(jsonResult), "customMetadata");
}

if (fileCreateRequest.transformation != null)
{
string jsonResult = JsonConvert.SerializeObject(fileCreateRequest.transformation);
formdata.Add(new StringContent(jsonResult), "transformation");
}

if (fileCreateRequest.checks != null)
{
formdata.Add(new StringContent(fileCreateRequest.checks), "checks");
}

if (fileCreateRequest.isPublished.HasValue)
{
formdata.Add(new StringContent(fileCreateRequest.isPublished.Value.ToString().ToLower()), "isPublished");
}

return formdata;
}

Expand Down Expand Up @@ -151,6 +168,12 @@ public static MultipartFormDataContent BuildUpdateFile(FileUpdateRequest fileCre
formdata.Add(new StringContent(jSONresult), "customMetadata");
}

if (fileCreateRequest.publish != null)
{
string jSONresult = JsonConvert.SerializeObject(fileCreateRequest.publish);
formdata.Add(new StringContent(jSONresult), "publish");
}

return formdata;
}
}
Expand Down
Loading
Loading