Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Carbaugh committed Nov 30, 2015
0 parents commit 34aa81f
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{py,rst,ini}]
indent_style = space
indent_size = 4

[*.{html,css,scss,js,json,yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
*~
*.DS_Store
*.lock
*.swp
*.out
*.pid
*.pyc
*.sql
*.sqlite
*.db
*.swp
*~
__pycache__/
/tmp/
.bundle/
.sass-cache/
bower_components/
bundle/
dist/
tests/
node_modules/
.env
npm-debug.log
newrelic.ini
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2015, ISL

All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ogs3proxy nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: waitress-serve --port=$PORT web:app

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Open Graph S3 Proxy

Try [locally](http://localhost:8000/2015/07/[email protected]?fb)
25 changes: 25 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "ogs3proxy",
"env":{
"REDIRECT_URL": {
"description": "URL for non-Facebook redirects"
},
"OG_TITLE": {
"description": "Object Open Graph title"
},
"OG_DESCRIPTION": {
"description": "Object Open Graph description"
},
"S3_BUCKET": {
"description": "The S3 bucket to pull images from"
},
"SECRET_KEY": {
"generator": "secret"
}
},
"buildpacks": [
{
"url": "https://github.com/heroku/heroku-buildpack-python"
}
]
}
9 changes: 9 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PORT=8000
DEBUG=True

S3_BUCKET=media.isl.co
OG_TITLE=A digital agency founded on invention.
OG_DESCRIPTION=ISL invents digital & physical experiences for the world’s biggest brands. Our designers, developers, marketers and makers build everything from apps, to connected devices, to wildly creative campaigns that reach audiences globally. Take a look for yourself!
REDIRECT_URL=https://isl.co

SECRET_KEY=notasecret
4 changes: 4 additions & 0 deletions mo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
domain: ogs3proxy.herokuapp.com
heroku:
staging: ogs3proxy-staging
production: ogs3proxy-prod
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Flask==0.10.1
waitress==0.8.10
python-decouple==2.3
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.4.2
12 changes: 12 additions & 0 deletions templates/opengraph.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="utf-8">
<meta property="og:type" content="website" />
<meta property="og:title" content="{{ og_title }}" />
<meta property="og:description" content="{{ og_description }}" />
<meta property="og:image" content="{{ og_image }}" />
<meta property="og:url" content="{{ og_url }}" />
</head>
<body></body>
</html>
46 changes: 46 additions & 0 deletions web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from decouple import config
from flask import Flask, redirect, render_template, request

try:
from urlparse import urljoin
except ImportError:
from urllib.parse import urljoin

S3_BUCKET = config('S3_BUCKET')
REDIRECT_URL = config('REDIRECT_URL')
OG_TITLE = config('OG_TITLE')
OG_DESCRIPTION = config('OG_DESCRIPTION')

S3_ROOT = 'https://s3.amazonaws.com/'

app = Flask(__name__)


def is_facebook(ua):
return ua.startswith('facebookexternalhit') or ua == 'Facebot'


@app.route("/<path:path>", methods=['GET'])
def opengraph(path):

ua = request.headers.get('User-Agent')

if is_facebook(ua) or 'fb' in request.args:

context = {
'og_title': OG_TITLE,
'og_description': OG_DESCRIPTION,
'og_image': urljoin(S3_ROOT, '{}/{}'.format(S3_BUCKET, path)),
'og_url': REDIRECT_URL,
}
return render_template('opengraph.html', **context)

else:

return redirect(REDIRECT_URL)


if __name__ == "__main__":
DEBUG = config('DEBUG', default=False, cast=bool)
PORT = config('PORT', default=8000, cast=int)
app.run(debug=DEBUG, port=PORT)

0 comments on commit 34aa81f

Please sign in to comment.