Add clan homeworld affiliation and managed heraldic emblems across profiles and forums

This commit is contained in:
unimatrixgit 2026-11-15 11:32:02 +01:00
commit 46685c5da0
4 changed files with 291 additions and 82 deletions

View file

@ -0,0 +1,20 @@
"""Validate uploaded raster files and make a bounded, metadata-free emblem."""
import io
import sys
import warnings
from PIL import Image
Image.MAX_IMAGE_PIXELS = 4194304
warnings.simplefilter('error', Image.DecompressionBombWarning)
data = sys.stdin.buffer.read(2097153)
if not data or len(data)>2097152:
raise ValueError('Image exceeds 2 MB')
image = Image.open(io.BytesIO(data))
if image.format not in ('PNG','JPEG','WEBP') or getattr(image,'n_frames',1)!=1:
raise ValueError('Use a still PNG, JPEG or WebP image')
if min(image.size)<32 or max(image.size)>4096:
raise ValueError('Invalid emblem dimensions')
image.verify()
image = Image.open(io.BytesIO(data)).convert('RGBA')
image.thumbnail((512,512), Image.Resampling.LANCZOS)
image.save(sys.stdout.buffer, 'WEBP', quality=90, method=6)

View file

@ -69,8 +69,8 @@ export async function memberProfileData(db,target,settings={}){
const office=await optional(()=>db.prepare('SELECT roles_json,expires_at FROM drforum_dune_political_roles WHERE website_id=?').bind(target.id).first(),null);
if(office&&Number(office.expires_at)>Date.now()/1000){const known={emperor:'Emperor',house_leader:'Faction leader',specerhuis:'Specerhuis',welvaart:'House of Water',guild_staff:'Vaerkring',landsraad:'Landsraad'};for(const key of JSON.parse(office.roles_json||'[]'))if(known[key])add('office-'+key,known[key],'https://forums.dunerealms.com/assets/seals/office-'+key+'.png','Political offices');}
const memorial=await optional(()=>db.prepare("SELECT m.slug FROM site_memorials m LEFT JOIN site_life_status l ON l.user_id=m.user_id WHERE m.user_id=? AND (l.status IS NULL OR l.status='deceased')").bind(target.id).first(),null);
const clan=await optional(()=>db.prepare('SELECT c.name,c.tag,c.description,m.clan_role,m.joined_at,(SELECT COUNT(*) FROM site_clan_members n WHERE n.clan_id=c.id) AS member_count FROM site_clan_members m JOIN site_clans c ON c.id=m.clan_id WHERE m.user_id=? AND c.active=1').bind(target.id).first(),undefined);
return{showcase,memorial:memorial?'/memorial/'+memorial.slug:null,personalSeal:namedPersonal?medals.find(m=>m.key==='personal-role'):null,username:target.username,displayName:target.display_name,joinedAt:Number(target.created_at),functions:access.organisation?.assignments||[],avatar:'https://cp.dunerealms.com/api/avatars/face/member/'+encodeURIComponent(target.username),avatarMode:'image',bio:publicProfile.bio,publicInfo:publicProfile.publicInfo,socials:publicProfile.socials,ranks,medals,forum:await publicForumFor(db,target.id),support:{status:staff?(stats?'available':'unavailable'):'not-staff',closed:stats?.totalClosed??null,departments:stats?.departments||{}},quests:{status:'placeholder',completed:null,active:null},clan:clan===undefined?{status:'unavailable'}:clan?{status:'member',name:clan.name,tag:clan.tag,description:clan.description,role:clan.clan_role,joinedAt:Number(clan.joined_at),members:Math.max(0,Number(clan.member_count))}:{status:'none'}};
const clan=await optional(()=>db.prepare('SELECT c.id,c.name,c.tag,c.description,m.clan_role,m.joined_at,(SELECT COUNT(*) FROM site_clan_members n WHERE n.clan_id=c.id) AS member_count FROM site_clan_members m JOIN site_clans c ON c.id=m.clan_id WHERE m.user_id=? AND c.active=1').bind(target.id).first(),undefined);
return{showcase,memorial:memorial?'/memorial/'+memorial.slug:null,personalSeal:namedPersonal?medals.find(m=>m.key==='personal-role'):null,username:target.username,displayName:target.display_name,joinedAt:Number(target.created_at),functions:access.organisation?.assignments||[],avatar:'https://cp.dunerealms.com/api/avatars/face/member/'+encodeURIComponent(target.username),avatarMode:'image',bio:publicProfile.bio,publicInfo:publicProfile.publicInfo,socials:publicProfile.socials,ranks,medals,forum:await publicForumFor(db,target.id),support:{status:staff?(stats?'available':'unavailable'):'not-staff',closed:stats?.totalClosed??null,departments:stats?.departments||{}},quests:{status:'placeholder',completed:null,active:null},clan:clan===undefined?{status:'unavailable'}:clan?{status:'member',emblem:'https://cp.dunerealms.com/api/clan-emblems/'+clan.id,name:clan.name,tag:clan.tag,description:clan.description,role:clan.clan_role,joinedAt:Number(clan.joined_at),members:Math.max(0,Number(clan.member_count))}:{status:'none'}};
}
export function createMemberProfiles(db,settings={}){return async request=>{
const from=request.headers.get('origin');if(from&&from!==origin)return json({message:'Origin rejected.'},403);

View file

@ -1 +1,3 @@
*{box-sizing:border-box}body{margin:0;background:#0b221b;color:#eee6ce;font:15px/1.7 system-ui,sans-serif}a{color:#e4ca83}.citizen-profile{max-width:1240px;margin:36px auto 60px;padding:0 28px}.citizen-profile [hidden]{display:none!important}.profile-breadcrumb{margin-bottom:22px;font-size:13px;color:#b8c5b7}.profile-breadcrumb a{text-decoration:none}.profile-hero,.profile-panel{border:1px solid #7f8c61;border-radius:16px;padding:30px;margin-bottom:24px;background:linear-gradient(135deg,#1d4031,#102c23);box-shadow:0 8px 25px #0002}.profile-hero{border-top:3px solid #d2b76b;background:linear-gradient(105deg,#173e2bf2,#102e28e8),url('/assets/sietch.webp') center/cover}.citizen-profile .eyebrow{font-size:10px;font-weight:700;letter-spacing:.16em;color:#c4ad6d;margin:0 0 12px}.identity{display:flex;align-items:center;gap:26px;margin:22px 0}.identity>div{min-width:0}#avatar{width:112px;height:112px;flex-shrink:0;border-radius:13px;border:2px solid #c6ab64;object-fit:cover;image-rendering:pixelated;background:#0a241b}.citizen-profile h1,.citizen-profile h2,.citizen-profile h3{font-family:Georgia,serif;color:#efdcab;line-height:1.25;overflow-wrap:anywhere}.citizen-profile h1{font-size:38px;margin:0 0 6px}.citizen-profile h2{font-size:25px;margin:0 0 18px}.citizen-profile h3{font-size:18px}.citizen-profile p{margin-top:0}.muted,#handle,#status{color:#b9ccbd}#handle{margin-bottom:6px}.metadata{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:24px;margin-top:26px}.metadata>div{border-top:1px solid #8d9a6b55;padding-top:16px}.metadata small{display:block;color:#b5c6b5;font-size:12px;margin-bottom:5px}.metadata strong{overflow-wrap:anywhere}.chips{display:flex;gap:10px;flex-wrap:wrap}.chip{display:inline-block;border:1px solid #a89058;border-radius:20px;padding:5px 13px;background:#9b87481c;font-size:12px;text-decoration:none}.chip[data-staff=true]{border-color:#90b2bb;color:#b8d8e3;background:#456d7b30}.profile-columns{display:grid;grid-template-columns:minmax(0,1.1fr) minmax(0,1fr);gap:24px}.profile-prose{white-space:pre-line;overflow-wrap:anywhere;color:#d4dfce}.profile-functions{display:grid;gap:12px;margin-bottom:20px}.profile-function{padding:13px 16px;border:1px solid #71856677;border-left:3px solid #d1b66c;border-radius:8px;background:#0b281d}.profile-function strong{display:block;color:#e4cb8e}.profile-function span,.profile-function small{display:block;color:#b8cdbb;font-size:12px}.profile-award-groups{display:grid;gap:28px;margin-top:26px}.profile-awards{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:18px}.profile-seal{margin:0!important;min-width:0;padding:22px 16px;border:1px solid #7f8b645c;border-radius:12px;background:linear-gradient(145deg,#274936,#102d24);text-align:center;display:flex;flex-direction:column;align-items:center;gap:14px}.profile-seal img{width:128px;height:128px;max-width:100%;object-fit:contain;filter:drop-shadow(0 4px 7px #0005)}.profile-seal figcaption{font-size:13px;color:#e8d6a5;overflow-wrap:anywhere;line-height:1.5;width:100%}.profile-seal small{font-size:11px;color:#b4bd9f}.personal-seal-panel,.profile-order{display:flex;align-items:center;justify-content:space-between;gap:30px}.personal-seal-panel .profile-seal{min-width:210px}.profile-order{justify-content:flex-start;border-color:#c7a955;background:linear-gradient(115deg,#5d502936,#173b2c)}.profile-order>img{object-fit:contain;flex-shrink:0}.profile-community{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:18px}.profile-community>article{padding:20px;border:1px solid #6e886777;border-radius:10px;background:#0c281e}.profile-community strong{display:block;color:#e8d6a5;font-size:21px}.profile-community small{color:#b7cbb8}.profile-community a{font-size:12px}.citizen-profile a:focus-visible{outline:2px solid #e8cb7c;outline-offset:4px}
.profile-clan-emblem{display:block;width:110px;height:110px;object-fit:contain;margin:0 auto 18px;filter:drop-shadow(0 4px 8px #0005)}

View file

@ -18,11 +18,12 @@ function render(p){
for(const [name,items]of groups){const section=el('section'),cards=el('div',null,'profile-awards');section.append(el('h3',name));for(const m of items)cards.append(sealCard(m));section.append(cards);$('seals').append(section);}
if(!groups.size)$('seals').append(el('p','No additional seals or awards recorded.','muted'));
if(/^\/memorial\/[a-z0-9-]+$/.test(p.memorial||'')){const a=el('a','Visit community memorial →','chip');a.href=p.memorial;$('socials').append(a);text('status','Community remembrance profile');}
const community=(heading,value,note,link)=>{const c=el('article');c.append(el('h3',heading),el('strong',value),el('small',note));if(link){const a=el('a','Open →');a.href=link;c.append(el('br'),a);}$('community').append(c);};
const community=(heading,value,note,link)=>{const c=el('article');c.append(el('h3',heading),el('strong',value),el('small',note));if(link){const a=el('a','Open →');a.href=link;c.append(el('br'),a);}$('community').append(c);return c;};
if(p.forum?.status==='linked')community('Forum contributions',String(p.forum.posts||0)+' posts',String(p.forum.threads||0)+' threads · '+String(p.forum.reputation||0)+' reputation',p.forum.url);
else community('Forum','Not linked','No linked forum record is available.');
if(p.clan?.status==='member')community('Clan',p.clan.name,(p.clan.role||'Member')+' · '+String(p.clan.members||0)+' members','https://clans.dunerealms.com/');
else community('Clan','No membership listed','Clan membership is maintained by the clan system.');
const clanImage=el('img');clanImage.src=p.clan?.emblem||'https://www.dunerealms.com/assets/nav-clan-v2.webp';clanImage.alt=p.clan?.status==='member'?p.clan.name+' clan emblem':'Clan placeholder';clanImage.width=clanImage.height=110;clanImage.className='profile-clan-emblem';
if(p.clan?.status==='member')community('Clan',p.clan.name,(p.clan.role||'Member')+' · '+String(p.clan.members||0)+' members','https://clans.dunerealms.com/').prepend(clanImage);
else community('Clan','No membership listed','Clan membership is maintained by the clan system.').prepend(clanImage);
community('Adventures',p.quests?.completed==null?'No verified totals':String(p.quests.completed)+' completed',p.quests?.completed==null?'Quest statistics are not connected yet.':'Verified quest progress');
}
async function load(){if(!/^[a-z0-9_]{3,32}$/.test(username)){text('status','Invalid profile name');return;}text('handle','@'+username);try{const response=await fetch('https://cp.dunerealms.com/api/people/'+encodeURIComponent(username),{credentials:'include',cache:'no-store'});if(response.status===401){text('status','Sign in to view this member’s profile.');const a=el('a','Sign in');a.href='https://cp.dunerealms.com/?return_to='+encodeURIComponent('/people/'+username);$('status').append(' ',a);return;}if(!response.ok){text('status',response.status===404?'Profile not found':'Profile temporarily unavailable');return;}render((await response.json()).profile);}catch{text('status','Unable to load the profile. Please try again.');}}