From 7d26700bbf23f856fa0f8498940c1bf83c8de8cf Mon Sep 17 00:00:00 2001 From: C4illin Date: Mon, 20 May 2024 01:27:16 +0200 Subject: [PATCH] add workflow --- .github/workflows/docker-publish.yml | 68 ++++++++++++++++++++++++++++ src/index.tsx | 25 ++++++++++ 2 files changed, 93 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..cbfba98 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,68 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + push: + branches: [ "main" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + workflow_dispatch: + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v4 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index 5fe7ef6..3dff8f5 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -703,6 +703,31 @@ const app = new Elysia() return Bun.file(filePath); }, ) + .get("/zip/:userId/:jobId", async ({ params, jwt, redirect, cookie: { auth } }) => { + // TODO: Implement zip download + if (!auth?.value) { + return redirect("/login"); + } + + const user = await jwt.verify(auth.value); + if (!user) { + return redirect("/login"); + } + + const job = await db + .query("SELECT * FROM jobs WHERE user_id = ? AND id = ?") + .get(user.id, params.jobId); + + if (!job) { + return redirect("/results"); + } + + const userId = decodeURIComponent(params.userId); + const jobId = decodeURIComponent(params.jobId); + const outputPath = `${outputDir}${userId}/${jobId}/`; + + // return Bun.zip(outputPath); + }) .onError(({ code, error, request }) => { // log.error(` ${request.method} ${request.url}`, code, error); console.error(error);