NewsBlur/apps/static/views.py

138 lines
3.5 KiB
Python
Raw Normal View History

import os
2024-04-24 09:50:42 -04:00
2015-08-05 19:33:19 -07:00
import redis
2024-04-24 09:50:42 -04:00
import yaml
from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import render
2024-04-24 09:50:42 -04:00
2015-08-05 19:33:19 -07:00
from apps.rss_feeds.models import Feed, MStory
from apps.search.models import SearchFeed
from utils import log as logging
2024-04-24 09:43:56 -04:00
def about(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/about.xhtml")
def faq(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/faq.xhtml")
def api(request):
2024-04-24 09:43:56 -04:00
filename = settings.TEMPLATES[0]["DIRS"][0] + "/static/api.yml"
2011-04-23 18:22:52 -04:00
api_yml_file = open(filename).read()
2024-04-24 09:43:56 -04:00
data = yaml.load(api_yml_file)
return render(request, "static/api.xhtml", {"data": data})
def press(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/press.xhtml")
2017-11-28 16:22:46 -08:00
def privacy(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/privacy.xhtml")
def tos(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/tos.xhtml")
2022-01-20 11:48:07 -05:00
def webmanifest(request):
2024-04-24 09:43:56 -04:00
filename = settings.MEDIA_ROOT + "/extensions/edge/manifest.json"
2022-01-20 11:48:07 -05:00
manifest = open(filename).read()
2024-04-24 09:43:56 -04:00
return HttpResponse(manifest, content_type="application/manifest+json")
2022-01-20 11:48:07 -05:00
2017-11-28 23:13:05 -08:00
def apple_app_site_assoc(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/apple_app_site_assoc.xhtml")
2022-01-21 16:44:03 -05:00
def apple_developer_merchantid(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/apple_developer_merchantid.xhtml")
2022-01-21 16:44:03 -05:00
def feedback(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/feedback.xhtml")
2011-12-06 17:57:02 -08:00
def firefox(request):
2024-04-24 09:43:56 -04:00
filename = settings.MEDIA_ROOT + "/extensions/firefox/manifest.json"
manifest = open(filename).read()
2024-04-24 09:43:56 -04:00
return HttpResponse(manifest, content_type="application/x-web-app-manifest+json")
def ios(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/ios.xhtml")
def android(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/android.xhtml")
def ios_download(request):
2024-04-24 09:43:56 -04:00
return render(request, "static/ios_download.xhtml")
def ios_plist(request):
2024-04-24 09:43:56 -04:00
filename = os.path.join(settings.NEWSBLUR_DIR, "clients/ios/NewsBlur.plist")
manifest = open(filename).read()
2024-04-24 09:43:56 -04:00
logging.user(request, "~SK~FR~BBDownloading NewsBlur.plist...")
2024-04-24 09:43:56 -04:00
return HttpResponse(manifest, content_type="text/xml")
def ios_ipa(request):
2024-04-24 09:43:56 -04:00
filename = os.path.join(settings.NEWSBLUR_DIR, "clients/ios/NewsBlur.ipa")
manifest = open(filename).read()
2024-04-24 09:43:56 -04:00
logging.user(request, "~SK~FR~BBDownloading NewsBlur.ipa...")
2024-04-24 09:43:56 -04:00
return HttpResponse(manifest, content_type="application/octet-stream")
2013-07-30 18:13:09 -07:00
def haproxy_check(request):
return HttpResponse("OK")
2015-08-05 19:33:19 -07:00
2024-04-24 09:43:56 -04:00
2015-08-05 19:33:19 -07:00
def postgres_check(request):
2024-04-24 09:43:56 -04:00
feed = Feed.objects.latest("pk").pk
2015-08-05 19:33:19 -07:00
if feed:
return HttpResponse(unicode(feed))
assert False, "Cannot read from postgres database"
2024-04-24 09:43:56 -04:00
2015-08-05 19:33:19 -07:00
def mongo_check(request):
stories = MStory.objects.count()
if stories:
return HttpResponse(unicode(stories))
assert False, "Cannot read from mongo database"
2024-04-24 09:43:56 -04:00
2015-08-05 19:33:19 -07:00
def elasticsearch_check(request):
client = SearchFeed.ES()
if client.indices.exists_index(SearchFeed.index_name()):
return HttpResponse(SearchFeed.index_name())
assert False, "Cannot read from elasticsearch database"
2024-04-24 09:43:56 -04:00
2015-08-05 19:33:19 -07:00
def redis_check(request):
2024-04-24 09:43:56 -04:00
pool = request.GET["pool"]
if pool == "main":
2015-08-05 19:33:19 -07:00
r = redis.Redis(connection_pool=settings.REDIS_POOL)
2024-04-24 09:43:56 -04:00
elif pool == "story":
2015-08-05 19:33:19 -07:00
r = redis.Redis(connection_pool=settings.REDIS_STORY_HASH_POOL)
2024-04-24 09:43:56 -04:00
elif pool == "sessions":
2015-08-05 19:33:19 -07:00
r = redis.Redis(connection_pool=settings.REDIS_SESSION_POOL)
2024-04-24 09:43:56 -04:00
2015-08-05 19:33:19 -07:00
key = r.randomkey()
if key:
return HttpResponse(unicode(key))
assert False, "Cannot read from redis-%s database" % pool
def health_check(request):
return HttpResponse("OK")