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: 1 addition & 0 deletions apps/web/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ TWITTER_CLIENT_SECRET=
TIKTOK_CLIENT_ID=
TIKTOK_CLIENT_SECRET=
YOUTUBE_API_KEY=
AHREFS_API_KEY=

# Scrape Creators
SCRAPECREATORS_API_KEY=
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions apps/web/app/(ee)/api/cron/partner-platforms/website/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ahrefsClient } from "@/lib/ahrefs/client";
import { withCron } from "@/lib/cron/with-cron";
import { prisma } from "@/lib/prisma";
import { chunk, getDomainWithoutWWW } from "@dub/utils";
import { PlatformType } from "@prisma/client";
import { logAndRespond } from "../../utils";
import { getDomainRating } from "./get-domain-rating";

export const dynamic = "force-dynamic";

Expand Down Expand Up @@ -49,7 +49,7 @@ export const GET = withCron(async () => {
}

try {
const domainRating = await getDomainRating(target);
const domainRating = await ahrefsClient.getDomainRating(target);

await prisma.partnerPlatform.update({
where: {
Expand Down
37 changes: 37 additions & 0 deletions apps/web/lib/ahrefs/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { assertEnv } from "@/lib/assert-env";
import { HttpBaseClient } from "@/lib/http/base-client";
import {
getDomainRatingInputSchema,
getDomainRatingOutputSchema,
} from "./schema";

class AhrefsClient extends HttpBaseClient {
protected readonly vendor = "Ahrefs";
protected readonly baseUrl = "https://api.ahrefs.com/v3/public";

constructor() {
super({ timeout: 5_000 });
}

protected buildAuthHeaders() {
return {
Authorization: `Bearer ${assertEnv("AHREFS_API_KEY")}`,
};
Comment thread
devkiran marked this conversation as resolved.
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// GET /v3/public/domain-rating-free
async getDomainRating(target: string) {
const data = await this.get("/domain-rating-free", {
input: {
target,
output: "json",
},
inputSchema: getDomainRatingInputSchema,
outputSchema: getDomainRatingOutputSchema,
});

return Math.round(data.domain_rating.domain_rating);
}
}

export const ahrefsClient = new AhrefsClient();
14 changes: 14 additions & 0 deletions apps/web/lib/ahrefs/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as z from "zod/v4";

// GET /v3/public/domain-rating-free query params
export const getDomainRatingInputSchema = z.object({
target: z.string(),
output: z.literal("json"),
});

// GET /v3/public/domain-rating-free response
export const getDomainRatingOutputSchema = z.object({
domain_rating: z.object({
domain_rating: z.number(),
Comment thread
devkiran marked this conversation as resolved.
}),
});
Loading