-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add uploadcare cdn * feat: ensure the URL's always ends with an slash * test: update test image * test: fixed using correct uuid * feat: add example * fix: correct signature sign * fix: correct signature sign
- Loading branch information
Showing
8 changed files
with
567 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,141 @@ | ||
import { assertEquals } from "https://deno.land/std@0.172.0/testing/asserts.ts"; | ||
import { ParsedUrl } from "../types.ts"; | ||
import { parse, transform, UploadcareParams } from "./uploadcare.ts"; | ||
|
||
const baseImage = "https://ucarecdn.com/661bd414-064c-477a-b50f-8ffd8f66aa49/"; | ||
const img = | ||
"https://ucarecdn.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/resize/800x550/"; | ||
|
||
const imgNoOperations = baseImage; | ||
|
||
const imgSubdomain = | ||
"https://private-name.example.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/resize/800x550/"; | ||
|
||
const imgWithFilename = | ||
"https://ucarecdn.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/resize/800x550/auto/tshirt1.jpg"; | ||
|
||
Deno.test("uploadcare parser", async (t) => { | ||
await t.step("parses a URL", () => { | ||
const parsed = parse(img); | ||
const expected: ParsedUrl<UploadcareParams> = { | ||
base: | ||
"https://ucarecdn.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/resize/800x550/-/format/auto/", | ||
cdn: "uploadcare", | ||
params: { | ||
host: "ucarecdn.com", | ||
uuid: "661bd414-064c-477a-b50f-8ffd8f66aa49", | ||
operations: { | ||
resize: "800x550", | ||
format: "auto", | ||
}, | ||
filename: undefined, | ||
}, | ||
}; | ||
assertEquals(parsed, expected); | ||
}); | ||
|
||
await t.step("parses a URL without operations", () => { | ||
const parsed = parse(imgNoOperations); | ||
const expected: ParsedUrl<UploadcareParams> = { | ||
base: `${baseImage}-/format/auto/`, | ||
cdn: "uploadcare", | ||
params: { | ||
host: "ucarecdn.com", | ||
uuid: "661bd414-064c-477a-b50f-8ffd8f66aa49", | ||
operations: { | ||
format: "auto", | ||
}, | ||
filename: undefined, | ||
}, | ||
}; | ||
assertEquals(parsed, expected); | ||
}); | ||
|
||
await t.step("parses a URL with custom domain", () => { | ||
const parsed = parse(imgSubdomain); | ||
const expected: ParsedUrl<UploadcareParams> = { | ||
base: | ||
"https://private-name.example.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/resize/800x550/-/format/auto/", | ||
cdn: "uploadcare", | ||
params: { | ||
host: "private-name.example.com", | ||
uuid: "661bd414-064c-477a-b50f-8ffd8f66aa49", | ||
operations: { | ||
resize: "800x550", | ||
format: "auto", | ||
}, | ||
filename: undefined, | ||
}, | ||
}; | ||
assertEquals(parsed, expected); | ||
}); | ||
|
||
await t.step("parses a URL with filename", () => { | ||
const parsed = parse(imgWithFilename); | ||
const expected: ParsedUrl<UploadcareParams> = { | ||
base: | ||
"https://ucarecdn.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/resize/800x550/-/format/auto/tshirt1.jpg", | ||
cdn: "uploadcare", | ||
params: { | ||
host: "ucarecdn.com", | ||
uuid: "661bd414-064c-477a-b50f-8ffd8f66aa49", | ||
operations: { | ||
resize: "800x550", | ||
format: "auto", | ||
}, | ||
filename: "tshirt1.jpg", | ||
}, | ||
}; | ||
assertEquals(parsed, expected); | ||
}); | ||
}); | ||
|
||
Deno.test("uploadcare transformer", async (t) => { | ||
await t.step("transforms a URL", () => { | ||
const result = transform({ | ||
url: img, | ||
width: 100, | ||
height: 200, | ||
}); | ||
assertEquals( | ||
result?.toString(), | ||
"https://ucarecdn.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/resize/100x200/-/format/auto/", | ||
); | ||
}); | ||
|
||
await t.step("rounds non-integer values", () => { | ||
const result = transform({ | ||
url: img, | ||
width: 100.6, | ||
height: 200.2, | ||
}); | ||
assertEquals( | ||
result?.toString(), | ||
"https://ucarecdn.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/resize/100.6x200.2/-/format/auto/", | ||
); | ||
}); | ||
|
||
await t.step("transforms a URL without parsed transforms", () => { | ||
const result = transform({ | ||
url: imgNoOperations, | ||
width: 100, | ||
height: 200, | ||
}); | ||
assertEquals( | ||
result?.toString(), | ||
"https://ucarecdn.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/format/auto/-/resize/100x200/", | ||
); | ||
}); | ||
|
||
await t.step("transforms a URL with path and version", () => { | ||
const result = transform({ | ||
url: imgWithFilename, | ||
width: 100, | ||
height: 200, | ||
}); | ||
assertEquals( | ||
result?.toString(), | ||
"https://ucarecdn.com/661bd414-064c-477a-b50f-8ffd8f66aa49/-/resize/100x200/-/format/auto/tshirt1.jpg", | ||
); | ||
}); | ||
}); |
Oops, something went wrong.