1
- import { makeImagePersistencePlan } from "./MakeImagePersistencePlan";
1
+ import {
2
+ hashOfString,
3
+ makeImagePersistencePlan,
4
+ } from "./MakeImagePersistencePlan";
2
5
import { ImageSet } from "./images";
3
6
4
7
test("primary file with explicit file output path and prefix", () => {
@@ -9,11 +12,16 @@ test("primary file with explicit file output path and prefix", () => {
9
12
fileType: { ext: "png", mime: "image/png" },
10
13
};
11
14
makeImagePersistencePlan(imageSet, "./static/notion_imgs", "/notion_imgs");
12
- expect(imageSet.outputFileName).toBe("463556435.png");
15
+ const expectedHash = hashOfString(
16
+ "https://s3.us-west-2.amazonaws.com/primaryImage"
17
+ );
18
+ expect(imageSet.outputFileName).toBe(`${expectedHash}.png`);
13
19
expect(imageSet.primaryFileOutputPath).toBe(
14
- "static/notion_imgs/463556435.png"
20
+ `static/notion_imgs/${expectedHash}.png`
21
+ );
22
+ expect(imageSet.filePathToUseInMarkdown).toBe(
23
+ `/notion_imgs/${expectedHash}.png`
15
24
);
16
- expect(imageSet.filePathToUseInMarkdown).toBe("/notion_imgs/463556435.png");
17
25
});
18
26
test("primary file with defaults for image output path and prefix", () => {
19
27
const imageSet: ImageSet = {
@@ -23,13 +31,39 @@ test("primary file with defaults for image output path and prefix", () => {
23
31
fileType: { ext: "png", mime: "image/png" },
24
32
};
25
33
makeImagePersistencePlan(imageSet, "", "");
26
- expect(imageSet.outputFileName).toBe("463556435.png");
34
+ const expectedHash = hashOfString(
35
+ "https://s3.us-west-2.amazonaws.com/primaryImage"
36
+ );
37
+ expect(imageSet.outputFileName).toBe(`${expectedHash}.png`);
27
38
28
39
// the default behavior is to put the image next to the markdown file
29
40
expect(imageSet.primaryFileOutputPath).toBe(
30
- " /pathToParentSomewhere/463556435 .png"
41
+ ` /pathToParentSomewhere/${expectedHash} .png`
31
42
);
32
- expect(imageSet.filePathToUseInMarkdown).toBe("./463556435.png");
43
+ expect(imageSet.filePathToUseInMarkdown).toBe(`./${expectedHash}.png`);
44
+ });
45
+
46
+ test("properly extract UUID from old-style notion image url", () => {
47
+ const imageSet: ImageSet = {
48
+ primaryUrl:
49
+ "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/e1058f46-4d2f-4292-8388-4ad393383439/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220516%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220516T233630Z&X-Amz-Expires=3600&X-Amz-Signature=f215704094fcc884d37073b0b108cf6d1c9da9b7d57a898da38bc30c30b4c4b5&X-Amz-SignedHeaders=host&x-id=GetObject",
50
+ localizedUrls: [],
51
+ fileType: { ext: "png", mime: "image/png" },
52
+ };
53
+ makeImagePersistencePlan(imageSet, "./static/notion_imgs", "/notion_imgs");
54
+ const expectedHash = hashOfString("e1058f46-4d2f-4292-8388-4ad393383439");
55
+ expect(imageSet.outputFileName).toBe(`${expectedHash}.png`);
56
+ });
57
+ test("properly extract UUID from new-style (Sept 2023) notion image url", () => {
58
+ const imageSet: ImageSet = {
59
+ primaryUrl:
60
+ "https://prod-files-secure.s3.us-west-2.amazonaws.com/d9a2b712-cf69-4bd6-9d65-87a4ceeacca2/d1bcdc8c-b065-4e40-9a11-392aabeb220e/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20230915%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20230915T161258Z&X-Amz-Expires=3600&X-Amz-Signature=28fca48e65fba86d539c3c4b7676fce1fa0857aa194f7b33dd4a468ecca6ab24&X-Amz-SignedHeaders=host&x-id=GetObject",
61
+ localizedUrls: [],
62
+ fileType: { ext: "png", mime: "image/png" },
63
+ };
64
+ makeImagePersistencePlan(imageSet, "./static/notion_imgs", "/notion_imgs");
65
+ const expectedHash = hashOfString("d1bcdc8c-b065-4e40-9a11-392aabeb220e");
66
+ expect(imageSet.outputFileName).toBe(`${expectedHash}.png`);
33
67
});
34
68
35
69
// In order to make image fallback work with other languages, we have to have
0 commit comments