Misc fixes
This commit is contained in:
@@ -20,7 +20,7 @@ import settings
|
|||||||
import database
|
import database
|
||||||
import search
|
import search
|
||||||
import feed
|
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 flask import abort, Flask, request, render_template, stream_with_context, Response
|
||||||
from werkzeug.exceptions import NotFound
|
from werkzeug.exceptions import NotFound
|
||||||
@@ -60,6 +60,8 @@ def apistats():
|
|||||||
'ref_list': ref_list,
|
'ref_list': ref_list,
|
||||||
'len_ref_list': len(ref_list),
|
'len_ref_list': len(ref_list),
|
||||||
'current_item': current_item,
|
'current_item': current_item,
|
||||||
|
'total_stories': database.count_stories(),
|
||||||
|
'id_space': 26**NUM_ID_CHARS,
|
||||||
}
|
}
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
@@ -111,7 +113,12 @@ def submit():
|
|||||||
ref = url
|
ref = url
|
||||||
|
|
||||||
existing = database.get_story_by_ref(ref)
|
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}
|
return {'nid': existing.sid}
|
||||||
else:
|
else:
|
||||||
story = dict(id=nid, ref=ref, source=source)
|
story = dict(id=nid, ref=ref, source=source)
|
||||||
@@ -129,9 +136,10 @@ def submit():
|
|||||||
raise Exception('Invalid article')
|
raise Exception('Invalid article')
|
||||||
|
|
||||||
except Exception as e:
|
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())
|
print(traceback.format_exc())
|
||||||
return {'error': str(e)}, 400
|
return {'error': msg.split('\n')[0]}, 400
|
||||||
|
|
||||||
|
|
||||||
@flask_app.route('/api/<sid>')
|
@flask_app.route('/api/<sid>')
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ def alert_tanner(message):
|
|||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
logging.error('Problem alerting Tanner: ' + str(e))
|
logging.error('Problem alerting Tanner: ' + str(e))
|
||||||
|
|
||||||
|
NUM_ID_CHARS = 4
|
||||||
def gen_rand_id():
|
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):
|
def render_md(md):
|
||||||
if md:
|
if md:
|
||||||
|
|||||||
@@ -99,8 +99,6 @@ function App() {
|
|||||||
<br />
|
<br />
|
||||||
<span className='slogan'>Hacker News, Reddit, Lobsters, and Tildes articles rendered in reader mode.</span>
|
<span className='slogan'>Hacker News, Reddit, Lobsters, and Tildes articles rendered in reader mode.</span>
|
||||||
</p>
|
</p>
|
||||||
<Route path='/(|search)' component={Search} />
|
|
||||||
<Route path='/(|search)' component={Submit} />
|
|
||||||
{fullScreenAvailable &&
|
{fullScreenAvailable &&
|
||||||
<Route path='/(|search)' render={() => !isFullScreen ?
|
<Route path='/(|search)' render={() => !isFullScreen ?
|
||||||
<button className='fullscreen' onClick={() => goFullScreen()}>Enter Fullscreen</button>
|
<button className='fullscreen' onClick={() => goFullScreen()}>Enter Fullscreen</button>
|
||||||
@@ -108,6 +106,8 @@ function App() {
|
|||||||
<button className='fullscreen' onClick={() => exitFullScreen()}>Exit Fullscreen</button>
|
<button className='fullscreen' onClick={() => exitFullScreen()}>Exit Fullscreen</button>
|
||||||
} />
|
} />
|
||||||
}
|
}
|
||||||
|
<Route path='/(|search)' component={Search} />
|
||||||
|
<Route path='/(|search)' component={Submit} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Route path='/' exact render={(props) => <Feed {...props} updateCache={updateCache} />} />
|
<Route path='/' exact render={(props) => <Feed {...props} updateCache={updateCache} />} />
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ function Feed({ updateCache }) {
|
|||||||
<details style={{marginBottom: '1rem'}}>
|
<details style={{marginBottom: '1rem'}}>
|
||||||
<summary>Connection error? Click to expand.</summary>
|
<summary>Connection error? Click to expand.</summary>
|
||||||
<p>{error}</p>
|
<p>{error}</p>
|
||||||
|
{stories && <p>Loaded feed from cache.</p>}
|
||||||
</details>
|
</details>
|
||||||
}
|
}
|
||||||
{stories ?
|
{stories ?
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ function Submit() {
|
|||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
{progress ? progress : ''}
|
{progress && <p>{progress}</p>}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user