diff --git a/pub.py b/pub.py index 3e09561..8fb15c4 100755 --- a/pub.py +++ b/pub.py @@ -5,6 +5,7 @@ import hashlib import os import subprocess import sys +from functools import cache import boto3 @@ -37,18 +38,25 @@ def cache_length(ext): else: return '31536000' +@cache +def current_keys(): + print('Fetching existing keys in {}'.format(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 keys + def upload_file(filename, overwrite=True): - print('Uploading {} to {}/{}'.format(filename, BUCKET, filename)) ext = filename.split('.')[-1] - if not overwrite: - try: - existing = s3.get_object(Bucket=BUCKET, Key=filename) - print('\tSkipping existing key ', filename) - return - except: - pass + if not overwrite and filename in current_keys(): + print('Skipping existing key {}'.format(filename)) + return + print('Uploading {} to {}/{}'.format(filename, BUCKET, filename)) s3.upload_file(filename, BUCKET, filename, ExtraArgs={ 'ACL': 'public-read', 'ContentType': TYPE_MAP[ext], diff --git a/src/components/root.tsx b/src/components/root.tsx index e9ef2a1..98300e9 100644 --- a/src/components/root.tsx +++ b/src/components/root.tsx @@ -21,33 +21,24 @@ export class Root extends React.PureComponent { // innerWidth gets messed up when rotating phones from landscape -> portrait, // and chrome seems to not report innerWidth correctly when scrollbars are present private _viewWidth = (): number => { - // iOS Safari does not set outerWidth/outerHeight - if (!window.outerWidth) { - return window.innerWidth; - } - return Math.min( window.innerWidth, - window.outerWidth, - document.getElementById("mount")!.clientWidth + window.outerWidth || Infinity, + document.getElementById("mount")!.clientWidth || Infinity ); }; - private _viewHeight = (): number => { - // iOS Safari does not set outerWidth/outerHeight - if (!window.outerHeight) { - return window.innerHeight; - } + private _viewHeight = (): number => { return Math.min( window.innerHeight, - window.outerHeight, - document.body.clientHeight + window.outerHeight || Infinity, + document.body.clientHeight || Infinity ); }; state: State = { gridHeights: [], - pageBottom: window.innerHeight + window.pageYOffset, + pageBottom: this._viewHeight() + window.pageYOffset, width: this._viewWidth(), height: this._viewHeight() }; @@ -123,7 +114,7 @@ export class Root extends React.PureComponent { private _onViewChange = () => { this.setState({ - pageBottom: window.innerHeight + window.pageYOffset, + pageBottom: this._viewHeight() + window.pageYOffset, width: this._viewWidth(), height: this._viewHeight(), });