6 const userResult = await sqlite.execute({
7 sql: `SELECT id, name, bio, username, email, location, currently_listening, currently_reading_title,
8 currently_reading_author, currently_reading_cover_image, currently_watching_title,
9 currently_watching_platform, currently_watching_poster_image, profile_theme, updated_at, profile_img
10 FROM users WHERE username = ?`,
11 args: [username],
16 }
17
18 const [id, name, bio, usernameRetrieved, email, location, currentlyListening, currentlyReadingTitle, currentlyReadingAuthor, currentlyReadingCoverImage, currentlyWatchingTitle, currentlyWatchingPlatform, currentlyWatchingPosterImage, profile_theme, updated_at, profile_img] = userResult.rows[0];
19
20 const linksResult = await sqlite.execute({
25 const links = linksResult.rows.map(([id, label, url]) => ({ id, label, url }));
26
27 return { id, name, bio, username: usernameRetrieved, email, location, currentlyListening, currentlyReading: { title: currentlyReadingTitle || '', author: currentlyReadingAuthor || '', coverImage: currentlyReadingCoverImage || '' }, currentlyWatching: { title: currentlyWatchingTitle || '', platform: currentlyWatchingPlatform || '', posterImage: currentlyWatchingPosterImage || '' }, links, profile_theme, updated_at, profile_img };
28}
29
39 await sqlite.execute({
40 sql: `UPDATE users SET name = ?, bio = ?, location = ?, currently_listening = ?, currently_reading_title = ?,
41 currently_reading_author = ?, currently_reading_cover_image = ?, currently_watching_title = ?,
42 currently_watching_platform = ?, currently_watching_poster_image = ?, profile_theme = ?,
43 updated_at = CURRENT_TIMESTAMP WHERE id = ? profile_img = ?`,
44 args: [name, bio, location || null, currentlyListening || null, currentlyReading?.title || null, currentlyReading?.author || null, currentlyReading?.coverImage || null, currentlyWatching?.title || null, currentlyWatching?.platform || null, currentlyWatching?.posterImage || null, profile_theme || null, profile_img || userId],
45 });
46}
121
122
123export const uploadProfileImage = async (file, username) => {
124 const blobKey = `profile_img/${username}`;
125 const reader = new FileReader();
140
141
142export async function getProfileImageUrl(username) {
143 const key = `profile_img/${username}`;
144 const imageUrl = await blob.get(key);
145 return imageUrl;
146}
147
1/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
2import { getUserByUsername, updateUser, uploadProfileImage } from "https://esm.town/v/iamseeley/Queries";
3import EditProfilePage from "https://esm.town/v/iamseeley/EditProfilePage";
4import RootLayout from "https://esm.town/v/iamseeley/RootLayout";
41 title: body.currentlyReadingTitle,
42 author: body.currentlyReadingAuthor,
43 coverImage: body.currentlyReadingCoverImage,
44 };
45 const currentlyWatching = {
46 title: body.currentlyWatchingTitle,
47 platform: body.currentlyWatchingPlatform,
48 posterImage: body.currentlyWatchingPosterImage,
49 };
50 const profile_theme = body.profile_theme;
56 const existingUser = await getUserByUsername(username);
57
58 // Handle profile image upload
59 const profileImgFile = body.profile_img;
60 let profileImgUrl = existingUser.profile_img; // Default to existing image URL
61
62 if (profileImgFile && profileImgFile.size) {
63 profileImgUrl = await uploadProfileImage(profileImgFile, username);
64 }
65
11 { name: 'currently_reading_title', type: 'TEXT' },
12 { name: 'currently_reading_author', type: 'TEXT' },
13 { name: 'currently_reading_cover_image', type: 'TEXT' },
14 { name: 'currently_watching_title', type: 'TEXT' },
15 { name: 'currently_watching_platform', type: 'TEXT' },
16 { name: 'currently_watching_poster_image', type: 'TEXT' },
17];
18