From a84c1c694df0a9e11914c47eaf83989e034cc4db Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Mon, 19 Aug 2024 17:31:34 +0800 Subject: chore: update content --- .github/workflows/Build_Web_App.yml | 91 ++++++++++++++++++++++++++ api/.gitkeep | 0 api/index.py | 127 ------------------------------------ files/cmp/ffmpeg-6.0-full_build.7z | Bin 0 -> 49047457 bytes files/image/face_id.jpg | Bin 0 -> 118131 bytes index.py | 127 ++++++++++++++++++++++++++++++++++++ 6 files changed, 218 insertions(+), 127 deletions(-) create mode 100644 .github/workflows/Build_Web_App.yml create mode 100644 api/.gitkeep delete mode 100644 api/index.py create mode 100644 files/cmp/ffmpeg-6.0-full_build.7z create mode 100644 files/image/face_id.jpg create mode 100644 index.py diff --git a/.github/workflows/Build_Web_App.yml b/.github/workflows/Build_Web_App.yml new file mode 100644 index 0000000..f0359a2 --- /dev/null +++ b/.github/workflows/Build_Web_App.yml @@ -0,0 +1,91 @@ +name: Web Build + Deployment to GitHub Pages + +on: + # Runs on push to any of the below branches + push: + branches: + - master + - main + # Runs on pull request events that target one of the below branches + pull_request: + branches: + - master + - main + + # Allows you to run this workflow manually from the Actions tab of the repository + workflow_dispatch: + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +env: + # https://flet.dev/docs/publish#versioning + BUILD_NUMBER: 1 + BUILD_VERSION: 1.0.0 + PYTHON_VERSION: 3.12.2 + FLUTTER_VERSION: 3.22.2 + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Python ${{ env.PYTHON_VERSION }} + uses: actions/setup-python@v2 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Install Python Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Setup Flutter ${{ env.FLUTTER_VERSION }} + uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ env.FLUTTER_VERSION }} + + - name: Flet Build Web + run: | + echo "GITHUB_REPOSITORY: ${GITHUB_REPOSITORY}, USER: ${GITHUB_REPOSITORY%/*}, PROJECT_BASE_URL: ${GITHUB_REPOSITORY#*/}" + flutter config --no-analytics + flet build web --base-url ${GITHUB_REPOSITORY#*/} --route-url-strategy hash + + - name: Upload Artifact + uses: actions/upload-pages-artifact@v3 + with: + name: web-build-artifact # the name of the artifact + path: build/web + + deploy: + needs: build # wait for the "build" job to get done before executing this "deploy" job + + runs-on: ubuntu-latest + + # Grant GITHUB_TOKEN the permissions required to make a Pages deployment + permissions: + pages: write # to deploy to Pages + id-token: write # to verify the deployment originates from an appropriate source + + # Deploy to the github-pages environment + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Deploy to GitHub Pages 🚀 + if: github.event_name == 'push' # deploy only on push + id: deployment + uses: actions/deploy-pages@v4.0.5 + with: + artifact_name: web-build-artifact + \ No newline at end of file diff --git a/api/.gitkeep b/api/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/api/index.py b/api/index.py deleted file mode 100644 index 2a289cc..0000000 --- a/api/index.py +++ /dev/null @@ -1,127 +0,0 @@ -from flask import Flask, render_template, request, redirect, send_file, url_for, send_from_directory, session, flash -from werkzeug.utils import secure_filename -import os -import zipfile -import io -import urllib.parse - - -app = Flask(__name__) -app.secret_key = 'supersecretkey' -app.config['UPLOAD_FOLDER'] = 'files' -app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB - -ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'zip'} - -def allowed_file(filename): - return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS - -@app.route('/') -def index(): - if 'username' in session: - return redirect(url_for('upload_file')) - return redirect(url_for('login')) - -@app.route('/login', methods=['GET', 'POST']) -def login(): - if request.method == 'POST': - username = request.form['username'] - password = request.form['password'] - # įŽ€å•įš„į”¨æˆˇåå’Œå¯†į énj蝁 - if username == 'admin' and password == 'password': - session['username'] = username - return redirect(url_for('upload_file')) - else: - flash('Invalid credentials') - return render_template('templates/login.html') - -@app.route('/logout') -def logout(): - session.pop('username', None) - return redirect(url_for('login')) - -@app.route('/upload', methods=['GET', 'POST']) -def upload_file(): - if 'username' not in session: - return redirect(url_for('login')) - if request.method == 'POST': - if 'file' not in request.files: - flash('No file part') - return redirect(request.url) - file = request.files['file'] - if file.filename == '': - flash('No selected file') - return redirect(request.url) - if file and allowed_file(file.filename): - filename = secure_filename(file.filename) - file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) - flash('File successfully uploaded') - return redirect(url_for('uploaded_files')) - return render_template('templates/upload.html') - -@app.route('/files') -def uploaded_files(): - if 'username' not in session: - return redirect(url_for('login')) - files = os.listdir(app.config['UPLOAD_FOLDER']) - return render_template('templates/files.html', files=files) - -@app.route('/files/') -def file_info(filename): - if 'username' not in session: - return redirect(url_for('login')) - file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) - if os.path.exists(file_path): - file_ext = filename.rsplit('.', 1)[1].lower() - if file_ext in {'png', 'jpg', 'jpeg', 'gif'}: - file_type = 'image' - elif file_ext in {'txt', 'pdf'}: - file_type = 'text' - elif file_ext == 'zip': - file_type = 'zip' - with zipfile.ZipFile(file_path, 'r') as zip_ref: - zip_contents = zip_ref.namelist() - return render_template('templates/file_info.html', filename=filename, file_type=file_type, zip_contents=zip_contents) - else: - file_type = 'other' - return render_template('templates/file_info.html', filename=filename, file_type=file_type) - else: - flash('File not found') - return redirect(url_for('uploaded_files')) - -@app.route('/files//') -def view_inner_file(zip_filename, inner_filename): - if 'username' not in session: - return redirect(url_for('login')) - zip_path = os.path.join(app.config['UPLOAD_FOLDER'], zip_filename) - if os.path.exists(zip_path): - with zipfile.ZipFile(zip_path, 'r') as zip_ref: - if inner_filename in zip_ref.namelist(): - file_ext = inner_filename.rsplit('.', 1)[1].lower() - if file_ext in {'png', 'jpg', 'jpeg', 'gif'}: - file_type = 'image' - file_data = zip_ref.read(inner_filename) - return send_file(io.BytesIO(file_data), mimetype=f'image/{file_ext}') - elif file_ext in {'txt', 'pdf'}: - file_type = 'text' - file_data = zip_ref.read(inner_filename) - return send_file(io.BytesIO(file_data), mimetype=f'application/{file_ext}') - else: - flash('Unsupported file type inside zip') - return redirect(url_for('file_info', filename=zip_filename)) - else: - flash('File not found inside zip') - return redirect(url_for('file_info', filename=zip_filename)) - else: - flash('Zip file not found') - return redirect(url_for('uploaded_files')) - - -@app.route('/download/') -def download_file(filename): - if 'username' not in session: - return redirect(url_for('login')) - return send_from_directory(app.config['UPLOAD_FOLDER'], filename) - -if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file diff --git a/files/cmp/ffmpeg-6.0-full_build.7z b/files/cmp/ffmpeg-6.0-full_build.7z new file mode 100644 index 0000000..9f2de0b Binary files /dev/null and b/files/cmp/ffmpeg-6.0-full_build.7z differ diff --git a/files/image/face_id.jpg b/files/image/face_id.jpg new file mode 100644 index 0000000..4cf4b6d Binary files /dev/null and b/files/image/face_id.jpg differ diff --git a/index.py b/index.py new file mode 100644 index 0000000..2a289cc --- /dev/null +++ b/index.py @@ -0,0 +1,127 @@ +from flask import Flask, render_template, request, redirect, send_file, url_for, send_from_directory, session, flash +from werkzeug.utils import secure_filename +import os +import zipfile +import io +import urllib.parse + + +app = Flask(__name__) +app.secret_key = 'supersecretkey' +app.config['UPLOAD_FOLDER'] = 'files' +app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB + +ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'zip'} + +def allowed_file(filename): + return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS + +@app.route('/') +def index(): + if 'username' in session: + return redirect(url_for('upload_file')) + return redirect(url_for('login')) + +@app.route('/login', methods=['GET', 'POST']) +def login(): + if request.method == 'POST': + username = request.form['username'] + password = request.form['password'] + # įŽ€å•įš„į”¨æˆˇåå’Œå¯†į énj蝁 + if username == 'admin' and password == 'password': + session['username'] = username + return redirect(url_for('upload_file')) + else: + flash('Invalid credentials') + return render_template('templates/login.html') + +@app.route('/logout') +def logout(): + session.pop('username', None) + return redirect(url_for('login')) + +@app.route('/upload', methods=['GET', 'POST']) +def upload_file(): + if 'username' not in session: + return redirect(url_for('login')) + if request.method == 'POST': + if 'file' not in request.files: + flash('No file part') + return redirect(request.url) + file = request.files['file'] + if file.filename == '': + flash('No selected file') + return redirect(request.url) + if file and allowed_file(file.filename): + filename = secure_filename(file.filename) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) + flash('File successfully uploaded') + return redirect(url_for('uploaded_files')) + return render_template('templates/upload.html') + +@app.route('/files') +def uploaded_files(): + if 'username' not in session: + return redirect(url_for('login')) + files = os.listdir(app.config['UPLOAD_FOLDER']) + return render_template('templates/files.html', files=files) + +@app.route('/files/') +def file_info(filename): + if 'username' not in session: + return redirect(url_for('login')) + file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) + if os.path.exists(file_path): + file_ext = filename.rsplit('.', 1)[1].lower() + if file_ext in {'png', 'jpg', 'jpeg', 'gif'}: + file_type = 'image' + elif file_ext in {'txt', 'pdf'}: + file_type = 'text' + elif file_ext == 'zip': + file_type = 'zip' + with zipfile.ZipFile(file_path, 'r') as zip_ref: + zip_contents = zip_ref.namelist() + return render_template('templates/file_info.html', filename=filename, file_type=file_type, zip_contents=zip_contents) + else: + file_type = 'other' + return render_template('templates/file_info.html', filename=filename, file_type=file_type) + else: + flash('File not found') + return redirect(url_for('uploaded_files')) + +@app.route('/files//') +def view_inner_file(zip_filename, inner_filename): + if 'username' not in session: + return redirect(url_for('login')) + zip_path = os.path.join(app.config['UPLOAD_FOLDER'], zip_filename) + if os.path.exists(zip_path): + with zipfile.ZipFile(zip_path, 'r') as zip_ref: + if inner_filename in zip_ref.namelist(): + file_ext = inner_filename.rsplit('.', 1)[1].lower() + if file_ext in {'png', 'jpg', 'jpeg', 'gif'}: + file_type = 'image' + file_data = zip_ref.read(inner_filename) + return send_file(io.BytesIO(file_data), mimetype=f'image/{file_ext}') + elif file_ext in {'txt', 'pdf'}: + file_type = 'text' + file_data = zip_ref.read(inner_filename) + return send_file(io.BytesIO(file_data), mimetype=f'application/{file_ext}') + else: + flash('Unsupported file type inside zip') + return redirect(url_for('file_info', filename=zip_filename)) + else: + flash('File not found inside zip') + return redirect(url_for('file_info', filename=zip_filename)) + else: + flash('Zip file not found') + return redirect(url_for('uploaded_files')) + + +@app.route('/download/') +def download_file(filename): + if 'username' not in session: + return redirect(url_for('login')) + return send_from_directory(app.config['UPLOAD_FOLDER'], filename) + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file -- cgit v1.2.3-70-g09d2