-
Notifications
You must be signed in to change notification settings - Fork 34
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 #394 from d02ev/d02ev/issue#332
PR for Issue#332
- Loading branch information
Showing
11 changed files
with
237 additions
and
31 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
14 changes: 14 additions & 0 deletions
14
backend/migrations/20241216195934-server_url_col_team_rel.js
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,14 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
async up (queryInterface, Sequelize) { | ||
await queryInterface.addColumn('teams', 'serverUrl', { | ||
type: Sequelize.STRING(255), | ||
allowNull: true, | ||
}) | ||
}, | ||
|
||
async down (queryInterface, Sequelize) { | ||
await queryInterface.removeColumn('teams', 'serverUrl') | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { URL_PROTOCOL_REGEX, URL_DOMAIN_REGEX } = require('./constants.helper'); | ||
const { check } = require('express-validator'); | ||
|
||
require('dotenv').config(); | ||
|
||
const validateServerUrl = url => { | ||
if (url === "") { | ||
return { valid: true, errors: null } | ||
} | ||
|
||
const errors = []; | ||
|
||
if (!URL_PROTOCOL_REGEX.test(url)) { | ||
errors.push("Invalid or missing protocol (must be 'http://' or 'https://').") | ||
} | ||
|
||
const domainMatch = url.match(URL_DOMAIN_REGEX); | ||
if (!domainMatch) { | ||
errors.push("Invalid domain name (must include a valid top-level domain like '.com')."); | ||
} else { | ||
const domain = domainMatch[1]; | ||
if (!/^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(domain)) { | ||
errors.push(`Malformed domain: '${domain}'.`); | ||
} | ||
} | ||
|
||
if (errors.length === 0) { | ||
return { valid: true, errors: null } | ||
} | ||
|
||
return { valid: false, errors } | ||
}; | ||
|
||
const validateSetServerUrl = [ | ||
check('serverUrl') | ||
.optional({ | ||
values: ["", null, undefined] | ||
}) | ||
.isString().withMessage('Server URL must be a string') | ||
.trim() | ||
.custom(value => { | ||
const result = validateServerUrl(value); | ||
if (result.valid) { | ||
return true; | ||
} | ||
throw new Error(result.errors); | ||
}) | ||
]; | ||
|
||
module.exports = { validateSetServerUrl }; |
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.