-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.js
79 lines (71 loc) · 2.69 KB
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function GET_SHOP_IMAGE_PATH(file_name, size = null, random_fill = false) {
// Debug information
console.log('Debug > GET_SHOP_IMAGE_PATH ', file_name, size);
if (!file_name) {
if (random_fill && Number.isInteger(random_fill)) {
return PlaceholderImages.GetIDImage(random_fill);
}
if (random_fill) {
return PlaceholderImages.GetRamonImage();
}
return imagePlaceholder;
}
// Invalid size mode file formats:
try {
if (file_name.endsWith(".svg")) {
// SVG not supported for direct size mode!
size = null;
}
} catch (e) {
console.error(e);
return null;
}
// Check if it is an absolute path (In the page builder template!):
if (
file_name.startsWith("https://") ||
file_name.startsWith("http://") ||
file_name.startsWith("/") /*Relative Path*/
) {
// Absolute CDN address: (Can assign size to path!)
if (file_name.startsWith("https://cdn.selldone.") && size) {
return `${file_name}${size}.png`;
} else if (size) {
// return `${file_name}?size=${size}`; // Important: Some websites like Reddit block added queries!
}
return file_name;
}
// Handle direct storage URLs
if (
(!size || window.storage_direct_thumbnails) &&
window.storage_direct_url &&
window.storage_direct
) {
// No query only can get directly from cloud storage!
// Replace _ to slash (File format save in DB to real path)
file_name = file_name.replace(/_/gi, "/");
if (file_name.startsWith("repository:")) {
// Handle repository files address
file_name = file_name.replace("repository:", "");
return `${window.storage_direct_url}/repository/${file_name}`;
} else if (file_name.startsWith("instagram:")) {
// Handle Instagram files address
file_name = file_name.replace("instagram:", "");
return `${window.storage_direct_url}/instagram/${file_name}`;
} else {
// Handle normal files address
file_name = file_name + (size ? `${size}.png` : "");
return `${window.storage_direct_url}/app/${file_name}`;
}
} else {
return (
`${window.shop_cdn_images}/${file_name}` +
(size !== null ? `?size=${size}` : "")
);
}
}
// Ensure global variables are defined
window.imagePlaceholder = "https://via.placeholder.com/150";
window.shop_cdn_images = "https://cdn.selldone.com";
window.storage_direct_url = "https://cdn.selldone.com";
window.storage_direct = true;
window.storage_direct_thumbnails = true;