-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into utm-templates
- Loading branch information
Showing
17 changed files
with
342 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import "dotenv-flow/config"; | ||
|
||
async function main() { | ||
const domains = await prisma.domain.findMany({ | ||
where: { | ||
notFoundUrl: null, | ||
project: { | ||
plan: { | ||
not: "free", | ||
}, | ||
}, | ||
links: { | ||
some: { | ||
key: "_root", | ||
url: { | ||
not: "", | ||
}, | ||
}, | ||
}, | ||
}, | ||
select: { | ||
id: true, | ||
slug: true, | ||
notFoundUrl: true, | ||
project: { | ||
select: { | ||
slug: true, | ||
plan: true, | ||
}, | ||
}, | ||
links: { | ||
select: { | ||
key: true, | ||
url: true, | ||
}, | ||
where: { | ||
key: "_root", | ||
}, | ||
}, | ||
}, | ||
take: 10, | ||
orderBy: { | ||
createdAt: "asc", | ||
}, | ||
}); | ||
|
||
const updatedDomains = await Promise.all( | ||
domains.map((domain) => { | ||
return prisma.domain.update({ | ||
where: { id: domain.id }, | ||
data: { notFoundUrl: domain.links[0].url }, | ||
select: { | ||
id: true, | ||
slug: true, | ||
notFoundUrl: true, | ||
project: { | ||
select: { | ||
slug: true, | ||
plan: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}), | ||
); | ||
|
||
console.table(updatedDomains); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { DubConfig } from "@/types"; | ||
import { setConfig } from "@/utils/config"; | ||
import { logger } from "@/utils/logger"; | ||
import { OAuth2Client } from "@badgateway/oauth2-client"; | ||
import chalk from "chalk"; | ||
import * as http from "http"; | ||
import { Ora } from "ora"; | ||
import * as url from "url"; | ||
|
||
interface OAuthCallbackServerProps { | ||
oauthClient: OAuth2Client; | ||
redirectUri: string; | ||
spinner: Ora; | ||
codeVerifier: string; | ||
} | ||
|
||
export function oauthCallbackServer({ | ||
oauthClient, | ||
redirectUri, | ||
codeVerifier, | ||
spinner, | ||
}: OAuthCallbackServerProps) { | ||
const server = http.createServer(async (req, res) => { | ||
const reqUrl = url.parse(req.url || "", true); | ||
|
||
if (reqUrl.pathname !== "/callback" || req.method !== "GET") { | ||
res.writeHead(404); | ||
res.end("Not found"); | ||
return; | ||
} | ||
|
||
const code = reqUrl.query.code as string; | ||
|
||
if (!code) { | ||
res.writeHead(400); | ||
res.end( | ||
"Authorization code not found. Please start the login process again.", | ||
); | ||
|
||
return; | ||
} | ||
|
||
try { | ||
spinner.text = "Verifying"; | ||
|
||
const { accessToken, refreshToken, expiresAt } = | ||
await oauthClient.authorizationCode.getToken({ | ||
code, | ||
redirectUri, | ||
codeVerifier, | ||
}); | ||
|
||
spinner.text = "Configuring"; | ||
|
||
const configInfo: DubConfig = { | ||
access_token: accessToken.trim(), | ||
refresh_token: refreshToken, | ||
expires_at: expiresAt ? Date.now() + expiresAt * 1000 : null, | ||
domain: "dub.sh", | ||
}; | ||
|
||
await setConfig(configInfo); | ||
spinner.succeed("Configuration completed"); | ||
|
||
logger.info(""); | ||
logger.info(chalk.green("Logged in successfully!")); | ||
logger.info(""); | ||
|
||
res.writeHead(200, { "Content-Type": "text/html" }); | ||
res.end("Authentication successful! You can close this window."); | ||
} catch (error) { | ||
res.writeHead(500, { "Content-Type": "text/html" }); | ||
res.end("An error occurred during authentication. Please try again."); | ||
} finally { | ||
server.close(); | ||
process.exit(0); | ||
} | ||
}); | ||
|
||
setTimeout(() => { | ||
server.close(); | ||
process.exit(0); | ||
}, 300000); | ||
|
||
server.listen(4587); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.