-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from vigneshshettyin/link_qr
Fixed some bugs and added some functionalities
- Loading branch information
Showing
14 changed files
with
315 additions
and
61 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
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
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 |
---|---|---|
@@ -1,28 +1,36 @@ | ||
import { NextRequest } from "next/server"; | ||
import { urlSchema } from "../zod/url"; | ||
import cheerio from 'cheerio'; | ||
|
||
import { IUrlCreateReq } from "@/interfaces/url"; | ||
const validateURLCreateReq = async (formdata: FormData) => { | ||
try { | ||
const long_url = formdata.get("longUrl"); | ||
let title:any = formdata.get("title"); | ||
|
||
const validateURLCreateReq = (formdata: FormData) => { | ||
try { | ||
|
||
const long_url = formdata.get("longUrl"); | ||
const title = formdata.get("title"); | ||
|
||
// validation of title need to be done | ||
const errors = urlSchema.safeParse({ | ||
long_url, | ||
}); | ||
return { title,long_url, status: errors.success, msg: errors.error }; | ||
} catch (e) { | ||
return { | ||
title: "", | ||
long_url: "", | ||
status: false, | ||
msg : JSON.stringify(e) | ||
}; | ||
// validation of title need to be done | ||
const errors = urlSchema.safeParse({ | ||
long_url, | ||
}); | ||
|
||
const urlHit: any = long_url; | ||
|
||
if (title?.toString().length == 0) { | ||
const response = await fetch(urlHit); | ||
const html = await response.text(); | ||
const $ = cheerio.load(html); | ||
const newTitle = $('title').text(); | ||
title = newTitle; | ||
} | ||
}; | ||
|
||
return { title, long_url, status: errors.success, msg: errors.error }; | ||
} catch (e) { | ||
console.log(e) | ||
return { | ||
title: "", | ||
long_url: "", | ||
status: false, | ||
msg: JSON.stringify(e), | ||
}; | ||
} | ||
}; | ||
|
||
export default validateURLCreateReq; | ||
export default validateURLCreateReq; |
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,7 +1,7 @@ | ||
import { z } from "zod"; | ||
|
||
const urlSchema = z.object({ | ||
long_url: z.string().url(), | ||
long_url: z.string().url() | ||
}); | ||
|
||
export { urlSchema }; |
Oops, something went wrong.