Add meme name to header
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tyler Perkins 2023-03-09 20:28:41 -05:00
parent ca239183f5
commit 6c8b9dfc45

View File

@ -1,6 +1,6 @@
from flask_restx import Namespace, Resource, fields from flask_restx import Namespace, Resource, fields
from flask_restx import reqparse from flask_restx import reqparse
from flask import make_response, abort, request from flask import make_response, abort, request, Response
from minio.commonconfig import Tags from minio.commonconfig import Tags
from werkzeug.datastructures import FileStorage from werkzeug.datastructures import FileStorage
from api.clientGetter import getClientSafely from api.clientGetter import getClientSafely
@ -103,7 +103,11 @@ class getRandomFile(Resource):
if client is None: if client is None:
abort(500, "S3 failed to start") abort(500, "S3 failed to start")
choice = random.choice(tuple(client.getCurrentMemeList())) choice = random.choice(tuple(client.getCurrentMemeList()))
return make_response(client.getMeme(choice))
response = make_response(client.getMeme(choice))
response.headers['X-Meme-Name'] = choice
return response
@api.route('/psuedorandom') @api.route('/psuedorandom')
@api.doc(description="Returns a psuedorandom meme. Will not return the same meme for a set number of requests") @api.doc(description="Returns a psuedorandom meme. Will not return the same meme for a set number of requests")
@ -129,5 +133,8 @@ class getRandomFile(Resource):
logging.debug("Contents of cache : " + str(self.cache)) logging.debug("Contents of cache : " + str(self.cache))
return make_response(client.getMeme(choice)) response = make_response(client.getMeme(choice))
response.headers['X-Meme-Name'] = choice
return response