soiz1 commited on
Commit
354cd44
·
verified ·
1 Parent(s): 43f08bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -86,18 +86,23 @@ def close():
86
  window.close();
87
  </script>"""
88
 
 
89
  @app.route('/close2', methods=['GET', 'POST'])
90
  def close2():
91
- return """<script>if (window.opener) {
 
 
92
  const hashParams = new URLSearchParams(window.location.hash.substring(1));
93
  const token = hashParams.get("access_token");
94
- if (token) {
95
- window.opener.postMessage({ token }, "https://soiz1-penguinmod-editor-2.hf.space");
96
  window.close();
97
- }
98
- }
99
  window.close();
100
  </script>"""
101
 
 
 
102
  if __name__ == '__main__':
103
  app.run(host='0.0.0.0', port=7860)
 
86
  window.close();
87
  </script>"""
88
 
89
+
90
  @app.route('/close2', methods=['GET', 'POST'])
91
  def close2():
92
+ target_origin = request.args.get('target_origin', '*') # デフォルトはワイルドカード
93
+ return f"""<script>
94
+ if (window.opener) {{
95
  const hashParams = new URLSearchParams(window.location.hash.substring(1));
96
  const token = hashParams.get("access_token");
97
+ if (token) {{
98
+ window.opener.postMessage({{ token }}, "{target_origin}");
99
  window.close();
100
+ }}
101
+ }}
102
  window.close();
103
  </script>"""
104
 
105
+
106
+
107
  if __name__ == '__main__':
108
  app.run(host='0.0.0.0', port=7860)