update readme

This commit is contained in:
2025-07-26 17:25:18 -07:00
parent b81872440f
commit a29ec39252
20 changed files with 335 additions and 95 deletions

View File

@ -1,12 +0,0 @@
#!/bin/bash
# create timelapse
# Check if the timestamp is provided
#if [ -z "$1" ]; then
# echo "Usage: ./test.sh --timestamp=\"2025-07-25 12:00:00\""
# exit 1
#fi
# Extract the timestamp from the argument
#TIMESTAMP=$(echo $1 | awk -F'=' '{print $2}')4

View File

@ -0,0 +1,11 @@
services:
photo_refresh:
container_name: photo_refresh
image: php:8.0-apache
ports:
- 8080:80
volumes:
- /opt/docker/photo_refresh/:/var/www/html/
network_mode: bridge
restart: always

17
files/getImage.php Normal file
View File

@ -0,0 +1,17 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Image Update</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<img id="refreshedImage" src="getImage.php" width="400" alt="Refreshed Image">
<script>
// Function to update the image every other second using AJAX
setInterval(function() {
$('#refreshedImage').attr('src', 'getImage.php?_=' + new Date().getTime()); // Adding timestamp to avoid caching
}, 2000);
</script>
</body>
</html>

View File

@ -0,0 +1,23 @@
# Use an official Node runtime as a parent image
FROM node:14
# Create and change to the app directory
WORKDIR /usr/src/app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install any needed packages specified in package.json
RUN npm install
# Bundle app source inside Docker container
COPY . .
# Make port 3000 available to the world outside this container
EXPOSE 3000
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["node", "server.js"]

View File

@ -0,0 +1,12 @@
{
"name": "docker_web_app",
"version": "1.0.0",
"description": "A simple Docker Web app",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.1"
}
}

View File

@ -0,0 +1,39 @@
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3000;
app.use(express.static('public')); // Serve static files from the 'public' directory
// Endpoint to get the most recent image
app.get('/most-recent-image', (req, res) => {
const imagesDirectory = path.join(__dirname, 'images');
fs.readdir(imagesDirectory, (err, files) => {
if (err) {
return res.status(500).send('Unable to scan directory');
}
let mostRecentImage = null;
let maxDate = Date.now();
files.forEach(file => {
const filePath = path.join(imagesDirectory, file);
const stats = fs.statSync(filePath);
if (stats.isFile() && /\.(jpg|jpeg|png|gif)$/i.test(file)) {
const currentDate = new Date(stats.mtime).getTime();
if (currentDate < maxDate) {
mostRecentImage = file;
maxDate = currentDate;
}
}
});
if (mostRecentImage) {
res.json({ imagePath: `/images/${mostRecentImage}` });
} else {
res.status(404).send('No images found');
}
});
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});

22
files/index.php Normal file
View File

@ -0,0 +1,22 @@
<?php
header("Cache-Control: no-cache, must-revalidate");
// Path to the directory where the images are stored
$imageDirectory = 'capture/';
// Get the list of image files in the directory
$imageFiles = glob($imageDirectory . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
// If there are no image files, return a default image
if (empty($imageFiles)) {
$defaultImage = 'default.jpg'; // Provide path to your default image
header('Content-Type: image/jpeg'); // Adjust content type if default image type is different
readfile($defaultImage);
exit;
}
// Sort the image files by modification time, latest first
array_multisort(array_map('filemtime', $imageFiles), SORT_DESC, $imageFiles);
// Get the path to the latest image file
$latestImage = $imageFiles[0];
// Set header type
header('Content-Type: image/jpeg');
// Get the image
readfile($latestImage);
?>

View File

@ -1,13 +0,0 @@
[Unit]
Description=Timelapse service
After=network.target
[Service]
ExecStart=/opt/carputer/timelapse/timelapse_service.sh
Restart=always
User=timelapse
Group=timelapse
[Install]
WantedBy=multi-user.target