Initial commit

master
gz 1 month ago
commit ed2b4a773c

@ -0,0 +1,211 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>缅邈岁月</title>
<style>
html, body {
margin: 0;
padding: 0;
overflow-x: hidden;
font-family: Arial, sans-serif;
touch-action: manipulation;
}
body.modal-open {
overflow: hidden;
position: fixed;
width: 100%;
top: 0;
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 10px;
width: 100%;
max-width: 100vw;
margin: 20px 0;
padding: 0 10px;
box-sizing: border-box;
}
.media {
position: relative;
overflow: hidden;
border-radius: 10px;
background-color: #f0f0f0;
aspect-ratio: 1 / 1;
}
.media img,
.media video {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 10px;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s, transform 0.3s;
}
.media img.loaded,
.media video.loaded {
opacity: 1;
}
.media img:hover,
.media video:hover {
transform: scale(1.05);
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.9);
justify-content: center;
align-items: center;
z-index: 1000;
flex-direction: column;
touch-action: none;
}
.modal.active {
display: flex;
}
.modal-content {
position: relative;
max-width: 100vw;
max-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
padding: 10px;
}
.modal-content img,
.modal-content video {
max-width: 100vw;
max-height: 100vh;
width: auto;
height: auto;
object-fit: contain;
border-radius: 10px;
display: block;
}
</style>
</head>
<body>
<div class="gallery">
{% for file in files %}
<div class="media">
{% if file.endswith(('.jpg', '.jpeg', '.png', '.gif', '.JPG', '.JPEG', '.PNG', '.GIF')) %}
<img data-src="/media/{{ file }}" alt="{{ file }}" onclick="openModal('{{ file }}', 'image')">
{% elif file.endswith(('.mp4', '.avi', '.mov', '.wmv', '.m4v', '.mpg')) %}
<video data-src="/media/{{ file }}" muted playsinline onclick="openModal('{{ file }}', 'video')">
Your browser does not support the video tag.
</video>
{% endif %}
</div>
{% endfor %}
</div>
<!-- 模态框 -->
<div id="modal" class="modal">
<div class="modal-content" id="modalContent"></div>
</div>
<script>
const mediaElements = document.querySelectorAll('.media img, .media video');
const lazyLoadObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target;
el.src = el.dataset.src;
el.classList.add('loaded');
observer.unobserve(el);
}
});
}, { rootMargin: '0px 0px 200px 0px' });
mediaElements.forEach(el => lazyLoadObserver.observe(el));
const modal = document.getElementById('modal');
const modalContent = document.getElementById('modalContent');
const body = document.body;
let scrollY = 0;
let files = [{% for file in files %}"{{ file }}",{% endfor %}];
let currentIndex = 0;
function openModal(file, type) {
currentIndex = files.indexOf(file);
showModal(file, type);
scrollY = window.scrollY;
body.classList.add('modal-open');
body.style.top = `-${scrollY}px`;
modal.classList.add('active');
}
function closeModal() {
modal.classList.remove('active');
body.classList.remove('modal-open');
modalContent.innerHTML = '';
window.scrollTo(0, scrollY);
}
function showModal(file, type) {
modalContent.innerHTML = '';
const media = document.createElement(type === 'image' ? 'img' : 'video');
media.src = `/media/${file}`;
if (type === 'video') {
media.controls = true;
media.muted = true;
media.autoplay = true;
media.playsInline = true;
media.loop = true;
}
modalContent.appendChild(media);
}
modal.addEventListener('click', (e) => {
if (!modalContent.contains(e.target)) {
closeModal();
}
});
// 滑动切换
let startY = 0;
modal.addEventListener('touchstart', e => {
startY = e.touches[0].clientY;
});
modal.addEventListener('touchend', e => {
const endY = e.changedTouches[0].clientY;
const deltaY = endY - startY;
if (Math.abs(deltaY) > 50) {
if (deltaY < 0) {
currentIndex = (currentIndex + 1) % files.length;
} else {
currentIndex = (currentIndex - 1 + files.length) % files.length;
}
const nextFile = files[currentIndex];
const ext = nextFile.split('.').pop().toLowerCase();
const isImage = ['jpg', 'jpeg', 'png', 'gif'].includes(ext);
showModal(nextFile, isImage ? 'image' : 'video');
}
});
</script>
</body>
</html>

@ -0,0 +1,174 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ttings</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
overflow-x: hidden;
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 10px;
width: 100%;
max-width: 100vw;
margin: 20px 0;
padding: 0 10px;
}
.media {
position: relative;
overflow: hidden;
border-radius: 10px;
background-color: #f0f0f0;
aspect-ratio: 1 / 1;
}
.media img, .media video {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 10px;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s, transform 0.3s;
}
.media img.loaded, .media video.loaded {
opacity: 1;
}
.media img:hover, .media video:hover {
transform: scale(1.05);
}
.filename {
position: absolute;
bottom: 5px;
left: 5px;
right: 5px;
background: rgba(0, 0, 0, 0.6);
color: white;
font-size: 12px;
text-align: center;
padding: 2px 5px;
border-radius: 5px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal.active {
display: flex;
}
.modal-content img, .modal-content video {
max-width: 90vw;
max-height: 90vh;
border-radius: 10px;
}
body.modal-open {
overflow: hidden;
}
</style>
</head>
<body>
<div class="gallery">
<!-- 假设这是动态渲染的静态目录文件,支持懒加载 -->
{% for file in files %}
<div class="media">
{% if file.endswith(('.jpg', '.jpeg', '.png', '.gif', '.JPG', '.JPEG', '.PNG', '.GIF')) %}
<img data-src="/media/{{ file }}" alt="{{ file }}" onclick="openModal('/media/{{ file }}', 'image')">
{% elif file.endswith(('.mp4', '.avi', '.mov', '.wmv', '.m4v', '.mpg')) %}
<video data-src="/media/{{ file }}" controls onclick="openModal('/media/{{ file }}', 'video')">
Your browser does not support the video tag.
</video>
{% endif %}
<!-- <div class="filename">{{ file }}</div> -->
</div>
{% endfor %}
</div>
<!-- 模态框 -->
<div id="modal" class="modal">
<div class="modal-content">
<img id="modal-image" src="" alt="Full view">
<video id="modal-video" controls>
Your browser does not support the video tag.
</video>
</div>
</div>
<script>
// 使用 IntersectionObserver 进行懒加载和渐显效果
const mediaElements = document.querySelectorAll('.media img, .media video');
const lazyLoadObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const mediaElement = entry.target;
if (mediaElement.tagName.toLowerCase() === 'img') {
mediaElement.src = mediaElement.dataset.src; // 加载图片
mediaElement.classList.add('loaded'); // 添加渐显效果
} else if (mediaElement.tagName.toLowerCase() === 'video') {
mediaElement.src = mediaElement.dataset.src; // 加载视频
mediaElement.classList.add('loaded'); // 添加渐显效果
}
observer.unobserve(mediaElement); // 停止观察该元素
}
});
}, {
rootMargin: '0px 0px 200px 0px' // 提前200px加载防止延迟
});
// 开始观察所有的图片和视频
mediaElements.forEach(element => {
lazyLoadObserver.observe(element);
});
// 点击图片或视频,显示完整内容
const modal = document.getElementById('modal');
const modalImage = document.getElementById('modal-image');
const modalVideo = document.getElementById('modal-video');
const body = document.body;
function openModal(src, type) {
modal.classList.add('active');
body.classList.add('modal-open');
if (type === 'image') {
modalImage.src = src;
modalImage.style.display = 'block';
modalVideo.style.display = 'none';
} else if (type === 'video') {
modalVideo.src = src;
modalVideo.style.display = 'block';
modalImage.style.display = 'none';
}
}
// 点击空白区域关闭模态框
modal.addEventListener('click', () => {
modal.classList.remove('active');
body.classList.remove('modal-open');
modalImage.style.display = 'none';
modalVideo.style.display = 'none';
});
</script>
</body>
</html>

@ -0,0 +1,196 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Optimized Media Gallery</title>
<style>
html, body {
margin: 0;
padding: 0;
overflow-x: hidden;
font-family: Arial, sans-serif;
touch-action: manipulation;
}
body.modal-open {
overflow: hidden;
position: fixed;
width: 100%;
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 10px;
width: 100%;
max-width: 100vw;
margin: 20px 0;
padding: 0 10px;
box-sizing: border-box;
}
.media {
position: relative;
overflow: hidden;
border-radius: 10px;
background-color: #f0f0f0;
aspect-ratio: 1 / 1;
}
.media img,
.media video {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 10px;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s, transform 0.3s;
}
.media img.loaded,
.media video.loaded {
opacity: 1;
}
.media img:hover,
.media video:hover {
transform: scale(1.05);
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.9);
justify-content: center;
align-items: center;
z-index: 1000;
flex-direction: column;
touch-action: none;
}
.modal.active {
display: flex;
}
.modal-content {
position: relative;
max-width: 100vw;
max-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
padding: 10px;
}
.modal-content img,
.modal-content video {
max-width: 100vw;
max-height: 100vh;
width: auto;
height: auto;
object-fit: contain;
border-radius: 10px;
display: block;
}
</style>
</head>
<body>
<div class="gallery">
<!-- 假设这是动态渲染的静态目录文件,支持懒加载 -->
{% for file in files %}
<div class="media">
{% if file.endswith(('.jpg', '.jpeg', '.png', '.gif', '.JPG', '.JPEG', '.PNG', '.GIF')) %}
<img data-src="/media/{{ file }}" alt="{{ file }}" onclick="openModal('{{ file }}', 'image')">
{% elif file.endswith(('.mp4', '.avi', '.mov', '.wmv', '.m4v', '.mpg')) %}
<video data-src="/media/{{ file }}" controls onclick="openModal('{{ file }}', 'video')">
Your browser does not support the video tag.
</video>
{% endif %}
</div>
{% endfor %}
</div>
<!-- 模态框 -->
<div id="modal" class="modal">
<div class="modal-content" id="modalContent"></div>
</div>
<script>
const mediaElements = document.querySelectorAll('.media img, .media video');
const lazyLoadObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target;
el.src = el.dataset.src;
el.classList.add('loaded');
observer.unobserve(el);
}
});
}, { rootMargin: '0px 0px 200px 0px' });
mediaElements.forEach(el => lazyLoadObserver.observe(el));
const modal = document.getElementById('modal');
const modalContent = document.getElementById('modalContent');
const body = document.body;
let files = [{% for file in files %}"{{ file }}",{% endfor %}];
let currentIndex = 0;
function openModal(file, type) {
currentIndex = files.indexOf(file);
showModal(file, type);
modal.classList.add('active');
body.classList.add('modal-open');
}
function showModal(file, type) {
modalContent.innerHTML = '';
const media = document.createElement(type === 'image' ? 'img' : 'video');
media.src = `/media/${file}`;
if (type === 'video') {
media.controls = true;
}
modalContent.appendChild(media);
}
modal.addEventListener('click', (e) => {
if (!modalContent.contains(e.target)) {
modal.classList.remove('active');
body.classList.remove('modal-open');
modalContent.innerHTML = '';
}
});
// 滑动切换(仅图片)
let startY = 0;
modal.addEventListener('touchstart', e => {
startY = e.touches[0].clientY;
});
modal.addEventListener('touchend', e => {
const endY = e.changedTouches[0].clientY;
const deltaY = endY - startY;
if (Math.abs(deltaY) > 50) {
if (deltaY < 0) {
currentIndex = (currentIndex + 1) % files.length;
} else {
currentIndex = (currentIndex - 1 + files.length) % files.length;
}
const nextFile = files[currentIndex];
const ext = nextFile.split('.').pop().toLowerCase();
const isImage = ['jpg', 'jpeg', 'png', 'gif'].includes(ext);
showModal(nextFile, isImage ? 'image' : 'video');
}
});
</script>
</body>
</html>

@ -0,0 +1,39 @@
from flask import Flask, send_from_directory, render_template, jsonify
import os
app = Flask(__name__)
# 静态文件主目录
#loc
#STATIC_DIR = "/Users/zgz/Documents/images/share/bak"
#server
STATIC_DIR = "/mnt/ttings"
# 支持的文件类型
IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".JPG", ".JPEG", ".PNG", ".GIF"}
VIDEO_EXTENSIONS = {".mp4", ".avi", ".mov", ".wmv", ".m4v", ".mpg"}
# 递归获取目录中的所有文件
def get_files(directory):
files = []
for root, _, filenames in os.walk(directory):
for filename in filenames:
ext = os.path.splitext(filename)[1].lower()
if ext in IMAGE_EXTENSIONS or ext in VIDEO_EXTENSIONS:
relative_path = os.path.relpath(os.path.join(root, filename), STATIC_DIR)
files.append(relative_path)
return files
@app.route('/')
def index():
files = get_files(STATIC_DIR)
return render_template('index.html', files=files)
@app.route('/media/<path:filename>')
def media(filename):
# 返回静态文件(支持子目录)
return send_from_directory(STATIC_DIR, filename)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8177)

@ -0,0 +1,30 @@
[uwsgi]
uid = uwsgi
gid = uwsgi
# 启动服务监听的地址和端口
http-socket = 0.0.0.0:8177
# 指定虚拟环境路径
virtualenv = /opt/service/python_prj/pictoHub.env
# 指定 Flask 应用文件的路径
wsgi-file = /opt/service/python_prj/ttingsHub/ttings.py
# 设置 Flask 的应用实例
callable = app
# 设置静态文件目录映射
static-map = /static=/opt/service/python_prj/ttingsHub/static/
# 日志文件
logto = /var/log/uwsgi/uwsgi.log
# 设置进程数
processes = 4
# 启动时的 Python 环境路径
home = /opt/service/python_prj/pictoHub.env
# 确保应用正常启动
touch-reload = /opt/service/python_prj/ttingsHub/ttings.py
Loading…
Cancel
Save