imageHandling.js
2.33 KB
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
export const cleanImage = originalImage => {
let imageUrl = "/images/default.svg";
if (originalImage) {
/** When the AWS S3 plugin is activated, images are uploaded to S3 rather than local file system. */
if (originalImage.url.startsWith("http")) {
imageUrl = originalImage.url;
} else {
/** If now S3, then images are stored under the public/uploads directory of Strapi */
imageUrl = `${process.env.NEXT_PUBLIC_BACKEND_API_URL}${originalImage.url}`;
}
}
return imageUrl;
};
export const renderImage = imagePath => {
let imageUrl = "/images/default.svg";
if (imagePath) {
/** When the AWS S3 plugin is activated, images are uploaded to S3 rather than local file system. */
if (imagePath.startsWith("http") || imagePath.startsWith("https")) {
imageUrl = imagePath;
} else if (process.env.NEXT_PUBLIC_IMAGE_URL) {
/** If now S3, then images are stored under the public/uploads directory of Strapi */
imageUrl = `${process.env.NEXT_PUBLIC_IMAGE_URL}${imagePath}`;
} else {
imageUrl = `http://localhost:3015${imagePath}`;
}
}
return imageUrl;
};
export const sanitizeTimeFormat = ({ data }) => {
console.log("here sant 1");
if (!data.fromHours || !data.fromMins || !data.toHours || !data.toMins) {
console.log("here sant");
return null;
}
const fromTime = `${data.fromHours}:${data.fromMins}:00`;
const toTime = `${data.toHours}:${data.toMins}:00`;
const day = data.day;
return { fromTime, toTime, day };
// const day
};
export const sanitizeTimeRange = ({ data }) => {
// console.log("data >", data[0].$d);
const date = new Date(data.$d);
const day = date.getDate();
const month = date.getMonth() + 1; // Month starts from 0, so add 1
const year = date.getFullYear();
const formattedDay = day < 10 ? "0" + day : day;
const formattedMonth = month < 10 ? "0" + month : month;
const formattedDate = `${year}-${formattedMonth}-${formattedDay}`;
// console.log("date", formattedDate);
return formattedDate;
// const endDate = new Date(data[1].$d);
};
export const dateFormatFn = rawDate => {
const date = new Date(rawDate);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero-indexed
const day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};