NapNeko / NapCat-Docker

NapCat-Docker
184 stars 28 forks source link

反向连接ws报错 Invalid URL #3

Closed ForElysia-Emen closed 5 months ago

ForElysia-Emen commented 5 months ago
downloadPath /root/.config/QQ/NapCat/temp
{
  selfUin: '手动删除',
  selfUid: 'u_r0-e5BSdgvyhDTDjgrq1Zg',
  desktopPathConfig: { account_path: '/root/.config/QQ' },
  clientVer: '9.9.9-22578',
  a2: '',
  d2: '',
  d2Key: '',
  machineId: '',
  platform: 3,
  platVer: '5.15.0-91-generic',
  appid: '537213710',
  rdeliveryConfig: {
    appKey: '',
    systemId: 0,
    appId: '',
    logicEnvironment: '',
    platform: 3,
    language: '',
    sdkVersion: '',
    userId: '',
    appVersion: '',
    osVersion: '',
    bundleId: '',
    serverUrl: '',
    fixedAfterHitKeys: [ '' ]
  },
  defaultFileDownloadPath: '/root/.config/QQ/NapCat/temp',
  deviceInfo: {
    guid: '17755563-a24d-4005-aa53-1a462e014e70',
    buildVer: '3.2.7-22868',
    localId: 2052,
    devName: '09f5266a88e0',
    devType: 'Linux',
    vendorName: '',
    osVer: '5.15.0-91-generic',
    vendorOsName: 'Linux',
    setMute: false,
    vendorType: 0
  },
  deviceConfig: '{"appearance":{"isSplitViewMode":true},"msg":{}}'
}
linux-bugly: init bugly ...
InitBuglyManager
SetLogger
fatalSetup
GetDllPath: 33
pub_key_path: /opt/QQ/resources/app/pub.key
[BuglyManager.cpp][InitBuglyManager][212]InitBuglyManager path: /root/.config/QQ/crash_files/
BuglyManager/opt/QQ/resources/app/pub.key
[BuglyService.cpp][CreatDir][70]!!!begin to CreatDir 0: /root/.config/QQ/crash_files/
[BuglyService.cpp][registBugly][589]set signal stack
[BuglyService.cpp][registSignalHandler][520]regist native handler
registBugly/opt/QQ/resources/app/pub.key
[BuglyService.cpp][setParam][618]setParam, key:appVersion, value:9.9.9-22578..
setParam/opt/QQ/resources/app/pub.key
StartWithOptions s/opt/QQ/resources/app/pub.key
StartWithOptions e/opt/QQ/resources/app/pub.key
PostDelayedTask s/opt/QQ/resources/app/pub.key
PostDelayedTask e/opt/QQ/resources/app/pub.key
linux-bugly: init bugly done.
ob11 ready
get config {
  httpPort: 3000,
  httpPostUrls: [ '' ],
  httpSecret: '',
  wsPort: 3001,
  wsReverseUrls: [ 'WS_URLS' ],
  enableHttp: false,
  enableHttpPost: false,
  enableWs: false,
  enableWsReverse: true,
  messagePostFormat: 'array',
  reportSelfMessage: false,
  debug: false,
  enableLocalFile2Url: false,
  heartInterval: 60000,
  token: ''
}
开始连接反向ws WS_URLS
SyntaxError: Invalid URL: WS_URLS
    at initAsClient (/root/node_modules/ws/lib/websocket.js:692:13)
    at new WebSocket (/root/node_modules/ws/lib/websocket.js:85:7)
    at x5.connect (/root/napcat.cjs:3:387729)
    at new x5 (/root/napcat.cjs:3:385448)
    at /root/napcat.cjs:3:388899
    at new Promise (<anonymous>)
    at r5.start (/root/napcat.cjs:3:388735)
    at p5.onReady (/root/napcat.cjs:3:407062)
    at /root/napcat.cjs:3:106665
    at new Promise (<anonymous>)
ob11 msg listener added
ob11 buddy listener added
ob11 group listener added
login success
[BuglyManager.cpp][UploadBugly][107]!!!in UploadBugly.
[NativeCrashHandler.cpp][getCrashDetailBeanFromRecord][52]!!!! in NativeCrashHandler getCrashDetailBeanFromRecord, open file error!!!,dumpFilePath:/root/.config/QQ/crash_files/rqd_record.eup.
[NativeCrashHandler.cpp][uploadCrashEvent][331]get null crashDetailBean, return!

ws地址为

ws://172.17.0.4:8080/onebot/v11/ws

当在宿主机中直接clone napcatqq使用sh脚本启动时,没有报错(已配置反向ws地址)

MliKiowa commented 5 months ago

给出配置文件的内容

ForElysia-Emen commented 5 months ago

给出配置文件的内容

宿主机上的配置文件

{
  "enableHttp": false,
  "httpPort": 3000,
  "enableWs": false,
  "wsPort": 3001,
  "enableWsReverse": true,
  "wsReverseUrls": ["ws://172.17.0.4:8080/onebot/v11/ws"],
  "enableHttpPost": false,
  "httpPostUrls": [],
  "httpSecret": "",
  "messagePostFormat": "array",
  "reportSelfMessage": false,
  "debug": false,
  "enableLocalFile2Url": true,
  "heartInterval": 30000,
  "token": ""
}

docker的启动命令

docker run -d -e ACCOUNT=1234567 -e WSR_ENABLE=true -e WS_URLS="ws://172.17.0.4:8080/onebot/v11/ws" --name napcat mlikiowa/napcat-docker:latest
initialencounter commented 5 months ago

docker镜像不是最新的吧,该问题已在(#2)中修复,请使用命令docker pull mlikiowa/napcat-docker:latest拉取最新的镜像

ForElysia-Emen commented 5 months ago

已经是最新的镜像了 但是entrypoint中的

 53     if [ "$WS_URLS" ]; then
 54         sed -i "s/WS_URLS/$WS_URLS/" $CONFIG_PATH
 55     else
 56         sed -i "s/\"WS_URLS\"/\"\"/" $CONFIG_PATH
 57     fi

没有按照预期执行 这是容器的config文件:

root@163eb74f0456:~# cat config.txt
{
    "httpPort": HTTP_PORT,
    "httpPostUrls": ["HTTP_URLS"],
    "httpSecret": "",
    "wsPort": WS_PORT,
    "wsReverseUrls": ["WS_URLS"],
    "enableHttp": HTTP_ENABLE,
    "enableHttpPost": HTTP_POST_ENABLE,
    "enableWs": WS_ENABLE,
    "enableWsReverse": WSR_ENABLE,
    "messagePostFormat": "array",
    "reportSelfMessage": RSM_ENABLE,
    "debug": DEBUG_ENABLE,
    "enableLocalFile2Url": F2U_ENABLE,
    "heartInterval": HEART,
    "token": "TOKEN"
}
root@163eb74f0456:~# cat config/onebot11_3825923451.json
{
    "httpPort": 3000,
    "httpPostUrls": [""],
    "httpSecret": "",
    "wsPort": 3001,
    "wsReverseUrls": ["WS_URLS"],
    "enableHttp": false,
    "enableHttpPost": false,
    "enableWs": false,
    "enableWsReverse": true,
    "messagePostFormat": "array",
    "reportSelfMessage": false,
    "debug": false,
    "enableLocalFile2Url": false,
    "heartInterval": 60000,
    "token": ""
}
ForElysia-Emen commented 5 months ago

按照copilot的说法: WS_URLS 的值包含了特殊字符 /,这在 sed 的替换表达式中被用作分隔符。因此,如果你直接使用这个值,sed 会将其解析为命令的一部分,从而导致错误。

例如,如果你运行 sed "s/WS_URLS/$WS_URLS/" $CONFIG_PATH,实际上 sed 会看到的命令是 sed "s/WS_URLS/ws://172.17.0.4:8080/onebot/v11/ws/" $CONFIG_PATH。这里的 // 和 /onebot/ 会被 sed 解析为命令的一部分,从而导致错误。

只需要把

sed -i "s/WS_URLS/$WS_URLS/" $CONFIG_PATH

改成

sed -i "s#WS_URLS#$WS_URLS#" $CONFIG_PATH

我已经提交了一个新的分支,fix-wsurl,如果测试后没有问题,请合并到主分支里

initialencounter commented 5 months ago

抱歉我忽略了这个问题,已合并(#4 )