async def assets(ctx, folder, filename): """Serve the images of the /img/ and other folders.""" location = folder + '/' + filename with open(location, mode='rb') as file: stream = file.read() header = {'Content-Type': mimetypes.guess_type(location)[0]} return util.Response(stream, status=200, headers=header)
async def assets(ctx, ourid): """Serve the content of the server.""" try: location = 'static/' + ourid filetype = ourid.split('.')[1] with open(location, mode='rb') as file: stream = file.read() header = { 'Content-Type': mimetypes.guess_type(location)[0] } return util.Response(stream, status=200, headers=header) except: response = r.table(tbname).get(ourid).run(conn) statisticTable = r.table(tbname).get(ourid).run(conn) try: newcount = statisticTable['count'] + 1 except: newcount = 1 r.table(tbname).get(ourid).update({"count": newcount}).run(conn) if response is None: return util.Response(status=404) if settings['monetise']['enabled']: with open(settings['templates']['monetise']) as file: stream = file.read() stream = stream.replace("{ LINK }", statisticTable['redirect_url']) header = { 'Content-Type': "text/html" } return util.Response(stream, status=200, headers=header) else: return util.Response("<meta http-equiv=\"refresh\" content=\"0; url=" + statisticTable['redirect_url'] + "/\" />", status=200)
async def image(ctx, filename): """Serve the images of the /img/ and other folders.""" location = 'img/' + filename filetype = filename.split('.')[1] with open(location, mode='rb') as file: stream = file.read() header = {'Content-Type': 'image/' + filetype} return util.Response(stream, status=200, headers=header)
async def tweetjson(ctx): """Host the API in which you can get random birbs from.""" if not settings['endpoints']['json']['enabled']: return url = randint(0, len(files) - 1) header = {'Content-Type': 'application/javascript'} return util.Response(json.dumps({'file': files[url]}), status=200, headers=header)
async def tweetrandom(ctx): """Host the API in which you can get random birbs from.""" if not settings['endpoints']['random']['enabled']: return url = randint(0, len(files) - 1) location = 'img/' + files[url] with open(location, mode='rb') as file: stream = file.read() header = {'Content-Type': mimetypes.guess_type(location)[0]} return util.Response(stream, status=200, headers=header)