Skip to content

Commit

Permalink
Merge pull request #283 from madeofpendletonwool/fix-cicd
Browse files Browse the repository at this point in the history
Upgraded depends - 0.6.6 finalized
  • Loading branch information
madeofpendletonwool authored Sep 21, 2024
2 parents 9f13c79 + 31d32e1 commit 423164f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 28 deletions.
3 changes: 2 additions & 1 deletion clients/clientapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def setup_connection_pool():
pool_name="pinepods_api_pool",
pool_size=32,
pool_reset_session=True,
collation="utf8mb4_general_ci",
host=db_host,
port=db_port,
user=db_user,
Expand Down Expand Up @@ -1540,7 +1541,7 @@ class AddCategoryData(BaseModel):
@app.post("/api/data/add_category")
async def api_add_category(data: AddCategoryData, cnx=Depends(get_database_connection),
api_key: str = Depends(get_api_key_from_header)):
is_valid_key = database_functions.functions.verify_api_key(cnx, "postgresql", api_key)
is_valid_key = database_functions.functions.verify_api_key(cnx, database_type, api_key)
if not is_valid_key:
raise HTTPException(status_code=403, detail="Your API key is either invalid or does not have correct permission")

Expand Down
5 changes: 5 additions & 0 deletions completed_todos.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pinepods-1 | warnings.warn("tzname {tzname} identified but not understood. "
- [] Implement episode filtering on local download page
- [] Implement episode filtering on queue page
- [] Implement episode filtering on search page
- [] Add loading spinner when adding podcast via people page
- [] Fix issues with refreshing

Version 0.6.6

Expand All @@ -54,6 +56,9 @@ Version 0.6.6
- [x] Added loading spinner when opening an episode to ensure you don't momentarily see the wrong episode
- [x] Improve Filtering css so that things align correctly
- [x] Made the button to add and remove podcasts more consistent (Sometimes it was just not registering)
- [x] Upgraded pulldown-cmark library
- [x] Upgraded python mysql-connection library to 9
- [x] Upgraded chrono-tz rust library

CI/CD:

Expand Down
22 changes: 16 additions & 6 deletions database_functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4472,6 +4472,7 @@ def get_queue_value(result, key, default=None):


def remove_queued_pod(database_type, cnx, episode_id, user_id):
print(f'ep id: {episode_id}')
if database_type == "postgresql":
from psycopg.rows import dict_row
cnx.row_factory = dict_row
Expand All @@ -4494,22 +4495,31 @@ def remove_queued_pod(database_type, cnx, episode_id, user_id):
cursor.execute(get_queue_data_query, (episode_id, user_id))
queue_data = cursor.fetchone()

logging.debug(f"Queue data: {queue_data}")
print(f"Queue data: {queue_data}")

if queue_data is None:
logging.warning(f"No queued episode found with ID {episode_id}")
print(f"No queued episode found with ID {episode_id}")
cursor.close()
return None

# Handle both dictionary and tuple results
episode_id = get_queue_value(queue_data, "EpisodeID")
removed_queue_position = get_queue_value(queue_data, "QueuePosition")

# episode_id = get_queue_value(queue_data, "EpisodeID")
removed_queue_position = queue_data['queueposition'] if database_type == "postgresql" else queue_data['QueuePosition']

print(f'delete on the way')
delete_query = (
'DELETE FROM "EpisodeQueue" WHERE UserID = %s AND EpisodeID = %s' if database_type == "postgresql" else
"DELETE FROM EpisodeQueue WHERE UserID = %s AND EpisodeID = %s"
)
cursor.execute(delete_query, (user_id, episode_id))
affected_rows = cursor.rowcount
print(f'Rows affected by delete: {affected_rows}')

if affected_rows == 0:
print(f"No rows were deleted. UserID: {user_id}, EpisodeID: {episode_id}")
return {"status": "error", "message": "No matching row found for deletion"}

print(f'ep deleted')
cnx.commit()

update_queue_query = (
Expand All @@ -4519,7 +4529,7 @@ def remove_queued_pod(database_type, cnx, episode_id, user_id):
cursor.execute(update_queue_query, (user_id, removed_queue_position))
cnx.commit()

logging.info(f"Successfully removed episode from queue.")
print(f"Successfully removed episode from queue.")
cursor.close()

return {"status": "success"}
Expand Down
4 changes: 2 additions & 2 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builder stage for compiling the Yew application
FROM rust:alpine3.19 as builder
FROM rust:alpine3.19 AS builder

# Install build dependencies
RUN apk update && apk upgrade && \
Expand Down Expand Up @@ -67,7 +67,7 @@ COPY clients/ /pinepods/clients/
COPY database_functions/ /pinepods/database_functions/
RUN chmod +x /pinepods/startup/startup.sh

ENV APP_ROOT /pinepods
ENV APP_ROOT=/pinepods

# Define the build argument
ARG PINEPODS_VERSION
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mysql-connector-python==8.1.0
mysql-connector-python
requests
python-dateutil
python-dateutil
Expand Down
47 changes: 31 additions & 16 deletions startup/setupdatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def hash_password(password: str):
user=db_user,
password=db_password,
database=db_name,
charset='utf8mb4'
charset='utf8mb4',
collation="utf8mb4_general_ci"
)

# Create a cursor to execute SQL statements
Expand Down Expand Up @@ -196,30 +197,44 @@ def user_exists(cursor, username):

def insert_or_update_user(cursor, hashed_password):
try:
if user_exists(cursor, 'guest'):
cursor.execute("""
UPDATE Users
SET Fullname = %s, Username = %s, Email = %s, Hashed_PW = %s, IsAdmin = %s
WHERE Username = %s
""", ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, 'guest'))
logging.info("Updated existing 'guest' user to 'bt' user.")
elif user_exists(cursor, 'bt'):
# First, check if 'background_tasks' user exists
cursor.execute("SELECT * FROM Users WHERE Username = %s", ('background_tasks',))
existing_user = cursor.fetchone()

if existing_user:
# Update existing 'background_tasks' user
cursor.execute("""
UPDATE Users
SET Fullname = %s, Email = %s, Hashed_PW = %s, IsAdmin = %s
WHERE Username = %s
""", ('Background Tasks', 'inactive', hashed_password, False, 'background_tasks'))
logging.info("Updated existing 'background_tasks' user.")
else:
# Check for 'guest' or 'bt' users to update
cursor.execute("SELECT Username FROM Users WHERE Username IN ('guest', 'bt')")
old_user = cursor.fetchone()

if old_user:
# Update old user to 'background_tasks'
cursor.execute("""
UPDATE Users
SET Fullname = %s, Username = %s, Email = %s, Hashed_PW = %s, IsAdmin = %s
WHERE Username = %s
""", ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, 'bt'))
logging.info("Updated existing 'bt' user.")
else:
cursor.execute("""
""", ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False, old_user[0]))
logging.info(f"Updated existing '{old_user[0]}' user to 'background_tasks' user.")
else:
# Insert new 'background_tasks' user
cursor.execute("""
INSERT INTO Users (Fullname, Username, Email, Hashed_PW, IsAdmin)
VALUES (%s, %s, %s, %s, %s)
""", ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False))
logging.info("Inserted new 'background_tasks' user.")
""", ('Background Tasks', 'background_tasks', 'inactive', hashed_password, False))
logging.info("Inserted new 'background_tasks' user.")


except Exception as e:
print(f"Error inserting or updating user: {e}")
logging.error("Error inserting or updating user: %s", e)

# Rollback the transaction in case of error

try:
# Generate and hash the password
Expand Down
4 changes: 2 additions & 2 deletions web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ gloo-utils = "0.2.0"
gloo-events = "0.2.0"
md5 = "0.7.0"
ammonia = "4.0.0"
pulldown-cmark = "0.11.0"
pulldown-cmark = "0.12.1"
async-std = "1.12.0"
argon2 = "0.5.3"
rand = "0.8.5"
Expand All @@ -67,7 +67,7 @@ percent-encoding = "2.3.1"
data-encoding = "2.6.0"
url = "2.5.2"
serde-wasm-bindgen = "0.6.5"
chrono-tz = "0.9.0"
chrono-tz = "0.10.0"
futures = "0.3.30"
futures-util = "0.3.30"
gloo-file = "0.3.0"
Expand Down

0 comments on commit 423164f

Please sign in to comment.