@qzhuli/qzhuli-cli 0.5.2 → 0.5.4
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/dist/cmd.js +60 -24
- package/package.json +1 -1
package/dist/cmd.js
CHANGED
|
@@ -12716,8 +12716,7 @@ async function searchByName(factory, name) {
|
|
|
12716
12716
|
};
|
|
12717
12717
|
}
|
|
12718
12718
|
const conversations3 = listResult.data ?? [];
|
|
12719
|
-
|
|
12720
|
-
if (matchedIds.length === 0) {
|
|
12719
|
+
if (conversations3.length === 0) {
|
|
12721
12720
|
return {
|
|
12722
12721
|
status: "success",
|
|
12723
12722
|
code: "NOT_FOUND" /* NOT_FOUND */,
|
|
@@ -12726,10 +12725,26 @@ async function searchByName(factory, name) {
|
|
|
12726
12725
|
};
|
|
12727
12726
|
}
|
|
12728
12727
|
const profileResults = await Promise.all(
|
|
12729
|
-
|
|
12728
|
+
conversations3.map((c) => factory.repos.conversation.getProfile(c.id))
|
|
12730
12729
|
);
|
|
12731
|
-
const
|
|
12732
|
-
|
|
12730
|
+
const queryLower = name.toLowerCase();
|
|
12731
|
+
const scored = profileResults.filter((r) => r.ok).flatMap((r) => {
|
|
12732
|
+
const p = r.data;
|
|
12733
|
+
const convName = p.conversation.name ?? "";
|
|
12734
|
+
const teamName = p.conversation.team_name ?? "";
|
|
12735
|
+
const fields = [convName, teamName].filter(Boolean);
|
|
12736
|
+
if (fields.length === 0) return [];
|
|
12737
|
+
let best = 0;
|
|
12738
|
+
for (const f of fields) {
|
|
12739
|
+
const lower = f.toLowerCase();
|
|
12740
|
+
if (lower === queryLower) best = Math.max(best, 3);
|
|
12741
|
+
else if (lower.startsWith(queryLower)) best = Math.max(best, 2);
|
|
12742
|
+
else if (lower.includes(queryLower)) best = Math.max(best, 1);
|
|
12743
|
+
}
|
|
12744
|
+
if (best === 0) return [];
|
|
12745
|
+
return [{ profile: p, score: best }];
|
|
12746
|
+
}).sort((a, b) => b.score - a.score);
|
|
12747
|
+
if (scored.length === 0) {
|
|
12733
12748
|
return {
|
|
12734
12749
|
status: "success",
|
|
12735
12750
|
code: "NOT_FOUND" /* NOT_FOUND */,
|
|
@@ -12737,7 +12752,7 @@ async function searchByName(factory, name) {
|
|
|
12737
12752
|
data: null
|
|
12738
12753
|
};
|
|
12739
12754
|
}
|
|
12740
|
-
const items =
|
|
12755
|
+
const items = scored.map((s) => profileToItem(s.profile));
|
|
12741
12756
|
const groupedByUid = /* @__PURE__ */ new Map();
|
|
12742
12757
|
for (const item of items) {
|
|
12743
12758
|
const primaryUser = item.users[0];
|
|
@@ -12755,7 +12770,19 @@ async function searchByName(factory, name) {
|
|
|
12755
12770
|
});
|
|
12756
12771
|
}
|
|
12757
12772
|
}
|
|
12758
|
-
const results = [...groupedByUid.values()]
|
|
12773
|
+
const results = [...groupedByUid.values()].sort((a, b) => {
|
|
12774
|
+
const maxScoreA = Math.max(
|
|
12775
|
+
...a.conversations.map(
|
|
12776
|
+
(c) => scored.find((s) => s.profile.conversation.conversation_id === c.conversationId)?.score ?? 0
|
|
12777
|
+
)
|
|
12778
|
+
);
|
|
12779
|
+
const maxScoreB = Math.max(
|
|
12780
|
+
...b.conversations.map(
|
|
12781
|
+
(c) => scored.find((s) => s.profile.conversation.conversation_id === c.conversationId)?.score ?? 0
|
|
12782
|
+
)
|
|
12783
|
+
);
|
|
12784
|
+
return maxScoreB - maxScoreA;
|
|
12785
|
+
});
|
|
12759
12786
|
if (results.length === 0) {
|
|
12760
12787
|
return {
|
|
12761
12788
|
status: "success",
|
|
@@ -12844,6 +12871,14 @@ async function friendListRun(factory) {
|
|
|
12844
12871
|
|
|
12845
12872
|
// src/commands/friend/profile.ts
|
|
12846
12873
|
init_cjs_shims();
|
|
12874
|
+
function matchScore(text, queryLower) {
|
|
12875
|
+
if (!text) return 0;
|
|
12876
|
+
const lower = text.toLowerCase();
|
|
12877
|
+
if (lower === queryLower) return 3;
|
|
12878
|
+
if (lower.startsWith(queryLower)) return 2;
|
|
12879
|
+
if (lower.includes(queryLower)) return 1;
|
|
12880
|
+
return 0;
|
|
12881
|
+
}
|
|
12847
12882
|
async function friendProfileRun(factory, opts) {
|
|
12848
12883
|
const listResult = await factory.repos.contact.getLinksContacts();
|
|
12849
12884
|
if (!listResult.ok) {
|
|
@@ -12884,17 +12919,17 @@ async function friendProfileRun(factory, opts) {
|
|
|
12884
12919
|
friend_name: team.name
|
|
12885
12920
|
}))
|
|
12886
12921
|
];
|
|
12887
|
-
const
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
}
|
|
12897
|
-
if (
|
|
12922
|
+
const queryLower = opts.query.toLowerCase();
|
|
12923
|
+
let scored;
|
|
12924
|
+
if (opts.byUid) {
|
|
12925
|
+
scored = allEntries.filter((e) => e.uid?.toLowerCase() === queryLower).map((e) => ({ ...e, score: 3 }));
|
|
12926
|
+
} else {
|
|
12927
|
+
scored = allEntries.map((e) => {
|
|
12928
|
+
const field = opts.byRemark ? e.friend_name : e.nickname;
|
|
12929
|
+
return { ...e, score: matchScore(field, queryLower) };
|
|
12930
|
+
}).filter((e) => e.score > 0).sort((a, b) => b.score - a.score);
|
|
12931
|
+
}
|
|
12932
|
+
if (scored.length === 0) {
|
|
12898
12933
|
return {
|
|
12899
12934
|
status: "error",
|
|
12900
12935
|
code: "NOT_FOUND" /* NOT_FOUND */,
|
|
@@ -12902,12 +12937,13 @@ async function friendProfileRun(factory, opts) {
|
|
|
12902
12937
|
data: null
|
|
12903
12938
|
};
|
|
12904
12939
|
}
|
|
12905
|
-
if (
|
|
12906
|
-
const suggestions =
|
|
12940
|
+
if (scored.length > 1) {
|
|
12941
|
+
const suggestions = scored.map((m) => ({
|
|
12907
12942
|
uid: m.uid,
|
|
12908
12943
|
nickname: m.nickname ?? "",
|
|
12909
12944
|
remark: m.friend_name ?? "",
|
|
12910
|
-
type: m._type
|
|
12945
|
+
type: m._type,
|
|
12946
|
+
score: m.score
|
|
12911
12947
|
}));
|
|
12912
12948
|
return {
|
|
12913
12949
|
status: "needs_resolution",
|
|
@@ -12916,12 +12952,12 @@ async function friendProfileRun(factory, opts) {
|
|
|
12916
12952
|
data: suggestions
|
|
12917
12953
|
};
|
|
12918
12954
|
}
|
|
12919
|
-
const match =
|
|
12955
|
+
const match = scored[0];
|
|
12920
12956
|
if (match._type !== "link") {
|
|
12921
12957
|
return {
|
|
12922
12958
|
status: "success",
|
|
12923
12959
|
code: "USER_FOUND" /* USER_FOUND */,
|
|
12924
|
-
message: t("messages.found").replace("{name}", match.nickname ?? match.friend_name),
|
|
12960
|
+
message: t("messages.found").replace("{name}", match.nickname ?? match.friend_name ?? ""),
|
|
12925
12961
|
data: {
|
|
12926
12962
|
uid: match.uid,
|
|
12927
12963
|
nickname: match.nickname ?? match.friend_name,
|
|
@@ -15107,7 +15143,7 @@ async function main() {
|
|
|
15107
15143
|
${t("cli.banner")}` : t("cli.banner");
|
|
15108
15144
|
program.addHelpText("beforeAll", `${banner}
|
|
15109
15145
|
`);
|
|
15110
|
-
program.name("qz").version(`v${"0.5.
|
|
15146
|
+
program.name("qz").version(`v${"0.5.4"}`, "-v, --version", t("options.version")).helpOption("-h, --help", t("options.help")).option("-q, --jq <expr>", t("options.jq")).option("--dry-run", t("options.dryRun"));
|
|
15111
15147
|
program.usage("<command> [subcommand] [options]");
|
|
15112
15148
|
program.hook("preAction", () => {
|
|
15113
15149
|
const opts = program.opts();
|