Skip to content

Commit

Permalink
9.10 v1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ltxhhz committed Sep 10, 2024
1 parent 5e43888 commit 366f16d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
*.zip
data
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"description": "插件列表查看·安装·更新",
"icon": "assets/icon.svg",
"thumb": "assets/icon.svg",
"version": "1.4.0",
"version": "1.4.1",
"authors": [
{
"name": "ltxhhz",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "list-viewer",
"version": "1.4.0",
"version": "1.4.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 1 addition & 5 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { GlobalMethods, HandleResult, Config } from '../global'
import fs from 'fs'
import path from 'path'
import StreamZip from 'node-stream-zip'
import { request } from './utils'
import { output, request } from './utils'
import { ProxyAgent } from 'proxy-agent'

const thisSlug = 'list-viewer'
Expand Down Expand Up @@ -102,10 +102,6 @@ handle('request', async (_, url, opt): Promise<HandleResult> => {
}
})

function output(...args: any[]) {
console.log('\x1b[32m[ListViewer]\x1b[0m', ...args)
}

async function installPlugin(cache_file_path: string, slug: string): Promise<HandleResult> {
const { plugins } = LiteLoader.path
let plugin_path = LiteLoader.plugins[slug]?.path?.plugin || path.join(plugins, slug)
Expand Down
38 changes: 35 additions & 3 deletions src/main/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import http from 'http'
import https from 'https'
import { URL } from 'url'
import fs from 'fs'
import path from 'path'

import { HttpsProxyAgent } from 'https-proxy-agent'
import { HttpProxyAgent } from 'http-proxy-agent'
import { SocksProxyAgent } from 'socks-proxy-agent'
import type { RequestOptions } from '../global'
import type { Config, RequestOptions } from '../global'

const thisSlug = 'list-viewer'
export function request(
url: string,
options: RequestOptions = {}
Expand Down Expand Up @@ -66,13 +69,15 @@ export function request(
res.on('data', chunk => chunks.push(chunk))
res.on('end', () => {
const data = Buffer.concat(chunks)
resolve({
const obj = {
data: data,
str: data.toString('utf-8'),
status: res.statusCode,
statusText: res.statusMessage,
url: res.url
})
}
output(obj)
resolve(obj)
})
})

Expand All @@ -86,3 +91,30 @@ export function request(
req.end() // 完成请求
})
}

export function output(...args: any[]) {
try {
if ((LiteLoader.api.config.get<Config>(thisSlug) as Config).debug) {
fs.appendFileSync(
path.join(LiteLoader.plugins[thisSlug].path.data, 'debug.log'),
`[${new Date().toLocaleString()}] ${args
.map(e =>
JSON.stringify(
e,
(key, value) => {
if (typeof value === 'bigint') return value.toString()
else if (value?.type === 'Buffer' && Array.isArray(value.data)) return `Buffer<${value?.data?.length}>`
return value
},
2
)
)
.join(' ')}\n`
)
}
} catch (error) {
console.warn('\x1b[32m[ListViewer]\x1b[0m', '输出到日志文件失败', error)
}

console.log('\x1b[32m[ListViewer]\x1b[0m', ...args)
}

0 comments on commit 366f16d

Please sign in to comment.