mirror of
https://git.0x0.st/mia/0x0.git
synced 2024-11-22 08:57:11 +01:00
refactor is_fhost_url to use regex for url matching
This commit is contained in:
parent
47ff3a1152
commit
1daf2e05c5
1 changed files with 6 additions and 7 deletions
13
fhost.py
13
fhost.py
|
@ -28,6 +28,7 @@ from hashlib import sha256
|
||||||
from magic import Magic
|
from magic import Magic
|
||||||
from mimetypes import guess_extension
|
from mimetypes import guess_extension
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
import requests
|
import requests
|
||||||
from short_url import UrlEncoder
|
from short_url import UrlEncoder
|
||||||
from validators import url as url_valid
|
from validators import url as url_valid
|
||||||
|
@ -207,14 +208,12 @@ class File(db.Model):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def fhost_url(scheme=None):
|
|
||||||
if not scheme:
|
|
||||||
return url_for(".fhost", _external=True).rstrip("/")
|
|
||||||
else:
|
|
||||||
return url_for(".fhost", _external=True, _scheme=scheme).rstrip("/")
|
|
||||||
|
|
||||||
def is_fhost_url(url):
|
def is_fhost_url(url):
|
||||||
return url.startswith(fhost_url()) or url.startswith(fhost_url("https"))
|
fhost_url = re.sub(r'https?://', '', url_for(".fhost", _external=True)).rstrip("/")
|
||||||
|
if re.match(rf'https?://{fhost_url}.*', url):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def shorten(url):
|
def shorten(url):
|
||||||
if len(url) > app.config["MAX_URL_LENGTH"]:
|
if len(url) > app.config["MAX_URL_LENGTH"]:
|
||||||
|
|
Loading…
Reference in a new issue