File size: 2,056 Bytes
ecb2a3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// A small, private record of recent problems for the Help page's "Copy details"
// button. It never stores emails, tokens, file names, notes or photos.
const MAX=15;
const issues=[];

/* global __APP_BUILD__ */
export const build=typeof __APP_BUILD__==='object'&&__APP_BUILD__?__APP_BUILD__:{version:'dev',commit:'local',built:''};

const scrub=value=>String(value||'')
 .replace(/[\w.+-]+@[\w-]+\.[\w.-]+/g,'[email]')
 .replace(/eyJ[\w-]+\.[\w-]+\.[\w-]+/g,'[token]')
 .replace(/(bearer|apikey|key|token)=?\s*[\w-]{16,}/gi,'$1 [hidden]')
 .slice(0,300);

export function recordIssue(kind,message,extra={}){
 const path=String(extra.path||'').split('?')[0].replace(/[0-9a-f]{8,}/gi,':id');
 issues.push({at:new Date().toISOString(),kind,message:scrub(message),status:extra.status??null,path});
 if(issues.length>MAX)issues.splice(0,issues.length-MAX);
}

export function recentIssues(){return issues.slice()}
export function clearIssues(){issues.length=0}

export function diagnosticReport(context={},env=globalThis){
 const nav=env.navigator||{},screen=env.innerWidth?env.innerWidth+'脳'+env.innerHeight:'unknown';
 const lines=[
  'DefectRAG diagnostic details',
  'Version: '+build.version+' 路 build '+build.commit+(build.built?' 路 '+build.built:''),
  'Page: '+(context.page||'unknown')+' 路 mode: '+(context.mode||'unknown')+' 路 sync: '+(context.sync||'unknown'),
  'Signed in: '+(context.signedIn?'yes':'no')+' 路 workspace: '+(context.workspace||'unknown'),
  'Screen: '+screen+' 路 theme: '+(context.theme||'unknown')+' 路 text size: '+(context.textSize?Math.round(context.textSize*100)+'%':'unknown'),
  'Browser: '+scrub(nav.userAgent||'unknown'),
  'Online: '+(nav.onLine===false?'no':'yes'),
  'Time: '+new Date().toISOString(),
  '',
  'Recent problems ('+issues.length+'):'
 ];
 if(!issues.length)lines.push('none recorded in this tab');
 for(const item of issues.slice().reverse())lines.push('- '+item.at+' 路 '+item.kind+(item.status?' '+item.status:'')+(item.path?' 路 '+item.path:'')+' 路 '+item.message);
 return lines.join('\n');
}