Fix pagination
- Paginate through S3 keys - Off-by-one in bench page navigation
This commit is contained in:
@@ -20,9 +20,9 @@
|
|||||||
{0}
|
{0}
|
||||||
</div>
|
</div>
|
||||||
<div class="nav">
|
<div class="nav">
|
||||||
<a href="{3}">Next</a>
|
<a href="{4}">Next</a>
|
||||||
<a href="/">Home</a>
|
<a href="/">Home</a>
|
||||||
<a href="{2}">Prev</a>
|
<a href="{3}">Prev</a>
|
||||||
</nav>
|
</nav>
|
||||||
</main>
|
</main>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
27
pub.py
27
pub.py
@@ -30,22 +30,23 @@ TYPE_MAP = {
|
|||||||
def current_keys():
|
def current_keys():
|
||||||
print('Fetching existing keys in {}'.format(BUCKET))
|
print('Fetching existing keys in {}'.format(BUCKET))
|
||||||
existing = s3.list_objects_v2(Bucket=BUCKET)
|
existing = s3.list_objects_v2(Bucket=BUCKET)
|
||||||
|
keys = set([content['Key'] for content in existing['Contents']])
|
||||||
|
while existing['IsTruncated']:
|
||||||
|
existing = s3.list_objects_v2(Bucket=BUCKET, ContinuationToken=existing['NextContinuationToken'])
|
||||||
|
keys = keys.union(set([content['Key'] for content in existing['Contents']]))
|
||||||
|
|
||||||
return [content['Key'] for content in existing['Contents']]
|
return keys
|
||||||
|
|
||||||
|
EXISTING_KEYS = current_keys()
|
||||||
|
|
||||||
def upload_file(filename, overwrite=True):
|
def upload_file(filename, overwrite=True):
|
||||||
|
if not overwrite and filename in EXISTING_KEYS:
|
||||||
|
print('Skipping existing key {}'.format(filename))
|
||||||
|
return
|
||||||
|
|
||||||
print('Uploading {} to {}/{}'.format(filename, BUCKET, filename))
|
print('Uploading {} to {}/{}'.format(filename, BUCKET, filename))
|
||||||
ext = filename.split('.')[-1]
|
ext = filename.split('.')[-1]
|
||||||
|
|
||||||
if not overwrite:
|
|
||||||
try:
|
|
||||||
existing = s3.get_object(Bucket=BUCKET, Key=filename)
|
|
||||||
print('\tSkipping existing key ', filename)
|
|
||||||
return
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
s3.upload_file(filename, BUCKET, filename, ExtraArgs={
|
s3.upload_file(filename, BUCKET, filename, ExtraArgs={
|
||||||
'ACL': 'public-read',
|
'ACL': 'public-read',
|
||||||
'ContentType': TYPE_MAP[ext],
|
'ContentType': TYPE_MAP[ext],
|
||||||
@@ -140,20 +141,16 @@ def upload_bench():
|
|||||||
grid = filter_filenames(os.listdir('bench'), 'html')
|
grid = filter_filenames(os.listdir('bench'), 'html')
|
||||||
view = filter_filenames(os.listdir('bench/view'), 'html')
|
view = filter_filenames(os.listdir('bench/view'), 'html')
|
||||||
|
|
||||||
existing_keys = current_keys()
|
|
||||||
|
|
||||||
for f in grid:
|
for f in grid:
|
||||||
upload_file('bench/{}'.format(f))
|
upload_file('bench/{}'.format(f))
|
||||||
|
|
||||||
for f in view:
|
for f in view:
|
||||||
key = 'bench/view/{}'.format(f)
|
key = 'bench/view/{}'.format(f)
|
||||||
if key not in existing_keys:
|
upload_file('bench/view/{}'.format(f), overwrite=False)
|
||||||
upload_file('bench/view/{}'.format(f))
|
|
||||||
|
|
||||||
for f in img_files:
|
for f in img_files:
|
||||||
key = 'img/bench/{}'.format(f)
|
key = 'img/bench/{}'.format(f)
|
||||||
if key not in existing_keys:
|
upload_file(key, overwrite=False)
|
||||||
upload_file(key, overwrite=False)
|
|
||||||
|
|
||||||
def upload_img():
|
def upload_img():
|
||||||
files = filter_filenames(os.listdir('img'), ['jpg', 'webp'])
|
files = filter_filenames(os.listdir('img'), ['jpg', 'webp'])
|
||||||
|
|||||||
Reference in New Issue
Block a user