-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate module concern between client and server
- Loading branch information
Showing
4 changed files
with
26 additions
and
26 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,22 @@ | ||
import { randomBytes } from 'crypto'; | ||
import { prisma } from './db'; | ||
|
||
/** | ||
* Returns true if slug exists in database. | ||
*/ | ||
export async function checkSlugExists(slug: string): Promise<boolean> { | ||
const link = await prisma.link.findUnique({ | ||
where: { | ||
slug | ||
} | ||
}); | ||
|
||
return !!link; | ||
} | ||
|
||
/** | ||
* Returns a random string for slug. | ||
*/ | ||
export function generateRandomSlug(): string { | ||
return randomBytes(3).toString('hex'); | ||
} |
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 |
---|---|---|
@@ -1,27 +1,8 @@ | ||
import { randomBytes } from 'crypto'; | ||
import { prisma } from './db'; | ||
import { URL_WITHOUT_PROTOCOL } from './env'; | ||
|
||
/** | ||
* Returns a random string for slug. | ||
* Returns true if the url is not from the same domain. | ||
*/ | ||
export function generateRandomSlug(): string { | ||
return randomBytes(3).toString('hex'); | ||
} | ||
|
||
/** | ||
* Returns true if slug exists in database. | ||
*/ | ||
export async function checkSlugExists(slug: string): Promise<boolean> { | ||
const link = await prisma.link.findUnique({ | ||
where: { | ||
slug | ||
} | ||
}); | ||
|
||
return !!link; | ||
} | ||
|
||
export function checkIfUrlIsValid(url: string): boolean { | ||
return !url.includes(URL_WITHOUT_PROTOCOL); | ||
} |