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:

View File

@@ -99,8 +99,6 @@ function App() {
<br />
<span className='slogan'>Hacker News, Reddit, Lobsters, and Tildes articles rendered in reader mode.</span>
</p>
<Route path='/(|search)' component={Search} />
<Route path='/(|search)' component={Submit} />
{fullScreenAvailable &&
<Route path='/(|search)' render={() => !isFullScreen ?
<button className='fullscreen' onClick={() => goFullScreen()}>Enter Fullscreen</button>
@@ -108,6 +106,8 @@ function App() {
<button className='fullscreen' onClick={() => exitFullScreen()}>Exit Fullscreen</button>
} />
}
<Route path='/(|search)' component={Search} />
<Route path='/(|search)' component={Submit} />
</div>
<Route path='/' exact render={(props) => <Feed {...props} updateCache={updateCache} />} />

View File

@@ -100,6 +100,7 @@ function Feed({ updateCache }) {
<details style={{marginBottom: '1rem'}}>
<summary>Connection error? Click to expand.</summary>
<p>{error}</p>
{stories && <p>Loaded feed from cache.</p>}
</details>
}
{stories ?

View File

@@ -45,7 +45,7 @@ function Submit() {
ref={inputRef}
/>
</form>
{progress ? progress : ''}
{progress && <p>{progress}</p>}
</span>
);
}