feishu-sidebar 0.1.0: a page that opens Magpie Web in Feishu's sidebar (#1212)
A page plugin that turns a Magpie Web address into Feishu's client/web_url/open AppLink (mode=appCenter), so Magpie Web opens in Feishu desktop's left sidebar. No permissions, no request: the page only builds the link. Addresses with credentials, a query or a fragment are refused (keeps ?k= keys out of a shared link), and plain HTTP only on loopback. By zhaiqiming. Run at the reviewed head f3164eb2 (mica, temp HOME): - bun test packages/feishu-sidebar: 3 pass, 0 fail. - bun scripts/check.mjs feishu-sidebar: ok. bun test scripts: 39 pass. - The page itself, with a stub bridge, in Playwright Chromium and WebKit at 400px, en and zh-CN: the title is translated, Enter on a loopback address shows the link, a ?k= address shows the error and hides the link, nothing scrolls sideways. Not tried: Feishu desktop itself (the author verified it on macOS). The package's first npm version waits for the owner; dist serves it.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
# Feishu sidebar
|
||||
|
||||
Open Magpie Web in the left sidebar of the Feishu desktop client. This page
|
||||
generates Feishu's `client/web_url/open` AppLink with `mode=appCenter`.
|
||||
|
||||
1. Enable **Settings → Network and sharing → Browser access** in Magpie, or
|
||||
start `magpie web`.
|
||||
2. In **Plugins → Feishu sidebar**, enter the Web address, for example
|
||||
`http://127.0.0.1:3430` on the same computer. Use a reachable HTTPS
|
||||
address for Magpie on another computer. Leave out the `?k=...` sign-in
|
||||
parameter from the URL printed by `magpie web`.
|
||||
3. Generate the link and copy the selected text to your own Feishu chat.
|
||||
Open it in Feishu desktop. If Magpie asks for its Web access key, enter
|
||||
the key on Magpie's sign-in screen. To keep the tab, right-click it in
|
||||
the left sidebar and pin it.
|
||||
|
||||
The plugin generates the link locally in a sandboxed page. It doesn't read
|
||||
Magpie data, store the address, or send a request. The link includes the
|
||||
destination address, so share it only where you intend to disclose that
|
||||
address. Magpie Web still handles authentication.
|
||||
@@ -0,0 +1,35 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { readFileSync } from "node:fs"
|
||||
|
||||
const source = readFileSync(new URL("./page/applink.js", import.meta.url), "utf8")
|
||||
const buildLink = new Function(source + "\nreturn buildFeishuLink")()
|
||||
|
||||
test("opens a Magpie Web URL with a path as an appCenter AppLink", () => {
|
||||
const { link } = buildLink(" https://magpie.example.test/panels/magpie%20web/ ")
|
||||
const url = new URL(link)
|
||||
expect(url.origin + url.pathname).toBe("https://applink.feishu.cn/client/web_url/open")
|
||||
expect(Object.fromEntries(url.searchParams)).toEqual({
|
||||
mode: "appCenter",
|
||||
url: "https://magpie.example.test/panels/magpie%20web/",
|
||||
})
|
||||
})
|
||||
|
||||
test("allows Magpie Web on the desktop computer over loopback HTTP", () => {
|
||||
for (const host of ["127.0.0.1", "localhost", "[::1]"]) {
|
||||
const address = `http://${host}:3430`
|
||||
expect(new URL(buildLink(address).link).searchParams.get("url")).toBe(address + "/")
|
||||
}
|
||||
})
|
||||
|
||||
test("does not generate a shareable link from a sign-in URL or an unencrypted remote console", () => {
|
||||
for (const address of [
|
||||
"https://magpie.example.test/?k=example-access-key",
|
||||
"https://user:secret@magpie.example.test/",
|
||||
"https://magpie.example.test/#token",
|
||||
]) expect(buildLink(address)).toEqual({ error: "plainAddress" })
|
||||
|
||||
expect(buildLink("http://magpie.example.test:3430")).toEqual({ error: "https" })
|
||||
for (const address of ["javascript:alert(1)", "https:///example.test", "magpie.example.test", ""]) {
|
||||
expect(buildLink(address)).toEqual({ error: "invalid" })
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@magpie-community/page-feishu-sidebar",
|
||||
"version": "0.1.0",
|
||||
"description": "Open Magpie Web in the Feishu desktop sidebar with an AppLink",
|
||||
"files": ["page", "README.md"],
|
||||
"keywords": ["magpie", "magpie-page", "feishu"],
|
||||
"license": "MIT",
|
||||
"repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/feishu-sidebar" },
|
||||
"magpie": {
|
||||
"page": {
|
||||
"title": "Feishu sidebar",
|
||||
"titles": { "zh": "飞书侧边栏" },
|
||||
"file": "page/index.html"
|
||||
},
|
||||
"permissions": []
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
(() => {
|
||||
const en = {
|
||||
title: "Feishu sidebar",
|
||||
setup: "Enable Browser access in Magpie, or run magpie web.",
|
||||
address: "Magpie Web address",
|
||||
hint: "Use the address without the sign-in key. Use HTTPS for another computer.",
|
||||
generate: "Generate Feishu link",
|
||||
link: "Feishu link",
|
||||
select: "Select link",
|
||||
steps: "Copy the link to your own Feishu chat and open it in Feishu desktop. Sign in on Magpie’s page, then right-click the sidebar tab to pin it.",
|
||||
invalid: "Enter a full Magpie Web address starting with http:// or https://.",
|
||||
plainAddress: "Remove credentials, query parameters and fragments from the address before sharing it.",
|
||||
https: "Use an HTTPS address for Magpie Web on another computer.",
|
||||
}
|
||||
const zh = {
|
||||
title: "飞书侧边栏",
|
||||
setup: "在 Magpie 设置里开启浏览器访问,或运行 magpie web。",
|
||||
address: "Magpie Web 地址",
|
||||
hint: "请填写不含登录密钥的网址。访问其他电脑上的 Magpie 时请用 HTTPS。",
|
||||
generate: "生成飞书链接",
|
||||
link: "飞书链接",
|
||||
select: "选中链接",
|
||||
steps: "复制链接,粘贴到飞书里发给自己,再用飞书桌面端打开。在 Magpie 页面登录后,可以右键点击左侧标签页将它固定。",
|
||||
invalid: "请输入以 http:// 或 https:// 开头的完整 Magpie Web 地址。",
|
||||
plainAddress: "请先从地址中移除身份凭据、查询参数和片段。",
|
||||
https: "访问其他电脑上的 Magpie Web 时请用 HTTPS 地址。",
|
||||
}
|
||||
const address = document.getElementById("web-url")
|
||||
const error = document.getElementById("error")
|
||||
const result = document.getElementById("result")
|
||||
const link = document.getElementById("applink")
|
||||
const text = document.querySelectorAll("[data-t]")
|
||||
let words = en
|
||||
let problem = ""
|
||||
|
||||
function translate(theme) {
|
||||
words = theme?.lang?.startsWith("zh") ? zh : en
|
||||
for (const element of text) element.textContent = words[element.dataset.t]
|
||||
error.textContent = words[problem] ?? ""
|
||||
}
|
||||
|
||||
function show(output) {
|
||||
problem = output.error ?? ""
|
||||
error.textContent = words[problem] ?? ""
|
||||
address.setAttribute("aria-invalid", String(Boolean(problem)))
|
||||
link.value = output.link ?? ""
|
||||
result.hidden = !output.link
|
||||
}
|
||||
|
||||
function selectLink() {
|
||||
link.focus()
|
||||
link.select()
|
||||
}
|
||||
|
||||
function generate() {
|
||||
const output = buildFeishuLink(address.value)
|
||||
show(output)
|
||||
if (output.link) selectLink()
|
||||
else address.focus()
|
||||
}
|
||||
|
||||
address.addEventListener("input", () => show({}))
|
||||
address.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter" && !event.isComposing) generate()
|
||||
})
|
||||
document.getElementById("generate").addEventListener("click", generate)
|
||||
document.getElementById("select").addEventListener("click", selectLink)
|
||||
|
||||
magpie.onTheme(translate)
|
||||
magpie.ready.then(translate)
|
||||
})()
|
||||
@@ -0,0 +1,20 @@
|
||||
// The inner address is a single AppLink query value. Keep sign-in material out of it.
|
||||
function buildFeishuLink(address) {
|
||||
const text = address.trim()
|
||||
if (!/^https?:\/\/[^/]/i.test(text) || /\s|\\/.test(text)) return { error: "invalid" }
|
||||
|
||||
let url
|
||||
try {
|
||||
url = new URL(text)
|
||||
} catch {
|
||||
return { error: "invalid" }
|
||||
}
|
||||
if (url.username || url.password || /[?#]/.test(text)) return { error: "plainAddress" }
|
||||
|
||||
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname)
|
||||
if (url.protocol === "http:" && !loopback) return { error: "https" }
|
||||
|
||||
return {
|
||||
link: "https://applink.feishu.cn/client/web_url/open?mode=appCenter&url=" + encodeURIComponent(url.href),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Feishu sidebar</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script src="_magpie/bridge.js"></script>
|
||||
<script src="applink.js" defer></script>
|
||||
<script src="app.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1 data-t="title">Feishu sidebar</h1>
|
||||
<p data-t="setup">Enable Browser access in Magpie, or run magpie web.</p>
|
||||
<label for="web-url" data-t="address">Magpie Web address</label>
|
||||
<input id="web-url" type="text" inputmode="url" spellcheck="false" autocomplete="off"
|
||||
placeholder="http://127.0.0.1:3430" aria-describedby="hint error">
|
||||
<p id="hint" data-t="hint">Use the address without the sign-in key. Use HTTPS for another computer.</p>
|
||||
<button id="generate" type="button" data-t="generate">Generate Feishu link</button>
|
||||
<p id="error" role="alert"></p>
|
||||
<section id="result" hidden>
|
||||
<label for="applink" data-t="link">Feishu link</label>
|
||||
<div class="link-row">
|
||||
<input id="applink" type="text" readonly aria-describedby="steps">
|
||||
<button id="select" type="button" data-t="select">Select link</button>
|
||||
</div>
|
||||
<p id="steps" data-t="steps">Copy the link to your own Feishu chat and open it in Feishu desktop. Sign in on Magpie’s page, then right-click the sidebar tab to pin it.</p>
|
||||
</section>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
body { margin: 0; padding: 20px 24px 32px; }
|
||||
main { max-width: 36rem; }
|
||||
label { display: block; font-weight: 600; margin: 1rem 0 .35rem; }
|
||||
input { box-sizing: border-box; width: 100%; }
|
||||
p { color: var(--magpie-muted, #6e6e73); }
|
||||
#hint, #steps { margin: .5rem 0 .75rem; }
|
||||
#error { color: var(--magpie-red, #d70015); }
|
||||
#error:empty { margin: 0; }
|
||||
.link-row { display: flex; gap: .5rem; }
|
||||
.link-row input { min-width: 0; }
|
||||
.link-row button { white-space: nowrap; }
|
||||
Reference in New Issue
Block a user