This commit is contained in:
parent
d5687ad289
commit
68a03d5229
@ -42,7 +42,6 @@ uploadForm.add_argument('nsfw',
|
|||||||
type=bool,
|
type=bool,
|
||||||
required=True)
|
required=True)
|
||||||
|
|
||||||
|
|
||||||
@api.route('/exact/<string:file_name>')
|
@api.route('/exact/<string:file_name>')
|
||||||
@api.route('/<string:file_name>', doc={
|
@api.route('/<string:file_name>', doc={
|
||||||
"description" : "Alias for /exact/{query}"
|
"description" : "Alias for /exact/{query}"
|
||||||
@ -138,3 +137,24 @@ class getRandomFile(Resource):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@api.route('/share/<string:file_name>')
|
||||||
|
@api.doc(description="Returns a share URL from the underlying bucket")
|
||||||
|
class getShareLink(Resource):
|
||||||
|
@api.response(200, 'Sucess')
|
||||||
|
@api.response(500, 'S3 Error')
|
||||||
|
@api.response(404, 'Requested file not found')
|
||||||
|
def get(self, file_name):
|
||||||
|
client = getClientSafely()
|
||||||
|
if client is None:
|
||||||
|
abort(500, "S3 failed to start")
|
||||||
|
|
||||||
|
if file_name in client.getCurrentMemeList():
|
||||||
|
url = client.getShareForMeme(file_name)
|
||||||
|
return {
|
||||||
|
"url": url,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
abort(400, "Requested file '" + file_name + "' not found")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -170,4 +170,25 @@ class Client:
|
|||||||
raise Exception("Requested meme '" + memeName + "' not found")
|
raise Exception("Requested meme '" + memeName + "' not found")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getShareForMeme(self, memeName: str) -> str:
|
||||||
|
"""
|
||||||
|
Returns the S3 bucket's share link for the meme
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not isinstance(memeName, str):
|
||||||
|
raise Exception("paramater memeName is of improper type, expected a str")
|
||||||
|
|
||||||
|
if memeName not in self.getCurrentMemeList():
|
||||||
|
raise Exception("Requested meme '" + memeName + "' not found")
|
||||||
|
|
||||||
|
reply = self.client.get_presigned_url(
|
||||||
|
method="GET",
|
||||||
|
bucket_name=S3_BUCKET,
|
||||||
|
object_name=memeName)
|
||||||
|
|
||||||
|
return reply
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user