Misc fixes

This commit is contained in:
2025-12-01 21:07:01 +00:00
parent 3acaf230c4
commit 6a329e3ba9
5 changed files with 18 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ import settings
import database
import search
import feed
from utils import gen_rand_id
from utils import gen_rand_id, NUM_ID_CHARS
from flask import abort, Flask, request, render_template, stream_with_context, Response
from werkzeug.exceptions import NotFound
@@ -60,6 +60,8 @@ def apistats():
'ref_list': ref_list,
'len_ref_list': len(ref_list),
'current_item': current_item,
'total_stories': database.count_stories(),
'id_space': 26**NUM_ID_CHARS,
}
return stats
@@ -111,7 +113,12 @@ def submit():
ref = url
existing = database.get_story_by_ref(ref)
if existing and not DEBUG:
if existing and DEBUG:
ref = ref + '#' + str(time.time())
existing = False
if existing:
return {'nid': existing.sid}
else:
story = dict(id=nid, ref=ref, source=source)
@@ -129,9 +136,10 @@ def submit():
raise Exception('Invalid article')
except Exception as e:
logging.error('Problem with article submission: {} - {}'.format(e.__class__.__name__, str(e)))
msg = 'Problem with article submission: {} - {}'.format(e.__class__.__name__, str(e))
logging.error(msg)
print(traceback.format_exc())
return {'error': str(e)}, 400
return {'error': msg.split('\n')[0]}, 400
@flask_app.route('/api/<sid>')

View File

@@ -16,8 +16,9 @@ def alert_tanner(message):
except BaseException as e:
logging.error('Problem alerting Tanner: ' + str(e))
NUM_ID_CHARS = 4
def gen_rand_id():
return ''.join(random.choice(string.ascii_uppercase) for _ in range(4))
return ''.join(random.choice(string.ascii_uppercase) for _ in range(NUM_ID_CHARS))
def render_md(md):
if md: