mirror of
https://github.com/mvt-project/mvt.git
synced 2026-10-30 17:56:25 +01:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35ae6c9c89 | ||
|
|
c834c18266 |
+15
-1
@@ -3,11 +3,16 @@
|
|||||||
# Use of this software is governed by the MVT License 1.1 that can be found at
|
# Use of this software is governed by the MVT License 1.1 that can be found at
|
||||||
# https://license.mvt.re/1.1/
|
# https://license.mvt.re/1.1/
|
||||||
|
|
||||||
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from tld import get_tld
|
from tld import get_tld
|
||||||
|
|
||||||
|
from .config import settings
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
SHORTENER_DOMAINS = [
|
SHORTENER_DOMAINS = [
|
||||||
"0rz.tw",
|
"0rz.tw",
|
||||||
"1drv.ms",
|
"1drv.ms",
|
||||||
@@ -375,7 +380,16 @@ class URL:
|
|||||||
|
|
||||||
def unshorten(self) -> Optional[str]:
|
def unshorten(self) -> Optional[str]:
|
||||||
"""Unshorten the URL by requesting an HTTP HEAD response."""
|
"""Unshorten the URL by requesting an HTTP HEAD response."""
|
||||||
res = requests.head(self.url)
|
|
||||||
|
if settings.NETWORK_ACCESS_ALLOWED is False:
|
||||||
|
log.info(
|
||||||
|
"Network access disabled (MVT_NETWORK_ACCESS_ALLOWED=False), "
|
||||||
|
"skipping unshorten for %s",
|
||||||
|
self.url,
|
||||||
|
)
|
||||||
|
return ""
|
||||||
|
|
||||||
|
res = requests.head(self.url, timeout=settings.NETWORK_TIMEOUT)
|
||||||
if str(res.status_code).startswith("30"):
|
if str(res.status_code).startswith("30"):
|
||||||
return res.headers["Location"]
|
return res.headers["Location"]
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user