未分類

onlyoffice

docker安裝

docker run -i -t -e JWT_ENABLED=false -d -p 80:80 onlyoffice/documentserver

#重啟服務

 docker exec -i -t 2a27fe290bda supervisorctl restart all

載入範本

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>abcd</title>
    <script type="text/javascript" src="http://10.3.101.101/web-apps/apps/api/documents/api.js"></script>
    <script>
        function aa()
        {
            //https://xie.infoq.cn/article/a0f97e801cfe5022a566e87a1
            var jwt="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkb2N1bWVudCI6eyJmaWxlVHlwZSI6ImRvY3giLCJ0aXRsZSI6ImZrMTY4Iiwia2V5Ijoiam9zaDE2ODEiLCJ1cmwiOiJodHRwczovL3d3dy50c2NzLmNvbS50dy9kdy9zYW1wbGUyLmRvY3gifX0.WZy01CMSZKz9ePxR2SKQ85nIX3BMI6YO43H8IMXrjU4";
            const config = {
                "document": {
                    "fileType": "docx",
                    "title": "fk168",
                    "key":"josh1681",
                    "url": "https://www.tscs.com.tw/dw/sample2.docx",
                    "permissions": {
                        "copy": false,
                        "download": false,
                        "print": true
                    }
                },
                "editorConfig": {
                    //"mode": "view",
                    "lang": "zh-TW",
                    "user": {
                        "name": "fk"
                    }
                },
                "token": jwt
            };
            new DocsAPI.DocEditor("placeholder", config);
        }
    </script>
</head>

<body onload="aa()" style="margin: 0;padding: 0;">
    <div id="placeholder" style=""></div>
</body>
</html>

c# JWT範例

需先取得密鑰,然後設定在JwtManager.cs

docker exec DOCKER-ID /var/www/onlyoffice/documentserver/npm/json -f /etc/onlyoffice/documentserver/local.json 'services.CoAuthoring.secret.session.string'

範例一

var json = @"{""document"": {""fileType"": ""docx"", ""title"": ""fk1689"", ""key"": ""a2"", ""url"": ""https://www.tscs.com.tw/dw/sample2.docx""}}";

Dictionary<string, object> payload = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);

string jwtToken = JwtManager.Encode(payload);

範例二

Dictionary<string, object> payload = new Dictionary<string, object>
{
    {
        "document", new Dictionary<string, object>
        {
            { "fileType", "docx" },
            { "title", "fk1689" },
            { "key", "a2" },
            { "url", "https://www.tscs.com.tw/dw/sample2.docx" }
        }
    }
};
string jwtToken = JwtManager.Encode(payload);

cache
/var/lib/onlyoffice/documentserver/App_Data/cache

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。