Fixed link-handling for self-referential links in chat

This commit is contained in:
rainbownapkin 2026-05-21 03:15:16 -04:00
parent 13e2b9fe11
commit 3b113df86a

View file

@ -14,6 +14,9 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
//Config
const config = require('../../config.json');
//NPM Imports
const validator = require('validator');//No express here, so regular validator it is!
const {sanitizeUrl} = require("@braintree/sanitize-url");
@ -32,6 +35,15 @@ module.exports.cache = new Map();
module.exports.markLink = async function(dirtyLink){
const link = sanitizeUrl(dirtyLink);
//If this link is referencing this web server
if(link.match(new RegExp(`^${config.protocol}://${config.domain}`)) != null){
//Lazily return it as a good link, since we know it'll at least return a good 404 page XP
return {
link,
type: "link"
}
}
//Check link cache for the requested link
const cachedLink = module.exports.cache.get(link);
@ -105,4 +117,4 @@ module.exports.markLink = async function(dirtyLink){
//return the link
return linkObj;
}
}