Добавление PWA
This commit is contained in:
parent
acf9360ad7
commit
03fa1ffe34
39
install.sh
39
install.sh
|
|
@ -1,8 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Определяем директорию, в которой находится скрипт
|
|
||||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
|
||||||
|
|
||||||
# === НАСТРОЙКИ РЕПОЗИТОРИЯ ===
|
# === НАСТРОЙКИ РЕПОЗИТОРИЯ ===
|
||||||
# Укажи здесь имя ветки (master или main)
|
# Укажи здесь имя ветки (master или main)
|
||||||
BRANCH="master"
|
BRANCH="master"
|
||||||
|
|
@ -39,40 +36,8 @@ mkdir -p "$INIT_DIR"
|
||||||
mkdir -p "/opt/etc/mihomo/profiles"
|
mkdir -p "/opt/etc/mihomo/profiles"
|
||||||
mkdir -p "/opt/etc/mihomo/backup"
|
mkdir -p "/opt/etc/mihomo/backup"
|
||||||
|
|
||||||
# Создаем директорию для PWA
|
# 3. Скачивание файлов
|
||||||
mkdir -p "/opt/etc/mihomo/public/icons"
|
echo "[3/4] Скачивание файлов с сервера..."
|
||||||
|
|
||||||
# 3. Скачивание и копирование файлов
|
|
||||||
echo "[3/4] Скачивание и копирование файлов..."
|
|
||||||
|
|
||||||
# Загружаем PWA файлы
|
|
||||||
echo "Загрузка PWA файлов..."
|
|
||||||
|
|
||||||
# Директории на роутере для PWA
|
|
||||||
PWA_DIR="/opt/etc/mihomo/public"
|
|
||||||
ICONS_DIR="$PWA_DIR/icons"
|
|
||||||
|
|
||||||
# Убедимся, что директории существуют
|
|
||||||
mkdir -p "$ICONS_DIR"
|
|
||||||
|
|
||||||
# URL-ы для сырых файлов PWA
|
|
||||||
MANIFEST_URL="$BASE_URL/public/manifest.json"
|
|
||||||
ICON192_URL="$BASE_URL/public/icons/icon-192x192.png"
|
|
||||||
ICON512_URL="$BASE_URL/public/icons/icon-512x512.png"
|
|
||||||
|
|
||||||
# Загрузка файлов
|
|
||||||
echo "Загрузка manifest.json..."
|
|
||||||
wget --no-check-certificate -O "$PWA_DIR/manifest.json" "$MANIFEST_URL"
|
|
||||||
|
|
||||||
echo "Загрузка icon-192x192.png..."
|
|
||||||
wget --no-check-certificate -O "$ICONS_DIR/icon-192x192.png" "$ICON192_URL"
|
|
||||||
|
|
||||||
echo "Загрузка icon-512x512.png..."
|
|
||||||
wget --no-check-certificate -O "$ICONS_DIR/icon-512x512.png" "$ICON512_URL"
|
|
||||||
|
|
||||||
# Загружаем service-worker.js
|
|
||||||
echo "Загрузка service-worker.js..."
|
|
||||||
wget -O "$PWA_DIR/service-worker.js" "$BASE_URL/public/service-worker.js"
|
|
||||||
|
|
||||||
# Скачиваем основной скрипт
|
# Скачиваем основной скрипт
|
||||||
echo "Загрузка $PY_SCRIPT..."
|
echo "Загрузка $PY_SCRIPT..."
|
||||||
|
|
|
||||||
|
|
@ -164,8 +164,6 @@ HTML_TEMPLATE = """<!DOCTYPE html>
|
||||||
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
||||||
<title>Mihomo Editor v18.4</title>
|
<title>Mihomo Editor v18.4</title>
|
||||||
<link rel="manifest" href="/manifest.json">
|
|
||||||
<link rel="apple-touch-icon" href="/icons/icon-192x192.png">
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.7/ace.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.7/ace.js"></script>
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
|
|
@ -677,15 +675,6 @@ function doRename() {
|
||||||
})
|
})
|
||||||
.catch(e => alert("Сетевая ошибка: " + e));
|
.catch(e => alert("Сетевая ошибка: " + e));
|
||||||
}
|
}
|
||||||
if ('serviceWorker' in navigator) {
|
|
||||||
window.addEventListener('load', () => {
|
|
||||||
navigator.serviceWorker.register('/service-worker.js').then(registration => {
|
|
||||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
|
||||||
}, err => {
|
|
||||||
console.log('ServiceWorker registration failed: ', err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script></body></html>"""
|
</script></body></html>"""
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -788,41 +777,6 @@ class H(http.server.SimpleHTTPRequestHandler):
|
||||||
pass # Silent fail to avoid crashing
|
pass # Silent fail to avoid crashing
|
||||||
|
|
||||||
def do_GET(s):
|
def do_GET(s):
|
||||||
if s.path == '/service-worker.js':
|
|
||||||
try:
|
|
||||||
with open('public/service-worker.js', 'rb') as f:
|
|
||||||
s.send_response(200)
|
|
||||||
s.send_header('Content-type', 'application/javascript')
|
|
||||||
s.end_headers()
|
|
||||||
s.wfile.write(f.read())
|
|
||||||
except FileNotFoundError:
|
|
||||||
s.send_error(404, "File not found")
|
|
||||||
return
|
|
||||||
|
|
||||||
if s.path == '/manifest.json':
|
|
||||||
try:
|
|
||||||
with open('public/manifest.json', 'rb') as f:
|
|
||||||
s.send_response(200)
|
|
||||||
s.send_header('Content-type', 'application/json')
|
|
||||||
s.end_headers()
|
|
||||||
s.wfile.write(f.read())
|
|
||||||
except FileNotFoundError:
|
|
||||||
s.send_error(404, "File not found")
|
|
||||||
return
|
|
||||||
|
|
||||||
if s.path.startswith('/icons/'):
|
|
||||||
try:
|
|
||||||
# Sanitize path to prevent directory traversal
|
|
||||||
safe_path = os.path.join('public', s.path[1:]).replace('\\\\', '/')
|
|
||||||
with open(safe_path, 'rb') as f:
|
|
||||||
s.send_response(200)
|
|
||||||
s.send_header('Content-type', 'image/png')
|
|
||||||
s.end_headers()
|
|
||||||
s.wfile.write(f.read())
|
|
||||||
except FileNotFoundError:
|
|
||||||
s.send_error(404, "File not found")
|
|
||||||
return
|
|
||||||
|
|
||||||
if s.path.startswith('/mihomo_panel/'):
|
if s.path.startswith('/mihomo_panel/'):
|
||||||
s.proxy_pass('GET')
|
s.proxy_pass('GET')
|
||||||
return
|
return
|
||||||
|
|
@ -1027,7 +981,7 @@ class H(http.server.SimpleHTTPRequestHandler):
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
socketserver.TCPServer.allow_reuse_address = True
|
socketserver.TCPServer.allow_reuse_address = True;
|
||||||
socketserver.TCPServer(("", PORT), H).serve_forever()
|
socketserver.TCPServer(("", PORT), H).serve_forever()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
{
|
|
||||||
"name": "Mihomo Studio",
|
|
||||||
"short_name": "Mihomo",
|
|
||||||
"start_url": "/",
|
|
||||||
"display": "standalone",
|
|
||||||
"background_color": "#1a1a1a",
|
|
||||||
"theme_color": "#1a1a1a",
|
|
||||||
"description": "Mihomo Config Editor",
|
|
||||||
"icons": [
|
|
||||||
{
|
|
||||||
"src": "/icons/icon-192x192.png",
|
|
||||||
"sizes": "192x192",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/icons/icon-512x512.png",
|
|
||||||
"sizes": "512x512",
|
|
||||||
"type": "image/png"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
// Список ресурсов для кэширования
|
|
||||||
const CACHE_NAME = 'mihomo-studio-cache-v1';
|
|
||||||
const urlsToCache = [
|
|
||||||
'/',
|
|
||||||
'/manifest.json',
|
|
||||||
'/icons/icon-192x192.png',
|
|
||||||
'/icons/icon-512x512.png'
|
|
||||||
];
|
|
||||||
|
|
||||||
// Установка Service Worker и кэширование ресурсов
|
|
||||||
self.addEventListener('install', event => {
|
|
||||||
event.waitUntil(
|
|
||||||
caches.open(CACHE_NAME)
|
|
||||||
.then(cache => {
|
|
||||||
console.log('Opened cache');
|
|
||||||
return cache.addAll(urlsToCache);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Обработка запросов: сначала из сети, потом из кэша
|
|
||||||
self.addEventListener('fetch', event => {
|
|
||||||
event.respondWith(
|
|
||||||
fetch(event.request).catch(() => {
|
|
||||||
return caches.match(event.request);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
Loading…
Reference in New Issue