### Setup Development Environment Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Install project dependencies for development. ```bash npm install ``` -------------------------------- ### Install Command-Line Tool Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Install the qrcode-terminal globally to use it as a command-line tool. ```bash $ npm install -g qrcode-terminal ``` -------------------------------- ### Install Node.js Library Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Install the qrcode-terminal package using npm. This is required to use the library in your Node.js projects. ```bash npm install qrcode-terminal ``` -------------------------------- ### Command-Line Usage Examples Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Examples of using the qrcode-terminal command-line tool to generate QR codes for given input. ```bash $ qrcode-terminal --help ``` ```bash $ qrcode-terminal 'http://github.com' ``` ```bash $ echo 'http://github.com' | qrcode-terminal ``` -------------------------------- ### Run Tests Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Execute the project's test suite. ```bash npm test ``` -------------------------------- ### Initialize Dashboard and Fetch Data Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-plugin-builtin/webui/dashboard.html Initializes the dashboard by fetching the plugin's status and configuration. It also sets up an interval to automatically refresh the status every 30 seconds. This code should be run when the dashboard page loads. ```javascript const urlParams = new URLSearchParams(window.location.search); const webuiToken = localStorage.getItem('token') || ''; const apiBase = '/api/Plugin/ext/napcat-plugin-builtin'; const staticBase = '/plugin/napcat-plugin-builtin/files'; const memBase = '/plugin/napcat-plugin-builtin/mem'; async function authFetch (url, options = {}) { const headers = options.headers || {}; if (webuiToken) { headers['Authorization'] = `Bearer ${webuiToken}`; } return fetch(url, { ...options, headers }); } async function fetchStatus () { try { const response = await authFetch(`${apiBase}/status`); const result = await response.json(); if (result.code === 0) { renderStatus(result.data); } else { showError('获取状态失败: ' + result.message); } } catch (error) { showError('请求失败: ' + error.message); } } async function fetchConfig () { try { const response = await authFetch(`${apiBase}/config`); const result = await response.json(); if (result.code === 0) { renderConfig(result.data); } else { showError('获取配置失败: ' + result.message); } } catch (error) { showError('请求失败: ' + error.message); } } function renderStatus (data) { const content = document.getElementById('content'); content.innerHTML = `
插件名称
${data.pluginName}
运行时间
${data.uptimeFormatted}
运行平台
${data.platform}
系统架构
${data.arch}
`; } function renderConfig (config) { const content = document.getElementById('config-content'); const items = Object.entries(config) .map(([key, value]) => `
  • ${key} ${JSON.stringify(value)}
  • `) .join(''); content.innerHTML = ` `; } function showError (message) { const content = document.getElementById('content'); content.innerHTML = `
    ${message}
    `; } function refresh () { document.getElementById('content').innerHTML = '
    加载中
    '; fetchStatus(); fetchConfig(); } refresh(); setInterval(refresh, 30000); ``` -------------------------------- ### Generate Small QR Code to String Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Generate a small QR code and receive it as a string via a callback, using the `small: true` option. ```javascript qrcode.generate('This will be a small QRCode, eh!', {small: true}, function (qrcode) { console.log(qrcode) }); ``` -------------------------------- ### Generate QR Code to String Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Generate a QR code and receive it as a string via a callback function, instead of displaying it directly in the terminal. ```javascript qrcode.generate('http://github.com', function (qrcode) { console.log(qrcode); }); ``` -------------------------------- ### Generate QR Code in Terminal Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Generate and display a QR code for the given data directly in the terminal. ```javascript qrcode.generate('This will be a QRCode, eh!'); ``` -------------------------------- ### Generate Small QR Code Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Generate a smaller QR code by passing the `small: true` option. This can be useful for limited terminal space. ```javascript qrcode.generate('This will be a small QRCode, eh!', {small: true}); ``` -------------------------------- ### Test Static Resource Access Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-plugin-builtin/webui/dashboard.html Tests the ability to access static resources provided by the plugin. This function fetches a 'test.txt' file from the plugin's static base path. It does not require authentication. ```javascript async function testStaticResource () { const resultDiv = document.getElementById('static-result'); resultDiv.innerHTML = '
    加载中
    '; try { const response = await fetch(`${staticBase}/static/test.txt`); if (response.ok) { const text = await response.text(); resultDiv.innerHTML = `
    文件系统静态资源访问成功
    ${text}
    `; } else { resultDiv.innerHTML = `
    请求失败: ${response.status} ${response.statusText}
    `; } } catch (error) { resultDiv.innerHTML = `
    请求失败: ${error.message}
    `; } } ``` -------------------------------- ### Test Memory Resource Access Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-plugin-builtin/webui/dashboard.html Tests the ability to access memory-based resources provided by the plugin. This function fetches a 'dynamic/info.json' file from the plugin's memory base path. It does not require authentication. ```javascript async function testMemoryResource () { const resultDiv = document.getElementById('static-result'); resultDiv.innerHTML = '
    加载中
    '; try { const response = await fetch(`${memBase}/dynamic/info.json`); if (response.ok) { const json = await response.json(); resultDiv.innerHTML = `
    内存生成资源访问成功
    ${JSON.stringify(json, null, 2)}
    `; } else { resultDiv.innerHTML = `
    请求失败: ${response.status} ${response.statusText}
    `; } } catch (error) { resultDiv.innerHTML = `
    请求失败: ${error.message}
    `; } } ``` -------------------------------- ### Require Node.js Library Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Require the qrcode-terminal module in your Node.js application to access its functions. ```javascript var qrcode = require('qrcode-terminal'); ``` -------------------------------- ### Set QR Code Error Level Source: https://github.com/napneko/napcatqq/blob/main/packages/napcat-qrcode/README.md Set the error correction level for subsequent QR code generations. The default is 'L'. 'Q' provides a higher level of error correction. ```javascript qrcode.setErrorLevel('Q'); qrcode.generate('This will be a QRCode with error level Q!'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.