diff --git a/app/main.py b/app/main.py index dc22b4a..0130889 100644 --- a/app/main.py +++ b/app/main.py @@ -2,6 +2,7 @@ from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import HTMLResponse, RedirectResponse from fastapi.templating import Jinja2Templates +from fastapi.staticfiles import StaticFiles from app.core.logger import get_main_logger from app.core.security import verify_auth_token from app.services.key_manager import get_key_manager_instance @@ -19,6 +20,9 @@ app = FastAPI() # 配置Jinja2模板 templates = Jinja2Templates(directory="app/templates") +# 配置静态文件 +app.mount("/static", StaticFiles(directory="app/static"), name="static") + # 创建 KeyManager 实例 key_manager = None diff --git a/app/static/icons/icon-192x192.png b/app/static/icons/icon-192x192.png new file mode 100644 index 0000000..a3bc465 Binary files /dev/null and b/app/static/icons/icon-192x192.png differ diff --git a/app/static/manifest.json b/app/static/manifest.json new file mode 100644 index 0000000..f5ad44f --- /dev/null +++ b/app/static/manifest.json @@ -0,0 +1,17 @@ +{ + "name": "Gemini Balance", + "short_name": "GBalance", + "description": "Gemini API密钥管理工具", + "start_url": "/", + "display": "standalone", + "background_color": "#667eea", + "theme_color": "#764ba2", + "icons": [ + { + "src": "/static/icons/icon-192x192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "any maskable" + } + ] +} diff --git a/app/static/service-worker.js b/app/static/service-worker.js new file mode 100644 index 0000000..937b4cd --- /dev/null +++ b/app/static/service-worker.js @@ -0,0 +1,43 @@ +const CACHE_NAME = 'gbalance-cache-v1'; +const urlsToCache = [ + '/', + '/static/manifest.json', + '/static/icons/icon-192x192.png' +]; + +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( + caches.match(event.request) + .then(response => { + if (response) { + return response; + } + return fetch(event.request); + }) + ); +}); + +self.addEventListener('activate', event => { + const cacheWhitelist = [CACHE_NAME]; + event.waitUntil( + caches.keys().then(cacheNames => { + return Promise.all( + cacheNames.map(cacheName => { + if (cacheWhitelist.indexOf(cacheName) === -1) { + return caches.delete(cacheName); + } + }) + ); + }) + ); +}); diff --git a/app/templates/auth.html b/app/templates/auth.html index b24681b..2949222 100644 --- a/app/templates/auth.html +++ b/app/templates/auth.html @@ -4,6 +4,12 @@