Skip to content

Commit

Permalink
Update plugin-share-profile-to-phone
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayideyia committed Oct 15, 2024
1 parent 09a1be5 commit c4f967b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions plugins/GFS/plugin-share-profile-to-phone.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ const onRun = async () => {
})
const config = await Plugins.generateConfig(_profile)
const ips = await getIPAddress()
const urls = await Promise.all(ips.map((ip) => getQRCode(`http://${ip}:${Plugin.Port}`)))
const urls = await Promise.all(ips.map((ip) => {
const url = `http://${ip}:${Plugin.Port}`
return getQRCode(url, `sing-box://import-remote-profile?url=${encodeURIComponent(url)}#${_profile.name}`)
}))
// await Plugins.StopServer(Plugin.id)
const { close } = await Plugins.StartServer('0.0.0.0:' + Plugin.Port, Plugin.id, async (req, res) => {
res.end(200, { 'Content-Type': 'application/json; charset=utf-8' }, JSON.stringify(config, null, 2))
})
await Plugins.alert(Plugin.name, '|分享链接|二维码|\n|-|-|\n' + urls.map((url) => `|${url.raw}|![](${url.url})|`).join('\n'), { type: 'markdown' })
await Plugins.alert(Plugin.name, '|分享链接|二维码|\n|-|-|\n' + urls.map((url) => `|${url.url}|![](${url.qrcode})|`).join('\n'), { type: 'markdown' })
close()
}

Expand Down Expand Up @@ -85,10 +88,10 @@ function loadDependence() {
})
}

function getQRCode(str) {
function getQRCode(rawUrl, rawStr) {
return new Promise((resolve) => {
QRCode.toDataURL(str, async (err, url) => {
resolve({ url, raw: str })
QRCode.toDataURL(rawStr, async (err, url) => {
resolve({ url: rawUrl, qrcode: url })
})
})
}
Expand Down

0 comments on commit c4f967b

Please sign in to comment.