Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/keep-supabase-active.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Keep-Alive

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0"

jobs:
keep-alive:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Generate random sleep duration
id: random_sleep
run: |
RANDOM_SECONDS=$(( RANDOM % 1800 ))
echo "Random sleep duration: ${RANDOM_SECONDS} seconds"
echo "random_seconds=${RANDOM_SECONDS}" >> $GITHUB_OUTPUT

- name: Sleep for random duration
run: sleep ${{ steps.random_sleep.outputs.random_seconds }}
shell: bash

- name: Call keep-alive API on Vercel backend
run: curl -X POST ${{ secrets.VERCEL_URL }}/api/keep-alive
41 changes: 41 additions & 0 deletions src/app/api/keep-alive/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { supabaseAdmin } from "@/lib/supabase";
import { NextResponse } from "next/server";

const generateRandomString = (sizeInBytes: number) => {
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
const charactersLength = characters.length;
for (let i = 0; i < sizeInBytes; i += 1) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};

export async function POST() {
try {
const fileSizeInBytes = 1024;
const randomText = generateRandomString(fileSizeInBytes);
const fileName = `keep-alive-${Date.now()}.txt`;

const { data, error } = await supabaseAdmin.storage
.from(process.env.SUPABASE_TEXT_BUCKET!)
.upload(`keep-alive/${fileName}`, randomText, {
contentType: "text/plain",
upsert: true,
});

if (error) {
console.error("Supabase upload error:", error);
return NextResponse.json(
{ msg: "Failed to upload file to Supabase", error: error.message },
{ status: 500 }
);
}

return NextResponse.json({ msg: "Keep-alive file uploaded successfully", path: data.path });
} catch (err) {
console.error("Server error in keep-alive endpoint:", err);
return NextResponse.json({ msg: "Server Error" }, { status: 500 });
}
}
4 changes: 2 additions & 2 deletions src/app/api/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function POST(req: Request) {
// Upload to Supabase Storage
// Ensure your bucket in Supabase is named 'images' and is set to Public
const { error } = await supabaseAdmin.storage
.from("project_images")
.from(process.env.SUPABASE_IMAGE_BUCKET!)
.upload(fileName, buffer, {
contentType: file.type,
upsert: false,
Expand All @@ -47,7 +47,7 @@ export async function POST(req: Request) {

// Get the Public URL
const { data: { publicUrl } } = supabaseAdmin.storage
.from("project_images")
.from(process.env.SUPABASE_IMAGE_BUCKET!)
.getPublicUrl(fileName);

return NextResponse.json({ url: publicUrl });
Expand Down