From b799bb53396ae602662a261158b8c500a0c0a7da Mon Sep 17 00:00:00 2001 From: n4n5 Date: Thu, 7 Dec 2023 21:07:47 +0100 Subject: [PATCH 1/3] add --- .github/workflows/static.yml | 44 ++++++++++++++++++++++++++++++++++++ download/build.py | 44 ++++++++++++++++++++++++++++++++++++ download/index.html | 36 +++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 .github/workflows/static.yml create mode 100644 download/build.py create mode 100644 download/index.html diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..95a588e --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,44 @@ +# Simple workflow for deploying static content to GitHub Pages +name: Deploy static content to Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# 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 + +jobs: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v4 + - name: render index.html + run: python3 download/build.py + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: "." + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v3 diff --git a/download/build.py b/download/build.py new file mode 100644 index 0000000..1761a3a --- /dev/null +++ b/download/build.py @@ -0,0 +1,44 @@ +from string import Template +import os +from os.path import getmtime, getsize +from datetime import datetime + + +def size(size_in_bytes): + """convert""" + size_kb = size_in_bytes / 1024.0 + size_mb = size_kb / 1024.0 + + if size_mb >= 1: + return f"{size_mb:.2f}M" + elif size_kb >= 1: + return f"{size_kb:.2f}K" + return size_in_bytes + + +PATH_TO_FILE = "index.html" +FOLDER = "download/" + +t = Template( + """ + [   ] + $file + $date + $size +   + """ +) +listed = os.listdir(FOLDER) +s = "" +for name in listed: + p = FOLDER + name + if name.endswith(".gz"): + date = datetime.fromtimestamp(getmtime(p)).strftime("%Y-%m-%d %H:%M:%S") + s += t.substitute(file=p, date=date, size=size(getsize(p))) +with open(FOLDER + PATH_TO_FILE, "r", encoding="utf-8") as file: + file_data = file.read() + file_data = file_data.replace("", s) + +with open(FOLDER + PATH_TO_FILE, "w", encoding="utf-8") as file: + file.write(file_data) +os.remove(FOLDER + "build.py") diff --git a/download/index.html b/download/index.html new file mode 100644 index 0000000..8384f91 --- /dev/null +++ b/download/index.html @@ -0,0 +1,36 @@ + + + + Index of /download + + +

Index of /download

+ + + + + + + + + + + + + + + + + + + + + + +
+ [ICO] + NameLast modifiedSizeDescription

+ [PARENTDIR] + Parent Directory - 

+ + From d7072cd58b43edad6983205b70b52ca2259c6901 Mon Sep 17 00:00:00 2001 From: n4n5 Date: Thu, 7 Dec 2023 21:12:25 +0100 Subject: [PATCH 2/3] fix: move build.py and better --- {download => .github/workflows}/build.py | 3 +-- .github/workflows/static.yml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) rename {download => .github/workflows}/build.py (92%) diff --git a/download/build.py b/.github/workflows/build.py similarity index 92% rename from download/build.py rename to .github/workflows/build.py index 1761a3a..782d74d 100644 --- a/download/build.py +++ b/.github/workflows/build.py @@ -34,11 +34,10 @@ def size(size_in_bytes): p = FOLDER + name if name.endswith(".gz"): date = datetime.fromtimestamp(getmtime(p)).strftime("%Y-%m-%d %H:%M:%S") - s += t.substitute(file=p, date=date, size=size(getsize(p))) + s += t.substitute(file=name, date=date, size=size(getsize(p))) with open(FOLDER + PATH_TO_FILE, "r", encoding="utf-8") as file: file_data = file.read() file_data = file_data.replace("", s) with open(FOLDER + PATH_TO_FILE, "w", encoding="utf-8") as file: file.write(file_data) -os.remove(FOLDER + "build.py") diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 95a588e..4022df6 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -34,7 +34,7 @@ jobs: - name: Setup Pages uses: actions/configure-pages@v4 - name: render index.html - run: python3 download/build.py + run: python3 .github/workflows/build.py - name: Upload artifact uses: actions/upload-pages-artifact@v2 with: From bcc16dce468cb970a322769b464ce7df14e13fd2 Mon Sep 17 00:00:00 2001 From: n4n5 Date: Thu, 7 Dec 2023 21:14:00 +0100 Subject: [PATCH 3/3] fix: better --- download/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/download/index.html b/download/index.html index 8384f91..3d136d6 100644 --- a/download/index.html +++ b/download/index.html @@ -22,7 +22,7 @@

Index of /download

[PARENTDIR] - Parent Directory + Parent Directory   -