publishport-opencli 1.0.52 → 1.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/clis/medium/whoami.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cli as
|
|
1
|
+
import{cli as r,Strategy as u}from"@jackwener/opencli/registry";import{checkLogin as m,cookieQuickCheck as t}from"../_shared/article/auth.js";import{mediumAuthProfile as o}from"./article.js";r({site:"medium",name:"whoami",access:"read",description:"查询当前登录的 Medium 账户信息。",domain:"medium.com",strategy:u.COOKIE,browser:!0,columns:["logged_in","user_id","username"],authStatus:{quickCheckRequiresNavigation:!0,quickCheck:t("https://medium.com",["sid","uid"])},func:async(i)=>{const e=await m(i,o);return[{logged_in:e.isAuthenticated,user_id:e.userId||"",username:e.username||""}]}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cli as
|
|
1
|
+
import{cli as i,Strategy as u}from"@jackwener/opencli/registry";import{checkLogin as o,cookieQuickCheck as m}from"../_shared/article/auth.js";import{segmentfaultProfile as h}from"./article.js";const authProfile={home:h.home,checkAuth:async(e)=>{const a=await(await fetch("https://segmentfault.com/user/settings",{credentials:"include"})).text(),s=a.match(/href="\/u\/([^"]+)"/);if(!s)return{isAuthenticated:!1,error:"未登录或无法解析用户信息"};const r=s[1],c=a.match(/src="(https:\/\/avatar-static\.segmentfault\.com\/[^"]+)"/),n=c?c[1]:"";return{isAuthenticated:!0,userId:r,username:r,avatar:n}}};export{authProfile};i({site:"segmentfault",name:"whoami",access:"read",description:"检查思否(SegmentFault)的登录状态并获取当前账号信息",domain:"segmentfault.com",strategy:u.COOKIE,browser:!0,columns:["logged_in","user_id","username"],authStatus:{quickCheckRequiresNavigation:!0,quickCheck:m("https://segmentfault.com",["PHPSESSID"])},func:async(e)=>{const t=await o(e,authProfile);return[{logged_in:t.isAuthenticated,user_id:t.userId,username:t.username}]}});
|
|
@@ -23,6 +23,10 @@ export declare class DebuggerBanner {
|
|
|
23
23
|
private readonly warn;
|
|
24
24
|
private readonly idleMs;
|
|
25
25
|
private anchorTabId;
|
|
26
|
+
private anchorTargetId;
|
|
27
|
+
/** An ensureAnchor run is already queued: further commands need not queue another. */
|
|
28
|
+
private ensurePending;
|
|
29
|
+
private noCandidateUntil;
|
|
26
30
|
private idleTimer;
|
|
27
31
|
private queue;
|
|
28
32
|
/** Target ids used by commands: their attachment belongs to the command, never anchor there. */
|
|
@@ -39,6 +43,13 @@ export declare class DebuggerBanner {
|
|
|
39
43
|
shutdown(): void;
|
|
40
44
|
/** Extension connection closed: nothing can be sent any more. */
|
|
41
45
|
dispose(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Every command reports activity, and a busy profile can have hundreds of tabs and frames:
|
|
48
|
+
* listing all debugger targets per command kept Chrome's browser process and the extension
|
|
49
|
+
* busy. Queue at most one check, and list targets only when no anchor is held, the anchor
|
|
50
|
+
* tab was taken over by a command, or the no-candidate back-off has expired.
|
|
51
|
+
*/
|
|
52
|
+
private scheduleEnsure;
|
|
42
53
|
private enqueue;
|
|
43
54
|
private expect;
|
|
44
55
|
private rememberCommandTarget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const BANNER_IDLE_MS=300000,BANNER_CAPABILITIES=["chrome-api","events"];const s="publishport:banner-anchor",r=500;export function supportsDebuggerBanner(t){return BANNER_CAPABILITIES.every((e)=>t.includes(e))}export class DebuggerBanner{call;warn;idleMs;anchorTabId=null;idleTimer=null;queue=Promise.resolve();commandTargets=new Set;active=!1;disposed=!1;constructor(t,e,a=BANNER_IDLE_MS){this.call=t;this.warn=e;this.idleMs=a}start(){return this.enqueue(async()=>{await this.expect(this.call({action:"events",events:[{name:"debugger.onDetach"}]}),"subscribe debugger.onDetach");const e=(await this.expect(this.call({action:"chrome-api",api:"storage.session.get",args:[s]}),"read stored anchor"))?.[s];if(typeof e==="number"&&!this.active)await this.detach(e)})}onActivity(t){if(this.disposed)return;if(t)this.rememberCommandTarget(t);this.active=!0;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=setTimeout(()=>{this.idleTimer=null;this.active=!1;this.enqueue(()=>this.releaseAnchor())},this.idleMs);this.idleTimer.unref?.();this.
|
|
1
|
+
export const BANNER_IDLE_MS=300000,BANNER_CAPABILITIES=["chrome-api","events"];const s="publishport:banner-anchor",r=500,n=30000;export function supportsDebuggerBanner(t){return BANNER_CAPABILITIES.every((e)=>t.includes(e))}export class DebuggerBanner{call;warn;idleMs;anchorTabId=null;anchorTargetId=null;ensurePending=!1;noCandidateUntil=0;idleTimer=null;queue=Promise.resolve();commandTargets=new Set;active=!1;disposed=!1;constructor(t,e,a=BANNER_IDLE_MS){this.call=t;this.warn=e;this.idleMs=a}start(){return this.enqueue(async()=>{await this.expect(this.call({action:"events",events:[{name:"debugger.onDetach"}]}),"subscribe debugger.onDetach");const e=(await this.expect(this.call({action:"chrome-api",api:"storage.session.get",args:[s]}),"read stored anchor"))?.[s];if(typeof e==="number"&&!this.active)await this.detach(e)})}onActivity(t){if(this.disposed)return;if(t)this.rememberCommandTarget(t);this.active=!0;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=setTimeout(()=>{this.idleTimer=null;this.active=!1;this.enqueue(()=>this.releaseAnchor())},this.idleMs);this.idleTimer.unref?.();this.scheduleEnsure()}onEvent(t,e){if(this.disposed||t!=="debugger.onDetach"||!Array.isArray(e))return;const a=e[0];if(typeof a?.tabId!=="number"||a.tabId!==this.anchorTabId)return;this.anchorTabId=null;this.anchorTargetId=null;if(e[1]==="canceled_by_user")return;if(this.active)this.scheduleEnsure()}shutdown(){this.active=!1;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=null;const t=this.anchorTabId;this.anchorTabId=null;this.anchorTargetId=null;this.disposed=!0;if(t!==null)this.call({action:"chrome-api",api:"debugger.detach",args:[{tabId:t}]}).catch((e)=>{this.warn(`[daemon] debugger banner: detach on shutdown failed: ${e instanceof Error?e.message:String(e)}`)})}dispose(){this.disposed=!0;if(this.idleTimer)clearTimeout(this.idleTimer);this.idleTimer=null}scheduleEnsure(){if(this.ensurePending)return;if(this.anchorTabId!==null&&!(this.anchorTargetId&&this.commandTargets.has(this.anchorTargetId)))return;if(this.anchorTabId===null&&Date.now()<this.noCandidateUntil)return;this.ensurePending=!0;this.enqueue(async()=>{this.ensurePending=!1;await this.ensureAnchor()})}enqueue(t){this.queue=this.queue.then(t).catch((e)=>{this.warn(`[daemon] debugger banner: ${e instanceof Error?e.message:String(e)}`)});return this.queue}async expect(t,e){const a=await t;if(!a?.ok)throw Error(`${e} failed: ${a?.error??"no result"}`);return a.data??null}rememberCommandTarget(t){this.commandTargets.delete(t);this.commandTargets.add(t);if(this.commandTargets.size>r){const e=this.commandTargets.values().next().value;if(e!==void 0)this.commandTargets.delete(e)}}async ensureAnchor(){if(!this.active||this.disposed)return;const t=await this.expect(this.call({action:"chrome-api",api:"debugger.getTargets"}),"list debugger targets");if(this.anchorTabId!==null){const a=t.find((i)=>i.tabId===this.anchorTabId);if(a?.attached&&!this.commandTargets.has(a.id))return;this.anchorTabId=null;this.anchorTargetId=null}const e=t.filter((a)=>a.type==="page"&&typeof a.tabId==="number"&&/^https?:/.test(a.url)&&!a.attached&&!this.commandTargets.has(a.id)).sort((a,i)=>a.tabId-i.tabId);for(const a of e){const i=a.tabId;if(!(await this.call({action:"chrome-api",api:"debugger.attach",args:[{tabId:i},"1.3"]}))?.ok)continue;this.anchorTabId=i;this.anchorTargetId=a.id;await this.expect(this.call({action:"chrome-api",api:"storage.session.set",args:[{[s]:i}]}),"store anchor");return}this.noCandidateUntil=Date.now()+n;this.warn("[daemon] debugger banner: no http(s) tab available to hold the debugger session")}async releaseAnchor(){if(this.active||this.anchorTabId===null)return;const t=this.anchorTabId;this.anchorTabId=null;this.anchorTargetId=null;await this.detach(t)}async detach(t){const e=await this.call({action:"chrome-api",api:"debugger.detach",args:[{tabId:t}]});if(!e?.ok&&!/not attached|No tab with given id/i.test(e?.error??""))throw Error(`detach anchor ${t} failed: ${e?.error??"no result"}`);await this.expect(this.call({action:"chrome-api",api:"storage.session.remove",args:[s]}),"clear stored anchor")}}
|