-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-list.js
58 lines (48 loc) · 2.11 KB
/
file-list.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
const fs = require("fs");
const path = require("path");
function renderFileList(req, res) {
const enDirectoryPath = path.join(__dirname, "posts-old", "en");
const ruDirectoryPath = path.join(__dirname, "posts-old", "ru");
// Helper function to process files from a given directory and language
const processFiles = (directoryPath, language) => {
const files = fs.readdirSync(directoryPath);
return files.map((file) => {
const parts = file.split("_");
const version = parts[0] || "N/A";
const ipAddress = (parts[2] && parts[2].replace(".md", "").replace(/-/g, ".")) || "Unknown IP";
const filePath = path.join(directoryPath, file);
const stats = fs.statSync(filePath);
const lastModified = stats.mtime;
const options = {
timeZone: "America/New_York",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
};
const easternTime = new Intl.DateTimeFormat("en-US", options).format(lastModified);
// Split the formatted string into date and time
const [date, time] = easternTime.split(", ");
return {
name: file,
version,
ipAddress,
size: stats.size, // File size in bytes
date, // Date in YYYY-MM-DD format
time, // Time in HH:MM:SS format
language, // Include the language in the file details
};
});
};
// Combine file details from both directories
const enFiles = processFiles(enDirectoryPath, "English");
const ruFiles = processFiles(ruDirectoryPath, "Russian");
const fileDetails = [...enFiles, ...ruFiles];
fileDetails.sort((a, b) => b.date.localeCompare(a.date) || b.time.localeCompare(a.time));
// Render the details in the EJS template
res.render("file_list", { fileDetails });
}
module.exports = renderFileList;