testing assets and fix source existance check bug

pull/3/head
Toni Melisma 3 years ago
parent b10c8c3bd6
commit e8a6c822c4
No known key found for this signature in database
GPG Key ID: FFF9A7EDDEA34756

@ -369,49 +369,49 @@ func compareDirectoryTrees(source *directory, gallery *directory, config configu
// Iterate over each file in source directory to see whether it exists in gallery
for i, sourceFile := range source.files {
sourceFileBasename := stripExtension(sourceFile.name)
fmt.Println("checking:", sourceFile.absPath, sourceFileBasename)
var thumbnailFile, fullsizeFile, originalFile *file
fmt.Println(sourceFile, thumbnailFile, fullsizeFile, originalFile)
fmt.Println("[1] --- ", sourceFile, thumbnailFile, fullsizeFile, originalFile)
// Go through all subdirectories, and check the ones that match
// the thumbnail, full-size or original subdirectories
for _, subDir := range gallery.subdirectories {
for h, subDir := range gallery.subdirectories {
if subDir.name == config.files.thumbnailDir {
for _, outputFile := range subDir.files {
for i, outputFile := range gallery.subdirectories[h].files {
outputFileBasename := stripExtension(outputFile.name)
if sourceFileBasename == outputFileBasename {
fmt.Println("match:", sourceFileBasename, outputFileBasename, thumbnailFile)
thumbnailFile = &outputFile
thumbnailFile = &gallery.subdirectories[h].files[i]
thumbnailFile.exists = true
fmt.Println("match2:", thumbnailFile)
fmt.Println("[2] --- ", sourceFile, thumbnailFile, fullsizeFile, originalFile)
}
}
} else if subDir.name == config.files.fullsizeDir {
for _, outputFile := range subDir.files {
for j, outputFile := range gallery.subdirectories[h].files {
outputFileBasename := stripExtension(outputFile.name)
if sourceFileBasename == outputFileBasename {
fullsizeFile = &outputFile
fullsizeFile = &gallery.subdirectories[h].files[j]
fullsizeFile.exists = true
fmt.Println("[3] --- ", sourceFile, thumbnailFile, fullsizeFile, originalFile)
}
}
} else if subDir.name == config.files.originalDir {
for _, outputFile := range subDir.files {
for k, outputFile := range gallery.subdirectories[h].files {
outputFileBasename := stripExtension(outputFile.name)
if sourceFileBasename == outputFileBasename {
originalFile = &outputFile
originalFile = &gallery.subdirectories[h].files[k]
originalFile.exists = true
fmt.Println("[4] --- ", sourceFile, thumbnailFile, fullsizeFile, originalFile)
}
}
}
}
fmt.Println("[5] --- ", sourceFile, thumbnailFile, fullsizeFile, originalFile)
// If all of thumbnail, full-size and original files exist in gallery, and they're
// modified after the source file, the source file exists and is up to date.
// Otherwise we overwrite gallery files in case source file's been updated since the thumbnail
// was created.
if thumbnailFile != nil && fullsizeFile != nil && originalFile != nil {
fmt.Println("three matches", sourceFile.name)
fmt.Println(sourceFile, thumbnailFile, fullsizeFile, originalFile)
fmt.Println("[6] --- ", sourceFile, thumbnailFile, fullsizeFile, originalFile)
if thumbnailFile.modTime.After(sourceFile.modTime) {
source.files[i].exists = true
} else {

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/2020-05-22 16.41.02.heic

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/2021-01-01 17.11.35.heic

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/2021-01-02 23.51.34.mp4

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/2021-02-22 15.36.43-1.heic

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/2021-02-25 15.40.44.png

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/_DSC9363_DxO.jpg

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/_DSC9439.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

@ -0,0 +1,33 @@
.box {
cursor: pointer;
}
#modalMedia {
max-width: 100%;
max-height: calc(100% - 74px);
}
.modalImage {
object-fit: scale-down;
max-width: 100%;
}
video {
max-width: 100%;
max-height: 100%;
}
#modalDownload {
color: inherit;
}
#modalHeader,
#modalFooter {
height: 37px;
width: 360px;
}
.modalControl:hover,
.modalControl:focus {
background-color: rgba(0, 0, 0, 0.2);
}

@ -0,0 +1,150 @@
// check that the HTML page including us has set the pictures array
if (typeof pictures == 'undefined') {
throw new Error("pictures array not defined")
}
// Hard-coded configuration
const videoExtension = "mp4"
const videoMIMEType = "video/mp4"
// global variable maintains currently shown picture number (pictures[] array)
var currentPicture
// create hover effect shadow for all box elements
const hoverOnBox = (event) => {
event.target.classList.remove("box-shadow")
event.target.classList.remove("border-gray")
event.target.classList.add("box-shadow-large")
event.target.classList.add("border-gray-dark")
}
const hoverOffBox = (event) => {
event.target.classList.remove("border-gray-dark")
event.target.classList.remove("box-shadow-large")
event.target.classList.add("box-shadow")
event.target.classList.add("border-gray")
}
const registerBoxEventHandlers = (element) => {
element.addEventListener("mouseenter", hoverOnBox)
element.addEventListener("mouseleave", hoverOffBox)
}
var boxes = document.getElementsByClassName("box")
for (let box of boxes) {
registerBoxEventHandlers(box)
}
// create hover effect for modal navigation elements
// const hoverOnNav = (event) => {}
// logic to show and hide picture modal
const displayModal = (display) => {
if (display) {
document.getElementById("modal").hidden = false
document.getElementById("thumbnails").hidden = true
} else {
document.getElementById("thumbnails").hidden = false
document.getElementById("modal").hidden = true
document.getElementById("modalMedia").innerHTML = ""
window.location.hash = ""
}
}
// TODO add swipe support https://stackoverflow.com/questions/2264072/detect-a-finger-swipe-through-javascript-on-the-iphone-and-android
// modal previous and next picture button logic
const preload = (number) => {
var preloadLink = document.createElement("link")
preloadLink.rel = "prefetch"
preloadLink.href = encodeURI(pictures[number].fullsize)
const fileExtension = preloadLink.href.split("\.").pop()
if (fileExtension == videoExtension) {
preloadLink.as = "video"
} else {
preloadLink.as = "image"
}
document.head.appendChild(preloadLink)
}
const prevPicture = () => {
changePicture(getPrevPicture())
preload(getPrevPicture())
}
const getPrevPicture = () => {
if (!isNaN(currentPicture)) {
if (currentPicture === 0) {
return (pictures.length - 1)
} else if (currentPicture < 0 || currentPicture >= pictures.length) {
console.error("Invalid currentPicture, 0.." + pictures.length - 1 + ": " + currentPicture)
} else {
return (currentPicture - 1)
}
} else {
console.error("Invalid currentPicture, NaN: " + currentPicture)
}
}
const nextPicture = () => {
changePicture(getNextPicture())
preload(getNextPicture())
}
const getNextPicture = () => {
if (!isNaN(currentPicture)) {
if (currentPicture === pictures.length - 1) {
return (0)
} else if (currentPicture < 0 || currentPicture >= pictures.length) {
console.error("Invalid currentPicture, 0.." + pictures.length - 1 + ": " + currentPicture)
} else {
return (currentPicture + 1)
}
} else {
console.error("Invalid currentPicture, NaN: " + currentPicture)
}
}
// function to change picture in modal, used by hashNavigate, and next/prevPicture
const changePicture = (number) => {
thumbnailFilename = pictures[number].thumbnail
window.location.hash = pictures[number].filename
const fileExtension = pictures[number].fullsize.split("\.").pop()
if (fileExtension == videoExtension) {
document.getElementById("modalMedia").innerHTML = "<video controls><source src=\"" + encodeURI(pictures[number].fullsize) + "\" type=\"" + videoMIMEType + "\"></video>"
} else {
document.getElementById("modalMedia").innerHTML = "<img src=\"" + encodeURI(pictures[number].fullsize) + "\" alt=\"" + pictures[number].filename + "\" class=\"modalImage\">"
}
document.getElementById("modalDescription").innerHTML = pictures[number].filename
document.getElementById("modalDownload").href = pictures[number].original
currentPicture = number
}
// if URL links directly to thumbnail via hash link, open modal for that pic on page load
const hashNavigate = () => {
if (window.location.hash) {
const filename = decodeURI(window.location.hash.substring(1))
id = pictures.findIndex(item => item.filename == filename)
if (id != -1 && id >= 0 && id < pictures.length) {
changePicture(id)
displayModal(true)
} else {
displayModal(false)
console.error("Invalid thumbnail link provided after # in URI")
}
} else {
displayModal(false)
}
}
const checkKey = (event) => {
if (event.key === "ArrowLeft") {
prevPicture()
} else if (event.key === "ArrowRight") {
nextPicture()
} else if (event.key === "Escape") {
displayModal(false)
}
}
document.onkeydown = checkKey
window.onpopstate = hashNavigate

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 KiB

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/subdir/2021-01-13 18.19.20.heic

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/subdir/2021-02-04 13.46.20.heic

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

@ -0,0 +1 @@
/home/toni/go/src/github.com/tonimelisma/fastgallery/testing/source/subdir/subsubdir/2021-02-17 18.59.30.heic

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Loading…
Cancel
Save