-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
150 lines (122 loc) · 4.73 KB
/
main.go
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
"log"
"os"
"github.com/captv89/photoGallery/cmd"
"github.com/captv89/photoGallery/model"
"github.com/captv89/photoGallery/web"
"github.com/joho/godotenv"
)
func init() {
// Log the line number and file name of the error
log.SetFlags(log.LstdFlags | log.Lshortfile)
// Load .env
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}
func main() {
// Run the action
action()
// Start the server
web.StartServer()
}
func action() {
// Image Thumbnails List
thumbsPath := "web/static/photos/thumbs"
fullsPath := "web/static/photos/fulls"
///////////////////////////////////////////////// FULLS //////////////////////////////////////////////////
// Check if the fulls folder exists
if _, err := os.Stat(fullsPath); os.IsNotExist(err) {
// Exit if the fulls folder does not exist
log.Fatal("Fulls folder does not exist")
}
var fCount int
if os.Getenv("SKIP_LOADING") == "false" {
// Count the number of image files in the fulls folder
fCount = cmd.CountImagesInFolder(fullsPath)
log.Printf("Image file count in directory: %d\n", fCount)
// Check if the image file count is zero
if fCount == 0 {
// Quit if there are no image files
log.Fatal("No image files found")
}
// Check if the imageNames.csv file exists
if _, err := os.Stat("imageMetadata.csv"); os.IsNotExist(err) {
log.Println("imageMetadata.csv does not exist, creating it...")
// Get all Full image metadata
log.Println("Getting full image metadata...")
imagesMetaData := cmd.WalkImageFiles(fullsPath)
// Save the image file names to the imageMetadata.csv file
log.Println("Saving full image metadata to imageMetadata.csv...")
cmd.SaveImageMetadata(imagesMetaData, "imageMetadata.csv")
}
}
// Load the image file names from the imageNames.txt file
fImageFiles := cmd.LoadImageMetadata("imageMetadata.csv")
log.Printf("Image file count in imageMetadata.csv: %d\n", len(fImageFiles))
if os.Getenv("SKIP_LOADING") == "false" {
// Check if the image file count is different from the number of image file names
if fCount != len(fImageFiles) {
log.Println("Image file count is different from the number of image file names, updating imageMetadata.csv...")
// Get all Full image metadata
log.Println("Getting full image metadata...")
imagesMetaData := cmd.WalkImageFiles(fullsPath)
// Save the image file names to the imageMetadata.csv file
log.Println("Saving full image metadata to imageMetadata.csv...")
cmd.SaveImageMetadata(imagesMetaData, "imageMetadata.csv")
}
}
// Set the image files in the thumbnails template
model.Fulls = fImageFiles
///////////////////////////////////////////////// THUMBS //////////////////////////////////////////////////
// Check if the thumbs folder exists
if _, err := os.Stat(thumbsPath); os.IsNotExist(err) {
// Exit if the thumbs folder does not exist
log.Fatal("Thumbs folder does not exist")
}
var tCount int
if os.Getenv("SKIP_LOADING") == "false" {
// Count the number of image files in the thumbs folder
tCount = cmd.CountImagesInFolder(thumbsPath)
log.Printf("Image file count in directory: %d\n", tCount)
// Check if the image file count is zero
if tCount == 0 {
// Quit if there are no image files
log.Fatal("No image files found")
}
// Check if the imageNames.csv file exists
if _, err := os.Stat("imageNames.csv"); os.IsNotExist(err) {
log.Println("imageNames.csv does not exist, creating it...")
// Get the image files in the thumbs folder
imageFiles := cmd.GetImageFilesInFolder(thumbsPath)
// Save the image file names to the imageNames.txt file
cmd.SaveImageNames(imageFiles)
}
}
// Load the image file names from the imageNames.txt file
tImageFiles := cmd.LoadImageNames("imageNames.csv")
log.Printf("Image file count in imageNames.csv: %d\n", len(tImageFiles))
if os.Getenv("SKIP_LOADING") == "false" {
// Check if the image file count is different from the number of image file names
if tCount != len(tImageFiles) {
log.Println("Image file count is different from the number of image file names, updating imageNames.csv...")
// Get the image files in the thumbs folder
tImageFiles = cmd.GetImageFilesInFolder(thumbsPath)
// Save the image file names to the imageNames.txt file
cmd.SaveImageNames(tImageFiles)
}
}
// Set the image files in the thumbnails template
model.Thumbnails = tImageFiles
///////////////////////////////////////////////// COMPARE //////////////////////////////////////////////////
if os.Getenv("SKIP_LOADING") == "false" {
// Check if the fCount and tCount are the same
if fCount != tCount {
log.Fatal("Fulls and Thumbs folder counts are different")
} else {
log.Println("Fulls and Thumbs folder counts are the same. Continue...")
}
}
}