Kanji
・クラウドエンジニア / フリーランス ・1993年生まれ ・愛媛県出身 / 東京都渋谷区在住 ・AWS歴5年 プロフィールの詳細
目次
・「${URL}」のファイルをどのように変更すれば良いか教えてください。 ・変更する内容はPythonのGitPatchで読み込めるようにしてください。 ・細かい解説は不要です。GitPatch形式の変更内容のみ返してください。 ・変更内容は以下のとおりです。 コメントをすべて削除してください
Default (GPT-3.5)
1. Google 検索エンジンに登録されているサイトの URL(.github.com ドメイン) 2. Google 検索エンジンに登録されているサイトの URL(GIP) 3. Google Cloud の Compute Engine で作成した Apache サイトの URL(.cont-aid.com ドメイン) 4. Google Cloud の Compute Engine で作成した Apache サイトの URL(GIP) 5. Google Cloud の Cloud Functions で 生成したサイトの URL(.cloudfunctions.net ドメイン) 6. Google Cloud の Cloud Functions で 生成したサイトの URL(.cont-aid.com ドメイン) 7. 公開されたクラウドストレージ(.google.com ドメイン)
Terraform.gitignore
import os from flask import Flask, render_template, request from google.cloud import storage app = Flask(__name__) @app.route("/") def show_file(request): client = storage.Client() bucket_name = os.environ["BUCKET_NAME"] bucket = client.bucket(bucket_name) filename = request.args.get('filename', '') blob = bucket.blob(filename) content = blob.download_as_string().decode('utf-8') lines = content.split('\n') line_count = len(lines) return render_template('index.html', filename=filename, content=content, line_count=line_count) if __name__ == "__main__": app.run(debug=True, host='0.0.0.0', port=80)
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Google Cloud Storageファイル一覧</title> <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> </head> <body> <div class="sidebar"> <ul> {% for folder in folders %} <li>{{ folder }}</li> {% endfor %} </ul> </div> <div class="main"> <h1>Google Cloud Storageファイル一覧</h1> <table class="table"> <thead> <tr> <th>ファイル名</th> <th>更新日時</th> <th>サイズ</th> </tr> </thead> <tbody> {% for file in files %} <tr> <td><a href="https://us-central1-gcos-202303.cloudfunctions.net/show_file?filename={{ file }}">{{ file }}</a></td> <td>{{ file.updated }}</td> <td>{{ file.size }}</td> </tr> {% endfor %} </tbody> </table> </div> </body> </html>
import os import logging from flask import Flask, render_template, request from google.cloud import storage app = Flask(__name__) # ロギングの設定 logging.basicConfig(level=logging.DEBUG) @app.route("/") def list_files(request): logging.debug('list_files 関数が呼ばれました') client = storage.Client() bucket_name = os.environ["BUCKET_NAME"] bucket = client.bucket(bucket_name) files = [] for blob in bucket.list_blobs(prefix="source_codes/"): if not blob.name.endswith('/'): files.append(blob.name) logging.debug(f'files: {files}') folders = set([file.split['/'](0) for file in files]) logging.debug(f'folders: {folders}') return render_template('index.html', files=files, folders=folders) if __name__ == "__main__": app.run(debug=True, host='0.0.0.0', port=80)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>{{ filename }} - Google Cloud Storageファイル表示</title> <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> </head> <body> <div class="sidebar"> <ul> {% for folder in folders %} <li>{{ folder }}</li> {% endfor %} </ul> </div> <div class="main"> <h1>{{ filename }}</h1> <pre class="pre">{{ content }}</pre> <p>行数: {{ line_count }}</p> </div> </body> </html>
.gitignore
modernizer