Fix meilisearch auth
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import database
|
import database
|
||||||
import search
|
import search
|
||||||
import sys
|
import sys
|
||||||
import settings
|
|
||||||
import logging
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
@@ -22,16 +20,8 @@ def database_del_story(sid):
|
|||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
def search_del_story(sid):
|
def search_del_story(sid):
|
||||||
try:
|
return search.meili_api(
|
||||||
r = requests.delete(settings.MEILI_URL + 'indexes/qotnews/documents/'+sid, timeout=2)
|
requests.delete, 'indexes/qotnews/documents/' + sid)
|
||||||
if r.status_code != 202:
|
|
||||||
raise Exception('Bad response code ' + str(r.status_code))
|
|
||||||
return r.json()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
raise
|
|
||||||
except BaseException as e:
|
|
||||||
logging.error('Problem deleting MeiliSearch story: {}'.format(str(e)))
|
|
||||||
return False
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ SEARCH_ENABLED = bool(settings.MEILI_URL)
|
|||||||
def meili_api(method, route, json=None, params=None, parse_json=True):
|
def meili_api(method, route, json=None, params=None, parse_json=True):
|
||||||
try:
|
try:
|
||||||
headers = {'Authorization': 'Bearer ' + settings.MEILI_API_KEY}
|
headers = {'Authorization': 'Bearer ' + settings.MEILI_API_KEY}
|
||||||
r = method(settings.MEILI_URL + route, json=json, params=params, timeout=4)
|
r = method(settings.MEILI_URL + route, json=json, params=params, headers=headers, timeout=4)
|
||||||
if r.status_code > 299:
|
if r.status_code > 299:
|
||||||
raise Exception('Bad response code ' + str(r.status_code))
|
raise Exception('Bad response code ' + str(r.status_code))
|
||||||
if parse_json:
|
if parse_json:
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ NUM_TILDES = 5
|
|||||||
# Leave blank if not using search
|
# Leave blank if not using search
|
||||||
#MEILI_URL = 'http://127.0.0.1:7700/'
|
#MEILI_URL = 'http://127.0.0.1:7700/'
|
||||||
MEILI_URL = ''
|
MEILI_URL = ''
|
||||||
|
MEILI_API_KEY = ''
|
||||||
|
|
||||||
# Readerserver URL
|
# Readerserver URL
|
||||||
# Leave blank if not using, but that defeats the whole point
|
# Leave blank if not using, but that defeats the whole point
|
||||||
|
|||||||
Reference in New Issue
Block a user