rbs@u2
Home
Php_u2
Html #1
Html #2
Html #3
Html #4
JS #1
JS #2
JS #3
JS #4
JsApi #1
JsApi #2
JsApi #3
JsApi #4
JsApi_u4
all-files
ori-v2
master
user
Logout
dsg
tool css
bootstrtap 5.3
auth
profile
waste
waste_group
venue
vehicle
event
comment
notification
discover
post
scanner
to_delete
const fetch = require('node-fetch'); async function profile(v) { let url=`${v.api}/profile/add-profile-links/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function profile(v) { let url=`${v.api}/profile/follow-user/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function profile(v) { let url=`${v.api}/profile/remove-profile-link/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function profile(v) { let url=`${v.api}/profile/update-cover-image/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function profile(v) { let url=`${v.api}/profile/update-profile-image/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function profile(v) { let url=`${v.api}/profile/update-social-links/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } const profile = { profile, profile, profile, profile, profile, profile, } module.exports = profile
Save
$id2, 'user_id'=>$js->user_id, 'url'=>$js->link->url, 'label'=>$js->link->label, ); $udt=array( 'url'=>$js->link->url, 'label'=>$js->link->label, ); InsertUpdate($db,"user_external_links",$idt,$udt,0); $sql="SELECT `id` from `user_external_links` where `url`='".$js->link->url."' and `user_id`=".$js->user_id.""; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)>0) { $r = mysqli_fetch_assoc($res); $id=$r['id']; } else { $id=0; } $dt['id']=$id; $dt['success']=true; $dt['message']="Profile link added"; return $dt; } function follow_user($js){ global $ar,$db; $dt=array(); $sql="SELECT * from `user_follow` where parent_id=".$js->following_id." and user_id=".$js->follower_id; //echo $sql8."
"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==0) { $idt=array( 'parent_id'=>$js->following_id, 'user_id'=>$js->follower_id, ); Insert($db,"user_follow",$idt,0); $dt['success']=true; $dt['message']="User followed"; } else { Delete($db,"user_follow","parent_id=".$js->following_id." and user_id=".$js->follower_id,0); $dt['success']=true; $dt['message']="User unfollowed"; } return $dt; } function remove_profile_link($js){ global $ar,$db; $dt=array(); Delete($db,"user_external_links","id=".$js->link_id); $dt['success']=true; $dt['message']="Profile link removed"; return $dt; } function update_cover_image($js){ global $ar,$db; $dt=array(); $user_id=$js->user_id; $data=$js->image; $image_info = getimagesize($data); $extension = (isset($image_info["mime"]) ? explode('/', $image_info["mime"] )[1]: ""); $dt['type']=$extension; $tmp_file=$ar['img_path']."users/tmp/".$user_id.".".$extension; $sub_folder=$ar['img_path']."/users/".$user_id; if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); } $sub_folder_p=$ar['img_path']."/users/".$user_id."/c"; if(!is_dir($sub_folder_p)){ mkdir($sub_folder_p, 0755); } $new_file=genRandom(10).".".$extension; $dt['newfile']=$new_file; $data = str_replace('data:image/'.$extension.';base64,', '', $data); $data = str_replace(' ','+',$data); $bin = base64_decode($data); if ($bin === false) { $dt['info']="convert invalid"; } //tmp file file_put_contents($tmp_file, $bin); ini_set('display_errors', '0'); resize_crop_image(1200,760,$tmp_file,$sub_folder_p."/".$new_file); unlink($tmp_file); $sql="SELECT `seq` from `images` where `modul`='users' and `item_id`=".$user_id." order by `seq` desc limit 1"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==1) { $r = mysqli_fetch_assoc($res); $seq2=$r['seq']+1; } else { $seq2=1; } $sql2="SELECT `id` from `images` order by `id` desc limit 1"; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)==1) { $r2 = mysqli_fetch_assoc($res2); $id2=$r2['id']+1; } else { $id2=1; } $idt=array( 'id'=>$id2, 'modul'=>'users', 'item_id'=>$user_id, 'seq'=>$seq2, 'create_at'=>time(), 'path'=>$ar['imgurl']."users/".$user_id."/c/".$new_file, ); Insert($db,"images",$idt,0); $udt=array( 'cover_image'=>$ar['imgurl']."users/".$user_id."/c/".$new_file, ); Update($db,"users",$udt,"id=".$user_id,0); $dt['idt']=$idt; $dt['udt']=$udt; $dt['success']=true; $dt['message']="Profile image added"; $dt['image_url']=$ar['imgurl']."users/".$user_id."/c/".$new_file; return $dt; } function update_profile_image($js){ global $ar,$db; $dt=array(); $user_id=$js->user_id; $data=$js->image; $image_info = getimagesize($data); $extension = (isset($image_info["mime"]) ? explode('/', $image_info["mime"] )[1]: ""); $dt['type']=$extension; $tmp_file=$ar['img_path']."users/tmp/".$user_id.".".$extension; $sub_folder=$ar['img_path']."/users/".$user_id; $new_file=genRandom(10).".".$extension; if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); } $sub_folder_p=$ar['img_path']."/users/".$user_id."/p"; if(!is_dir($sub_folder_p)){ mkdir($sub_folder_p, 0755); } //$dt['newfile']=$new_file; $data = str_replace('data:image/'.$extension.';base64,', '', $data); $data = str_replace(' ','+',$data); $bin = base64_decode($data); if ($bin === false) { //$dt['info']="convert invalid"; } //$img = imageCreateFromString($bin); //tmp file file_put_contents($tmp_file, $bin); //file_put_contents($sub_folder."/".$new_file, $bin); //crop& resize ini_set('display_errors', '0'); //resize(600,$sub_folder."/".$new_file,$tmp_file); resize_crop_image(400,400,$tmp_file,$sub_folder_p."/".$new_file); unlink($tmp_file); $sql="SELECT `seq` from `images` where `modul`='users' and `item_id`=".$user_id." order by `seq` desc limit 1"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==1) { $r = mysqli_fetch_assoc($res); $seq2=$r['seq']+1; } else { $seq2=1; } $sql2="SELECT `id` from `images` order by `id` desc limit 1"; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)==1) { $r2 = mysqli_fetch_assoc($res2); $id2=$r2['id']+1; } else { $id2=1; } $idt=array( 'id'=>$id2, 'modul'=>'users', 'item_id'=>$user_id, 'seq'=>$seq2, 'create_at'=>time(), 'path'=>$ar['imgurl']."users/".$user_id."/p/".$new_file, ); Insert($db,"images",$idt,0); $udt=array( 'profile_image'=>$ar['imgurl']."users/".$user_id."/p/".$new_file, ); Update($db,"users",$udt,"id=".$user_id,0); //$dt['idt']=$idt; //$dt['udt']=$udt; $dt['success']=true; $dt['message']="Profile image added"; $dt['image_url']=$ar['imgurl']."users/".$user_id."/p/".$new_file; return $dt; } function update_social_links($js){ global $ar,$db; $dt=array(); return $dt; } ?>
$id2, 'user_id'=>$js->user_id, 'url'=>$js->link->url, 'label'=>$js->link->label, ); $udt=array( 'url'=>$js->link->url, 'label'=>$js->link->label, ); InsertUpdate($db,"user_external_links",$idt,$udt,0); $sql="SELECT `id` from `user_external_links` where `url`='".$js->link->url."' and `user_id`=".$js->user_id.""; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)>0) { $r = mysqli_fetch_assoc($res); $id=$r['id']; } else { $id=0; } $dt['id']=$id; $dt['success']=true; $dt['message']="Profile link added"; return $dt; } function follow_user($js){ global $ar,$db; $dt=array(); $sql="SELECT * from `user_follow` where parent_id=".$js->following_id." and user_id=".$js->follower_id; //echo $sql8."
"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==0) { $idt=array( 'parent_id'=>$js->following_id, 'user_id'=>$js->follower_id, ); Insert($db,"user_follow",$idt,0); $dt['success']=true; $dt['message']="User followed"; } else { Delete($db,"user_follow","parent_id=".$js->following_id." and user_id=".$js->follower_id,0); $dt['success']=true; $dt['message']="User unfollowed"; } return $dt; } function get_user_profile($token){ global $ar,$db; $dt=array(); $sql="SELECT id,name,username,first_name,last_name,email,profile_image,can_update_username,next_update_username,posts_count,profile_image,cover_image from `users` where token='".$token."'"; //echo $sql8."
"; $res=mysqli_query($db,$sql); $r1 = mysqli_fetch_assoc($res); header('Allow: POST'); header('vary: Accept-Encoding, Origin'); header('x-content-type-options: nosniff'); header('x-robots-tag: noindex'); $dt['success']=true; $dt['user']=$r1; $dt['user']['last_location']=[]; $dt['user']['roles']=['drive-life-user']; $sql2="SELECT `address_1`,`address_2`,`city`,`country`,`phone`,`postcode`,`state` from `user_billing_info` where `user_id`='".$r1['id']."'"; //echo $sql8."
"; $res2=mysqli_query($db,$sql2); $r2 = mysqli_fetch_assoc($res2); $dt['user']['billing_info']=$r2; $sql3="SELECT category,username from `user_links` where `user_id`='".$r1['id']."'"; //echo $sql8."
"; $res3=mysqli_query($db,$sql3); while($r3 = mysqli_fetch_assoc($res3)) { $dt['user']['profile_links'][$r3['category']]=$r3['username']; } $sql4="SELECT * from `user_external_links` where `user_id`='".$r1['id']."'"; //echo $sql8."
"; $res4=mysqli_query($db,$sql4); $c=0; while($r4 = mysqli_fetch_assoc($res4)) { $dt['user']['profile_links']['external_links'][$c]['link']['label']=$r4['label']; $dt['user']['profile_links']['external_links'][$c]['link']['url']=$r4['url']; $dt['user']['profile_links']['external_links'][$c]['id']=$r4['id']; $c++; } $sql5="SELECT user_id from `user_follow` where `parent_id`='".$r1['id']."'"; //echo $sql8."
"; $res5=mysqli_query($db,$sql5); if(mysqli_num_rows($res5)>0) { $c=0; while($r5 = mysqli_fetch_assoc($res5)) { $dt['user']['followers'][$c]=$r5['user_id']; $c++; } } else { $dt['user']['followers']=[]; } $sql6="SELECT parent_id from `user_follow` where `user_id`='".$r1['id']."'"; //echo $sql8."
"; $res6=mysqli_query($db,$sql6); if(mysqli_num_rows($res6)>0) { $c=0; while($r6 = mysqli_fetch_assoc($res6)) { $dt['user']['following'][$c]=$r6['parent_id']; $c++; } } else { $dt['user']['following']=[]; } return $dt; } function get_user_profile_next($js){ global $ar,$db; $dt=array(); $sql="SELECT id,name,username,first_name,last_name,email,profile_image,can_update_username,next_update_username,posts_count,profile_image,cover_image from `users` where id=".$js->user_id; //echo $sql8."
"; $res=mysqli_query($db,$sql); $r1 = mysqli_fetch_assoc($res); if(mysqli_num_rows($res)==1) { $dt['success']=true; $dt['user']=$r1; $dt['user']['last_location']=[]; $dt['user']['roles']=['drive-life-user']; $sql2="SELECT `address_1`,`address_2`,`city`,`country`,`phone`,`postcode`,`state` from `user_billing_info` where `user_id`='".$r1['id']."'"; //echo $sql8."
"; $res2=mysqli_query($db,$sql2); $r2 = mysqli_fetch_assoc($res2); $dt['user']['billing_info']=$r2; $sql3="SELECT category,username from `user_links` where `user_id`='".$r1['id']."'"; //echo $sql8."
"; $res3=mysqli_query($db,$sql3); while($r3 = mysqli_fetch_assoc($res3)) { $dt['user']['profile_links'][$r3['category']]=$r3['username']; } $sql4="SELECT * from `user_external_links` where `user_id`='".$r1['id']."'"; //echo $sql8."
"; $res4=mysqli_query($db,$sql4); $c=0; while($r4 = mysqli_fetch_assoc($res4)) { $dt['user']['profile_links']['external_links'][$c]['link']['label']=$r4['label']; $dt['user']['profile_links']['external_links'][$c]['link']['url']=$r4['url']; $dt['user']['profile_links']['external_links'][$c]['id']=$r4['id']; $c++; } $sql5="SELECT user_id from `user_follow` where `parent_id`='".$r1['id']."'"; //echo $sql8."
"; $res5=mysqli_query($db,$sql5); if(mysqli_num_rows($res5)>0) { $d=0; while($r5 = mysqli_fetch_assoc($res5)) { $dt['user']['followers'][$d]=$r5['user_id']; $d++; } } else { $dt['user']['followers']=[]; } $sql6="SELECT parent_id from `user_follow` where `user_id`='".$r1['id']."'"; //echo $sql8."
"; $res6=mysqli_query($db,$sql6); if(mysqli_num_rows($res6)>0) { $d=0; while($r6 = mysqli_fetch_assoc($res6)) { $dt['user']['following'][$d]=$r6['parent_id']; $d++; } } else { $dt['user']['following']=[]; } //$dt['email2']=$email; } else { //$dt['error']=true; $dt['error']="No user found with that id"; } return $dt; } function remove_profile_link($js){ global $ar,$db; $dt=array(); Delete($db,"user_external_links","id=".$js->link_id); $dt['success']=true; $dt['message']="Profile link removed"; return $dt; } function update_cover_image($js){ global $ar,$db; $dt=array(); $user_id=$js->user_id; $data=$js->image; $image_info = getimagesize($data); $extension = (isset($image_info["mime"]) ? explode('/', $image_info["mime"] )[1]: ""); $dt['type']=$extension; $tmp_file=$ar['img_path']."users/tmp/".$user_id.".".$extension; $sub_folder=$ar['img_path']."/users/".$user_id; if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); } $sub_folder_p=$ar['img_path']."/users/".$user_id."/c"; if(!is_dir($sub_folder_p)){ mkdir($sub_folder_p, 0755); } $new_file=genRandom(10).".".$extension; $dt['newfile']=$new_file; $data = str_replace('data:image/'.$extension.';base64,', '', $data); $data = str_replace(' ','+',$data); $bin = base64_decode($data); if ($bin === false) { $dt['info']="convert invalid"; } //tmp file file_put_contents($tmp_file, $bin); ini_set('display_errors', '0'); resize_crop_image(1200,760,$tmp_file,$sub_folder_p."/".$new_file); unlink($tmp_file); $sql="SELECT `seq` from `images` where `modul`='users' and `item_id`=".$user_id." order by `seq` desc limit 1"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==1) { $r = mysqli_fetch_assoc($res); $seq2=$r['seq']+1; } else { $seq2=1; } $sql2="SELECT `id` from `images` order by `id` desc limit 1"; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)==1) { $r2 = mysqli_fetch_assoc($res2); $id2=$r2['id']+1; } else { $id2=1; } $idt=array( 'id'=>$id2, 'modul'=>'users', 'item_id'=>$user_id, 'seq'=>$seq2, 'create_at'=>time(), 'path'=>$ar['imgurl']."users/".$user_id."/c/".$new_file, ); Insert($db,"images",$idt,0); $udt=array( 'cover_image'=>$ar['imgurl']."users/".$user_id."/c/".$new_file, ); Update($db,"users",$udt,"id=".$user_id,0); $dt['idt']=$idt; $dt['udt']=$udt; $dt['success']=true; $dt['message']="Profile image added"; $dt['image_url']=$ar['imgurl']."users/".$user_id."/c/".$new_file; return $dt; } function update_profile_image($js){ global $ar,$db; $dt=array(); $user_id=$js->user_id; $data=$js->image; $image_info = getimagesize($data); $extension = (isset($image_info["mime"]) ? explode('/', $image_info["mime"] )[1]: ""); $dt['type']=$extension; $tmp_file=$ar['img_path']."users/tmp/".$user_id.".".$extension; $sub_folder=$ar['img_path']."/users/".$user_id; $new_file=genRandom(10).".".$extension; if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); } $sub_folder_p=$ar['img_path']."/users/".$user_id."/p"; if(!is_dir($sub_folder_p)){ mkdir($sub_folder_p, 0755); } //$dt['newfile']=$new_file; $data = str_replace('data:image/'.$extension.';base64,', '', $data); $data = str_replace(' ','+',$data); $bin = base64_decode($data); if ($bin === false) { //$dt['info']="convert invalid"; } //$img = imageCreateFromString($bin); //tmp file file_put_contents($tmp_file, $bin); //file_put_contents($sub_folder."/".$new_file, $bin); //crop& resize ini_set('display_errors', '0'); //resize(600,$sub_folder."/".$new_file,$tmp_file); resize_crop_image(400,400,$tmp_file,$sub_folder_p."/".$new_file); unlink($tmp_file); $sql="SELECT `seq` from `images` where `modul`='users' and `item_id`=".$user_id." order by `seq` desc limit 1"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==1) { $r = mysqli_fetch_assoc($res); $seq2=$r['seq']+1; } else { $seq2=1; } $sql2="SELECT `id` from `images` order by `id` desc limit 1"; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)==1) { $r2 = mysqli_fetch_assoc($res2); $id2=$r2['id']+1; } else { $id2=1; } $idt=array( 'id'=>$id2, 'modul'=>'users', 'item_id'=>$user_id, 'seq'=>$seq2, 'create_at'=>time(), 'path'=>$ar['imgurl']."users/".$user_id."/p/".$new_file, ); Insert($db,"images",$idt,0); $udt=array( 'profile_image'=>$ar['imgurl']."users/".$user_id."/p/".$new_file, ); Update($db,"users",$udt,"id=".$user_id,0); //$dt['idt']=$idt; //$dt['udt']=$udt; $dt['success']=true; $dt['message']="Profile image added"; $dt['image_url']=$ar['imgurl']."users/".$user_id."/p/".$new_file; return $dt; } function update_social_links($js){ global $ar,$db; $dt=array(); foreach ($js->links as $k => $v) { $udt=array( 'username'=>$v, ); //$dt['udt'][]=$udt; Update($db,"user_links",$udt,"user_id=".$js->user_id." and `category`='".$k."'",0); } $dt['success']=true; $dt['message']="Social link updated"; return $dt; } function update_user_details($js){ global $ar,$db; $dt=array(); //$dt['col']=file_get_contents('php://input'); $udt=array( 'first_name'=>trim($js->first_name), 'last_name'=>trim($js->last_name), 'name'=>trim($js->first_name)." ".trim($js->last_name), ); if($js->phone!='') { $udt2['phone']=to_hp($js->phone); Update($db,"user_billing_info",$udt2,"user_id=".$js->user_id,0); } if($js->email_changed===true) { //$udt['email']=$js->email; } Update($db,"users",$udt,"id=".$js->user_id,0); $dt['success']=true; $dt['message']="User details updated"; $dt['id']=$js->user_id; return $dt; } ?>
Save
export const addUserProfileLinks = async ({ link, type, }) => { const user = await getSessionUser(); if (!user) return null; const response = await fetch(`${API_URL}/wp-json/app/v1/add-profile-links`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, link, type }), }); const data = await response.json(); return data; }; export const maybeFollowUser = async (profileId) => { const user = await getSessionUser(); if (!user) return; const response = await fetch(`${API_URL}/wp-json/app/v1/follow-user`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ following_id: profileId, follower_id: user.id }), }); const data = await response.json(); return data; }; export const removeProfileLink = async (linkId) => { const user = await getSessionUser(); if (!user) return; const response = await fetch(`${API_URL}/wp-json/app/v1/remove-profile-link`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, link_id: linkId }), }); const data = await response.json(); console.log(response); if (response.status !== 200 || data.error) { return false } return true; }; export const updateCoverImage = async (image) => { const controller = new AbortController() const signal = controller.signal try { const user = await getSessionUser(); if (!user) return; setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGHER) const response = await fetch(`${API_URL}/wp-json/app/v1/update-cover-image`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, image }), signal }); const data = await response.json(); return data; } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to update your cover image, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } }; export const updateProfileImage = async (image) => { const controller = new AbortController() const signal = controller.signal try { const user = await getSessionUser(); if (!user) return; setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGHER) const response = await fetch(`${API_URL}/wp-json/app/v1/update-profile-image`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, image }), signal }); const data = await response.json(); return data; } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to update your profile image, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } }; export const updateSocialLinks = async (links) => { const user = await getSessionUser(); if (!user) return; const response = await fetch(`${API_URL}/wp-json/app/v1/update-social-links`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, links }), }); const data = await response.json(); return data; };
import { API_URL, TIMEOUT_MS_HIGHER } from "./consts.js" import { getSessionUser } from "./auth.js"; export const addUserProfileLinks = async ({ link, type, }) => { const user = await getSessionUser(); if (!user) return null; const response = await fetch(`${API_URL}/profile/add-profile-links`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, link, type }), }); const data = await response.json(); return data; }; export const maybeFollowUser = async (profileId) => { const user = await getSessionUser(); if (!user) return; const response = await fetch(`${API_URL}/profile/follow-user`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ following_id: profileId, follower_id: user.id }), }); const data = await response.json(); return data; }; export const getUserDetails = async (token) => { try { let url = `${API_URL}/profile/get-user-profile/` let response = await fetch(url, { method: "POST", mode: 'cors', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}`, }, }) const data = await response.json() if (response.status !== 200) throw new Error(data.message) return data } catch (error) { console.error('Error fetching user details:', error) return null } } export const getUserById = async (id) => { try { let url = `${API_URL}/profile/get-user-profile-next` let response = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: id }), }) const data = await response.json() if (response.status !== 200) throw new Error(data.message) return data } catch (error) { console.error('Error fetching user details:', error) return null } } export const removeProfileLink = async (linkId) => { const user = await getSessionUser(); if (!user) return; const response = await fetch(`${API_URL}/profile/remove-profile-link`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, link_id: linkId }), }); const data = await response.json(); console.log(response); if (response.status !== 200 || data.error) { return false } return true; }; export const updateCoverImage = async (image) => { try { const user = await getSessionUser(); if (!user) return; setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGHER) const response = await fetch(`${API_URL}/profile/update-cover-image`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, image }) }); const data = await response.json(); return data; } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to update your cover image, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } }; export const updateProfileImage = async (image) => { try { const user = await getSessionUser(); if (!user) return; setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGHER) const response = await fetch(`${API_URL}/profile/update-profile-image`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, image }) }); const data = await response.json(); return data; } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to update your profile image, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } }; export const updateSocialLinks = async (links) => { const user = await getSessionUser(); if (!user) return; const response = await fetch(`${API_URL}/profile/update-social-links`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, links }), }); const data = await response.json(); return data; }; export const updateUserDetails = async (details, email_changed) => { try { const user = await getSessionUser(); if (!user) return; setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGHER) const response = await fetch(`${API_URL}/profile/update-user-details`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, ...details, email_changed }) }); const data = await response.json(); return data; } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to update your details, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } };
Save
profile
-- add-profile-links
-- follow-user
-- remove-profile-link
-- update-cover-image
-- update-profile-image
-- update-social-links