commit
5a975aee8a
@ -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/sese"
|
||||
|
||||
# 支持的文件类型
|
||||
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=8099)
|
||||
@ -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>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%;
|
||||
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,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,30 @@
|
||||
[uwsgi]
|
||||
uid = uwsgi
|
||||
gid = uwsgi
|
||||
|
||||
# 启动服务监听的地址和端口
|
||||
http-socket = 0.0.0.0:8099
|
||||
|
||||
# 指定虚拟环境路径
|
||||
virtualenv = /opt/service/python_prj/pictoHub.env
|
||||
|
||||
# 指定 Flask 应用文件的路径
|
||||
wsgi-file = /opt/service/python_prj/sesetoHub/sese.py
|
||||
|
||||
# 设置 Flask 的应用实例
|
||||
callable = app
|
||||
|
||||
# 设置静态文件目录映射
|
||||
static-map = /static=/opt/service/python_prj/sesetoHub/static/
|
||||
|
||||
# 日志文件
|
||||
logto = /var/log/uwsgi/uwsgi.log
|
||||
|
||||
# 设置进程数
|
||||
processes = 4
|
||||
|
||||
# 启动时的 Python 环境路径
|
||||
home = /opt/service/python_prj/pictoHub.env
|
||||
|
||||
# 确保应用正常启动
|
||||
touch-reload = /opt/service/python_prj/sesetoHub/sese.py
|
||||
Loading…
Reference in new issue