Skip to content

Commit

Permalink
1.6.0: Add URL_REGEX option (#71)
Browse files Browse the repository at this point in the history
* Add URL_REGEX option

* Verify URL on link update

* Edit release script to not include version header

* Update docker-compose.yml env variables
  • Loading branch information
JackBailey authored Jul 29, 2023
1 parent ea03c09 commit edca8ab
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 126 deletions.
60 changes: 31 additions & 29 deletions .example.env
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
DB_HOST=localhost
DB_PORT=27017

DB_PASSWORD=
DB_USER=

JWT_KEY=

URL_LENGTH=8
URL_SET=standard
URL_ONLY_UNIQUE=false

NODE_ENV=production

HOME_REDIRECT=/dash/overview
FORCE_FRONTEND_REDIRECT=false
ENABLE_REGISTRATION=false
DOMAIN=http://example.com
DEMO=false

USE_HTTPS=true
CORS=*

UMAMI_SITEID=
UMAMI_URL=

BACKUP=true
BACKUP_SCHEDULE=* * * * *
BACKUP_COUNT=5
DB_HOST=localhost
DB_PORT=27017

DB_PASSWORD=
DB_USER=

JWT_KEY=

URL_LENGTH=8
URL_SET=standard
URL_ONLY_UNIQUE=false

NODE_ENV=production

HOME_REDIRECT=/dash/overview
FORCE_FRONTEND_REDIRECT=false
ENABLE_REGISTRATION=false
DOMAIN=http://example.com
DEMO=false

USE_HTTPS=true
CORS=*

UMAMI_SITEID=
UMAMI_URL=

BACKUP=true
BACKUP_SCHEDULE=* * * * *
BACKUP_COUNT=5

URL_REGEX="https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)"
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ jobs:
# Set capturing changes if line is a version header
if [[ "$line" == "## ["* ]]; then
if [[ "$line" == "## [$VERSION]"* ]]; then
CHANGES="$line"
CAPTURING_CHANGES=1
else
CAPTURING_CHANGES=0
fi
## Otherwise, add lines to the changelog if it is within the current version
elif [[ "$CAPTURING_CHANGES" == 1 ]]; then
## Otherwise, add lines to the changelog if it is within the current version and not just spaces
elif [[ "$CAPTURING_CHANGES" == 1 ]] && [[ $line = *[!\ ]* ]]; then
CHANGES="$CHANGES"$'\n'"$line"
fi
done < CHANGELOG.md
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.6.0] - 2023-07-29

- Add environment variable URL_REGEX to allow for custom URL regexes
- Verify URL on link update
- Edit release script to not include version header in releases

## [1.5.4] - 2023-06-27

- More uniform Umami tracking with better error handling
Expand Down Expand Up @@ -128,4 +134,3 @@ First release, production ready
- Main framework of Lynx
- Import/Export
- Add ShareX support

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.4
1.6.0
93 changes: 47 additions & 46 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
version: "3"
services:
lynx-db:
image: mongo
restart: always
container_name: lynx-db
environment:
- MONGO_INITDB_ROOT_USERNAME=user
- MONGO_INITDB_ROOT_PASSWORD=paswd
volumes:
- ./db:/data/db
ports:
- 27017:27017

lynx:
image: jackbailey/lynx
build:
context: .
restart: always
ports:
- 3000:3000
depends_on:
- lynx-db
volumes:
- ./backups:/app/backups
environment:
- NODE_ENV=production
- DB_USER=user
- DB_PASSWORD=paswd
- JWT_KEY=1234567890
- URL_LENGTH=8
- URL_SET=standard
- URL_ONLY_UNIQUE=false
- HOME_REDIRECT=/dash/overview
- FORCE_FRONTEND_REDIRECT=false
- ENABLE_REGISTRATION=false # First registration will always be allowed
- DOMAIN=http://example.com
- DEMO=false
- USE_HTTPS=false
- BACKUP=true
- BACKUP_SCHEDULE=* * * * * # Use crontab.guru to create
- BACKUP_COUNT=5 # A count of 1 will make a backup file called backup.json

## DO NOT CHANGE THESE:
- DB_HOST=lynx-db
- DB_PORT=27017
version: "3"
services:
lynx-db:
image: mongo
restart: always
container_name: lynx-db
environment:
- MONGO_INITDB_ROOT_USERNAME=user
- MONGO_INITDB_ROOT_PASSWORD=paswd
volumes:
- ./db:/data/db
ports:
- 27017:27017

lynx:
image: jackbailey/lynx
build:
context: .
restart: always
ports:
- 3000:3000
depends_on:
- lynx-db
volumes:
- ./backups:/app/backups
environment:
- NODE_ENV=production
- DB_USER=user
- DB_PASSWORD=paswd
- JWT_KEY=1234567890
- URL_LENGTH=8
- URL_SET=standard
- URL_ONLY_UNIQUE=false
- HOME_REDIRECT=/dash/overview
- FORCE_FRONTEND_REDIRECT=false
- ENABLE_REGISTRATION=false # First registration will always be allowed
- DOMAIN=http://example.com
- DEMO=false
- USE_HTTPS=false
- BACKUP=true
- BACKUP_SCHEDULE=* * * * * # Use crontab.guru to create
- BACKUP_COUNT=5 # A count of 1 will make a backup file called backup.json
- URL_REGEX=https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*) # Don't use quotation marks

## DO NOT CHANGE THESE:
- DB_HOST=lynx-db
- DB_PORT=27017
85 changes: 43 additions & 42 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
version: "3"
services:
db:
image: mongo
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=
- MONGO_INITDB_ROOT_PASSWORD=
volumes:
- ./db:/data/db

lynx:
image: jackbailey/lynx:1
restart: always
ports:
- 3000:3000
depends_on:
- db
volumes:
- ./backups:/app/backups
environment:
- NODE_ENV=production
- DB_USER=
- DB_PASSWORD=
- JWT_KEY=
- URL_LENGTH=8
- URL_SET=standard
- URL_ONLY_UNIQUE=false
- HOME_REDIRECT=/dash/overview
- FORCE_FRONTEND_REDIRECT=false
- ENABLE_REGISTRATION=false # First registration will always be allowed
- DOMAIN=http://example.com
- DEMO=false
- USE_HTTPS=true
- CORS=*
- BACKUP=true
- BACKUP_SCHEDULE=* * * * * # Use crontab.guru to create
- BACKUP_COUNT=5 # A count of 1 will make a backup file called backup.json

## DO NOT CHANGE THESE:
- DB_HOST=db
- DB_PORT=27017
version: "3"
services:
db:
image: mongo
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=
- MONGO_INITDB_ROOT_PASSWORD=
volumes:
- ./db:/data/db

lynx:
image: jackbailey/lynx:1
restart: always
ports:
- 3000:3000
depends_on:
- db
volumes:
- ./backups:/app/backups
environment:
- NODE_ENV=production
- DB_USER=
- DB_PASSWORD=
- JWT_KEY=
- URL_LENGTH=8
- URL_SET=standard
- URL_ONLY_UNIQUE=false
- HOME_REDIRECT=/dash/overview
- FORCE_FRONTEND_REDIRECT=false
- ENABLE_REGISTRATION=false # First registration will always be allowed
- DOMAIN=http://example.com
- DEMO=false
- USE_HTTPS=true
- CORS=*
- BACKUP=true
- BACKUP_SCHEDULE=* * * * * # Use crontab.guru to create
- BACKUP_COUNT=5 # A count of 1 will make a backup file called backup.json
- URL_REGEX=https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*) # Don't use quotation marks

## DO NOT CHANGE THESE:
- DB_HOST=db
- DB_PORT=27017
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"uuid": "^9.0.0"
},
"scripts": {
"dev": "nodemon . --ignore frontend",
"dev": "nodemon . --ignore frontend --ignore backups",
"serve": "npm run dev --prefix frontend"
},
"resolutions": {
Expand Down
11 changes: 11 additions & 0 deletions src/db/modules/link/update.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
const getLink = require("./get");
const Account = require("../../models/account");
const { url: validUrl } = require("../valid");

module.exports = async ({ id, slug, destination, account }) => {
if (!validUrl(destination)) {
return [
null,
{
message: "Invalid destination url format",
code: 422,
},
];
}

if (!slug)
return [
null,
Expand Down
9 changes: 6 additions & 3 deletions src/db/modules/valid/url.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = (url) => {
return /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/.test(url);
};
module.exports = (url) => {
let regex = new RegExp(
process.env.URL_REGEX || "https?://(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)"
);
return regex.test(url);
};

0 comments on commit edca8ab

Please sign in to comment.