docker部署onlyoffice,开启JWT权限校验Token

news2024/11/15 2:10:55

原来的部署方式

之前的方式是禁用了JWT:

docker run -itd -p 8080:80 --name docserver --network host  -e JWT_ENABLED=false --restart=always onlyoffice/documentserver:8 

新的部署方式

参考文档:https://helpcenter.onlyoffice.com/installation/docs-developer-install-docker.aspx?from=api

启用JWT Token:-e JWT_SECRET=my_jwt_secret

docker run -itd -p 8080:80 --name docserver --network host  -e JWT_SECRET=my_jwt_secret --restart=always onlyoffice/documentserver:8 

保存容器的数据:
参考命令:

sudo docker run -i -t -d -p 80:80 --restart=always \
    -v /app/onlyoffice/DocumentServer/logs:/var/log/onlyoffice  \
    -v /app/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data  \
    -v /app/onlyoffice/DocumentServer/lib:/var/lib/onlyoffice \
    -v /app/onlyoffice/DocumentServer/db:/var/lib/postgresql -e JWT_SECRET=my_jwt_secret onlyoffice/documentserver-de

创建相关的目录:

cd ~/docker/docserver
mkdir logs data lib db

停止容器:

docker stop docserver && docker rm docserver

构建容器:

docker run -itd --name docserver -p 18889:80 --restart=always \
    -v /home/zhangdapeng/docker/docserver/logs:/var/log/onlyoffice  \
    -v /home/zhangdapeng/docker/docserver/data:/var/www/onlyoffice/Data  \
    -v /home/zhangdapeng/docker/docserver/lib:/var/lib/onlyoffice \
    -v /home/zhangdapeng/docker/docserver/db:/var/lib/postgresql -e JWT_SECRET=zhangdapeng520 onlyoffice/documentserver:8

查看容器日志:

docker logs -f --tail 100 docserver

获取JWT Token

参考文档:https://api.onlyoffice.com/zh/editors/signature/

将配置文件复制出来:

docker cp docserver:/etc/onlyoffice/documentserver/local.json .

原始默认内容:

{
  "services": {
    "CoAuthoring": {
      "sql": {
        "type": "postgres",
        "dbHost": "localhost",
        "dbPort": "5432",
        "dbName": "onlyoffice",
        "dbUser": "onlyoffice",
        "dbPass": "onlyoffice"
      },
      "token": {
        "enable": {
          "request": {
            "inbox": true,
            "outbox": true
          },
          "browser": true
        },
        "inbox": {
          "header": "Authorization",
          "inBody": false
        },
        "outbox": {
          "header": "Authorization",
          "inBody": false
        }
      },
      "secret": {
        "inbox": {
          "string": "zhangdapeng520"
        },
        "outbox": {
          "string": "zhangdapeng520"
        },
        "session": {
          "string": "zhangdapeng520"
        }
      }
    }
  },
  "rabbitmq": {
    "url": "amqp://guest:guest@localhost"
  },
  "wopi": {
    "enable": false,
    "privateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC12HeKvvcytCl7\nvBpXP8uO8SSvntAHTT/hOZIJnCsMRs5OQiETa690iaU+Dos4xY6RyQW7jqioyWlC\n8cQXFu7JG9XhFkEmX2hIM3YouzjVnXr1C75U77q91svj2p2HG7c/UhglS/1plYuG\nmlqTMqxSKqERnbvtxpRweg629o+u9te++dJp+Lco5v0UE17xm5GmW85nG4NpMuf4\nrXx1m43nCjIPJ6+eVyDl1C1q9OoQz9azJjq6B2PDaLC/FI+HVsL55GD+CgFjmAjT\nooyqM7/5adbC4NjNGrxIi6pE28fndSiB3jlgrBYGMzK5G8fwWjbB3K+ZjZWsJY+d\n53PMueH1AgMBAAECggEADol0nDL1W2hoQCi16SkQhbSEv8T2d8oqCkAj16cHdyhH\nGgRF7tUD39EyVG2T0KDua3yCYk+E74iGZMa9OJe2bn2BeBVJqQUlUE9/QygdL4QZ\nQVl3SJ5cTQyZgqh5dMSqitVuJVEkiLPFRY61h4eCzuC/vPZHzaBuqAObhVUQAHPY\n8Y50kXFcCCsQdAuqV+jTG8+Er6nmktBBig6k+QP/XptwLtLpJiAdksVXvCDrHAJC\nzFTfDLCf0D4QIg5ecjIY/TfSOwPmXk11/xLLSmCJ9HnIWh9uReyo+aWKL748MRLk\nsVbRY4xT6DtDv5Ni47lECDQETg5h9d1NsrE4AQn40wKBgQDVbT2lu1Qma7AftFzW\nF1Zdkh1HROjnczTAJNSLhq5MkpD/WEDwbwdGdVZmW/xR+sEU1Wl/W0/gmD6PHK0i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qI67BcmRjsU4iw4+pYl0r2sTIUJOzkYMK5wJkjnhP00H0J6vJPGOyz9XGrx7KbQy976Kd9i1",
    "modulus": "B5D8778ABEF732B4297BBC1A573FCB8EF124AF9ED0074D3FE13992099C2B0C46CE4E4221136BAF7489A53E0E8B38C58E91C905BB8EA8A8C96942F1C41716EEC91BD5E11641265F6848337628BB38D59D7AF50BBE54EFBABDD6CBE3DA9D871BB73F5218254BFD69958B869A5A9332AC522AA1119DBBEDC694707A0EB6F68FAEF6D7BEF9D269F8B728E6FD14135EF19B91A65BCE671B836932E7F8AD7C759B8DE70A320F27AF9E5720E5D42D6AF4EA10CFD6B3263ABA0763C368B0BF148F8756C2F9E460FE0A01639808D3A28CAA33BFF969D6C2E0D8CD1ABC488BAA44DBC7E7752881DE3960AC16063332B91BC7F05A36C1DCAF998D95AC258F9DE773CCB9E1F5",
    "modulusOld": "B5D8778ABEF732B4297BBC1A573FCB8EF124AF9ED0074D3FE13992099C2B0C46CE4E4221136BAF7489A53E0E8B38C58E91C905BB8EA8A8C96942F1C41716EEC91BD5E11641265F6848337628BB38D59D7AF50BBE54EFBABDD6CBE3DA9D871BB73F5218254BFD69958B869A5A9332AC522AA1119DBBEDC694707A0EB6F68FAEF6D7BEF9D269F8B728E6FD14135EF19B91A65BCE671B836932E7F8AD7C759B8DE70A320F27AF9E5720E5D42D6AF4EA10CFD6B3263ABA0763C368B0BF148F8756C2F9E460FE0A01639808D3A28CAA33BFF969D6C2E0D8CD1ABC488BAA44DBC7E7752881DE3960AC16063332B91BC7F05A36C1DCAF998D95AC258F9DE773CCB9E1F5",
    "exponent": 65537,
    "exponentOld": 65537
  },
  "storage": {
    "fs": {
      "secretString": "HD97Gwvu8Z28TVQQOgMS"
    }
  }
}

参数说明:
在这里插入图片描述

修改:

{
  "services": {
    "CoAuthoring": {
      "sql": {
        "type": "postgres",
        "dbHost": "localhost",
        "dbPort": "5432",
        "dbName": "onlyoffice",
        "dbUser": "onlyoffice",
        "dbPass": "onlyoffice"
      },
      "token": {
        "enable": {
          "request": {
            "inbox": true,
            "outbox": true
          },
          "browser": true
        },
        "inbox": {
          "header": "Authorization",
          "inBody": true
        },
        "outbox": {
          "header": "Authorization",
          "inBody": true
        }
      },
      "secret": {
        "inbox": {
          "string": "zhangdapeng520"
        },
        "outbox": {
          "string": "zhangdapeng520"
        },
        "session": {
          "string": "zhangdapeng520"
        }
      }
    }
  },
  "rabbitmq": {
    "url": "amqp://guest:guest@localhost"
  },
  "wopi": {
    "enable": false,
    "privateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC12HeKvvcytCl7\nvBpXP8uO8SSvntAHTT/hOZIJnCsMRs5OQiETa690iaU+Dos4xY6RyQW7jqioyWlC\n8cQXFu7JG9XhFkEmX2hIM3YouzjVnXr1C75U77q91svj2p2HG7c/UhglS/1plYuG\nmlqTMqxSKqERnbvtxpRweg629o+u9te++dJp+Lco5v0UE17xm5GmW85nG4NpMuf4\nrXx1m43nCjIPJ6+eVyDl1C1q9OoQz9azJjq6B2PDaLC/FI+HVsL55GD+CgFjmAjT\nooyqM7/5adbC4NjNGrxIi6pE28fndSiB3jlgrBYGMzK5G8fwWjbB3K+ZjZWsJY+d\n53PMueH1AgMBAAECggEADol0nDL1W2hoQCi16SkQhbSEv8T2d8oqCkAj16cHdyhH\nGgRF7tUD39EyVG2T0KDua3yCYk+E74iGZMa9OJe2bn2BeBVJqQUlUE9/QygdL4QZ\nQVl3SJ5cTQyZgqh5dMSqitVuJVEkiLPFRY61h4eCzuC/vPZHzaBuqAObhVUQAHPY\n8Y50kXFcCCsQdAuqV+jTG8+Er6nmktBBig6k+QP/XptwLtLpJiAdksVXvCDrHAJC\nzFTfDLCf0D4QIg5ecjIY/TfSOwPmXk11/xLLSmCJ9HnIWh9uReyo+aWKL748MRLk\nsVbRY4xT6DtDv5Ni47lECDQETg5h9d1NsrE4AQn40wKBgQDVbT2lu1Qma7AftFzW\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5Vp/UslGFI/txuHndrjy9a9uu9Uvgv1ep3VOLsodjNIaF8mQRbh1RvJ7hYXxPFCacmoqI67BcmRjsU4iw4+pYl0r2sTIUJOzkYMK5wJkjnhP00H0J6vJPGOyz9XGrx7KbQy976Kd9i1",
    "modulus": "B5D8778ABEF732B4297BBC1A573FCB8EF124AF9ED0074D3FE13992099C2B0C46CE4E4221136BAF7489A53E0E8B38C58E91C905BB8EA8A8C96942F1C41716EEC91BD5E11641265F6848337628BB38D59D7AF50BBE54EFBABDD6CBE3DA9D871BB73F5218254BFD69958B869A5A9332AC522AA1119DBBEDC694707A0EB6F68FAEF6D7BEF9D269F8B728E6FD14135EF19B91A65BCE671B836932E7F8AD7C759B8DE70A320F27AF9E5720E5D42D6AF4EA10CFD6B3263ABA0763C368B0BF148F8756C2F9E460FE0A01639808D3A28CAA33BFF969D6C2E0D8CD1ABC488BAA44DBC7E7752881DE3960AC16063332B91BC7F05A36C1DCAF998D95AC258F9DE773CCB9E1F5",
    "modulusOld": "B5D8778ABEF732B4297BBC1A573FCB8EF124AF9ED0074D3FE13992099C2B0C46CE4E4221136BAF7489A53E0E8B38C58E91C905BB8EA8A8C96942F1C41716EEC91BD5E11641265F6848337628BB38D59D7AF50BBE54EFBABDD6CBE3DA9D871BB73F5218254BFD69958B869A5A9332AC522AA1119DBBEDC694707A0EB6F68FAEF6D7BEF9D269F8B728E6FD14135EF19B91A65BCE671B836932E7F8AD7C759B8DE70A320F27AF9E5720E5D42D6AF4EA10CFD6B3263ABA0763C368B0BF148F8756C2F9E460FE0A01639808D3A28CAA33BFF969D6C2E0D8CD1ABC488BAA44DBC7E7752881DE3960AC16063332B91BC7F05A36C1DCAF998D95AC258F9DE773CCB9E1F5",
    "exponent": 65537,
    "exponentOld": 65537
  },
  "storage": {
    "fs": {
      "secretString": "HD97Gwvu8Z28TVQQOgMS"
    }
  }
}

复制回去:

docker cp local.json docserver:/etc/onlyoffice/documentserver/local.json

重启:

docker restart docserver

使用Python生成Token

官方文档实例:https://api.onlyoffice.com/zh/editors/signature/#python

def encode(payload):
    return jwt.encode(payload, config.DOC_SERV_JWT_SECRET, algorithm='HS256')

使用zdppy_jwt框架生成Token:

import jwt

key = "zhangdapeng520"
algorithm = "HS256"
data = {"id": "1", "username": "zhangdapeng", "role": "admin"}
encoded = jwt.encode(data, key, algorithm=algorithm)
print(encoded)

得到结果:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEiLCJ1c2VybmFtZSI6InpoYW5nZGFwZW5nIiwicm9sZSI6ImFkbWluIn0.EyayWbKV5arHahTiXkSIKb6e1wF5a2pf6NhszyjZYfE

使用之前成功的代码进行测试

后端代码:

import json
import req

import api
from api import middleware
from api.zjson.response import JSONResponse


async def doc_callback(request):
    data = await api.req.get_json(request)
    print("callback === ", data)
    # status == 2 文档准备好被保存
    if data.get("status") == 2:
        req.download(data.get("url"), "data/test.docx")
    if data.get("status") == 6:
        req.download(data.get("url"), "data/test.docx")
    # status == 6 文档编辑会话关闭
    data = {"error": 0}
    # return JSONResponse('{"error":0}')
    return JSONResponse(json.dumps(data))


app = api.Api(
    routes=[
        api.resp.dir_route("/dist", "data"),
        api.resp.post("/callback", doc_callback),
    ],
    middleware=[middleware.cors()],
)

if __name__ == "__main__":
    app.run(port=18888)

前端代码:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite + Vue</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="text/javascript" src="http://127.0.0.1:18889/web-apps/apps/api/documents/api.js"></script>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

但是,现在当我们点击加载的时候,会报如下错误:
在这里插入图片描述

错误原因是因为我们之前的docserver是禁用了JWT的,但是现在我们启用了,而代码还是原来的代码,没有做任何修改。

实际上,我们应该加上JWT Token相关的信息配置。

添加JWT Token

注意:token的payload必须是文档config的完整信息:https://api.onlyoffice.com/zh/editors/signature/browser
在这里插入图片描述

改完后token生成代码如下:

import jwt

key = "zhangdapeng520"
algorithm = "HS256"
data = {
    "document": {
      "fileType": "docx",
      "key": "Khirz6zTPdfd7",
      "title": "Example Document Title.docx",
      "url": "http://127.0.0.1:18888/dist/test.docx"
    },
    "editorConfig": {
      "callbackUrl": "http://127.0.0.1:18888/callback",
      "lang": "zh-CN",
      "user": {
        "id": 1,
        "name": "zdp"
      },
      "customization": {
        "forcesave": True,
      },
      "coEditing": {
        "mode": "fast",
        "change": True
      },
    },
    "documentType": "word",
    "height": '500px',
    "width": '100%',
  }
encoded = jwt.encode(data, key, algorithm=algorithm)
print(encoded)

改完后前端代码如下:

<script setup>
import {message} from "ant-design-vue";

const onLoadDocumentClick = () => {
  message.success("load document")
  // isDocument.value = true
  new DocsAPI.DocEditor("doc", {
    "document": {
      "fileType": "docx",
      "key": `Khirz6zTPdfd7`,
      "title": "Example Document Title.docx",
      "url": "http://127.0.0.1:18888/dist/test.docx"
    },
    "editorConfig": {
      "callbackUrl": "http://127.0.0.1:18888/callback",
      "lang": "zh-CN",
      "user": {
        "id": 1,
        "name": `zdp`
      },
      "customization": {
        "forcesave": true,
      },
      "coEditing": {
        "mode": "fast",
        "change": true
      },
    },
    "documentType": "word",
    height: '500px',
    width: '100%',
    token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb2N1bWVudCI6eyJmaWxlVHlwZSI6ImRvY3giLCJrZXkiOiJLaGlyejZ6VFBkZmQ3IiwidGl0bGUiOiJFeGFtcGxlIERvY3VtZW50IFRpdGxlLmRvY3giLCJ1cmwiOiJodHRwOi8vMTI3LjAuMC4xOjE4ODg4L2Rpc3QvdGVzdC5kb2N4In0sImVkaXRvckNvbmZpZyI6eyJjYWxsYmFja1VybCI6Imh0dHA6Ly8xMjcuMC4wLjE6MTg4ODgvY2FsbGJhY2siLCJsYW5nIjoiemgtQ04iLCJ1c2VyIjp7ImlkIjoxLCJuYW1lIjoiemRwIn0sImN1c3RvbWl6YXRpb24iOnsiZm9yY2VzYXZlIjp0cnVlfSwiY29FZGl0aW5nIjp7Im1vZGUiOiJmYXN0IiwiY2hhbmdlIjp0cnVlfX0sImRvY3VtZW50VHlwZSI6IndvcmQiLCJoZWlnaHQiOiI1MDBweCIsIndpZHRoIjoiMTAwJSJ9.AolS4haisOZc9IxQcd99ovD5FixcfswrhWOnbSRaCJw",
  });
}
</script>
<template>
  <div class="bg-indigo-50 p-8 min-h-screen">
    <div class="bg-amber-200 p-8">
      <a-button type="primary" @click="onLoadDocumentClick">Load Document</a-button>
    </div>
    <div class="bg-amber-400 p-8 min-h-96">
      <div id="doc">doc</div>
    </div>
  </div>
</template>

此时token错误的问题已经解决了,但是出现了下载失败的问题:
在这里插入图片描述

解决下载失败的问题

把配置文件复制出来:

docker cp docserver:/etc/onlyoffice/documentserver/default.json ~/Downloads/default.json

修改:之前

"allowPrivateIPAddress": false,
"allowMetaIPAddress": false

修改:之后

"allowPrivateIPAddress": true,
"allowMetaIPAddress": true

把文件复制进去:

docker cp default.json docserver:/etc/onlyoffice/documentserver/default.json 

进入容器:

docker exec -it docserver bash

重启相关服务:

supervisorctl restart all

或者一次性执行:

docker exec docserver supervisorctl restart all

最终解决方案

生成token:

import jwt

key = "zhangdapeng520"
algorithm = "HS256"
data = {
    "document": {
      "fileType": "docx",
      "key": "Khirz6zTPdfd7",
      "title": "Example Document Title.docx",
      "url": "http://192.168.234.138:18888/dist/test.docx"
    },
    "editorConfig": {
      "callbackUrl": "http://192.168.234.138:18888/callback",
      "lang": "zh-CN",
      "user": {
        "id": "1",
        "name": "zdp"
      },
      "customization": {
        "forcesave": True,
      },
      "coEditing": {
        "mode": "fast",
        "change": True
      },
    },
    "documentType": "word",
    "height": '500px',
    "width": '100%',
  }
encoded = jwt.encode(data, key, algorithm=algorithm)
print(encoded)

前端代码:

<script setup>
import {message} from "ant-design-vue";

const onLoadDocumentClick = () => {
  message.success("load document")
  // isDocument.value = true
  new DocsAPI.DocEditor("doc", {
    "document": {
      "fileType": "docx",
      "key": `Khirz6zTPdfd7`,
      "title": "Example Document Title.docx",
      "url": "http://192.168.234.138:18888/dist/test.docx"
    },
    "editorConfig": {
      "callbackUrl": "http://192.168.234.138:18888/callback",
      "lang": "zh-CN",
      "user": {
        "id": "1",
        "name": "zdp"
      },
      "customization": {
        "forcesave": true,
      },
      "coEditing": {
        "mode": "fast",
        "change": true
      },
    },
    "documentType": "word",
    height: '500px',
    width: '100%',
    token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb2N1bWVudCI6eyJmaWxlVHlwZSI6ImRvY3giLCJrZXkiOiJLaGlyejZ6VFBkZmQ3IiwidGl0bGUiOiJFeGFtcGxlIERvY3VtZW50IFRpdGxlLmRvY3giLCJ1cmwiOiJodHRwOi8vMTkyLjE2OC4yMzQuMTM4OjE4ODg4L2Rpc3QvdGVzdC5kb2N4In0sImVkaXRvckNvbmZpZyI6eyJjYWxsYmFja1VybCI6Imh0dHA6Ly8xOTIuMTY4LjIzNC4xMzg6MTg4ODgvY2FsbGJhY2siLCJsYW5nIjoiemgtQ04iLCJ1c2VyIjp7ImlkIjoiMSIsIm5hbWUiOiJ6ZHAifSwiY3VzdG9taXphdGlvbiI6eyJmb3JjZXNhdmUiOnRydWV9LCJjb0VkaXRpbmciOnsibW9kZSI6ImZhc3QiLCJjaGFuZ2UiOnRydWV9fSwiZG9jdW1lbnRUeXBlIjoid29yZCIsImhlaWdodCI6IjUwMHB4Iiwid2lkdGgiOiIxMDAlIn0.vnSYKU22-IsBmuoSn5Po-Ukz1RrnM-G3ch3-JuJd1xg",
  });
}
</script>
<template>
  <div class="bg-indigo-50 p-8 min-h-screen">
    <div class="bg-amber-200 p-8">
      <a-button type="primary" @click="onLoadDocumentClick">Load Document</a-button>
    </div>
    <div class="bg-amber-400 p-8 min-h-96">
      <div id="doc">doc</div>
    </div>
  </div>
</template>

总结

虽然上面的方案解决了Token校验的问题,但是,我们一开始的目标并没有实现。 那就是我们想要解决文件下载失败和保存文件失败的问题。

在这里插入图片描述

在这里插入图片描述

这两个错误实际上都是警告,不是严格错误。而且,我们的文档最终也都被成功的加载或者是保存了,实际上并没有发生错误,而我docserver文档服务发出的警告。

如果要提高用户的体验,我们还是得想办法就这两个警告给禁止掉或者解决掉。

后面继续研究。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1908167.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【专项刷题】— 位运算

常见类型介绍&#xff1a; & &#xff1a;有 0 就是 0 | &#xff1a;有 1 就是 1 ^ &#xff1a;相同为 0 &#xff0c;相异为 1 或者 无进位相加给定一个数确定它的二进制位的第x个数是0还是1&#xff1a;将一个数的二进制的第x位改成1&#xff1a;将一个数的二进制的第x…

【Java探索之旅】多态:向上下转型、多态优缺点、构造函数陷阱

文章目录 &#x1f4d1;前言一、向上转型和向下转型1.1 向上转型1.2 向下转型 二、多态的优缺点2.1 多态优点2.2 多态缺陷 三、避免避免构造方法中调用重写的方法四、好的习惯&#x1f324;️全篇总结 &#x1f4d1;前言 在面向对象编程中&#xff0c;向上转型和向下转型是常用…

Redis组建哨兵模式

主172.17.60.131 从172.17.60.130、172.17.60.129 redis部署 [rootlocalhost app]# tar xf redis-6.2.9.tar.gz [rootlocalhost app]# cd redis-6.2.9/ [rootlocalhost redis-6.2.9]# make MALLOClibc [rootlocalhost redis-6.2.9]# make install PREFIX/usr/local/redis…

[ICS] Modbus未授权攻击S7协议漏洞利用

工业控制系统历史 在可编程逻辑控制器(plc)成为标准之前&#xff0c;工厂车间自动化是通过机架和机架的工业继电器&#xff0c;气动柱塞计时器和电磁计数器来控制电机的启动和停止&#xff0c;阀门的打开以及其他与控制相关的过程交互。运行这种设置的控制程序根本不是程序&am…

鲁能巴蜀中学洛谷团队

鲁能巴蜀中学洛谷团队出错了 - 洛谷https://www.luogu.com.cn/team/76926

案例精选 | 聚铭综合日志分析系统为江苏省电子口岸构建高效安全的贸易生态

江苏省电子口岸有限公司&#xff0c;成立于2009年&#xff0c;由江苏省贸促会携手南京海关、江苏检验检疫局及江苏海事局等部门共同出资组建。公司承载着推动江苏乃至长三角地区国际贸易便利化的重大使命&#xff0c;致力于打造一个集先进性、创新性、高效性于一体的电子口岸综…

学习笔记——动态路由——OSPF(认证)

十二、OSPF邻居认证 1、OSPF邻居认证概述 链路是路由器接口的另一种说法&#xff0c;因此OSPF也称为接口状态路由协议。OSPF通过路由器之间通告网络接口的状态来建立链路状态数据库&#xff0c;生成最短路径树&#xff0c;每个OSPF路由器使用这些最短路径构造路由表。 OSPF认…

vue3自自定义插件注册全局事件

一. 首先在components中定义自定义组件 二. 然后在components下建立一个index.ts文件 index.ts中的代码如下 // 引入项目中全部的全局组件 import SvgIcon from ./SvgIcon/index.vue import pagination from ./pagination/index.vue // 全局对象 const allGloablComponen…

一文清晰了解HTML——简单实例

想要仿照该页面编写HTML代码&#xff1a; 在vscode中输入&#xff01;自动生成默认模板&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevic…

vite工程化开发配置---持续更新

vite支持tsx开发 根据之前写的文章vue3vitetseslintprettierstylelinthuskylint-stagedcommitlintcommitizencz-git里面tsconfig配置了jsx相关选项&#xff0c;但是想要vite能够识别我们还需要配置一下 安装vitejs/plugin-vue-jsx pnpm i -D vitejs/plugin-vue-jsxvite.confi…

Linux系统编程——线程控制

目录 一&#xff0c;关于线程控制 二&#xff0c;线程创建 2.1 pthread_create函数 2.2 ps命令查看线程信息 三&#xff0c;线程等待 3.1 pthread_join函数 3.2 创建多个线程 3.3 pthread_join第二个参数 四&#xff0c;线程终止 4.1 关于线程终止 4.2 pthread_exit…

为什么KV Cache只需缓存K矩阵和V矩阵,无需缓存Q矩阵?

大家都知道大模型是通过语言序列预测下一个词的概率。假定{ x 1 x_1 x1​&#xff0c; x 2 x_2 x2​&#xff0c; x 3 x_3 x3​&#xff0c;…&#xff0c; x n − 1 x_{n-1} xn−1​}为已知序列&#xff0c;其中 x 1 x_1 x1​&#xff0c; x 2 x_2 x2​&#xff0c; x 3 x_3 x…

MathType7.4.6.8最新免费下载,数学表达神器来袭!

大家好啊&#xff0c;我是爱分享的小能手&#xff01;今天要给大家安利一款神奇的工具——MathType7.4免费版本。这不仅仅是一个简单的数学公式编辑器&#xff0c;而是你学术写作和数学研究的强大助手&#xff0c;简直是数学爱好者的“瑞士军刀”&#xff01; MathType最新mac…

前端面试题17(js快速检索方法详解)

在前端JavaScript中&#xff0c;快速检索数据通常涉及到数组或对象的搜索。这里我会介绍几种常见的快速检索方法&#xff0c;并提供相应的代码示例。 1. 数组的find和findIndex方法 find: 返回数组中满足条件的第一个元素的值。findIndex: 返回数组中满足条件的第一个元素的索…

ASAN排查程序中内存问题使用总结

简介 谷歌有一系列Sanitizer工具&#xff0c;可用于排查程序中内存相关的问题。常用的Sanitizer工具包括&#xff1a; Address Sanitizer&#xff08;ASan&#xff09;&#xff1a;用于检测内存使用错误。Leak Sanitizer&#xff08;LSan&#xff09;&#xff1a;用于检测内存…

2-28 基于matlab提取出频域和时域信号的29个特征

基于matlab提取出频域和时域信号的29个特征&#xff0c;主运行文件feature_extraction&#xff0c;fre_statistical_compute和time_statistical_compute分别提取频域和时域的特征&#xff0c;生成的29个特征保存在生成的feature矩阵中。程序已调通&#xff0c;可直接运行。 2-2…

mp4视频太大怎么压缩不影响画质,mp4文件太大怎么变小且清晰度高

在数字化时代&#xff0c;我们常常面临视频文件过大的问题。尤其是mp4格式的视频&#xff0c;文件大小往往令人望而却步。那么&#xff0c;如何在不影响画质的前提下&#xff0c;有效地压缩mp4视频呢&#xff1f;本文将为您揭秘几种简单实用的压缩技巧。 在分享和存储视频时&am…

入门 Vue Router

Vue Router Vue Router插件做了什么&#xff1f; 全局注册 RouterView 和 RouterLink 组件。添加全局 $router 和 $route 属性。启用 useRouter() 和 useRoute() 组合式函数。触发路由器解析初始路由。 标签介绍 RouterView 加载指定页面 <RouterLink to"/home"…

OpenAI Gym Atari on Windows

题意&#xff1a;在Windows系统上使用OpenAI Gym的Atari环境 问题背景&#xff1a; Im having issues installing OpenAI Gym Atari environment on Windows 10. I have successfully installed and used OpenAI Gym already on the same system. It keeps tripping up when t…

Java 静态变量、静态代码块、普通代码块、构造方法的执行顺序

今天碰到这个问题&#xff0c;看了课程以及资料&#xff0c;做出解答。这是我自己绘制的图&#xff0c;按从上到下&#xff0c;从左到右的顺序执行。如有问题请联系我修正。 要点&#xff1a; 1、执行顺序分为两步&#xff0c;类加载和初始化阶段。 2、因为静态变量和静态代码块…