Commit 14ca843c5bb32b7a0e789237c7f42f50dbc8dd6f
Adding API for getting media type of a resource at an URL.
| | | | 220 | style.set("type", "text/css") | 220 | style.set("type", "text/css") |
---|
221 | | 221 | |
---|
222 | | 222 | |
---|
| | 223 | @app.route('/getMediaType') |
---|
| | 224 | def getMediaType(): |
---|
| | 225 | request = requests.get(flask.request.args['where']) |
---|
| | 226 | content = request.text |
---|
| | 227 | if imghdr.what('ignore', content) is None: |
---|
| | 228 | return flask.jsonify({'type': 'html'}) |
---|
| | 229 | else: |
---|
| | 230 | return flask.jsonify({'type': 'image'}) |
---|
| | 231 | |
---|
223 | # if the app is run directly from command-line | 232 | # if the app is run directly from command-line |
---|
224 | # assume its being run locally in a dev environment | 233 | # assume its being run locally in a dev environment |
---|
225 | if __name__ == '__main__': | 234 | if __name__ == '__main__': |
---|