Skip to content

Commit

Permalink
feat: fix stupid bug
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfromyeg committed Dec 29, 2023
1 parent 027d7b7 commit 6e4eeea
Show file tree
Hide file tree
Showing 8 changed files with 862 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Custom

# New data directories
*.db

content/**/**
!content/.gitkeep

Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,17 @@ docker push michaelfromyeg/bereal-wrapped-cli

### Current Developments

* [ ] Add a SQLite database; expire videos after 24-hours
* [ ] Make files, paths specific to user (i.e., a phone number)
* [ ] Clean-up steps
* [x] Add a SQLite database; expire videos after 24-hours
* [x] Make files, paths specific to user (i.e., a phone number)
* [x] Clean-up steps
* [ ] Add 'no sound' option
* [x] Default music
* [ ] Display RealMoji
* [ ] Toggle date label setting
* [ ] Show render progress on webpage
* [ ] Batching algorithm for videos
* [ ] Better phone number support (start with CLI)
* [x] Better phone number support (start with CLI)
* [ ] Move files to cloud storage (e.g., AWS)

## Remarks

Expand Down
8 changes: 5 additions & 3 deletions bereal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Callable

from .bereal import memories, send_code, verify_code
from .images import cleanup_images, create_images
from .images import create_images
from .logger import logger
from .utils import CONTENT_PATH, YEARS, Mode, str2mode, year2dates
from .videos import build_slideshow
Expand Down Expand Up @@ -90,7 +90,7 @@ def validate() -> tuple[str, str] | None:
token = retry_api(
"Verifying your authentication token...",
verify_code,
{"session": otp_session, "code": user_code},
{"otp_session": otp_session, "otp_code": user_code},
"Hmm... there was an issue verifying the code.",
)
if token is None:
Expand Down Expand Up @@ -185,7 +185,9 @@ def step(idx: int, retval: dict[str, Any] | None) -> dict[str, Any] | None:
video_file = f"{short_token}-{retval['phone']}-{retval['year']}.mp4"

build_slideshow(retval["image_folder"], retval["song_path"], video_file, retval["mode"])
cleanup_images(retval["phone"], retval["year"])

# TODO(michaelfromyeg): delete images in production
# cleanup_images(retval["phone"], retval["year"])
case _:
raise ValueError(f"Invalid step: {idx}")

Expand Down
4 changes: 2 additions & 2 deletions bereal/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ def create_images(
os.makedirs(primary_folder, exist_ok=True)
os.makedirs(secondary_folder, exist_ok=True)

os.makedirs(output_folder, exist_ok=True)

if os.path.isdir(output_folder):
logger.info("Skipping 'create_images' stage; already created!")
return output_folder

os.makedirs(output_folder, exist_ok=True)

# Get a list of primary filenames
primary_filenames = os.listdir(primary_folder)

Expand Down
9 changes: 6 additions & 3 deletions bereal/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from itsdangerous import SignatureExpired, URLSafeTimedSerializer

from .bereal import memories, send_code, verify_code
from .images import cleanup_images, create_images
from .images import create_images
from .logger import logger
from .utils import (
CONTENT_PATH,
Expand All @@ -38,7 +38,8 @@
else:
CORS(app, resources={r"/*": {"origins": "https://michaeldemar.co"}})

app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///tokens.db"
basedir = os.path.abspath(os.path.dirname(__file__))
app.config["SQLALCHEMY_DATABASE_URI"] = f'sqlite:///{os.path.join(basedir, "tokens.db")}'
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)

Expand Down Expand Up @@ -150,7 +151,9 @@ def create_video() -> tuple[Response, int]:

image_folder = create_images(phone, year)
build_slideshow(image_folder, song_path, video_file, mode)
cleanup_images(phone, year)

# TODO(michaelfromyeg): delete images in production
# cleanup_images(phone, year)

return jsonify({"videoUrl": video_file}), 200

Expand Down
24 changes: 21 additions & 3 deletions client/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const BASE_URL = IS_PRODUCTION
: "http://localhost:5000";

const Footer: React.FC = () => {
const [loading, setLoading] = useState<boolean>(false);

const [stage, setStage] = useState<Stage>("phoneInput");
const [phoneNumber, setPhoneNumber] = useState<string>("");
const [countryCode, setCountryCode] = useState<string>("");
Expand All @@ -30,6 +32,8 @@ const Footer: React.FC = () => {

setStage("settings");
} else {
setLoading(true);

const response = await axios.post(`${BASE_URL}/request-otp`, {
phone: `${countryCode}${phoneNumber}`,
});
Expand All @@ -42,11 +46,14 @@ const Footer: React.FC = () => {
}
} catch (error) {
console.error("Error sending OTP:", error);
} finally {
setLoading(false);
}
};

const handleOtpSubmit = async () => {
try {
setLoading(true);
const response = await axios.post(`${BASE_URL}/validate-otp`, {
phone: `${countryCode}${phoneNumber}`,
otp_session: otpSession,
Expand All @@ -67,6 +74,8 @@ const Footer: React.FC = () => {
setStage("settings");
} catch (error) {
console.error("Error validating OTP:", error);
} finally {
setLoading(false);
}
};

Expand All @@ -84,6 +93,7 @@ const Footer: React.FC = () => {
}

try {
setLoading(true);
const response = await axios.post(`${BASE_URL}/video`, formData, {
headers: {
"Content-Type": "multipart/form-data",
Expand All @@ -98,6 +108,8 @@ const Footer: React.FC = () => {
setStage("videoDisplay");
} catch (error) {
console.error("Error submitting settings:", error);
} finally {
setLoading(false);
}
};

Expand Down Expand Up @@ -137,7 +149,9 @@ const Footer: React.FC = () => {
value={phoneNumber}
onChange={(e) => setPhoneNumber(e.target.value)}
/>
<button onClick={handlePhoneSubmit}>Send OTP</button>
<button onClick={handlePhoneSubmit} disabled={loading}>
Send OTP
</button>
</>
)}
{stage === "otpInput" && (
Expand All @@ -155,7 +169,9 @@ const Footer: React.FC = () => {
value={otpCode}
onChange={(e) => setOtpCode(e.target.value)}
/>
<button onClick={handleOtpSubmit}>Validate OTP</button>
<button onClick={handleOtpSubmit} disabled={loading}>
Validate OTP
</button>
</>
)}
{stage === "settings" && (
Expand Down Expand Up @@ -200,7 +216,9 @@ const Footer: React.FC = () => {
<option value="classic">Classic (30 seconds)</option>
<option value="full">Full</option>
</select>
<button onClick={handleSettingsSubmit}>Submit</button>
<button onClick={handleSettingsSubmit} disabled={loading}>
Submit
</button>
</>
)}
{stage === "videoDisplay" && (
Expand Down
Loading

0 comments on commit 6e4eeea

Please sign in to comment.