mirror of
https://github.com/boostorg/website-v2.git
synced 2026-01-19 04:42:17 +00:00
🚧 stubs out linkpreview service
Holding on this until after news is cleaned up Issue: #437
This commit is contained in:
@@ -394,6 +394,11 @@ STATIC_CONTENT_AWS_S3_ENDPOINT_URL = env(
|
||||
"STATIC_CONTENT_AWS_S3_ENDPOINT_URL", default="https://s3.us-east-2.amazonaws.com"
|
||||
)
|
||||
|
||||
# LinkPreview API Key
|
||||
LINK_PREVIEW_API_KEY = env(
|
||||
"LINK_PREVIEW_API_KEY", default="changeme"
|
||||
)
|
||||
|
||||
# JSON configuration of how we map static content in the S3 buckets to URL paths
|
||||
STATIC_CONTENT_MAPPING = env(
|
||||
"STATIC_CONTENT_MAPPING", default="stage_static_config.json"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from .helpers import get_link_preview_data
|
||||
from .models import BlogPost, Entry, Link, News, Poll, Video
|
||||
|
||||
|
||||
@@ -30,6 +31,15 @@ class LinkForm(EntryForm):
|
||||
model = Link
|
||||
fields = ["title", "publish_at", "external_url", "image"]
|
||||
|
||||
# Holding on this as it's a new feature Issue #437
|
||||
# def save(self, *args, commit=True, **kwargs):
|
||||
# instance = super().save(*args, commit=False, **kwargs)
|
||||
# if self.cleaned_data["external_url"] and not self.cleaned_data["image"]:
|
||||
# link_data = get_link_preview_data(self.cleaned_data["external_url"])
|
||||
# print(link_data)
|
||||
# instance.save()
|
||||
# return instance
|
||||
|
||||
|
||||
class NewsForm(EntryForm):
|
||||
class Meta:
|
||||
|
||||
18
news/helpers.py
Normal file
18
news/helpers.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import requests
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def get_link_preview_data(link):
|
||||
"""gets the link preview json response from LinkPreview api"""
|
||||
api_url = "https://api.linkpreview.net"
|
||||
api_key = settings.LINK_PREVIEW_API_KEY
|
||||
target = link
|
||||
|
||||
# TODO: Add additional field `image_size` to help validate image https://docs.linkpreview.net/#image-processing-and-validation
|
||||
response = requests.get(
|
||||
api_url,
|
||||
headers={'X-Linkpreview-Api-Key': api_key},
|
||||
params={'q': target},
|
||||
)
|
||||
return response.json()
|
||||
Reference in New Issue
Block a user