Skip to content

Commit

Permalink
feat: Add coupon support
Browse files Browse the repository at this point in the history
  • Loading branch information
noahpistilli committed Jun 30, 2024
1 parent 1e20d0b commit 3865db2
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 3 deletions.
29 changes: 29 additions & 0 deletions templates/room_add_coupon.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "generic/base.html" %}

{% block title %}
Add Link Content
{% endblock %}

{% block content %}
<form action="" method="post" enctype="multipart/form-data">
<p>
{{ form.hidden_tag() }}
<br>
{{ form.movie.label(class_="label") }} {{ form.movie(size=32) }}
<br>
<br>
{{ form.title.label(class_="label") }} {{ form.title(class_="input") }}
<br>
<br>
{{ form.tv.label(class_="label") }} {{ form.tv(size=32) }}
<br>
<br>
{{ form.image_after.label(class_="label") }} {{ form.image_after(size=32) }}
<br>
<br>
{{ form.coupon.label(class_="label") }} {{ form.coupon(size=32) }}
<br>
<br>
<p>{{ form.upload(class_="button is-success") }}</p>
</form>
{% endblock %}
9 changes: 9 additions & 0 deletions theunderground/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,12 @@ class PayCategoryHeaderForm(FlaskForm):
class CreditsForm(FlaskForm):
role_and_name_list = FieldList(StringField())
submit = SubmitField("Create!")


class RoomCouponData(FlaskForm):
title = StringField("Title", validators=[DataRequired()])
tv = FileField("TV Screen Image", validators=[FileRequired()])
image_after = FileField("Image After Movie", validators=[FileRequired()])
movie = FileField("Movie", validators=[FileRequired()])
coupon = FileField("Coupon", validators=[FileRequired()])
upload = SubmitField("Upload")
52 changes: 52 additions & 0 deletions theunderground/room_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,55 @@ def save_pic_data(

# Resize and write poster
write_to_path(f"assets/special/{room_id}/i{pic_num}.img", tv_data)


def save_coupon_data(
movie_id: int,
movie_data: bytes,
image_after_data: bytes,
tv_data: bytes,
coupon_data: bytes,
pic_num: int,
room_id: int,
):
image_after_data_enc = room_big_img_encode(image_after_data)
tv_data = room_tv_encode(tv_data)

if s3:
s3.upload_fileobj(
BytesIO(movie_data), config.r2_bucket_name, f"coupon/{movie_id}-H.mov"
)

s3.upload_fileobj(
BytesIO(image_after_data_enc),
config.r2_bucket_name,
f"coupon/{movie_id}-W.img",
ExtraArgs={"ContentType": "image/jpeg"},
)

s3.upload_fileobj(
BytesIO(tv_data),
config.r2_bucket_name,
f"special/{room_id}/img/d{pic_num}.img",
ExtraArgs={"ContentType": "image/jpeg"},
)

s3.upload_fileobj(
BytesIO(coupon_data),
config.r2_bucket_name,
f"coupon/{movie_id}.enc",
)
else:
movie_dir = "assets/coupon"

# Write movie
write_to_path(f"{movie_dir}/{movie_id}-H.mov", movie_data)

# Resize and write thumbnail
write_to_path(f"{movie_dir}/{movie_id}-W.img", image_after_data_enc)

# Write coupon
write_to_path(f"{movie_dir}/{movie_id}.enc", coupon_data)

# Resize and write poster
write_to_path(f"assets/special/{room_id}/d{pic_num}.img", tv_data)
63 changes: 60 additions & 3 deletions theunderground/room_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
RoomMovieData,
RoomLinkData,
RoomPicData,
RoomCouponData,
)
from theunderground.mobiclip import validate_mobiclip
from theunderground.mobiclip import validate_mobiclip, validate_mobi_dsi
from url1.special import room_content_types as tv
from url1.special.page import special_page_n
from theunderground.room_paths import (
Expand All @@ -23,6 +24,7 @@
save_mov_data,
save_link_data,
save_pic_data,
save_coupon_data,
)

import config
Expand All @@ -45,9 +47,8 @@ def choose_type(room_id):
if value == "Movie":
return redirect(url_for("movie", room_id=room_id))

# TODO: Figure out coupons for Dokodemo
if value == "Coupon":
return redirect(url_for("root"))
return redirect(url_for("coupon", room_id=room_id))

if value == "Website Link":
return redirect(url_for("link", room_id=room_id))
Expand Down Expand Up @@ -288,6 +289,62 @@ def pic(room_id):
return render_template("room_add_pic.html", form=form)


@app.route("/theunderground/rooms/<room_id>/add/coupon", methods=["GET", "POST"])
@oidc.require_login
def coupon(room_id):
form = RoomCouponData()

if form.validate_on_submit():
movie = form.movie.data
thumbnail = form.tv.data
image_after = form.image_after.data
coup = form.coupon.data
if movie and tv:
movie_data = movie.read()
tv_data = thumbnail.read()
image_after_data = image_after.read()
coupon_data = coup.read()
if validate_mobiclip(movie_data):
db_json = RoomMenu(
room_id=room_id,
data=tv.coupon(
photo_id(),
x_id(),
form.title.data,
),
)

validation_ds = validate_mobi_dsi(coupon_data)
if isinstance(validation_ds, bytes):
# We encrypted this movie.
coupon_data = validation_ds

if not validation_ds:
flash("Invalid coupon!")
else:
save_coupon_data(
x_id(),
movie_data,
image_after_data,
tv_data,
coupon_data,
photo_id(),
room_id,
)

db.session.add(db_json)
db.session.commit()

save_page_xml_to_s3(room_id)
return redirect(url_for("list_room_data", room_id=room_id))
else:
flash("Invalid movie!")
else:
flash("Error uploading movie!")

return render_template("room_add_coupon.html", form=form)


def save_page_xml_to_s3(page_id: int):
if s3:
page_xml = special_page_n(page_id)
Expand Down
12 changes: 12 additions & 0 deletions url1/special/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,15 @@ def handle_delivery(movie_id):
def handle_deliveryimg(img):
# Handles movies for room type "delivery"
return send_from_directory("assets/delivery", img + ".img")

@app.route("/url1/coupon/<movie_id>.mov")
def handle_coupon_movie(movie_id):
return send_from_directory("assets/coupon", movie_id + ".mov")

@app.route("/url1/coupon/<movie_id>-W.img")
def handle_coupon_image(movie_id):
return send_from_directory("assets/coupon", movie_id + "-W.img")

@app.route("/url1/coupon/<movie_id>.enc")
def handle_coupon(movie_id):
return send_from_directory("assets/coupon", movie_id + ".enc")

0 comments on commit 3865db2

Please sign in to comment.