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
1 change: 0 additions & 1 deletion supabase/functions/.env.dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
LEADMINER_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
LEADMINER_API_HASH_SECRET=change_me
SUPABASE_PROJECT_URL=http://host.docker.internal:54321/ # Required for self-hosted/prod: Your public Supabase URL (e.g., https://db.yourdomain.com)
LEADMINER_SECRET_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU

# Use an SMTP testing service like Ethereal for development https://ethereal.email/
SMTP_HOST=smtp.example.email
Expand Down
23 changes: 9 additions & 14 deletions supabase/functions/passive-mining/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getFolders } from "./boxes.ts";
const supabase = createSupabaseAdmin();

const SERVER_ENDPOINT = Deno.env.get("SERVER_ENDPOINT");
const LEADMINER_SECRET_TOKEN = Deno.env.get("LEADMINER_SECRET_TOKEN");
const SUPABASE_SERVICE_ROLE_KEY = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY"); // Edge Functions have access to this secret by default

const functionName = "passive-mining";
const app = new Hono().basePath(`/${functionName}`);
Expand Down Expand Up @@ -40,15 +40,6 @@ app.post("/", async (c: Context) => {
}
});

app.get("/", (c: Context) => {
try {
return c.json({ msg: "Passive mining is running" });
} catch (error) {
console.error("Error in passive-mining:", error);
return c.json({ error: "Failed to check passive-mining" }, 500);
}
});

Deno.serve((req) => app.fetch(req));

async function getMiningSources() {
Expand All @@ -66,7 +57,9 @@ async function getMiningSources() {
return data;
}

async function getLatestPassiveMiningDate(userId: string): Promise<string | null> {
async function getLatestPassiveMiningDate(
userId: string,
): Promise<string | null> {
const { data, error } = await supabase
.schema("private")
.from("tasks")
Expand All @@ -91,14 +84,16 @@ async function getLatestPassiveMiningDate(userId: string): Promise<string | null
}

async function getBoxes(miningSource: MiningSource) {
console.log(`Fetching IMAP boxes for ${miningSource.email}at ${SERVER_ENDPOINT}/api/imap/boxes?userId=${miningSource.user_id}`);
console.log(
`Fetching IMAP boxes for ${miningSource.email}at ${SERVER_ENDPOINT}/api/imap/boxes?userId=${miningSource.user_id}`,
);
const res = await fetch(
`${SERVER_ENDPOINT}/api/imap/boxes?userId=${miningSource.user_id}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${LEADMINER_SECRET_TOKEN}`,
Authorization: `Bearer ${SUPABASE_SERVICE_ROLE_KEY}`,
// originally its x-sb-jwt
},
body: JSON.stringify({ email: miningSource.email }),
Expand Down Expand Up @@ -126,7 +121,7 @@ async function startMiningEmail(miningSource: MiningSource) {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${LEADMINER_SECRET_TOKEN}`,
Authorization: `Bearer ${SUPABASE_SERVICE_ROLE_KEY}`,
},
body: JSON.stringify({
miningSource: { email: miningSource.email },
Expand Down
Loading