Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thedevs-network/kutt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorPouria Ezzati <ezzati.upt@gmail.com>2022-11-10 18:32:26 +0300
committerGitHub <noreply@github.com>2022-11-10 18:32:26 +0300
commit987bafdf368aea4168477288b6e1f7a428cef27a (patch)
tree05c88574a81c544994b92e3e328fe0a9f42569d9 /server
parentbd082d559dc3186022c1418e77c4c85bcbde1eaf (diff)
parent9cbbade1aee3a42406141a7fdb9e56edbdb7de62 (diff)
Merge pull request #537 from zzwt/feature/change-link-password
feat: change link password
Diffstat (limited to 'server')
-rw-r--r--server/handlers/links.ts6
-rw-r--r--server/handlers/validators.ts7
-rw-r--r--server/queries/link.ts5
3 files changed, 15 insertions, 3 deletions
diff --git a/server/handlers/links.ts b/server/handlers/links.ts
index a497cdd..857c857 100644
--- a/server/handlers/links.ts
+++ b/server/handlers/links.ts
@@ -108,8 +108,7 @@ export const create: Handler = async (req: CreateLinkReq, res) => {
};
export const edit: Handler = async (req, res) => {
- const { address, target, description, expire_in } = req.body;
-
+ const { address, target, description, expire_in, password } = req.body;
if (!address && !target) {
throw new CustomError("Should at least update one field.");
}
@@ -152,7 +151,8 @@ export const edit: Handler = async (req, res) => {
...(address && { address }),
...(description && { description }),
...(target && { target }),
- ...(expire_in && { expire_in })
+ ...(expire_in && { expire_in }),
+ ...(password && { password })
}
);
diff --git a/server/handlers/validators.ts b/server/handlers/validators.ts
index 635401b..7b5015c 100644
--- a/server/handlers/validators.ts
+++ b/server/handlers/validators.ts
@@ -145,6 +145,13 @@ export const editLink = [
.withMessage("URL is not valid.")
.custom(value => removeWww(URL.parse(value).host) !== env.DEFAULT_DOMAIN)
.withMessage(`${env.DEFAULT_DOMAIN} URLs are not allowed.`),
+ body("password")
+ .optional({ nullable: true, checkFalsy: true })
+ .custom(checkUser)
+ .withMessage("Only users can use this field.")
+ .isString()
+ .isLength({ min: 3, max: 64 })
+ .withMessage("Password length must be between 3 and 64."),
body("address")
.optional({ checkFalsy: true, nullable: true })
.isString()
diff --git a/server/queries/link.ts b/server/queries/link.ts
index 38c9a0e..e892df8 100644
--- a/server/queries/link.ts
+++ b/server/queries/link.ts
@@ -180,6 +180,11 @@ export const batchRemove = async (match: Match<Link>) => {
};
export const update = async (match: Partial<Link>, update: Partial<Link>) => {
+ if (update.password) {
+ const salt = await bcrypt.genSalt(12);
+ update.password = await bcrypt.hash(update.password, salt);
+ }
+
const links = await knex<Link>("links")
.where(match)
.update({ ...update, updated_at: new Date().toISOString() }, "*");