soiz1 commited on
Commit
14d78d0
·
verified ·
1 Parent(s): 260a17e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -7,6 +7,7 @@ import os
7
  import shutil
8
  import stat
9
  import logging
 
10
 
11
  # ロギング設定をDEBUGに
12
  logging.basicConfig(level=logging.DEBUG, format="%(asctime)s [%(levelname)s] %(message)s")
@@ -17,29 +18,35 @@ REPO_DIR = "SharkPools-Extensions"
17
  TARGET_FILE = os.path.join(REPO_DIR, "pages", "startup.js")
18
 
19
  # Flask アプリケーション設定
20
- app = Flask(__name__,
21
- template_folder="templates",
22
- static_folder="static",
23
- static_url_path="")
 
 
 
24
 
25
  # FlaskのロガーもDEBUGに
26
  app.logger.setLevel(logging.DEBUG)
27
 
 
28
  @app.route("/")
29
  def index():
30
  return render_template("index.html")
31
 
 
32
  @app.route("/<path:filepath>")
33
  def serve_any(filepath):
34
  app.logger.debug(f"📥 リクエストされたパス: {filepath!r}")
35
 
36
  # 1) static フォルダ
37
- static_path = os.path.join(app.static_folder, filepath)
38
  exists_static = os.path.isfile(static_path)
39
  app.logger.debug(f"→ static をチェック: {static_path!r} 存在? {exists_static}")
40
  if exists_static:
41
  app.logger.info(f"✅ static から返却: {filepath}")
42
- return send_from_directory(app.static_folder, filepath)
 
43
 
44
  # 2) リポジトリ直下
45
  full_path = os.path.join(REPO_DIR, filepath)
@@ -59,9 +66,10 @@ def remove_readonly(func, path, excinfo):
59
  os.chmod(path, stat.S_IWRITE)
60
  func(path)
61
 
 
62
  def clone_or_update_repo():
63
  logging.info("リポジトリの更新を開始します。")
64
-
65
  if not os.path.exists(REPO_DIR):
66
  logging.info("リポジトリをクローン中...")
67
  subprocess.run(["git", "clone", REPO_URL])
@@ -110,7 +118,6 @@ def clone_or_update_repo():
110
  with open(index_path, "r", encoding="utf-8") as f:
111
  html = f.read()
112
 
113
- import re
114
  # <base href="https://sharkpools-extensions.vercel.app/"> を削除
115
  new_html = re.sub(r'<base\s+href="https://sharkpools-extensions\.vercel\.app/"\s*/?>', '', html, flags=re.IGNORECASE)
116
 
@@ -123,7 +130,8 @@ def clone_or_update_repo():
123
 
124
  logging.info("リポジトリの更新が完了しました。")
125
 
126
- # スケジューラを実行する関数(1分ごと)
 
127
  def run_scheduler():
128
  schedule.every(60).minutes.do(clone_or_update_repo)
129
  try:
@@ -133,6 +141,7 @@ def run_scheduler():
133
  except Exception as e:
134
  logging.error(f"スケジューラでエラーが発生しました: {e}")
135
 
 
136
  # 初回実行およびスケジューラ起動
137
  clone_or_update_repo()
138
  scheduler_thread = threading.Thread(target=run_scheduler, daemon=True)
 
7
  import shutil
8
  import stat
9
  import logging
10
+ import re
11
 
12
  # ロギング設定をDEBUGに
13
  logging.basicConfig(level=logging.DEBUG, format="%(asctime)s [%(levelname)s] %(message)s")
 
18
  TARGET_FILE = os.path.join(REPO_DIR, "pages", "startup.js")
19
 
20
  # Flask アプリケーション設定
21
+ # static_folder=None にして組み込みの静的配信はOFFにする
22
+ app = Flask(
23
+ __name__,
24
+ template_folder="templates",
25
+ static_folder=None,
26
+ static_url_path=None
27
+ )
28
 
29
  # FlaskのロガーもDEBUGに
30
  app.logger.setLevel(logging.DEBUG)
31
 
32
+
33
  @app.route("/")
34
  def index():
35
  return render_template("index.html")
36
 
37
+
38
  @app.route("/<path:filepath>")
39
  def serve_any(filepath):
40
  app.logger.debug(f"📥 リクエストされたパス: {filepath!r}")
41
 
42
  # 1) static フォルダ
43
+ static_path = os.path.join("static", filepath) # app.static_folder は None なので手動で指定
44
  exists_static = os.path.isfile(static_path)
45
  app.logger.debug(f"→ static をチェック: {static_path!r} 存在? {exists_static}")
46
  if exists_static:
47
  app.logger.info(f"✅ static から返却: {filepath}")
48
+ directory, filename = os.path.split(static_path)
49
+ return send_from_directory(directory, filename)
50
 
51
  # 2) リポジトリ直下
52
  full_path = os.path.join(REPO_DIR, filepath)
 
66
  os.chmod(path, stat.S_IWRITE)
67
  func(path)
68
 
69
+
70
  def clone_or_update_repo():
71
  logging.info("リポジトリの更新を開始します。")
72
+
73
  if not os.path.exists(REPO_DIR):
74
  logging.info("リポジトリをクローン中...")
75
  subprocess.run(["git", "clone", REPO_URL])
 
118
  with open(index_path, "r", encoding="utf-8") as f:
119
  html = f.read()
120
 
 
121
  # <base href="https://sharkpools-extensions.vercel.app/"> を削除
122
  new_html = re.sub(r'<base\s+href="https://sharkpools-extensions\.vercel\.app/"\s*/?>', '', html, flags=re.IGNORECASE)
123
 
 
130
 
131
  logging.info("リポジトリの更新が完了しました。")
132
 
133
+
134
+ # スケジューラを実行する関数(60分ごと)
135
  def run_scheduler():
136
  schedule.every(60).minutes.do(clone_or_update_repo)
137
  try:
 
141
  except Exception as e:
142
  logging.error(f"スケジューラでエラーが発生しました: {e}")
143
 
144
+
145
  # 初回実行およびスケジューラ起動
146
  clone_or_update_repo()
147
  scheduler_thread = threading.Thread(target=run_scheduler, daemon=True)