diff --git a/apps/golinks-v2/src/lib/auth.ts b/apps/golinks-v2/src/lib/auth.ts index 759b04a..1a6bd6b 100644 --- a/apps/golinks-v2/src/lib/auth.ts +++ b/apps/golinks-v2/src/lib/auth.ts @@ -59,59 +59,6 @@ export async function slackOAuthExchange(payload: object) { return api; } -export async function lookupBotToken(db: EnvBindings["golinks"], teamId: string, is_enterprise_install?: boolean) { - const adapter = new PrismaD1(db); - const prisma = new PrismaClient({ adapter }); - try { - const team = await prisma.slackBotToken.findFirst({ - where: { - teamId, - enterprise_install: is_enterprise_install, - }, - }); - return team; - } catch (error) { - return Promise.reject(Error(`${error}`)); - } -} - -export async function addBotToken(db: EnvBindings["golinks"], teamId: string, token: string, enterprise_install?: boolean) { - const adapter = new PrismaD1(db); - const prisma = new PrismaClient({ adapter }); - try { - const result = await prisma.slackBotToken.create({ - data: { - teamId, - enterprise_install: enterprise_install !== undefined ? enterprise_install : false, - token, - }, - }); - return result; - } catch (error) { - return Promise.reject(Error(`${error}`)); - } -} - -export async function updateBotToken(db: EnvBindings["golinks"], teamId: string, token: string, enterprise_install?: boolean) { - const adapter = new PrismaD1(db); - const prisma = new PrismaClient({ adapter }); - try { - const result = await prisma.slackBotToken.update({ - where: { - teamId, - }, - data: { - teamId, - enterprise_install, - token, - }, - }); - return result; - } catch (error) { - return Promise.reject(Error(`${error}`)); - } -} - export async function githubOAuthExchange(payload: object) { let formBody = Object.entries(payload) .map(([key, value]) => encodeURIComponent(key) + "=" + encodeURIComponent(value)) @@ -138,27 +85,6 @@ export async function getUserInfoAndGenerateTicket(token: string, context: Conte } } -export async function addNewChallenge(db: EnvBindings["golinks"], challenge, metadata) { - const adapter = new PrismaD1(db); - const prisma = new PrismaClient({ adapter }); - try { - const result = await prisma.gitHubOAuthChallenge.create({ - data: { - challenge, - metadata, - expires_on: add(Date(), { - minutes: 15, - }), - }, - }); - console.log(`[dbops] ${result}`); - return result; - } catch (error) { - console.error(error); - return Promise.reject(Error(error)); - } -} - /** * * @param env The `context.env` object from Hono diff --git a/apps/golinks-v2/src/lib/constants.ts b/apps/golinks-v2/src/lib/constants.ts index 51f34b7..9c8e45d 100644 --- a/apps/golinks-v2/src/lib/constants.ts +++ b/apps/golinks-v2/src/lib/constants.ts @@ -1,15 +1,6 @@ import { EnvBindings } from "types"; - -export const adminApiKey = { - type: "apiKey", - name: "X-Golinks-Admin-Key", - in: "header", - description: "This is being deprecated for the use of bearer token-based `userApiKey` instead", - externalDocs: { - description: "Learn more about admin access", - url: homepage, - }, -}; +export const homepage = "https://wiki.andreijiroh.xyz/golinks"; +export const sources = "https://github.com/andreijiroh-dev/api-servers/tree/main/apps/golinks-v2"; export const userApiKey = { type: "http", @@ -23,9 +14,6 @@ export const userApiKey = { }, }; -export const homepage = "https://wiki.andreijiroh.xyz/golinks"; -export const sources = "https://github.com/andreijiroh-dev/api-servers/tree/main/apps/golinks-v2"; - export const contact = { name: "Andrei Jiroh Halili", url: sources, @@ -68,6 +56,10 @@ export const tags = [ url: homepage, }, }, + { + name: "wikilinks", + description: "golink-styled wikilinks" + }, { name: "discord-invites", description: "Custom Discord invite links at `go/discord/`", diff --git a/apps/golinks-v2/src/lib/db.ts b/apps/golinks-v2/src/lib/db.ts index ededd96..8950205 100644 --- a/apps/golinks-v2/src/lib/db.ts +++ b/apps/golinks-v2/src/lib/db.ts @@ -1,6 +1,6 @@ import { DiscordInviteLink, GoLink, Prisma, PrismaClient } from "@prisma/client"; import { PrismaD1 } from "@prisma/adapter-d1"; -import { Env, EnvBindings } from "../types"; +import { EnvBindings } from "../types"; import { Str } from "chanfana"; import { getOffset, PAGE_SIZE } from "./utils"; @@ -11,7 +11,7 @@ import { getOffset, PAGE_SIZE } from "./utils"; * @param isActive Filter by disabled links * @returns */ -export async function getGoLinks(db: EnvBindings["golinks"], page: number, isActive?: boolean, type?: "golinks" | "wikilinks" | null) { +export async function getGoLinks(db: EnvBindings["golinks"], page: number, isActive?: boolean, type?: "golinks" | "wikilinks" | null) { const adapter = new PrismaD1(db); const prisma = new PrismaClient({ adapter }); // Assuming you have a Prisma client instance @@ -64,7 +64,7 @@ export async function getGoLinks(db: EnvBindings["golinks"], page: number, * @returns */ export async function getLink( - db: EnvBindings["golinks"], + db: EnvBindings["golinks"], slug: string, type?: "golinks" | "wikilinks" | null, ): Promise | null { @@ -100,7 +100,7 @@ export async function getLink( } export async function addGoLink( - db: EnvBindings["golinks"], + db: EnvBindings["golinks"], slug: string, targetUrl: string, type?: "golinks" | "wikilinks" | null, @@ -143,7 +143,7 @@ export async function addGoLink( } export async function updateGoLink( - db: EnvBindings["golinks"], + db: EnvBindings["golinks"], slug: string, targetUrl: string, type?: "golinks" | "wikilinks" | null, @@ -192,7 +192,7 @@ export async function updateGoLink( } } -export async function deprecateGoLink(db: EnvBindings["golinks"], slug: string, reason: string, type: "golinks" | "wikilinks" | null) { +export async function deprecateGoLink(db: EnvBindings["golinks"], slug: string, reason: string, type: "golinks" | "wikilinks" | null) { const adapter = new PrismaD1(db); const prisma = new PrismaClient({ adapter }); @@ -236,7 +236,7 @@ export async function deprecateGoLink(db: EnvBindings["golinks"], slug: str } } -export async function undeprecateGoLink(db: EnvBindings["golinks"], slug: string, type: "golinks" | "wikilinks" | null) { +export async function undeprecateGoLink(db: EnvBindings["golinks"], slug: string, type: "golinks" | "wikilinks" | null) { const adapter = new PrismaD1(db); const prisma = new PrismaClient({ adapter }); @@ -280,7 +280,7 @@ export async function undeprecateGoLink(db: EnvBindings["golinks"], slug: s } } -export async function deleteGoLink(db: EnvBindings["golinks"], slug: string, type: "golinks" | "wikilinks" | null) { +export async function deleteGoLink(db: EnvBindings["golinks"], slug: string, type: "golinks" | "wikilinks" | null) { const adapter = new PrismaD1(db); const prisma = new PrismaClient({ adapter }); @@ -320,7 +320,7 @@ export async function deleteGoLink(db: EnvBindings["golinks"], slug: string * @param isNsfw * @returns */ -export async function getDiscordInvites(db: EnvBindings["golinks"], page: number, isActive?: boolean, isNsfw?: boolean) { +export async function getDiscordInvites(db: EnvBindings["golinks"], page: number, isActive?: boolean, isNsfw?: boolean) { const adapter = new PrismaD1(db); const prisma = new PrismaClient({ adapter }); // Assuming you have a Prisma client instance @@ -341,7 +341,7 @@ export async function getDiscordInvites(db: EnvBindings["golinks"], page: n return result; } -export async function getDiscordInvite(db: EnvBindings["golinks"], slug: string): Promise | null { +export async function getDiscordInvite(db: EnvBindings["golinks"], slug: string): Promise | null { const adapter = new PrismaD1(db); const prisma = new PrismaClient({ adapter }); @@ -369,7 +369,7 @@ export async function getDiscordInvite(db: EnvBindings["golinks"], slug: st } export async function addDiscordInvite( - db: EnvBindings["golinks"], + db: EnvBindings["golinks"], slug: string, inviteCode: string, name: string, @@ -408,7 +408,7 @@ export async function addDiscordInvite( } export async function updateDiscordLink( - db: EnvBindings["golinks"], + db: EnvBindings["golinks"], slug: string, inviteCode: string, name?: string, @@ -451,7 +451,7 @@ export async function updateDiscordLink( } } -export async function deleteDiscordLink(db: EnvBindings["golinks"], slug: string) { +export async function deleteDiscordLink(db: EnvBindings["golinks"], slug: string) { const adapter = new PrismaD1(db); const prisma = new PrismaClient({ adapter }); diff --git a/apps/golinks-v2/src/lib/utils.ts b/apps/golinks-v2/src/lib/utils.ts index 7a6bf75..5061b0b 100644 --- a/apps/golinks-v2/src/lib/utils.ts +++ b/apps/golinks-v2/src/lib/utils.ts @@ -40,7 +40,7 @@ export function generateNewIssueUrl(type: string, prefix: "golinks" | "wikilinks if (prefix == "wikilinks") { templateUrl.searchParams.append("prefix", "wiki.andreijiroh.xyz/go/"); } else { - templateUrl.searchParams.append("prefix", "go.andreijiroh.xyz"); + templateUrl.searchParams.append("prefix", "go.andreijiroh.xyz/"); } if (url) { templateUrl.searchParams.append("url", url);