Fix inventory bucket access
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
This commit is contained in:
parent
9c329e31be
commit
c1e6872e8e
@ -13,7 +13,8 @@ def file_exists(path):
|
|||||||
ENVIRONMENT_TYPE = getenv_in("ENVIRONMENT_TYPE", "DEV", "PROD")
|
ENVIRONMENT_TYPE = getenv_in("ENVIRONMENT_TYPE", "DEV", "PROD")
|
||||||
|
|
||||||
SECRET_KEY = os.environ["SECRET_KEY"]
|
SECRET_KEY = os.environ["SECRET_KEY"]
|
||||||
AWS_ENDPOINT_URL = os.environ["AWS_ENDPOINT_URL"]
|
AWS_S3_ENDPOINT_URL = os.environ["AWS_S3_ENDPOINT_URL"]
|
||||||
|
BUCKET_NAME = os.environ["BUCKET_NAME"]
|
||||||
INVENTORY_ASSETS_BASE_URL = os.environ["INVENTORY_ASSETS_BASE_URL"]
|
INVENTORY_ASSETS_BASE_URL = os.environ["INVENTORY_ASSETS_BASE_URL"]
|
||||||
MONGO_URI = os.environ["MONGO_URI"]
|
MONGO_URI = os.environ["MONGO_URI"]
|
||||||
MEMBERS_HOST = os.environ["MEMBERS_HOST"]
|
MEMBERS_HOST = os.environ["MEMBERS_HOST"]
|
||||||
|
@ -25,8 +25,15 @@ def view_inventory_view(item_id):
|
|||||||
if not item["inventory"].get("public"):
|
if not item["inventory"].get("public"):
|
||||||
return do_login()
|
return do_login()
|
||||||
template = "inventory_view_public.html"
|
template = "inventory_view_public.html"
|
||||||
base_url = const.INVENTORY_ASSETS_BASE_URL
|
bucket=get_bucket()
|
||||||
photo_url = "%s/kspace-inventory/%s" % (base_url, item_id)
|
photo_url = bucket.generate_presigned_url(
|
||||||
|
ClientMethod='get_object',
|
||||||
|
Params={
|
||||||
|
'Bucket': const.BUCKET_NAME,
|
||||||
|
'Key': item_id
|
||||||
|
},
|
||||||
|
ExpiresIn=3600
|
||||||
|
)
|
||||||
return render_template(template , **locals())
|
return render_template(template , **locals())
|
||||||
|
|
||||||
def fetch_members_select():
|
def fetch_members_select():
|
||||||
@ -213,7 +220,7 @@ def is_image_ext(filename):
|
|||||||
|
|
||||||
def get_bucket():
|
def get_bucket():
|
||||||
return boto3.client('s3',
|
return boto3.client('s3',
|
||||||
endpoint_url=const.AWS_ENDPOINT_URL,
|
endpoint_url=const.AWS_S3_ENDPOINT_URL,
|
||||||
config=boto3.session.Config(signature_version='s3v4'),
|
config=boto3.session.Config(signature_version='s3v4'),
|
||||||
region_name='us-east-1')
|
region_name='us-east-1')
|
||||||
|
|
||||||
@ -238,7 +245,7 @@ def upload_photo(item_id):
|
|||||||
return "Image must have smallest dimension of at least 576px", 400
|
return "Image must have smallest dimension of at least 576px", 400
|
||||||
bucket = get_bucket()
|
bucket = get_bucket()
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
bucket.upload_fileobj(file, 'kspace-inventory', item_id)
|
bucket.upload_fileobj(file, const.BUCKET_NAME, item_id)
|
||||||
|
|
||||||
db.inventory.update_one({ "_id": ObjectId(item_id) }, {"$set": {"has_photo": True}})
|
db.inventory.update_one({ "_id": ObjectId(item_id) }, {"$set": {"has_photo": True}})
|
||||||
delete_thumbs(item)
|
delete_thumbs(item)
|
||||||
|
Loading…
Reference in New Issue
Block a user