mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
Compare commits
568 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05a3110c99 | |||
| 8bafa3ff3a | |||
| 56679a3b75 | |||
| d4d758770f | |||
| 874ebff886 | |||
| 4f2f877f0e | |||
| 5cc6b4cb15 | |||
| 7a70a44bcb | |||
| e42bd53664 | |||
| 23e616aade | |||
| f035da0db4 | |||
| 3e12ec4ebe | |||
| 589ca9b601 | |||
| 32f1ec82d1 | |||
| 54bb5b0a24 | |||
| 8274c16f6d | |||
| 7a982fc785 | |||
| 6f5800fbde | |||
| 8ec632eebd | |||
| b6ca4535ce | |||
| 089fc8bfa0 | |||
| 0b4c17ea0a | |||
| 405be2847b | |||
| f809c7e525 | |||
| 44061c82a9 | |||
| ef4e283804 | |||
| 4b0ad1a192 | |||
| 60469b0dba | |||
| f5ac95e1cc | |||
| c4c2fbb945 | |||
| 99b5fcd562 | |||
| 7e34067410 | |||
| a44787c625 | |||
| 105afb2c34 | |||
| 002f9b958e | |||
| 56d5913808 | |||
| 6664864bed | |||
| 6c9e6e9304 | |||
| 416b1fde8c | |||
| 383f240825 | |||
| 642e145142 | |||
| 8f09dadfa0 | |||
| 495f1cf49a | |||
| cf01b5e0ae | |||
| 0673fed928 | |||
| 9b0b30a0b0 | |||
| 200187edce | |||
| 23176ddf07 | |||
| 9857cef8fc | |||
| 204f770401 | |||
| 61834e3ec6 | |||
| 2ca6185ac4 | |||
| e818bb978b | |||
| 3a4cf5e6e6 | |||
| 7ec16b90e3 | |||
| fcfb6efda7 | |||
| e4c72c98d1 | |||
| c2bbda542a | |||
| 2c12393c78 | |||
| 4e93f6ebac | |||
| d10ba9f773 | |||
| a0bf7db118 | |||
| e40e7cc41c | |||
| f616655f4c | |||
| 4ba708631e | |||
| b9c1bc0f42 | |||
| 215ade01a3 | |||
| 4d25418fc8 | |||
| 4539bac5db | |||
| eb196613e7 | |||
| 7ac788f589 | |||
| 55119458af | |||
| 3c18add1fc | |||
| 6bf63b7166 | |||
| 32df2d3e34 | |||
| 97c7859db5 | |||
| 492f9c7baa | |||
| e0c0595796 | |||
| 40b8fb88a8 | |||
| b0df0d72df | |||
| 1053add1d9 | |||
| f1fc0e5fae | |||
| a192c6ce1f | |||
| e8aec0b68c | |||
| d9667f9757 | |||
| 3a985da120 | |||
| a88f84ddac | |||
| 6525d7210f | |||
| 6b93311ce5 | |||
| 999561ffd6 | |||
| e539c1205f | |||
| 9a52a538cb | |||
| e8038a8e88 | |||
| 1045b314b6 | |||
| 1636732521 | |||
| daa9a5f3fa | |||
| 9bf3973215 | |||
| cad2a20cdf | |||
| 82a5a68e6c | |||
| 0e1a580a86 | |||
| c09f3fc4b9 | |||
| d4d7c4e222 | |||
| 14429c5b05 | |||
| 131e33c6af | |||
| 8a04e5fbc4 | |||
| 1b6435a7dc | |||
| b8eecab45f | |||
| a55cb60542 | |||
| f7259409a2 | |||
| 0ea9e68c7c | |||
| 4b72e0a664 | |||
| f4ae62e02d | |||
| 935377a941 | |||
| 3690aacb66 | |||
| b8b375a19a | |||
| 69d2e14438 | |||
| fec77a9e75 | |||
| f0171cbb18 | |||
| fe49aeb815 | |||
| 8416f36581 | |||
| b9f3bfd2e2 | |||
| 02b22e9e26 | |||
| f43f08012d | |||
| 1c27610e8d | |||
| 148caf6225 | |||
| b24e4503bc | |||
| 58378827d4 | |||
| 502f14c7be | |||
| ded2d19672 | |||
| 6116f05625 | |||
| 1e2a9cf4f2 | |||
| 1d7775f25b | |||
| 05c7a5a6db | |||
| c3500e39fd | |||
| 23169c6fea | |||
| f2fddc75c6 | |||
| f542e9dcfc | |||
| 6737a7e0d0 | |||
| e9c17c55da | |||
| f334bf4b19 | |||
| f2139949de | |||
| 48314b2c7f | |||
| 8804844281 | |||
| 3a21d29568 | |||
| b6a08e242d | |||
| 596235d34b | |||
| 254fbaccea | |||
| 69c07a30a7 | |||
| 6283ff934d | |||
| db231faca0 | |||
| a3dd0394d2 | |||
| f9fd73fc7e | |||
| 0931936b3c | |||
| b91b49c8fa | |||
| b0a0050201 | |||
| 1c780a639f | |||
| ad6ac4dedd | |||
| 8ba33f524b | |||
| 2f5b25d6ab | |||
| 44eef53a03 | |||
| 08388f739c | |||
| 1d8175b88f | |||
| 1400ec5a4b | |||
| e5f61ec95e | |||
| 7c669cca19 | |||
| 81f8bd1a9b | |||
| c4c819c513 | |||
| 03332b3cd9 | |||
| ebc864736d | |||
| af86ec1ca3 | |||
| d1d9915953 | |||
| c663bfe464 | |||
| 1bb7dd152a | |||
| a52000fc97 | |||
| 88b7fbf55c | |||
| f9449f7742 | |||
| 9d2b8c4830 | |||
| 4068e23556 | |||
| fc760af338 | |||
| c55ab7cc75 | |||
| 00c9b3e2b9 | |||
| 47074c588d | |||
| 018d1bbead | |||
| 82713572ab | |||
| 34d06235f4 | |||
| 468488c384 | |||
| ff4b387acf | |||
| 20012c7678 | |||
| 382160f2fc | |||
| 761e578faf | |||
| 7b7cbebc75 | |||
| dbc5ebf098 | |||
| c5d61b685b | |||
| f3acca4b4b | |||
| b92c4191f9 | |||
| 5b6f2696d2 | |||
| 625df85b51 | |||
| 6716d38a40 | |||
| 84d574906d | |||
| 3c760c3136 | |||
| bf28236d0d | |||
| 6d71a553be | |||
| fed5598294 | |||
| 02351113e1 | |||
| a07edeb5de | |||
| 5bbc4c6232 | |||
| 770c2fe551 | |||
| 4916537977 | |||
| 77ec1649a5 | |||
| 204ff947c3 | |||
| d36fe2466a | |||
| e927da28f5 | |||
| 17b5c6e4c9 | |||
| 03f853dfef | |||
| 1d7e65b2ba | |||
| 8ebb67c925 | |||
| 8524ff27ed | |||
| 7bedc4b877 | |||
| f25c211630 | |||
| 0f4785d14f | |||
| 288add4d45 | |||
| 1ee492838c | |||
| f9ce3d1d33 | |||
| 5f6687571a | |||
| a1e5a4d48e | |||
| 6e9518631f | |||
| 88d8086853 | |||
| d22f4f11ca | |||
| 29cbe66d09 | |||
| c2410268eb | |||
| 57cd71095d | |||
| 224d2bc570 | |||
| c7f18f1085 | |||
| fb05ad32ab | |||
| bac989efd1 | |||
| 8a203ac062 | |||
| 7e1386008b | |||
| 8ff206a411 | |||
| 83a0330725 | |||
| c5269a53cf | |||
| f86b26928d | |||
| f8d77947c8 | |||
| a62ac23aeb | |||
| a900183056 | |||
| 67d34f4bfa | |||
| 507a7f3162 | |||
| 703281aa07 | |||
| aefec3e105 | |||
| 8cc211b011 | |||
| 68ec626970 | |||
| 065f338a79 | |||
| 43548c04b9 | |||
| c7c95ecfbe | |||
| 064c0dcc35 | |||
| 9a01f465d0 | |||
| 2d85a4166e | |||
| 77c598049c | |||
| c1baac3d6f | |||
| c5e30b6512 | |||
| 0fa6f43716 | |||
| edc43bdf31 | |||
| f75453bf2d | |||
| d03326a1e1 | |||
| 8be501a0ab | |||
| a4c71eb69a | |||
| 132545c655 | |||
| 5caaf0b1c6 | |||
| 8f18cc8ab2 | |||
| db976766cc | |||
| 57f6028829 | |||
| 05706ff038 | |||
| 9cf7ce276e | |||
| 0b35179ef0 | |||
| d396f92f4d | |||
| 1e78da4cfc | |||
| a8c9c331c1 | |||
| 0b2e09cf1d | |||
| f81ae23a64 | |||
| 6f90ff3391 | |||
| 4f3882f892 | |||
| 727418277f | |||
| 2f795de6ad | |||
| bb28257a2d | |||
| 379dba8b7c | |||
| 05ea165f77 | |||
| 7a61fac6b7 | |||
| 31c3e050af | |||
| 0c677f3d65 | |||
| 6efa357c19 | |||
| 3b33846f9d | |||
| 3de8463359 | |||
| e05ead7ce6 | |||
| cdc8647f21 | |||
| c2b333fac7 | |||
| cae75d9888 | |||
| ee674e6a57 | |||
| 7207a9d860 | |||
| 8cc5f685af | |||
| a61a8ccb4f | |||
| e857a2bed7 | |||
| 514303d053 | |||
| 7d4f511a5d | |||
| 9b11e8b098 | |||
| 8351905cee | |||
| 15b7a07963 | |||
| ef1c53d330 | |||
| 9bcb871132 | |||
| 25a4b9c97b | |||
| a21fbd6802 | |||
| c7249ab27f | |||
| 450d37161b | |||
| ee46a77684 | |||
| 3b7e3c9258 | |||
| 783ad9f2de | |||
| 78571f6c23 | |||
| a5c0b9bfb1 | |||
| 5047e64f3b | |||
| d115e4092f | |||
| e7a1c2c6eb | |||
| 85f95ba4b9 | |||
| 133013dfde | |||
| 6acdc34e10 | |||
| 19304920d1 | |||
| 13b3eed5ed | |||
| d9c1c7e051 | |||
| 2d0b17e334 | |||
| 384381cebc | |||
| 16d830baf4 | |||
| efcfaf95e8 | |||
| 606f7d2d44 | |||
| 357c14b6d4 | |||
| c5a2b72b39 | |||
| dab9e4bb16 | |||
| 27b6cb3293 | |||
| 058b0c4f23 | |||
| 05c62bbdf3 | |||
| 425bd81f08 | |||
| 096102fa59 | |||
| c612320a65 | |||
| e0b60a6956 | |||
| 16a0846248 | |||
| 71e1b28f47 | |||
| 182f5f378e | |||
| 9d3f4b2300 | |||
| ab3d385c61 | |||
| 8d194b78a1 | |||
| b8e726a7be | |||
| dfd2d49e6c | |||
| fbe0c18315 | |||
| ec6ea72069 | |||
| 2accdeac3b | |||
| 63f4b6fbb6 | |||
| 642caddae8 | |||
| dac09bd1e1 | |||
| c6e3af5d3b | |||
| 183fb80077 | |||
| 63c3337938 | |||
| 0268298f2b | |||
| 32ea01784c | |||
| 8e4a2c6359 | |||
| 71041fea9f | |||
| 8b25a7a869 | |||
| dd20d79236 | |||
| 299a68e0bd | |||
| 9ad27d2cf0 | |||
| 828115e5b0 | |||
| 461a005cfa | |||
| 24cfd661ef | |||
| 6481ac7e13 | |||
| a194af0d19 | |||
| c0d240728d | |||
| 89c0f03318 | |||
| bc1c9f455c | |||
| df1a5f38c1 | |||
| 6559c76fbd | |||
| a7db14811f | |||
| abffa3e75f | |||
| 631f70148f | |||
| c7e7c9c19d | |||
| f2d4eb2a42 | |||
| 778cb91317 | |||
| beb9885b03 | |||
| 65e34e52f9 | |||
| b453aa19f0 | |||
| 600570f7c7 | |||
| 20f28afec1 | |||
| 2768ca5f6c | |||
| 7841822c54 | |||
| f3e24a8b5e | |||
| 2425898cc8 | |||
| 8d85281be8 | |||
| 081d704a8b | |||
| d3b962dcb8 | |||
| 2949d24b49 | |||
| 2f0d783ba6 | |||
| 644d9b8ba6 | |||
| 7184928a6c | |||
| 2d7df99daf | |||
| 5339b60226 | |||
| 5e0f54be68 | |||
| 3cee92d3a3 | |||
| 77c6715481 | |||
| 95ea50210f | |||
| d3639d1697 | |||
| 40016395a8 | |||
| b6c0bf4db0 | |||
| 3be5035ab3 | |||
| ad9d627c82 | |||
| a26a559921 | |||
| cf2f60f8cd | |||
| 80e1be2261 | |||
| a3e84f50fa | |||
| 796433cf8a | |||
| 7309d942d6 | |||
| b5c90ee7d5 | |||
| 8688ef1db5 | |||
| 56a4f6073d | |||
| 6d67b740b6 | |||
| e97fe56914 | |||
| 946819926f | |||
| e89b6040fb | |||
| d673fd86e0 | |||
| 901b2a83fa | |||
| 08119d7458 | |||
| d1fee87d8d | |||
| 83cefae85b | |||
| f1a64c92d2 | |||
| 8f2c2f96d2 | |||
| f9dbe89fd9 | |||
| c3a4c0a66b | |||
| cb583e48e3 | |||
| c3878a9431 | |||
| 50821067d7 | |||
| 18bd45e4ab | |||
| 79aac3ccd6 | |||
| fac436f5e6 | |||
| a4600b31a6 | |||
| b52196ec91 | |||
| 2314e74ade | |||
| 59801951e6 | |||
| 3233e257cb | |||
| 6b4f56373e | |||
| cd1a312aba | |||
| 8cd0297917 | |||
| 4568dcfdce | |||
| ace2677062 | |||
| d3cd62f5ae | |||
| c7cd0ba828 | |||
| 5cb3267660 | |||
| 1a2c68abe8 | |||
| cbaebe50c0 | |||
| c8aac65af6 | |||
| 5f8e9370a7 | |||
| 7fd0882c06 | |||
| c6a8cd0ff1 | |||
| 73797dcf31 | |||
| 19ebecd4d0 | |||
| bee95b4e6a | |||
| 4418d8e5d5 | |||
| 873267a784 | |||
| 605028151f | |||
| 2429668b57 | |||
| 5ecb4226e8 | |||
| 7f4165f958 | |||
| 7cd7f1bf66 | |||
| 608c21c60b | |||
| f44af24267 | |||
| be7a1e8ab2 | |||
| 9bab8edc3c | |||
| 4d852a23cd | |||
| a497401b30 | |||
| 94cb70c0db | |||
| 8e60c60e46 | |||
| 1cd275188b | |||
| edd423cd87 | |||
| e026a7027b | |||
| 70836bb67d | |||
| 0de0b172c0 | |||
| adc549bf7e | |||
| 8de69d18cb | |||
| 11e8f40f8c | |||
| bf18854ec0 | |||
| 08d1080527 | |||
| 9ca242fe82 | |||
| b3c02a5afd | |||
| ec65ebbfb8 | |||
| 8544974202 | |||
| 90eeae5334 | |||
| 970cfa6dd0 | |||
| f04a26a0f4 | |||
| 02eceb6565 | |||
| 53a58e2666 | |||
| f5371db950 | |||
| 0ab0762aa5 | |||
| 64f82872b3 | |||
| 7ff4c65a91 | |||
| f272654532 | |||
| 39e7cea624 | |||
| b36f96f9c8 | |||
| 8b3b3268bf | |||
| 5d2abdb634 | |||
| 3556073f5c | |||
| b724366c33 | |||
| aeff6a4e9e | |||
| 97dad58428 | |||
| 2ce861d39b | |||
| 9d21924160 | |||
| 48239b29aa | |||
| b2545c6289 | |||
| c7907e13be | |||
| 7bea2f6e49 | |||
| 4b79d778de | |||
| 1fe0769a2c | |||
| e25f27c304 | |||
| ed22141a63 | |||
| 589e59c13c | |||
| 1e6585e324 | |||
| 3b283d6e80 | |||
| 15576a53a5 | |||
| 2e812c4584 | |||
| c578099c03 | |||
| 35ab4b678d | |||
| 4446196919 | |||
| 90a6514b6e | |||
| 693941a949 | |||
| e5cbac6d89 | |||
| 43d60f2adc | |||
| 4aeef2b873 | |||
| 60c03c1403 | |||
| a82258269a | |||
| b9654f722e | |||
| 0f82f8bc30 | |||
| c20bf3a527 | |||
| a597c37684 | |||
| 5206171a70 | |||
| 4ebe9b5832 | |||
| 3a11a42f9e | |||
| 841fd9f27f | |||
| 79326160a6 | |||
| 6112ff4d02 | |||
| f84a031581 | |||
| 375d916fe2 | |||
| a9e2df73ca | |||
| fd456f59e8 | |||
| d4f4b2bd95 | |||
| 35afb7a8fe | |||
| 8d1c4d8042 | |||
| b969944ede | |||
| da7450c732 | |||
| 1db5e865a6 | |||
| 34b066f846 | |||
| 9e9f177508 | |||
| 1392a567d7 | |||
| 8ed261dabc | |||
| 27982b0aa6 | |||
| 08edfca9b0 | |||
| a4122c1393 | |||
| a412f3f591 | |||
| 01132d78c2 | |||
| b61e7574bb | |||
| f148233e64 | |||
| 92a322f2a7 | |||
| 689ac66bba | |||
| c3774d8cb6 | |||
| 69ac7771d5 | |||
| 04f5cac85d | |||
| ccdd2a4cdc | |||
| 33140a2ca6 |
@ -223,10 +223,6 @@ serve-favicon - Node.js middleware for serving a favicon. (https://github.com/ex
|
||||
License: MIT
|
||||
License File: serve-favicon.license
|
||||
|
||||
sync-request - Make synchronous web requests with cross-platform support. (https://github.com/ForbesLindesay/sync-request/blob/master/LICENSE)
|
||||
License: MIT
|
||||
License File: sync-request.license
|
||||
|
||||
urllib - Request HTTP URLs in a complex world — basic and digest authentication, redirections, cookies, timeout and more. (https://github.com/node-modules/urllib/blob/master/LICENSE)
|
||||
License: MIT
|
||||
License File: urllib.license
|
||||
|
||||
18
Readme.md
18
Readme.md
@ -1,10 +1,11 @@
|
||||
## Integration examples
|
||||
|
||||
Test examples are simple document management systems that can be built into your
|
||||
application for testing (please, do not use it for production without proper code
|
||||
modifications).
|
||||
Test examples are simple document management systems that can be built into your application for testing.
|
||||
Do NOT use these integration examples on your own server without proper code modifications!
|
||||
In case you enabled any of the test examples, disable it before going for production.
|
||||
|
||||
These examples show the way to integrate [ONLYOFFICE Docs][2] into your own website or application using one of the programming languages. The package contains examples written in .Net (C# MVC), .Net (C#), Java, Node.js, PHP and Ruby.
|
||||
These examples show the way to integrate [ONLYOFFICE Docs][2] into your own website or application using one of the programming languages.
|
||||
The package contains examples written in .Net (C# MVC), .Net (C#), Java, Node.js, PHP and Ruby.
|
||||
|
||||
You should change `http://documentserver` to your server address in these files:
|
||||
* [.Net (C# MVC)](https://github.com/ONLYOFFICE/document-server-integration/tree/master/web/documentserver-example/csharp-mvc) - `web/documentserver-example/csharp-mvc/web.appsettings.config`
|
||||
@ -66,6 +67,15 @@ The methods described below are available for all of the test examples.
|
||||
| **Response** | **Code:** 200 OK <br />**Content on success:**<br /> `[{ "version": <file_version>, "id": <file_id>, "contentLength": <file_size_in_kilobytes>, "pureContentLength": <file_size_in_bytes>, "title": <file_name>, "updated": <last_change_date>}]`<br />**Content on error:**<br /> `"File not found"` |
|
||||
| **Sample** | `curl -X GET http://localhost/files/{fileId}` |
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
|
||||
## Project Information
|
||||
|
||||
Official website: [https://www.onlyoffice.com](https://www.onlyoffice.com/?utm_source=github&utm_medium=cpc&utm_campaign=GitHubIntegrationEx)
|
||||
|
||||
@ -4,9 +4,9 @@
|
||||
<PropertyGroup>
|
||||
<To Condition=" '$(To)' == '' ">..\deploy\</To>
|
||||
<RootDir Condition="$(RootDir)==''">..\..\</RootDir>
|
||||
<NameCSharp>$(To).Net (C#) Example</NameCSharp>
|
||||
<NameCSharp>$(To)DotNet (Csharp) Example</NameCSharp>
|
||||
<DirCSharp>$(RootDir)web\documentserver-example\csharp\</DirCSharp>
|
||||
<NameMvc>$(To).Net (C# MVC) Example</NameMvc>
|
||||
<NameMvc>$(To)DotNet (Csharp MVC) Example</NameMvc>
|
||||
<DirMvc>$(RootDir)web\documentserver-example\csharp-mvc\</DirMvc>
|
||||
<NameJava>$(To)Java Example</NameJava>
|
||||
<DirJava>$(RootDir)web\documentserver-example\java\</DirJava>
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M0 3C0 1.34315 1.34315 0 3 0H22.9167L30 7.08333V37C30 38.6569 28.6569 40 27 40H3C1.34315 40 0 38.6569 0 37V3Z" fill="#27ABA3"/>
|
||||
<path d="M22.9165 0L29.9998 7.08333H25.9165C24.2597 7.08333 22.9165 5.74019 22.9165 4.08333V0Z" fill="#008078"/>
|
||||
<rect x="6.5" y="15.5" width="17" height="5" stroke="white"/>
|
||||
<rect x="6.5" y="23.5" width="17" height="5" stroke="white"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 477 B |
@ -0,0 +1,6 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M5 5C5 3.89543 5.89543 3 7 3H16C17.1046 3 18 3.89543 18 5V8H17V6H6V18H17V16H18V19C18 20.1046 17.1046 21 16 21H7C5.89543 21 5 20.1046 5 19V5ZM13 4H10V5H13V4ZM12 19.5C12 19.7761 11.7761 20 11.5 20C11.2239 20 11 19.7761 11 19.5C11 19.2239 11.2239 19 11.5 19C11.7761 19 12 19.2239 12 19.5Z" fill="#444444"/>
|
||||
<rect x="7" y="9" width="1" height="6" fill="#444444"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 8V9L11 9V15H12V16H9V15H10V9H9V8H12Z" fill="#444444"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 10H18V14H15H14H13V15H14H18C18.5523 15 19 14.5523 19 14V10C19 9.44772 18.5523 9 18 9H14H13V10H14H15Z" fill="#444444"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 790 B |
@ -87,10 +87,6 @@
|
||||
}
|
||||
|
||||
@media (max-width: 1008px) {
|
||||
#portal-info {
|
||||
width: 65vw;
|
||||
}
|
||||
|
||||
.left-panel {
|
||||
margin-left: 0;
|
||||
}
|
||||
@ -128,6 +124,10 @@
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.main {
|
||||
height: calc(100% - 128px);
|
||||
}
|
||||
|
||||
.main-panel {
|
||||
left: 0;
|
||||
padding: 48px 18px 24px;
|
||||
@ -312,6 +312,9 @@
|
||||
.tableRow td:first-child {
|
||||
max-width: 17%;
|
||||
}
|
||||
#portal-info {
|
||||
max-width: 60vw;
|
||||
}
|
||||
}
|
||||
|
||||
.downloadContentCellShift:after {
|
||||
@ -363,6 +366,10 @@
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.main {
|
||||
height: calc(100% - 128px);
|
||||
}
|
||||
|
||||
.copy {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
@ -436,6 +443,58 @@
|
||||
display: none;
|
||||
width: 1%;
|
||||
}
|
||||
/* Mobile Upload*/
|
||||
.blockUI.blockMsg.blockPage.ui-dialog.ui-widget.ui-corner-all.ui-widget-content.ui-draggable {
|
||||
width: 344px !important;
|
||||
box-shadow: 0px 7px 15px rgba(85, 85, 85, 0.1);
|
||||
border-radius: 2px;
|
||||
top: 10% !important;
|
||||
margin-left: -172px !important;
|
||||
}
|
||||
|
||||
.ui-dialog .ui-dialog-titlebar {
|
||||
padding: 0;
|
||||
}
|
||||
.ui-dialog .ui-dialog-content {
|
||||
padding: 0 !important;
|
||||
}
|
||||
#mainProgress {
|
||||
margin: 24px 16px 0 !important;
|
||||
}
|
||||
.blockTitle {
|
||||
padding: 10px 10px 6px 16px !important;
|
||||
font-size: 14px !important;
|
||||
}
|
||||
#mainProgress .describeUpload {
|
||||
padding: 8px 0 !important;
|
||||
}
|
||||
.dialog-close {
|
||||
margin: 0 !important;
|
||||
}
|
||||
.step-descr{
|
||||
line-height: 150%;
|
||||
}
|
||||
.step {
|
||||
line-height: 160%;
|
||||
}
|
||||
.buttonsMobile{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.button.gray{
|
||||
margin: 0;
|
||||
}
|
||||
.button, .button:hover{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 0 !important;
|
||||
width: 144px;
|
||||
height: 56px;
|
||||
margin-bottom: 24px !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 560px) and (min-width: 510px) {
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
}
|
||||
|
||||
body {
|
||||
display: block;
|
||||
background: #FFFFFF;
|
||||
color: #333333;
|
||||
font-family: Open Sans;
|
||||
@ -71,6 +72,7 @@ header img {
|
||||
}
|
||||
|
||||
.main {
|
||||
display: table;
|
||||
height: calc(100% - 112px);
|
||||
min-height: 536px;
|
||||
}
|
||||
@ -97,6 +99,10 @@ header img {
|
||||
width: 896px;
|
||||
}
|
||||
|
||||
#portal-info {
|
||||
max-width: 65vw;
|
||||
}
|
||||
|
||||
.portal-name {
|
||||
color: #FF6F3D;
|
||||
font-size: 24px;
|
||||
@ -157,6 +163,10 @@ label .checkbox {
|
||||
background-image: url("images/file_pptx.svg");
|
||||
}
|
||||
|
||||
.try-editor.form {
|
||||
background-image: url("images/file_docxf.svg");
|
||||
}
|
||||
|
||||
.create-sample {
|
||||
color: #666666;
|
||||
line-height: 24px;
|
||||
@ -724,17 +734,9 @@ html {
|
||||
width: 30vw;
|
||||
min-width: 200px;
|
||||
max-width: 400px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.user-descr > b {
|
||||
margin-left: 25px;
|
||||
}
|
||||
|
||||
#portal-info {
|
||||
display: block;
|
||||
width: 70vw;
|
||||
}
|
||||
|
||||
.portal-descr:nth-child(3) {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
@ -25,6 +25,7 @@ using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Script.Serialization;
|
||||
using OnlineEditorsExampleMVC.Models;
|
||||
using System.Net;
|
||||
|
||||
namespace OnlineEditorsExampleMVC.Helpers
|
||||
{
|
||||
@ -44,7 +45,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
// get all the supported file extensions
|
||||
public static List<string> FileExts
|
||||
{
|
||||
get { return ViewedExts.Concat(EditedExts).Concat(ConvertExts).ToList(); }
|
||||
get { return ViewedExts.Concat(EditedExts).Concat(ConvertExts).Concat(FillFormExts).ToList(); }
|
||||
}
|
||||
|
||||
// get file extensions that can be viewed
|
||||
@ -53,6 +54,11 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
get { return (WebConfigurationManager.AppSettings["files.docservice.viewed-docs"] ?? "").Split(new char[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); }
|
||||
}
|
||||
|
||||
public static List<string> FillFormExts
|
||||
{
|
||||
get { return (WebConfigurationManager.AppSettings["files.docservice.fillform-docs"] ?? "").Split(new char[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); }
|
||||
}
|
||||
|
||||
// get file extensions that can be edited
|
||||
public static List<string> EditedExts
|
||||
{
|
||||
@ -74,19 +80,37 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
// get the storage path of the file
|
||||
public static string StoragePath(string fileName, string userAddress = null)
|
||||
{
|
||||
var directory = HttpRuntime.AppDomainAppPath + CurUserHostAddress(userAddress) + "\\";
|
||||
var directory = "";
|
||||
if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["storage-path"]) && Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
|
||||
{
|
||||
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
|
||||
}
|
||||
else
|
||||
{
|
||||
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
|
||||
}
|
||||
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
return directory + Path.GetFileName(fileName);
|
||||
return directory + (fileName.Contains("\\") ? fileName : Path.GetFileName(fileName));
|
||||
}
|
||||
|
||||
// get the path to the forcesaved file version
|
||||
public static string ForcesavePath(string fileName, string userAddress, Boolean create)
|
||||
{
|
||||
// create the directory to this file version
|
||||
var directory = HttpRuntime.AppDomainAppPath + CurUserHostAddress(userAddress) + "\\";
|
||||
var directory = "";
|
||||
if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["storage-path"]) && Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
|
||||
{
|
||||
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
|
||||
}
|
||||
else
|
||||
{
|
||||
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
|
||||
}
|
||||
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
return "";
|
||||
@ -167,7 +191,16 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
// get all the stored files from the user host address
|
||||
public static List<FileInfo> GetStoredFiles()
|
||||
{
|
||||
var directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\";
|
||||
var directory = "";
|
||||
if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["storage-path"]) && Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
|
||||
{
|
||||
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
|
||||
}
|
||||
else
|
||||
{
|
||||
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\";
|
||||
}
|
||||
|
||||
if (!Directory.Exists(directory)) return new List<FileInfo>();
|
||||
|
||||
var directoryInfo = new DirectoryInfo(directory);
|
||||
@ -223,8 +256,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{
|
||||
var uri = new UriBuilder(GetServerUrl(true))
|
||||
{
|
||||
Path = HttpRuntime.AppDomainAppVirtualPath + "/"
|
||||
+ path,
|
||||
Path = HttpRuntime.AppDomainAppVirtualPath + "/" + path,
|
||||
Query = ""
|
||||
};
|
||||
|
||||
@ -279,6 +311,24 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
return createUrl.ToString();
|
||||
}
|
||||
|
||||
// create the public history url
|
||||
public static string GetHistoryDownloadUrl(string filename, string version, string file)
|
||||
{
|
||||
var downloadUrl = new UriBuilder(GetServerUrl(true))
|
||||
{
|
||||
Path =
|
||||
HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx",
|
||||
Query = "type=downloadhistory"
|
||||
+ "&fileName=" + HttpUtility.UrlEncode(filename)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress)
|
||||
+ "&ver=" + version
|
||||
+ "&file="+ file
|
||||
};
|
||||
return downloadUrl.ToString();
|
||||
}
|
||||
|
||||
// get url to download a file
|
||||
public static string GetDownloadUrl(string fileName)
|
||||
{
|
||||
@ -367,5 +417,27 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
// enable certificate ignore
|
||||
public static void VerifySSL()
|
||||
{
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if(WebConfigurationManager.AppSettings["files.docservice.verify-peer-off"].Equals("true")) {
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetLanguages()
|
||||
{
|
||||
var languages = new Dictionary<string, string>();
|
||||
String[] couples = (WebConfigurationManager.AppSettings["files.docservice.languages"] ?? "").Split('|');
|
||||
foreach (string couple in couples)
|
||||
{
|
||||
String[] tmp = couple.Split(':');
|
||||
languages.Add(tmp[0],tmp[1]);
|
||||
}
|
||||
return languages;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
string documentRevisionId,
|
||||
bool isAsync,
|
||||
out string convertedDocumentUri,
|
||||
string filePass = null)
|
||||
string filePass = null,
|
||||
string lang = null)
|
||||
{
|
||||
convertedDocumentUri = string.Empty;
|
||||
|
||||
@ -114,7 +115,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{ "outputtype", toExtension.Trim('.') },
|
||||
{ "title", title },
|
||||
{ "url", documentUri },
|
||||
{ "password", filePass }
|
||||
{ "password", filePass },
|
||||
{ "region", lang }
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
@ -141,6 +143,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
requestStream.Write(bytes, 0, bytes.Length); // and write the serialized body object to it
|
||||
}
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
string dataResponse;
|
||||
using (var response = request.GetResponse())
|
||||
using (var stream = response.GetResponseStream()) // get the response stream
|
||||
|
||||
@ -76,7 +76,9 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
|
||||
if (token != null && !token.Equals("")) // invalid signature error
|
||||
{
|
||||
fileData = (Dictionary<string, object>)jss.Deserialize<Dictionary<string, object>>(token)["payload"];
|
||||
fileData = jss.Deserialize<Dictionary<string, object>>(token);
|
||||
if (fileData.ContainsKey("payload"))
|
||||
fileData = (Dictionary<string, object>)fileData["payload"];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -95,7 +97,11 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
var downloadUri = (string)fileData["url"];
|
||||
string curExt = Path.GetExtension(fileName).ToLower(); // get current file extension
|
||||
string downloadExt = Path.GetExtension(downloadUri).ToLower() ?? ""; // get the extension of the downloaded file
|
||||
|
||||
var downloadExt = fileData.ContainsKey("filetype")
|
||||
? "." + (string)fileData["filetype"]
|
||||
: Path.GetExtension(downloadUri).ToLower() ?? ""; // TODO: Delete in version 7.0 or higher. Support for versions below 7.0
|
||||
|
||||
var newFileName = fileName;
|
||||
|
||||
// convert downloaded file to the file with the current extension if these extensions aren't equal
|
||||
@ -122,6 +128,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
var storagePath = DocManagerHelper.StoragePath(newFileName, userAddress); // get the file path
|
||||
var histDir = DocManagerHelper.HistoryDir(storagePath); // get the path to the history directory
|
||||
if (!Directory.Exists(histDir)) Directory.CreateDirectory(histDir);
|
||||
@ -167,7 +175,11 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
var downloadUri = (string)fileData["url"];
|
||||
|
||||
string curExt = Path.GetExtension(fileName).ToLower(); // get current file extension
|
||||
string downloadExt = Path.GetExtension(downloadUri).ToLower(); // get the extension of the downloaded file
|
||||
|
||||
var downloadExt = fileData.ContainsKey("filetype")
|
||||
? "." + (string)fileData["filetype"]
|
||||
: Path.GetExtension(downloadUri).ToLower(); // TODO: Delete in version 7.0 or higher. Support for versions below 7.0
|
||||
|
||||
Boolean newFileName = false;
|
||||
|
||||
// convert downloaded file to the file with the current extension if these extensions aren't equal
|
||||
@ -193,6 +205,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
string forcesavePath = "";
|
||||
Boolean isSubmitForm = fileData["forcesavetype"].ToString().Equals("3"); // SubmitForm
|
||||
|
||||
@ -235,8 +249,10 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
|
||||
// create a command request
|
||||
public static void commandRequest(string method, string key)
|
||||
public static void commandRequest(string method, string key, object meta = null)
|
||||
{
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
string documentCommandUrl = WebConfigurationManager.AppSettings["files.docservice.url.site"] + WebConfigurationManager.AppSettings["files.docservice.url.command"];
|
||||
|
||||
var request = (HttpWebRequest)WebRequest.Create(documentCommandUrl);
|
||||
@ -248,6 +264,11 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{ "key", key }
|
||||
};
|
||||
|
||||
if (meta != null)
|
||||
{
|
||||
body.Add("meta", meta);
|
||||
}
|
||||
|
||||
// check if a secret key to generate token exists or not
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
|
||||
@ -30,7 +30,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
"Can review all the changes",
|
||||
"Can perform all actions with comments",
|
||||
"The file favorite state is undefined",
|
||||
"Can create files from templates using data from the editor"
|
||||
"Can create files from templates using data from the editor",
|
||||
"Can see the information about all users"
|
||||
};
|
||||
|
||||
static List<string> descr_user_2 = new List<string>()
|
||||
@ -39,7 +40,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
"Can review only his own changes or changes made by users with no group",
|
||||
"Can view comments, edit his own comments and comments left by users with no group. Can remove his own comments only",
|
||||
"This file is marked as favorite",
|
||||
"Can create new files from the editor"
|
||||
"Can create new files from the editor",
|
||||
"Can see the information about users from Group2 and users who don’t belong to any group"
|
||||
};
|
||||
|
||||
static List<string> descr_user_3 = new List<string>()
|
||||
@ -51,7 +53,8 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
"Can’t copy data from the file to clipboard",
|
||||
"Can’t download the file",
|
||||
"Can’t print the file",
|
||||
"Can create new files from the editor"
|
||||
"Can create new files from the editor",
|
||||
"Can see the information about Group2 users"
|
||||
};
|
||||
|
||||
static List<string> descr_user_0 = new List<string>()
|
||||
@ -62,7 +65,9 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
"Can perform all actions with comments",
|
||||
"The file favorite state is undefined",
|
||||
"Can't mention others in comments",
|
||||
"Can't create new files from the editor"
|
||||
"Can't create new files from the editor",
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor"
|
||||
};
|
||||
|
||||
private static List<User> users = new List<User>() {
|
||||
@ -70,10 +75,11 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
"uid-1",
|
||||
"John Smith",
|
||||
"smith@example.com",
|
||||
null,
|
||||
"",
|
||||
null,
|
||||
new Dictionary<string, object>(),
|
||||
null,
|
||||
null,
|
||||
new List<string>(),
|
||||
descr_user_1,
|
||||
true
|
||||
@ -90,6 +96,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{ "edit", new List<string>() { "group-2", "" } },
|
||||
{ "remove", new List<string>() { "group-2" } }
|
||||
},
|
||||
new List<string>() { "group-2", "" },
|
||||
true,
|
||||
new List<string>(),
|
||||
descr_user_2,
|
||||
@ -107,6 +114,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{ "edit", new List<string>() { "group-2" } },
|
||||
{ "remove", new List<string>() { } }
|
||||
},
|
||||
new List<string>() { "group-2" },
|
||||
false,
|
||||
new List<string>() { "copy", "download", "print" },
|
||||
descr_user_3,
|
||||
@ -116,9 +124,10 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
"uid-0",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"",
|
||||
null,
|
||||
new Dictionary<string,object>(),
|
||||
new List<string>(),
|
||||
null,
|
||||
new List<string>(),
|
||||
descr_user_0,
|
||||
@ -173,8 +182,9 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
public List<string> deniedPermissions;
|
||||
public List<string> descriptions;
|
||||
public bool templates;
|
||||
public List<string> userInfoGroups;
|
||||
|
||||
public User(string id, string name, string email, string group, List<string> reviewGroups, Dictionary<string, object> commentGroups, bool? favorite, List<string> deniedPermissions, List<string> descriptions, bool templates)
|
||||
public User(string id, string name, string email, string group, List<string> reviewGroups, Dictionary<string, object> commentGroups, List<string> userInfoGroups, bool? favorite, List<string> deniedPermissions, List<string> descriptions, bool templates)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
@ -186,6 +196,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
this.deniedPermissions = deniedPermissions;
|
||||
this.descriptions = descriptions;
|
||||
this.templates = templates;
|
||||
this.userInfoGroups = userInfoGroups;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
40
web/documentserver-example/csharp-mvc/Models/FileModel.cs
Normal file → Executable file
40
web/documentserver-example/csharp-mvc/Models/FileModel.cs
Normal file → Executable file
@ -21,6 +21,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Script.Serialization;
|
||||
using OnlineEditorsExampleMVC.Helpers;
|
||||
@ -42,7 +43,7 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
// get file url for user
|
||||
public string FileUriUser
|
||||
{
|
||||
get { return DocManagerHelper.GetFileUri(FileName, false); }
|
||||
get { return Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? DownloadUrl + "&dmode=emb" : DocManagerHelper.GetFileUri(FileName, false); }
|
||||
}
|
||||
|
||||
public string FileName { get; set; } // file name
|
||||
@ -79,11 +80,16 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
var editorsMode = Mode ?? "edit"; // get editor mode
|
||||
|
||||
var canEdit = DocManagerHelper.EditedExts.Contains(ext); // check if the file with such an extension can be edited
|
||||
var mode = canEdit && editorsMode != "view" ? "edit" : "view"; // set the mode parameter: change it to view if the document can't be edited
|
||||
var submitForm = canEdit && (editorsMode.Equals("edit") || editorsMode.Equals("fillForms")); // check if the Submit form button is displayed or not
|
||||
|
||||
var id = request.Cookies.GetOrDefault("uid", null);
|
||||
var user = Users.getUser(id); // get the user
|
||||
|
||||
if ((!canEdit && editorsMode.Equals("edit") || editorsMode.Equals("fillForms")) && DocManagerHelper.FillFormExts.Contains(ext)) {
|
||||
editorsMode = "fillForms";
|
||||
canEdit = true;
|
||||
}
|
||||
var submitForm = editorsMode.Equals("fillForms") && id.Equals("uid-1") && false; // check if the Submit form button is displayed or not
|
||||
var mode = canEdit && editorsMode != "view" ? "edit" : "view"; // set the mode parameter: change it to view if the document can't be edited
|
||||
|
||||
// favorite icon state
|
||||
bool? favorite = user.favorite;
|
||||
@ -143,7 +149,8 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
{ "modifyContentControl", editorsMode != "blockcontent" },
|
||||
{ "review", canEdit && (editorsMode == "edit" || editorsMode == "review") },
|
||||
{ "reviewGroups", user.reviewGroups },
|
||||
{ "commentGroups", user.commentGroups }
|
||||
{ "commentGroups", user.commentGroups },
|
||||
{ "userInfoGroups", user.userInfoGroups }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -161,7 +168,7 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
// the user currently viewing or editing the document
|
||||
"user", new Dictionary<string, object>
|
||||
{
|
||||
{ "id", user.id },
|
||||
{ "id", !user.id.Equals("uid-0") ? user.id : null },
|
||||
{ "name", user.name },
|
||||
{ "group", user.group }
|
||||
}
|
||||
@ -181,6 +188,7 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
"customization", new Dictionary<string, object>
|
||||
{
|
||||
{ "about", true }, // the About section display
|
||||
{ "comments", true },
|
||||
{ "feedback", true }, // the Feedback & Support menu button display
|
||||
{ "forcesave", false }, // adds the request for the forced file saving to the callback handler
|
||||
{ "submitForm", submitForm }, // if the Submit form button is displayed or not
|
||||
@ -209,7 +217,8 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
|
||||
// get the document history
|
||||
public void GetHistory(out string history, out string historyData)
|
||||
{
|
||||
{
|
||||
var storagePath = WebConfigurationManager.AppSettings["storage-path"];
|
||||
var jss = new JavaScriptSerializer();
|
||||
var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(FileName, null));
|
||||
|
||||
@ -248,9 +257,22 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
}
|
||||
}
|
||||
|
||||
var ext = Path.GetExtension(FileName).ToLower();
|
||||
dataObj.Add("fileType", ext.Replace(".", ""));
|
||||
dataObj.Add("key", key);
|
||||
// write file url to the data object
|
||||
dataObj.Add("url", i == currentVersion ? FileUri : DocManagerHelper.GetPathUri(Directory.GetFiles(verDir, "prev.*")[0].Substring(HttpRuntime.AppDomainAppPath.Length)));
|
||||
string prevFileUrl;
|
||||
if (Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath))
|
||||
{
|
||||
prevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext)
|
||||
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
|
||||
}
|
||||
else {
|
||||
prevFileUrl = i == currentVersion ? FileUri
|
||||
: DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext);
|
||||
}
|
||||
|
||||
dataObj.Add("url", prevFileUrl);
|
||||
dataObj.Add("version", i);
|
||||
if (i > 1) // check if the version number is greater than 1 (the file was modified)
|
||||
{
|
||||
@ -269,11 +291,13 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
|
||||
var prev = (Dictionary<string, object>)histData[(i - 2).ToString()]; // get the history data from the previous file version
|
||||
dataObj.Add("previous", new Dictionary<string, object>() { // write information about previous file version to the data object
|
||||
{ "fileType", prev["fileType"] },
|
||||
{ "key", prev["key"] }, // write key and url information about previous file version
|
||||
{ "url", prev["url"] },
|
||||
});
|
||||
// write the path to the diff.zip archive with differences in this file version
|
||||
dataObj.Add("changesUrl", DocManagerHelper.GetPathUri(Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "diff.zip").Substring(HttpRuntime.AppDomainAppPath.Length)));
|
||||
var changesUrl = DocManagerHelper.GetHistoryDownloadUrl(FileName, (i - 1).ToString(), "diff.zip");
|
||||
dataObj.Add("changesUrl", changesUrl);
|
||||
}
|
||||
if(JwtManager.Enabled)
|
||||
{
|
||||
|
||||
@ -49,13 +49,13 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
".dot", ".dotx", ".dotm",
|
||||
".odt", ".fodt", ".ott", ".rtf", ".txt",
|
||||
".html", ".htm", ".mht", ".xml",
|
||||
".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps"
|
||||
".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps", ".oform"
|
||||
};
|
||||
|
||||
// spreadsheet extensions
|
||||
public static readonly List<string> ExtsSpreadsheet = new List<string>
|
||||
{
|
||||
".xls", ".xlsx", ".xlsm",
|
||||
".xls", ".xlsx", ".xlsm", ".xlsb",
|
||||
".xlt", ".xltx", ".xltm",
|
||||
".ods", ".fods", ".ots", ".csv"
|
||||
};
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>OnlineEditorsExampleMVC</RootNamespace>
|
||||
<AssemblyName>OnlineEditorsExampleMVC</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<MvcBuildViews>false</MvcBuildViews>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<IISExpressSSLPort />
|
||||
@ -120,31 +120,38 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Content\editor.css" />
|
||||
<Content Include="Content\images\alert.png" />
|
||||
<Content Include="Content\images\block-content-24.png" />
|
||||
<Content Include="Content\images\block-content.svg" />
|
||||
<Content Include="Content\images\cell.ico" />
|
||||
<Content Include="Content\images\close.png" />
|
||||
<Content Include="Content\images\comment-24.png" />
|
||||
<Content Include="Content\images\corner.png" />
|
||||
<Content Include="Content\images\delete-24.png" />
|
||||
<Content Include="Content\images\desktop-24.png" />
|
||||
<Content Include="Content\images\done.png" />
|
||||
<Content Include="Content\images\download-24.png" />
|
||||
<Content Include="Content\images\embeded-24.png" />
|
||||
<Content Include="Content\images\file_docx.png" />
|
||||
<Content Include="Content\images\file_pptx.png" />
|
||||
<Content Include="Content\images\file_upload.png" />
|
||||
<Content Include="Content\images\file_xlsx.png" />
|
||||
<Content Include="Content\images\fill-forms-24.png" />
|
||||
<Content Include="Content\images\filter-24.png" />
|
||||
<Content Include="Content\images\close.svg" />
|
||||
<Content Include="Content\images\comment.svg" />
|
||||
<Content Include="Content\images\delete.svg" />
|
||||
<Content Include="Content\images\desktop.svg" />
|
||||
<Content Include="Content\images\done.svg" />
|
||||
<Content Include="Content\images\download.svg" />
|
||||
<Content Include="Content\images\embeded.svg" />
|
||||
<Content Include="Content\images\error.svg" />
|
||||
<Content Include="Content\images\file_docx.svg" />
|
||||
<Content Include="Content\images\file_docxf.svg" />
|
||||
<Content Include="Content\images\file_pptx.svg" />
|
||||
<Content Include="Content\images\file_upload.svg" />
|
||||
<Content Include="Content\images\file_xlsx.svg" />
|
||||
<Content Include="Content\images\fill-forms.svg" />
|
||||
<Content Include="Content\images\filter.svg" />
|
||||
<Content Include="Content\images\icon_docx.svg" />
|
||||
<Content Include="Content\images\icon_pptx.svg" />
|
||||
<Content Include="Content\images\icon_xlsx.svg" />
|
||||
<Content Include="Content\images\info.svg" />
|
||||
<Content Include="Content\images\loader16.gif" />
|
||||
<Content Include="Content\images\logo.png" />
|
||||
<Content Include="Content\images\mobile-24.png" />
|
||||
<Content Include="Content\images\question_small.png" />
|
||||
<Content Include="Content\images\review-24.png" />
|
||||
<Content Include="Content\images\logo.svg" />
|
||||
<Content Include="Content\images\mobile-fill-forms.svg" />
|
||||
<Content Include="Content\images\mobile.svg" />
|
||||
<Content Include="Content\images\notdone.svg" />
|
||||
<Content Include="Content\images\review.svg" />
|
||||
<Content Include="Content\images\slide.ico" />
|
||||
<Content Include="Content\images\word.ico" />
|
||||
<Content Include="Content\jquery-ui.css" />
|
||||
<Content Include="Content\media.css" />
|
||||
<Content Include="Content\stylesheet.css" />
|
||||
<Content Include="favicon.ico" />
|
||||
<Content Include="Global.asax" />
|
||||
|
||||
@ -2,22 +2,25 @@
|
||||
|
||||
This example will help you integrate ONLYOFFICE Docs into your web application written in .Net (C# MVC).
|
||||
|
||||
It is aimed at testing the editors. Please, do not use it for production without proper modifications.
|
||||
**Please note**: It is intended for testing purposes and demonstrating functionality of the editors. Do NOT use this integration example on your own server without proper code modifications! In case you enabled the test example, disable it before going for production.
|
||||
|
||||
## Step 1. Install ONLYOFFICE Docs
|
||||
|
||||
Download and install ONLYOFFICE Docs (packaged as Document Server).
|
||||
Download and install ONLYOFFICE Docs (packaged as Document Server).
|
||||
|
||||
See the detailed guide to learn how to install Document Server [for Windows](https://helpcenter.onlyoffice.com/installation/docs-developer-install-windows.aspx), [for Linux](https://helpcenter.onlyoffice.com/installation/docs-developer-install-ubuntu.aspx), or [for Docker](https://helpcenter.onlyoffice.com/server/developer-edition/docker/docker-installation.aspx).
|
||||
|
||||
## Step 2. Download the .Net (C# MVC) code for the editors integration
|
||||
|
||||
Download the [.Net (C# MVC) example](https://api.onlyoffice.com/editors/demopreview) from our site.
|
||||
You need to connnect the editors to your website. Specify path to the editors installation in the *settings.config* file:
|
||||
|
||||
To connect the editors to your website, specify the path to the editors installation and the path to the storage folder in the *settings.config* file:
|
||||
```
|
||||
<add key="storage-path" value=""/>
|
||||
<add key="files.docservice.url.site" value="https://documentserver/" />
|
||||
```
|
||||
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
|
||||
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **storage-path** is the path where files will be created and stored. You can set an absolute path.
|
||||
|
||||
If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) in the *DocEditor.aspx* file.
|
||||
|
||||
## Step 3. Install the prerequisites
|
||||
@ -25,31 +28,41 @@ If you want to experiment with the editor configuration, modify the [parameters]
|
||||
* **Microsoft .NET Framework**: version 4.5 (download it from the [official Microsoft website](https://www.microsoft.com/en-US/download/details.aspx?id=30653));
|
||||
* **Internet Information Services**: version 7 or later.
|
||||
|
||||
Configure the IIS components for the server to work correctly:
|
||||
1. Open Windows features:
|
||||
|
||||
**Start** -> **Control Panel** -> **Programs** -> **Programs and Features** -> **Turn Windows features on or off**
|
||||
|
||||
2. In the opened window, find **Internet Information Services** and choose all the necessary features. To do this, open the **World Wide Web Services** list and check the following components:
|
||||
* **Application Development Features**: .NET Extensibility 4.8, ASP.NET 4.8, ISAPI Extensions, ISAPI Filters,
|
||||
* **Common HTTP Features**: Default Document,
|
||||
* **Security**: Request Filtering.
|
||||
|
||||
## Step 4. Run your website with the editors
|
||||
1. Run the Internet Information Service (IIS) Manager:
|
||||
|
||||
**Start** -> **Control Panel** -> **System and Security** -> **Administrative Tools** -> **Internet Information Services (IIS) Manager**
|
||||
2. Add your website in the IIS Manager.
|
||||
|
||||
|
||||
On the **Connections** panel right-click the **Sites** node in the tree, then click **Add Website**.
|
||||
|
||||

|
||||
3. In the **Add Website** dialog box specify the name of the folder with the .Net (C# MVC) project in the **Site name** box.
|
||||
|
||||
|
||||
Specify the path to the folder with your project in the **Physical Path** box.
|
||||
|
||||
|
||||
Specify the unique value used only for this website in the **Port** box.
|
||||
|
||||
|
||||

|
||||
4. Check for the .NET platform version specified in IIS Manager for you website. Choose **v4.0.** version.
|
||||
|
||||
**Application Pools** -> right-click the platform name -> **Set application Pool defaults** -> **.NET CLR version**
|
||||
|
||||
|
||||

|
||||
5. Browse your website with the IIS Manager:
|
||||
|
||||
Right-click the site -> **Manage Website** -> **Browse**
|
||||
|
||||
|
||||

|
||||
|
||||
## Step 5. Check accessibility
|
||||
@ -57,3 +70,12 @@ If you want to experiment with the editor configuration, modify the [parameters]
|
||||
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files.
|
||||
|
||||
Make sure that the Document Server has access to the server with the example installed with the address which you specify instead of **example.com** in the configuration files.
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
@ -74,7 +74,8 @@ if (typeof jQuery != "undefined") {
|
||||
});
|
||||
|
||||
var timer = null;
|
||||
var checkConvert = function (filePass = null) {
|
||||
var checkConvert = function (filePass) {
|
||||
filePass = filePass ? filePass : null;
|
||||
if (timer != null) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
@ -167,7 +168,7 @@ if (typeof jQuery != "undefined") {
|
||||
var posExt = fileName.lastIndexOf('.');
|
||||
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : '';
|
||||
|
||||
if (EditedExtList.indexOf(posExt) != -1) {
|
||||
if (EditedExtList.indexOf(posExt) != -1 || FillExtList.indexOf(posExt) != -1) {
|
||||
jq("#beginEdit").removeClass("disable");
|
||||
}
|
||||
};
|
||||
@ -226,7 +227,7 @@ if (typeof jQuery != "undefined") {
|
||||
|
||||
jq(document).on("click", "#beginView:not(.disable)", function () {
|
||||
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
|
||||
var url = UrlEditor + "?mode=view&fileName=" + fileId;
|
||||
var url = UrlEditor + "?editorsMode=view&fileName=" + fileId;
|
||||
window.open(url, "_blank");
|
||||
jq('#hiddenFileName').val("");
|
||||
jq.unblockUI();
|
||||
@ -289,10 +290,6 @@ if (typeof jQuery != "undefined") {
|
||||
};
|
||||
|
||||
var fileList = jq("tr.tableRow");
|
||||
if (fileList.length > 0) {
|
||||
console.log(jq("div#portal-info").is(":visible"));
|
||||
jq("div#portal-info").hide();
|
||||
}
|
||||
|
||||
var mouseIsOverTooltip = false;
|
||||
var hideTooltipTimeout = null;
|
||||
|
||||
@ -46,10 +46,13 @@
|
||||
<script type="text/javascript" language="javascript">
|
||||
|
||||
var docEditor;
|
||||
var config;
|
||||
|
||||
var innerAlert = function (message) {
|
||||
var innerAlert = function (message, inEditor) {
|
||||
if (console && console.log)
|
||||
console.log(message);
|
||||
if (inEditor && docEditor)
|
||||
docEditor.showMessage(message);
|
||||
};
|
||||
|
||||
// the application is loaded into the browser
|
||||
@ -105,10 +108,14 @@
|
||||
|
||||
// the meta information of the document is changed via the meta command
|
||||
var onMetaChange = function (event) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
if (event.data.favorite) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
}
|
||||
|
||||
innerAlert("onMetaChange: " + JSON.stringify(event.data));
|
||||
};
|
||||
|
||||
// the user is trying to insert an image by clicking the Image from Storage button
|
||||
@ -134,8 +141,43 @@
|
||||
<% Model.GetMailMergeConfig(out dataMailMergeRecipients); %>
|
||||
docEditor.setMailMergeRecipients(<%= dataMailMergeRecipients%>); // insert recipient data for mail merge into the file
|
||||
};
|
||||
|
||||
var onRequestSaveAs = function (event) { // the user is trying to save file by clicking Save Copy as... button
|
||||
var title = event.data.title;
|
||||
var url = event.data.url;
|
||||
var data = {
|
||||
title: title,
|
||||
url: url
|
||||
};
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=saveas");
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
innerAlert(JSON.parse(xhr.responseText).file, true);
|
||||
}
|
||||
};
|
||||
|
||||
var config = <%= Model.GetDocConfig(Request, Url) %>;
|
||||
var onRequestRename = function(event) { // the user is trying to rename file by clicking Rename... button
|
||||
innerAlert("onRequestRename: " + JSON.stringify(event.data));
|
||||
|
||||
var newfilename = event.data;
|
||||
var data = {
|
||||
newfilename: newfilename,
|
||||
dockey: config.document.key,
|
||||
};
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=rename");
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
}
|
||||
};
|
||||
|
||||
config = <%= Model.GetDocConfig(Request, Url) %>;
|
||||
|
||||
config.width = "100%";
|
||||
config.height = "100%";
|
||||
@ -155,44 +197,60 @@
|
||||
|
||||
<% string hist, histData; %>
|
||||
<% Model.GetHistory(out hist, out histData); %>
|
||||
<% if (!string.IsNullOrEmpty(hist) && !string.IsNullOrEmpty(histData))
|
||||
{ %>
|
||||
// the user is trying to show the document version history
|
||||
config.events['onRequestHistory'] = function () {
|
||||
docEditor.refreshHistory(<%= hist %>); // show the document version history
|
||||
};
|
||||
// the user is trying to click the specific document version in the document version history
|
||||
config.events['onRequestHistoryData'] = function (event) {
|
||||
var ver = event.data;
|
||||
var histData = <%= histData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
// the user is trying to go back to the document from viewing the document version history
|
||||
config.events['onRequestHistoryClose '] = function () {
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
|
||||
<% string usersForMentions; %>
|
||||
<% Model.GetUsersMentions(Request, out usersForMentions); %>
|
||||
<% if (!string.IsNullOrEmpty(usersForMentions))
|
||||
// add mentions for not anonymous users
|
||||
{ %>
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
"users": <%= usersForMentions%>
|
||||
});
|
||||
|
||||
if (config.editorConfig.user.id) {
|
||||
<% if (!string.IsNullOrEmpty(hist) && !string.IsNullOrEmpty(histData))
|
||||
{ %>
|
||||
// the user is trying to show the document version history
|
||||
config.events['onRequestHistory'] = function () {
|
||||
docEditor.refreshHistory(<%= hist %>); // show the document version history
|
||||
};
|
||||
// the user is trying to click the specific document version in the document version history
|
||||
config.events['onRequestHistoryData'] = function (event) {
|
||||
var ver = event.data;
|
||||
var histData = <%= histData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
// the user is trying to go back to the document from viewing the document version history
|
||||
config.events['onRequestHistoryClose '] = function () {
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
|
||||
// add mentions for not anonymous users
|
||||
<% if (!string.IsNullOrEmpty(usersForMentions))
|
||||
{ %>
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
"users": <%= usersForMentions %>
|
||||
});
|
||||
};
|
||||
<% } %>
|
||||
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink));
|
||||
var data = JSON.stringify(event.data);
|
||||
innerAlert("onRequestSendNotify: " + data);
|
||||
};
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
config.events.onRequestSaveAs = onRequestSaveAs;
|
||||
};
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
var actionLink = JSON.stringify(event.data.actionLink);
|
||||
console.log("onRequestSendNotify:");
|
||||
console.log(event.data);
|
||||
console.log("Link to comment: " + replaceActionLink(location.href, actionLink));
|
||||
};
|
||||
<% } %>
|
||||
|
||||
var сonnectEditor = function () {
|
||||
if ((config.document.fileType === "docxf" || config.document.fileType === "oform")
|
||||
&& DocsAPI.DocEditor.version().split(".")[0] < 7) {
|
||||
innerAlert("Please update ONLYOFFICE Docs to version 7.0 to work on fillable forms online.");
|
||||
return;
|
||||
}
|
||||
|
||||
docEditor = new DocsAPI.DocEditor("iframeEditor", config);
|
||||
};
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
<%@ Import Namespace="System.Web.Configuration" %>
|
||||
<%@ Import Namespace="OnlineEditorsExampleMVC.Helpers" %>
|
||||
<%@ Import Namespace="OnlineEditorsExampleMVC.Models" %>
|
||||
<%@ Import Namespace="System.Collections.Generic" %>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
@ -65,6 +66,9 @@
|
||||
<li>
|
||||
<a class="try-editor slide" data-type="pptx">Presentation</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="try-editor form" data-type="docxf">Form template</a>
|
||||
</li>
|
||||
</ul>
|
||||
<label class="create-sample">
|
||||
<input id="createSample" class="checkbox" type="checkbox" />With sample content
|
||||
@ -82,11 +86,11 @@
|
||||
<tr>
|
||||
<td valign="middle">
|
||||
<span class="select-user">Username</span>
|
||||
<img class="info" src="app_themes/images/info.svg" />
|
||||
<img class="info" src="content/images/info.svg" />
|
||||
<select class="select-user" id="user">
|
||||
<% foreach (User user in Users.getAllUsers())
|
||||
{ %>
|
||||
<b><%= user.name.IsEmpty() ? "Anonymous" : user.name %></b>
|
||||
<option value="<%= user.id %>"><%= user.name.IsEmpty() ? "Anonymous" : user.name %></option>
|
||||
<% } %>
|
||||
</select>
|
||||
</td>
|
||||
@ -95,37 +99,11 @@
|
||||
<td valign="middle">
|
||||
<span class="select-user">Language editors interface</span>
|
||||
<select class="select-user" id="language">
|
||||
<option value="en">English</option>
|
||||
<option value="be">Belarusian</option>
|
||||
<option value="bg">Bulgarian</option>
|
||||
<option value="ca">Catalan</option>
|
||||
<option value="zh">Chinese</option>
|
||||
<option value="cs">Czech</option>
|
||||
<option value="da">Danish</option>
|
||||
<option value="nl">Dutch</option>
|
||||
<option value="fi">Finnish</option>
|
||||
<option value="fr">French</option>
|
||||
<option value="de">German</option>
|
||||
<option value="el">Greek</option>
|
||||
<option value="hu">Hungarian</option>
|
||||
<option value="id">Indonesian</option>
|
||||
<option value="it">Italian</option>
|
||||
<option value="ja">Japanese</option>
|
||||
<option value="ko">Korean</option>
|
||||
<option value="lv">Latvian</option>
|
||||
<option value="lo">Lao</option>
|
||||
<option value="nb">Norwegian</option>
|
||||
<option value="pl">Polish</option>
|
||||
<option value="pt">Portuguese</option>
|
||||
<option value="ro">Romanian</option>
|
||||
<option value="ru">Russian</option>
|
||||
<option value="sk">Slovak</option>
|
||||
<option value="sl">Slovenian</option>
|
||||
<option value="sv">Swedish</option>
|
||||
<option value="es">Spanish</option>
|
||||
<option value="tr">Turkish</option>
|
||||
<option value="uk">Ukrainian</option>
|
||||
<option value="vi">Vietnamese</option>
|
||||
<% Dictionary<string, string> languages = DocManagerHelper.GetLanguages();
|
||||
foreach (var lang in languages)
|
||||
{ %>
|
||||
<option value="<%= lang.Key %>"><%= lang.Value %></option>
|
||||
<% } %>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@ -135,12 +113,14 @@
|
||||
</td>
|
||||
<td class="section">
|
||||
<div class="main-panel">
|
||||
<div id="portal-info">
|
||||
<% var storedFiles = DocManagerHelper.GetStoredFiles(); %>
|
||||
<div id="portal-info" style="display: <%= storedFiles.Any() ? "none" : "table-cell" %>">
|
||||
<span class="portal-name">ONLYOFFICE Document Editors – Welcome!</span>
|
||||
<span class="portal-descr">
|
||||
Get started with a demo-sample of ONLYOFFICE Document Editors, the first html5-based editors.
|
||||
<br /> You may upload your own documents for testing using the "<b>Upload file</b>" button and <b>selecting</b> the necessary files on your PC.
|
||||
</span>
|
||||
<span class="portal-descr">Please do NOT use this integration example on your own server without proper code modifications, it is intended for testing purposes only. In case you enabled this test example, disable it before going for production.</span>
|
||||
<span class="portal-descr">You can open the same document using different users in different Web browser sessions, so you can check out multi-user editing functions.</span>
|
||||
<% foreach (User user in Users.getAllUsers())
|
||||
{ %>
|
||||
@ -155,14 +135,14 @@
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
<% var storedFiles = GetStoredFiles();
|
||||
if storedFiles.Any())
|
||||
<%
|
||||
if (storedFiles.Any())
|
||||
{ %>
|
||||
<div class="stored-list">
|
||||
<span class="header-list">Your documents</span>
|
||||
<table class="tableHeader" cellspacing="0" cellpadding="0" width="100%">
|
||||
<thead>
|
||||
<tr >
|
||||
<tr>
|
||||
<td class="tableHeaderCell tableHeaderCellFileName">Filename</td>
|
||||
<td class="tableHeaderCell tableHeaderCellEditors contentCells-shift">Editors</td>
|
||||
<td class="tableHeaderCell tableHeaderCellViewers">Viewers</td>
|
||||
@ -174,11 +154,14 @@
|
||||
<div class="scroll-table-body">
|
||||
<table cellspacing="0" cellpadding="0" width="100%">
|
||||
<tbody>
|
||||
<% foreach (var storedFile in storedFiles)
|
||||
{
|
||||
<% foreach (var storedFile in storedFiles)
|
||||
{
|
||||
var editUrl = "doceditor.aspx?fileID=" + HttpUtility.UrlEncode(storedFile.Name);
|
||||
var docType = DocumentType(storedFile.Name);
|
||||
var canEdit = EditedExts.Contains(Path.GetExtension(storedFile.Name).ToLower());
|
||||
var docType = FileUtility.GetFileType(storedFile.Name).ToString().ToLower();
|
||||
var ext = Path.GetExtension(storedFile.Name).ToLower();
|
||||
var canEdit = DocManagerHelper.EditedExts.Contains(ext);
|
||||
var isFillFormDoc = DocManagerHelper.FillFormExts.Contains(ext);
|
||||
%>
|
||||
|
||||
<tr class="tableRow" title="<%= storedFile.Name %> [<%= DocManagerHelper.GetFileVersion(storedFile.Name, HttpContext.Current.Request.UserHostAddress) %>]">
|
||||
<td class="contentCells">
|
||||
@ -186,7 +169,7 @@
|
||||
<span><%= storedFile.Name %></span>
|
||||
</a>
|
||||
</td>
|
||||
<% if (canEdir) { %>
|
||||
<% if (canEdit) { %>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="<%= Url.Action("Editor", "Home", new { fileName = storedFile.Name, editorsType = "desktop", editorsMode = "edit" }) %>" target="_blank">
|
||||
<img src="content/images/desktop.svg" alt="Open in editor for full size screens" title="Open in editor for full size screens"/>
|
||||
@ -215,30 +198,42 @@
|
||||
</a>
|
||||
</td>
|
||||
<% } %>
|
||||
<% if (docType != "word" && docType != "cell") { %>
|
||||
<td class="contentCells contentCells-icon contentCellsEmpty"></td>
|
||||
<% } %>
|
||||
<% if (docType == "word") { %>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="<%= Url.Action("Editor", "Home", new { fileName = storedFile.Name, editorsType = "desktop", editorsMode = "fillForms" }) %>" target="_blank">
|
||||
<img src="content/images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms"/>
|
||||
</a>
|
||||
</td>
|
||||
<% } else { %>
|
||||
<td class="contentCells contentCells-icon"></td>
|
||||
<% } %>
|
||||
<% if (docType == "word"){ %>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
|
||||
<a href="<%= Url.Action("Editor", "Home", new { fileName = storedFile.Name, editorsType = "desktop", editorsMode = "blockcontent" }) %>" target="_blank">
|
||||
<img src="content/images/block-content.svg" alt="Open in editor without content control modification" title="Open in editor without content control modification"/>
|
||||
</a>
|
||||
</td>
|
||||
<% } else { %>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift"></td>
|
||||
<td class="contentCells contentCells-icon"></td>
|
||||
<% } %>
|
||||
<% if (docType != "word" && docType != "cell") { %>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<% } %>
|
||||
<% if (isFillFormDoc) { %>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
|
||||
<a href="<%= Url.Action("Editor", "Home", new { fileName = storedFile.Name, editorsType = "desktop", editorsMode = "fillForms" }) %>" target="_blank">
|
||||
<img src="content/images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms"/>
|
||||
</a>
|
||||
</td>
|
||||
<% } else { %>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift"></td>
|
||||
<% } %>
|
||||
<% } else if (isFillFormDoc) { %>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="<%= Url.Action("Editor", "Home", new { fileName = storedFile.Name, editorsType = "mobile", editorsMode = "fillForms" }) %>" target="_blank">
|
||||
<img src="content/images/mobile-fill-forms.svg" alt="Open in editor for filling in forms for mobile devices" title="Open in editor for filling in forms for mobile devices"/>
|
||||
</a>
|
||||
</td>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
|
||||
<a href="<%= Url.Action("Editor", "Home", new { fileName = storedFile.Name, editorsType = "desktop", editorsMode = "fillForms" }) %>" target="_blank">
|
||||
<img src="content/images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms"/>
|
||||
</a>
|
||||
</td>
|
||||
<% } else { %>
|
||||
<td class="contentCells contentCells-shift contentCells-icon contentCellsEmpty" colspan="6"></td>
|
||||
<% } %>
|
||||
@ -306,10 +301,8 @@
|
||||
<span class="step-descr">They are loaded only once, they will be cached on your computer.</span>
|
||||
<input type="hidden" name="hiddenFileName" id="hiddenFileName" />
|
||||
<br />
|
||||
<br />
|
||||
<span class="progress-descr">Note the speed of all operations depends on your connection quality and server location.</span>
|
||||
<br />
|
||||
<br />
|
||||
<div class="error-message">
|
||||
<b>Upload error: </b><span></span>
|
||||
<br />
|
||||
@ -318,10 +311,12 @@
|
||||
</div>
|
||||
<iframe id="embeddedView" src="" height="345px" width="432px" frameborder="0" scrolling="no" allowtransparency></iframe>
|
||||
<br />
|
||||
<div id="beginEdit" class="button orange disable">Edit</div>
|
||||
<div id="beginView" class="button gray disable">View</div>
|
||||
<div id="beginEmbedded" class="button gray disable">Embedded view</div>
|
||||
<div id="cancelEdit" class="button gray">Cancel</div>
|
||||
<div class="buttonsMobile">
|
||||
<div id="beginEdit" class="button orange disable">Edit</div>
|
||||
<div id="beginView" class="button gray disable">View</div>
|
||||
<div id="beginEmbedded" class="button gray disable">Embedded view</div>
|
||||
<div id="cancelEdit" class="button gray">Cancel</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span id="loadScripts" data-docs="<%= WebConfigurationManager.AppSettings["files.docservice.url.site"] + WebConfigurationManager.AppSettings["files.docservice.url.preloader"] %>"></span>
|
||||
@ -349,6 +344,7 @@
|
||||
<%: Scripts.Render("~/bundles/jquery", "~/bundles/scripts") %>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
var FillExtList = '<%= string.Join(",", DocManagerHelper.FillFormExts.ToArray()) %>';
|
||||
var ConverExtList = '<%= string.Join(",", DocManagerHelper.ConvertExts.ToArray()) %>';
|
||||
var EditedExtList = '<%= string.Join(",", DocManagerHelper.EditedExts.ToArray()) %>';
|
||||
var UrlConverter = '<%= Url.Content("~/webeditor.ashx?type=convert") %>';
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
For more information on how to configure your ASP.NET application, please visit
|
||||
http://go.microsoft.com/fwlink/?LinkId=152368
|
||||
@ -10,7 +10,7 @@
|
||||
</configSections>
|
||||
<appSettings configSource="web.appsettings.config" />
|
||||
<system.web>
|
||||
<httpRuntime targetFramework="4.5" />
|
||||
<httpRuntime maxRequestLength="51200" targetFramework="4.5" />
|
||||
<compilation debug="true" targetFramework="4.5" />
|
||||
<pages>
|
||||
<namespaces>
|
||||
@ -37,6 +37,11 @@
|
||||
<remove name="TRACEVerbHandler" />
|
||||
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
|
||||
</handlers>
|
||||
<security>
|
||||
<requestFiltering>
|
||||
<requestLimits maxAllowedContentLength="52428800" />
|
||||
</requestFiltering>
|
||||
</security>
|
||||
</system.webServer>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
@ -46,6 +47,9 @@ namespace OnlineEditorsExampleMVC
|
||||
case "download":
|
||||
Download(context);
|
||||
break;
|
||||
case "downloadhistory":
|
||||
DownloadHistory(context);
|
||||
break;
|
||||
case "convert":
|
||||
Convert(context);
|
||||
break;
|
||||
@ -64,6 +68,86 @@ namespace OnlineEditorsExampleMVC
|
||||
case "files":
|
||||
Files(context);
|
||||
break;
|
||||
case "saveas":
|
||||
SaveAs(context);
|
||||
break;
|
||||
case "rename":
|
||||
Rename(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveAs(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "text/plain";
|
||||
try
|
||||
{
|
||||
string fileData;
|
||||
try
|
||||
{
|
||||
using (var receiveStream = context.Request.InputStream)
|
||||
using (var readStream = new StreamReader(receiveStream))
|
||||
{
|
||||
fileData = readStream.ReadToEnd();
|
||||
if (string.IsNullOrEmpty(fileData)) context.Response.Write("{\"error\":\"Request stream is empty\"}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
|
||||
var jss = new JavaScriptSerializer();
|
||||
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
|
||||
var fileUrl = (string) body["url"];
|
||||
var title = (string) body["title"];
|
||||
var fileName = DocManagerHelper.GetCorrectName(title);
|
||||
var extension = "." + (Path.GetExtension(fileName).ToLower() ?? "").Trim('.');
|
||||
|
||||
var allExt = DocManagerHelper.ConvertExts
|
||||
.Concat(DocManagerHelper.EditedExts)
|
||||
.Concat(DocManagerHelper.ViewedExts)
|
||||
.Concat(DocManagerHelper.FillFormExts)
|
||||
.ToArray();
|
||||
|
||||
if (!allExt.Contains(extension))
|
||||
{
|
||||
context.Response.Write("{\"error\":\"File type is not supported\"}");
|
||||
}
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(fileUrl);
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream())
|
||||
{
|
||||
|
||||
if (stream == null || req.GetResponse().ContentLength <= 0 || req.GetResponse().ContentLength > DocManagerHelper.MaxFileSize)
|
||||
{
|
||||
context.Response.Write("{\"error\": \"File size is incorrect\"}");
|
||||
}
|
||||
const int bufferSize = 4096;
|
||||
|
||||
using (var fs = File.Open(DocManagerHelper.StoragePath(fileName, null), FileMode.Create))
|
||||
{
|
||||
var buffer = new byte[bufferSize];
|
||||
int readed;
|
||||
while ((readed = stream.Read(buffer, 0, bufferSize)) != 0)
|
||||
{
|
||||
fs.Write(buffer, 0, readed); // write bytes to the output stream
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var id = context.Request.Cookies.GetOrDefault("uid", null);
|
||||
var user = Users.getUser(id); // get the user
|
||||
DocManagerHelper.CreateMeta(fileName, user.id, user.name, null);
|
||||
|
||||
context.Response.Write("{ \"file\": \"" + fileName + "\"}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"" + 1 + "\", \"message\": \"" + e.Message + "\"}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,6 +157,8 @@ namespace OnlineEditorsExampleMVC
|
||||
context.Response.ContentType = "text/plain";
|
||||
try
|
||||
{
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
var httpPostedFile = context.Request.Files[0];
|
||||
string fileName;
|
||||
|
||||
@ -136,6 +222,7 @@ namespace OnlineEditorsExampleMVC
|
||||
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
|
||||
|
||||
var fileName = Path.GetFileName(body["filename"].ToString());
|
||||
var lang = context.Request.Cookies.GetOrDefault("ulang", null);
|
||||
var filePass = body["filePass"] != null ? body["filePass"].ToString() : null;
|
||||
var fileUri = DocManagerHelper.GetDownloadUrl(fileName);
|
||||
|
||||
@ -159,7 +246,7 @@ namespace OnlineEditorsExampleMVC
|
||||
|
||||
// get the url to the converted file
|
||||
string newFileUri;
|
||||
var result = ServiceConverter.GetConvertedUri(downloadUri.ToString(), extension, internalExtension, key, true, out newFileUri, filePass);
|
||||
var result = ServiceConverter.GetConvertedUri(downloadUri.ToString(), extension, internalExtension, key, true, out newFileUri, filePass, lang);
|
||||
if (result != 100)
|
||||
{
|
||||
context.Response.Write("{ \"step\" : \"" + result + "\", \"filename\" : \"" + fileName + "\"}");
|
||||
@ -171,6 +258,8 @@ namespace OnlineEditorsExampleMVC
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(newFileUri);
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream()) // get response stream of the converting file
|
||||
{
|
||||
if (stream == null) throw new Exception("Stream is null");
|
||||
@ -224,7 +313,7 @@ namespace OnlineEditorsExampleMVC
|
||||
var userAddress = context.Request["userAddress"];
|
||||
var fileName = Path.GetFileName(context.Request["fileName"]);
|
||||
var status = (TrackerStatus) (int) fileData["status"]; // get status from the request body
|
||||
var saved = 1; // editing
|
||||
var saved = 0;
|
||||
switch (status)
|
||||
{
|
||||
case TrackerStatus.Editing:
|
||||
@ -281,7 +370,7 @@ namespace OnlineEditorsExampleMVC
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.Write("{\"error\":0}");
|
||||
context.Response.Write("{\"error\":" + saved + "}");
|
||||
}
|
||||
|
||||
// remove a file
|
||||
@ -367,10 +456,12 @@ namespace OnlineEditorsExampleMVC
|
||||
{
|
||||
try
|
||||
{
|
||||
var fileName = Path.GetFileName(context.Request["fileName"]);
|
||||
var fileName = Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? context.Request["fileName"]
|
||||
: Path.GetFileName(context.Request["fileName"]);
|
||||
var userAddress = context.Request["userAddress"];
|
||||
var isEmbedded = context.Request["dmode"];
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && isEmbedded == null)
|
||||
{
|
||||
string JWTheader = WebConfigurationManager.AppSettings["files.docservice.header"].Equals("") ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
@ -416,5 +507,80 @@ namespace OnlineEditorsExampleMVC
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
// download a history file
|
||||
private static void DownloadHistory(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fileName = Path.GetFileName(context.Request["fileName"]);
|
||||
var userAddress = Path.GetFileName(context.Request["userAddress"]);
|
||||
var version = System.Convert.ToInt32(context.Request["ver"]);
|
||||
var file = Path.GetFileName(context.Request["file"]);
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
string JWTheader = WebConfigurationManager.AppSettings["files.docservice.header"].Equals("") ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
if (context.Request.Headers.AllKeys.Contains(JWTheader, StringComparer.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var headerToken = context.Request.Headers.Get(JWTheader).Substring("Bearer ".Length);
|
||||
string token = JwtManager.Decode(headerToken);
|
||||
|
||||
if (token == null || token.Equals(""))
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
context.Response.Write("JWT validation failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
context.Response.Write("JWT validation failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
var histPath = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, userAddress));
|
||||
var filePath = Path.Combine(DocManagerHelper.VersionDir(histPath, version), file); // get the path to document version
|
||||
|
||||
download(filePath, context);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"File not found!\"}");
|
||||
}
|
||||
}
|
||||
|
||||
// rename a file
|
||||
private static void Rename(HttpContext context)
|
||||
{
|
||||
// read request body
|
||||
context.Response.ContentType = "text/plain";
|
||||
string fileData;
|
||||
try
|
||||
{
|
||||
using (var receiveStream = context.Request.InputStream)
|
||||
using (var readStream = new StreamReader(receiveStream))
|
||||
{
|
||||
fileData = readStream.ReadToEnd();
|
||||
if (string.IsNullOrEmpty(fileData)) context.Response.Write("{\"error\":\"Request stream is empty\"}");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
|
||||
var jss = new JavaScriptSerializer();
|
||||
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
|
||||
var newFileName = (string) body["newfilename"];
|
||||
var docKey = (string) body["dockey"];
|
||||
var meta = new Dictionary<string, object>() {
|
||||
{ "title", newFileName }
|
||||
};
|
||||
TrackManager.commandRequest("meta", docKey, meta);
|
||||
context.Response.Write("{ \"result\": \"OK\"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Submodule web/documentserver-example/csharp-mvc/assets updated: f9fc118e43...1d601d84c4
@ -1,18 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml version="1.0"?>
|
||||
<appSettings>
|
||||
<clear />
|
||||
<add key="version" value="1.0.0"/>
|
||||
|
||||
<add key="filesize-max" value="5242880"/>
|
||||
<add key="version" value="1.2.0"/>
|
||||
|
||||
<add key="filesize-max" value="52428800"/>
|
||||
<add key="storage-path" value=""/>
|
||||
|
||||
<add key="files.docservice.fillform-docs" value=".oform|.docx"/>
|
||||
<add key="files.docservice.viewed-docs" value=".pdf|.djvu|.xps|.oxps"/>
|
||||
<add key="files.docservice.edited-docs" value=".docx|.xlsx|.csv|.pptx|.txt"/>
|
||||
<add key="files.docservice.convert-docs" value=".docm|.dotx|.dotm|.dot|.doc|.odt|.fodt|.ott|.xlsm|.xltx|.xltm|.xlt|.xls|.ods|.fods|.ots|.pptm|.ppt|.ppsx|.ppsm|.pps|.potx|.potm|.pot|.odp|.fodp|.otp|.rtf|.mht|.html|.htm|.xml|.epub|.fb2"/>
|
||||
<add key="files.docservice.edited-docs" value=".docx|.xlsx|.csv|.pptx|.txt|.docxf"/>
|
||||
<add key="files.docservice.convert-docs" value=".docm|.dotx|.dotm|.dot|.doc|.odt|.fodt|.ott|.xlsm|.xlsb|.xltx|.xltm|.xlt|.xls|.ods|.fods|.ots|.pptm|.ppt|.ppsx|.ppsm|.pps|.potx|.potm|.pot|.odp|.fodp|.otp|.rtf|.mht|.html|.htm|.xml|.epub|.fb2"/>
|
||||
<add key="files.docservice.timeout" value="120000" />
|
||||
<add key="files.docservice.secret" value="" />
|
||||
<add key="files.docservice.header" value="Authorization" />
|
||||
|
||||
<add key="files.docservice.url.site" value="https://documentserver/"/>
|
||||
<add key="files.docservice.verify-peer-off" value="true"/>
|
||||
|
||||
<add key="files.docservice.languages" value="en:English|az:Azerbaijani|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lv:Latvian|lo:Lao|nb:Norwegian|pl:Polish|pt:Portuguese|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese"/>
|
||||
|
||||
<add key="files.docservice.url.site" value="http://documentserver/"/>
|
||||
|
||||
<add key="files.docservice.url.converter" value="ConvertService.ashx"/>
|
||||
<add key="files.docservice.url.api" value="web-apps/apps/api/documents/api.js"/>
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M0 3C0 1.34315 1.34315 0 3 0H22.9167L30 7.08333V37C30 38.6569 28.6569 40 27 40H3C1.34315 40 0 38.6569 0 37V3Z" fill="#27ABA3"/>
|
||||
<path d="M22.9165 0L29.9998 7.08333H25.9165C24.2597 7.08333 22.9165 5.74019 22.9165 4.08333V0Z" fill="#008078"/>
|
||||
<rect x="6.5" y="15.5" width="17" height="5" stroke="white"/>
|
||||
<rect x="6.5" y="23.5" width="17" height="5" stroke="white"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 477 B |
@ -0,0 +1,6 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M5 5C5 3.89543 5.89543 3 7 3H16C17.1046 3 18 3.89543 18 5V8H17V6H6V18H17V16H18V19C18 20.1046 17.1046 21 16 21H7C5.89543 21 5 20.1046 5 19V5ZM13 4H10V5H13V4ZM12 19.5C12 19.7761 11.7761 20 11.5 20C11.2239 20 11 19.7761 11 19.5C11 19.2239 11.2239 19 11.5 19C11.7761 19 12 19.2239 12 19.5Z" fill="#444444"/>
|
||||
<rect x="7" y="9" width="1" height="6" fill="#444444"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 8V9L11 9V15H12V16H9V15H10V9H9V8H12Z" fill="#444444"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 10H18V14H15H14H13V15H14H18C18.5523 15 19 14.5523 19 14V10C19 9.44772 18.5523 9 18 9H14H13V10H14H15Z" fill="#444444"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 790 B |
@ -87,10 +87,6 @@
|
||||
}
|
||||
|
||||
@media (max-width: 1008px) {
|
||||
#portal-info {
|
||||
width: 65vw;
|
||||
}
|
||||
|
||||
.left-panel {
|
||||
margin-left: 0;
|
||||
}
|
||||
@ -128,6 +124,10 @@
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.main {
|
||||
height: calc(100% - 128px);
|
||||
}
|
||||
|
||||
.main-panel {
|
||||
left: 0;
|
||||
padding: 48px 18px 24px;
|
||||
@ -312,6 +312,9 @@
|
||||
.tableRow td:first-child {
|
||||
max-width: 17%;
|
||||
}
|
||||
#portal-info {
|
||||
max-width: 60vw;
|
||||
}
|
||||
}
|
||||
|
||||
.downloadContentCellShift:after {
|
||||
@ -363,6 +366,10 @@
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.main {
|
||||
height: calc(100% - 128px);
|
||||
}
|
||||
|
||||
.copy {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
@ -436,6 +443,58 @@
|
||||
display: none;
|
||||
width: 1%;
|
||||
}
|
||||
/* Mobile Upload*/
|
||||
.blockUI.blockMsg.blockPage.ui-dialog.ui-widget.ui-corner-all.ui-widget-content.ui-draggable {
|
||||
width: 344px !important;
|
||||
box-shadow: 0px 7px 15px rgba(85, 85, 85, 0.1);
|
||||
border-radius: 2px;
|
||||
top: 10% !important;
|
||||
margin-left: -172px !important;
|
||||
}
|
||||
|
||||
.ui-dialog .ui-dialog-titlebar {
|
||||
padding: 0;
|
||||
}
|
||||
.ui-dialog .ui-dialog-content {
|
||||
padding: 0 !important;
|
||||
}
|
||||
#mainProgress {
|
||||
margin: 24px 16px 0 !important;
|
||||
}
|
||||
.blockTitle {
|
||||
padding: 10px 10px 6px 16px !important;
|
||||
font-size: 14px !important;
|
||||
}
|
||||
#mainProgress .describeUpload {
|
||||
padding: 8px 0 !important;
|
||||
}
|
||||
.dialog-close {
|
||||
margin: 0 !important;
|
||||
}
|
||||
.step-descr{
|
||||
line-height: 150%;
|
||||
}
|
||||
.step {
|
||||
line-height: 160%;
|
||||
}
|
||||
.buttonsMobile{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
.button.gray{
|
||||
margin: 0;
|
||||
}
|
||||
.button, .button:hover{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 0 !important;
|
||||
width: 144px;
|
||||
height: 56px;
|
||||
margin-bottom: 24px !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 560px) and (min-width: 510px) {
|
||||
|
||||
@ -22,6 +22,7 @@ html {
|
||||
}
|
||||
|
||||
body {
|
||||
display: block;
|
||||
background: #FFFFFF;
|
||||
color: #333333;
|
||||
font-family: Open Sans;
|
||||
@ -71,6 +72,7 @@ header img {
|
||||
}
|
||||
|
||||
.main {
|
||||
display: table;
|
||||
height: calc(100% - 112px);
|
||||
min-height: 536px;
|
||||
}
|
||||
@ -97,6 +99,10 @@ header img {
|
||||
width: 896px;
|
||||
}
|
||||
|
||||
#portal-info {
|
||||
max-width: 65vw;
|
||||
}
|
||||
|
||||
.portal-name {
|
||||
color: #FF6F3D;
|
||||
font-size: 24px;
|
||||
@ -157,6 +163,10 @@ label .checkbox {
|
||||
background-image: url("images/file_pptx.svg");
|
||||
}
|
||||
|
||||
.try-editor.form {
|
||||
background-image: url("images/file_docxf.svg");
|
||||
}
|
||||
|
||||
.create-sample {
|
||||
color: #666666;
|
||||
line-height: 24px;
|
||||
@ -728,17 +738,9 @@ html {
|
||||
width: 30vw;
|
||||
min-width: 200px;
|
||||
max-width: 400px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.user-descr > b {
|
||||
margin-left: 25px;
|
||||
}
|
||||
|
||||
#portal-info {
|
||||
display: block;
|
||||
width: 70vw;
|
||||
}
|
||||
|
||||
.portal-descr:nth-child(3) {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
@ -5,12 +5,14 @@
|
||||
<%@ Import Namespace="System.Linq" %>
|
||||
<%@ Import Namespace="System.Web.Configuration" %>
|
||||
<%@ Import Namespace="OnlineEditorsExample" %>
|
||||
<%@ Import Namespace="System.Collections.Generic" %>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head runat="server">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>ONLYOFFICE</title>
|
||||
<!--
|
||||
*
|
||||
@ -67,6 +69,9 @@
|
||||
<li>
|
||||
<a class="try-editor slide" data-type="slide">Presentation</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="try-editor form" data-type="docxf">Form template</a>
|
||||
</li>
|
||||
</ul>
|
||||
<label class="create-sample">
|
||||
<input id="createSample" class="checkbox" type="checkbox" />With sample content
|
||||
@ -96,37 +101,11 @@
|
||||
<td valign="middle">
|
||||
<span class="select-user">Language editors interface</span>
|
||||
<select class="select-user" id="language">
|
||||
<option value="en">English</option>
|
||||
<option value="be">Belarusian</option>
|
||||
<option value="bg">Bulgarian</option>
|
||||
<option value="ca">Catalan</option>
|
||||
<option value="zh">Chinese</option>
|
||||
<option value="cs">Czech</option>
|
||||
<option value="da">Danish</option>
|
||||
<option value="nl">Dutch</option>
|
||||
<option value="fi">Finnish</option>
|
||||
<option value="fr">French</option>
|
||||
<option value="de">German</option>
|
||||
<option value="el">Greek</option>
|
||||
<option value="hu">Hungarian</option>
|
||||
<option value="id">Indonesian</option>
|
||||
<option value="it">Italian</option>
|
||||
<option value="ja">Japanese</option>
|
||||
<option value="ko">Korean</option>
|
||||
<option value="lv">Latvian</option>
|
||||
<option value="lo">Lao</option>
|
||||
<option value="nb">Norwegian</option>
|
||||
<option value="pl">Polish</option>
|
||||
<option value="pt">Portuguese</option>
|
||||
<option value="ro">Romanian</option>
|
||||
<option value="ru">Russian</option>
|
||||
<option value="sk">Slovak</option>
|
||||
<option value="sl">Slovenian</option>
|
||||
<option value="sv">Swedish</option>
|
||||
<option value="es">Spanish</option>
|
||||
<option value="tr">Turkish</option>
|
||||
<option value="uk">Ukrainian</option>
|
||||
<option value="vi">Vietnamese</option>
|
||||
<% Dictionary<string, string> languages = GetLanguages();
|
||||
foreach (var lang in languages)
|
||||
{ %>
|
||||
<option value="<%= lang.Key %>"><%= lang.Value %></option>
|
||||
<% } %>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@ -135,13 +114,15 @@
|
||||
</div>
|
||||
</td>
|
||||
<td class="section">
|
||||
<% var storedFiles = GetStoredFiles(); %>
|
||||
<div class="main-panel">
|
||||
<div id="portal-info">
|
||||
<div id="portal-info" style="display: <%= storedFiles.Any() ? "none" : "table-cell" %>">
|
||||
<span class="portal-name">ONLYOFFICE Document Editors – Welcome!</span>
|
||||
<span class="portal-descr">
|
||||
Get started with a demo-sample of ONLYOFFICE Document Editors, the first html5-based editors.
|
||||
<br /> You may upload your own documents for testing using the "<b>Upload file</b>" button and <b>selecting</b> the necessary files on your PC.
|
||||
</span>
|
||||
<span class="portal-descr">Please do NOT use this integration example on your own server without proper code modifications, it is intended for testing purposes only. In case you enabled this test example, disable it before going for production.</span>
|
||||
<span class="portal-descr">You can open the same document using different users in different Web browser sessions, so you can check out multi-user editing functions.</span>
|
||||
<% foreach (User user in Users.getAllUsers())
|
||||
{ %>
|
||||
@ -156,8 +137,8 @@
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
<% var storedFiles = GetStoredFiles();
|
||||
if storedFiles.Any())
|
||||
<%
|
||||
if (storedFiles.Any())
|
||||
{ %>
|
||||
<div class="stored-list">
|
||||
<span class="header-list">Your documents</span>
|
||||
@ -178,8 +159,10 @@
|
||||
<% foreach (var storedFile in storedFiles)
|
||||
{
|
||||
var editUrl = "doceditor.aspx?fileID=" + HttpUtility.UrlEncode(storedFile.Name);
|
||||
var ext = Path.GetExtension(storedFile.Name).ToLower();
|
||||
var docType = DocumentType(storedFile.Name);
|
||||
var canEdit = EditedExts.Contains(Path.GetExtension(storedFile.Name).ToLower());
|
||||
var canEdit = EditedExts.Contains(ext);
|
||||
var isFillFormDoc = FillFormsExts.Contains(ext);
|
||||
%>
|
||||
|
||||
<tr class="tableRow" title="<%= storedFile.Name %> [<%= GetFileVersion(storedFile.Name, HttpContext.Current.Request.UserHostAddress) %>]">
|
||||
@ -217,30 +200,42 @@
|
||||
</a>
|
||||
</td>
|
||||
<% } %>
|
||||
<%if (docType != "word" && docType != "cell") { %>
|
||||
<td class="contentCells contentCells-icon contentCellsEmpty"></td>
|
||||
<% } %>
|
||||
<% if (docType == "word") { %>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="<%= editUrl + "&editorsType=desktop&editorsMode=fillForms" %>" target="_blank">
|
||||
<img src="app_themes/images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms"/>
|
||||
</a>
|
||||
</td>
|
||||
<% } else { %>
|
||||
<td class="contentCells contentCells-icon"></td>
|
||||
<% } %>
|
||||
<% if (docType == "word") { %>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
|
||||
<a href="<%= editUrl + "&editorsType=desktop&editorsMode=blockcontent" %>" target="_blank">
|
||||
<img src="app_themes/images/block-content.svg" alt="Open in editor without content control modification" title="Open in editor without content control modification"/>
|
||||
</a>
|
||||
</td>
|
||||
<% } else{%>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift"></td>
|
||||
<td class="contentCells contentCells-icon"></td>
|
||||
<%} %>
|
||||
<%if (docType != "word" && docType != "cell"){%>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<% } %>
|
||||
<% if (isFillFormDoc) { %>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
|
||||
<a href="<%= editUrl + "&editorsType=desktop&editorsMode=fillForms" %>" target="_blank">
|
||||
<img src="app_themes/images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms"/>
|
||||
</a>
|
||||
</td>
|
||||
<% } else { %>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift"></td>
|
||||
<% } %>
|
||||
<% } else if (isFillFormDoc) { %>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<td class="contentCells contentCells-icon">
|
||||
<a href="<%= editUrl + "&editorsType=mobile&editorsMode=fillForms" %>" target="_blank">
|
||||
<img src="app_themes/images/mobile-fill-forms.svg" alt="Open in editor for filling in forms for mobile devices" title="Open in editor for filling in forms for mobile devices"/>
|
||||
</a>
|
||||
</td>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<td class="contentCells contentCells-icon "></td>
|
||||
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
|
||||
<a href="<%= editUrl + "&editorsType=desktop&editorsMode=fillForms" %>" target="_blank">
|
||||
<img src="app_themes/images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms"/>
|
||||
</a>
|
||||
</td>
|
||||
<% } else { %>
|
||||
<td class="contentCells contentCells-shift contentCells-icon contentCellsEmpty" colspan="6"></td>
|
||||
<% } %>
|
||||
@ -308,10 +303,8 @@
|
||||
<span class="step-descr">They are loaded only once, they will be cached on your computer.</span>
|
||||
<input type="hidden" name="hiddenFileName" id="hiddenFileName" />
|
||||
<br />
|
||||
<br />
|
||||
<span class="progress-descr">Note the speed of all operations depends on your connection quality and server location.</span>
|
||||
<br />
|
||||
<br />
|
||||
<div class="error-message">
|
||||
<b>Upload error: </b><span></span>
|
||||
<br />
|
||||
@ -320,10 +313,12 @@
|
||||
</div>
|
||||
<iframe id="embeddedView" src="" height="345px" width="432px" frameborder="0" scrolling="no" allowtransparency></iframe>
|
||||
<br />
|
||||
<div id="beginEdit" class="button orange disable">Edit</div>
|
||||
<div id="beginView" class="button gray disable">View</div>
|
||||
<div id="beginEmbedded" class="button gray disable">Embedded view</div>
|
||||
<div id="cancelEdit" class="button gray">Cancel</div>
|
||||
<div class="buttonsMobile">
|
||||
<div id="beginEdit" class="button orange disable">Edit</div>
|
||||
<div id="beginView" class="button gray disable">View</div>
|
||||
<div id="beginEmbedded" class="button gray disable">Embedded view</div>
|
||||
<div id="cancelEdit" class="button gray">Cancel</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span id="loadScripts" data-docs="<%= UrlPreloadScripts %>"></span>
|
||||
@ -357,6 +352,7 @@
|
||||
<script language="javascript" type="text/javascript" src="script/jquery.dropdownToggle.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="script/jscript.js"></script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
var FillFormExtList = '<%= string.Join(",", FillFormsExts.ToArray()) %>';
|
||||
var ConverExtList = '<%= string.Join(",", ConvertExts.ToArray()) %>';
|
||||
var EditedExtList = '<%= string.Join(",", EditedExts.ToArray()) %>';
|
||||
</script>
|
||||
|
||||
@ -35,7 +35,7 @@ namespace OnlineEditorsExample
|
||||
// the spreadsheet extension list
|
||||
public static readonly List<string> ExtsSpreadsheet = new List<string>
|
||||
{
|
||||
".xls", ".xlsx", ".xlsm",
|
||||
".xls", ".xlsx", ".xlsm", ".xlsb",
|
||||
".xlt", ".xltx", ".xltm",
|
||||
".ods", ".fods", ".ots", ".csv"
|
||||
};
|
||||
@ -56,7 +56,7 @@ namespace OnlineEditorsExample
|
||||
".dot", ".dotx", ".dotm",
|
||||
".odt", ".fodt", ".ott", ".rtf", ".txt",
|
||||
".html", ".htm", ".mht", ".xml",
|
||||
".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps"
|
||||
".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps", ".oform"
|
||||
};
|
||||
|
||||
// get an internal file extension
|
||||
@ -78,7 +78,9 @@ namespace OnlineEditorsExample
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
return Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ?
|
||||
WebConfigurationManager.AppSettings["storage-path"] + "/"
|
||||
:
|
||||
HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ WebConfigurationManager.AppSettings["storage-path"]
|
||||
@ -107,7 +109,7 @@ namespace OnlineEditorsExample
|
||||
// get all the supported file extensions
|
||||
private static List<string> FileExts
|
||||
{
|
||||
get { return ViewedExts.Concat(EditedExts).Concat(ConvertExts).ToList(); }
|
||||
get { return ViewedExts.Concat(EditedExts).Concat(ConvertExts).Concat(FillFormsExts).ToList(); }
|
||||
}
|
||||
|
||||
// file extensions that can be viewed
|
||||
@ -115,6 +117,11 @@ namespace OnlineEditorsExample
|
||||
{
|
||||
get { return (WebConfigurationManager.AppSettings["files.docservice.viewed-docs"] ?? "").Split(new char[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); }
|
||||
}
|
||||
|
||||
public static List<string> FillFormsExts
|
||||
{
|
||||
get { return (WebConfigurationManager.AppSettings["files.docservice.fillform-docs"] ?? "").Split(new char[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); }
|
||||
}
|
||||
|
||||
// file extensions that can be edited
|
||||
public static List<string> EditedExts
|
||||
@ -139,18 +146,52 @@ namespace OnlineEditorsExample
|
||||
// get the storage path of the given file
|
||||
public static string StoragePath(string fileName, string userAddress)
|
||||
{
|
||||
var directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
|
||||
var directory = "";
|
||||
if (Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
|
||||
{
|
||||
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
|
||||
}
|
||||
else
|
||||
{
|
||||
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
|
||||
}
|
||||
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory); // if the file directory doesn't exist, make it
|
||||
}
|
||||
return directory + Path.GetFileName(fileName);
|
||||
return directory + (fileName.Contains("\\") ? fileName : Path.GetFileName(fileName));
|
||||
}
|
||||
|
||||
// get the path to the history file version
|
||||
public static string HistoryPath(string fileName, string userAddress, string version, string file)
|
||||
{
|
||||
var directory = "";
|
||||
if (Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
|
||||
{
|
||||
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
|
||||
}
|
||||
else
|
||||
{
|
||||
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
|
||||
}
|
||||
var filepath = directory + Path.GetFileName(fileName) + "-hist" + "\\" + version + "\\" + file;
|
||||
return filepath;
|
||||
}
|
||||
|
||||
// get the path to the forcesaved file version
|
||||
public static string ForcesavePath(string fileName, string userAddress, Boolean create)
|
||||
{
|
||||
var directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
|
||||
var directory = "";
|
||||
if (Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
|
||||
{
|
||||
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
|
||||
}
|
||||
else
|
||||
{
|
||||
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\";
|
||||
}
|
||||
|
||||
if (!Directory.Exists(directory)) // the directory with host address doesn't exist
|
||||
{
|
||||
return "";
|
||||
@ -312,11 +353,7 @@ namespace OnlineEditorsExample
|
||||
|
||||
try
|
||||
{
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream()) // get response stream of the uploading file
|
||||
{
|
||||
@ -346,6 +383,68 @@ namespace OnlineEditorsExample
|
||||
return _fileName;
|
||||
}
|
||||
|
||||
public static string DoSaveAs(HttpContext context)
|
||||
{
|
||||
string fileData;
|
||||
try
|
||||
{
|
||||
using (var receiveStream = context.Request.InputStream)
|
||||
using (var readStream = new StreamReader(receiveStream))
|
||||
{
|
||||
fileData = readStream.ReadToEnd();
|
||||
if (string.IsNullOrEmpty(fileData)) return "{\"error\":\"Request stream is empty\"}";
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
|
||||
var jss = new JavaScriptSerializer();
|
||||
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
|
||||
var fileUrl = (string) body["url"];
|
||||
var title = (string) body["title"];
|
||||
var fileName = GetCorrectName(title);
|
||||
var extension = "." + (Path.GetExtension(fileName).ToLower() ?? "").Trim('.');
|
||||
|
||||
var allExt = ConvertExts.Concat(EditedExts).Concat(ViewedExts).Concat(FillFormsExts).ToArray();
|
||||
|
||||
if (!allExt.Contains(extension))
|
||||
{
|
||||
return "{\"error\":\"File type is not supported\"}";
|
||||
}
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(fileUrl);
|
||||
|
||||
VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream())
|
||||
{
|
||||
|
||||
if (stream == null || req.GetResponse().ContentLength <= 0 || req.GetResponse().ContentLength > MaxFileSize)
|
||||
{
|
||||
return "{\"error\": \"File size is incorrect\"}";
|
||||
}
|
||||
const int bufferSize = 4096;
|
||||
|
||||
using (var fs = File.Open(StoragePath(fileName, null), FileMode.Create))
|
||||
{
|
||||
var buffer = new byte[bufferSize];
|
||||
int readed;
|
||||
while ((readed = stream.Read(buffer, 0, bufferSize)) != 0)
|
||||
{
|
||||
fs.Write(buffer, 0, readed); // write bytes to the output stream
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var id = context.Request.Cookies.GetOrDefault("uid", null);
|
||||
var user = Users.getUser(id); // get the user
|
||||
DocEditor.CreateMeta(fileName, user.id, user.name, null);
|
||||
|
||||
return "{\"file\": \"" + fileName + "\"}";
|
||||
}
|
||||
|
||||
// converting a file
|
||||
public static string DoConvert(HttpContext context)
|
||||
{
|
||||
@ -369,6 +468,7 @@ namespace OnlineEditorsExample
|
||||
|
||||
_fileName = Path.GetFileName(body["filename"].ToString());
|
||||
var filePass = body["filePass"] != null ? body["filePass"].ToString() : null;
|
||||
var lang = context.Request.Cookies.GetOrDefault("ulang", null);
|
||||
|
||||
var extension = (Path.GetExtension(_fileName).ToLower() ?? "").Trim('.');
|
||||
var internalExtension = FileType.GetInternalExtension(_fileName).Trim('.');
|
||||
@ -389,7 +489,7 @@ namespace OnlineEditorsExample
|
||||
|
||||
// get the url to the converted file
|
||||
string newFileUri;
|
||||
var result = ServiceConverter.GetConvertedUri(fileUrl.ToString() , extension, internalExtension, key, true, out newFileUri, filePass); ;
|
||||
var result = ServiceConverter.GetConvertedUri(fileUrl.ToString() , extension, internalExtension, key, true, out newFileUri, filePass, lang);
|
||||
if (result != 100)
|
||||
{
|
||||
return "{ \"step\" : \"" + result + "\", \"filename\" : \"" + _fileName + "\"}";
|
||||
@ -400,11 +500,7 @@ namespace OnlineEditorsExample
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(newFileUri);
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
VerifySSL();
|
||||
|
||||
using (var stream = req.GetResponse().GetResponseStream()) // get response stream of the converting file
|
||||
{
|
||||
@ -456,7 +552,16 @@ namespace OnlineEditorsExample
|
||||
// get all the stored files from the folder
|
||||
protected static List<FileInfo> GetStoredFiles()
|
||||
{
|
||||
var directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\";
|
||||
var directory = "";
|
||||
if (Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]))
|
||||
{
|
||||
directory = WebConfigurationManager.AppSettings["storage-path"] + "\\";
|
||||
}
|
||||
else
|
||||
{
|
||||
directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\";
|
||||
}
|
||||
|
||||
if (!Directory.Exists(directory)) return new List<FileInfo>();
|
||||
|
||||
var directoryInfo = new DirectoryInfo(directory); // read the user host directory contents
|
||||
@ -499,5 +604,27 @@ namespace OnlineEditorsExample
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
// enable certificate ignore
|
||||
public static void VerifySSL()
|
||||
{
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if(WebConfigurationManager.AppSettings["files.docservice.verify-peer-off"].Equals("true")) {
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetLanguages()
|
||||
{
|
||||
var languages = new Dictionary<string, string>();
|
||||
String[] couples = (WebConfigurationManager.AppSettings["files.docservice.languages"] ?? "").Split('|');
|
||||
foreach (string couple in couples)
|
||||
{
|
||||
String[] tmp = couple.Split(':');
|
||||
languages.Add(tmp[0],tmp[1]);
|
||||
}
|
||||
return languages;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,10 +64,13 @@
|
||||
<script type="text/javascript" language="javascript">
|
||||
|
||||
var docEditor;
|
||||
var config;
|
||||
|
||||
var innerAlert = function (message) {
|
||||
var innerAlert = function (message, inEditor) {
|
||||
if (console && console.log)
|
||||
console.log(message);
|
||||
if (inEditor && docEditor)
|
||||
docEditor.showMessage(message);
|
||||
};
|
||||
|
||||
// the application is loaded into the browser
|
||||
@ -123,10 +126,14 @@
|
||||
|
||||
// the meta information of the document is changed via the meta command
|
||||
var onMetaChange = function (event) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
if (event.data.favorite) {
|
||||
var favorite = !!event.data.favorite;
|
||||
var title = document.title.replace(/^\☆/g, "");
|
||||
document.title = (favorite ? "☆" : "") + title;
|
||||
docEditor.setFavorite(favorite); // change the Favorite icon state
|
||||
}
|
||||
|
||||
innerAlert("onMetaChange: " + JSON.stringify(event.data));
|
||||
};
|
||||
|
||||
// the user is trying to insert an image by clicking the Image from Storage button
|
||||
@ -146,8 +153,43 @@
|
||||
var onRequestMailMergeRecipients = function (event) {
|
||||
docEditor.setMailMergeRecipients(<%= DataMailMergeRecipients %>); // insert recipient data for mail merge into the file
|
||||
};
|
||||
|
||||
var onRequestSaveAs = function (event) { // the user is trying to save file by clicking Save Copy as... button
|
||||
var title = event.data.title;
|
||||
var url = event.data.url;
|
||||
var data = {
|
||||
title: title,
|
||||
url: url
|
||||
};
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=saveas");
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
innerAlert(JSON.parse(xhr.responseText).file, true);
|
||||
}
|
||||
};
|
||||
|
||||
var config = <%= DocConfig %>;
|
||||
var onRequestRename = function(event) { // the user is trying to rename file by clicking Rename... button
|
||||
innerAlert("onRequestRename: " + JSON.stringify(event.data));
|
||||
|
||||
var newfilename = event.data;
|
||||
var data = {
|
||||
newfilename: newfilename,
|
||||
dockey: config.document.key,
|
||||
};
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=rename");
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
}
|
||||
};
|
||||
|
||||
config = <%= DocConfig %>;
|
||||
|
||||
config.width = "100%";
|
||||
config.height = "100%";
|
||||
@ -165,39 +207,53 @@
|
||||
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
|
||||
};
|
||||
|
||||
<% if (!string.IsNullOrEmpty(History) && !string.IsNullOrEmpty(HistoryData))
|
||||
{ %>
|
||||
config.events['onRequestHistory'] = function () { // the user is trying to show the document version history
|
||||
docEditor.refreshHistory(<%= History %>); // show the document version history
|
||||
};
|
||||
config.events['onRequestHistoryData'] = function (event) { // the user is trying to click the specific document version in the document version history
|
||||
var ver = event.data;
|
||||
var histData = <%= HistoryData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
config.events['onRequestHistoryClose '] = function () { // the user is trying to go back to the document from viewing the document version history
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
if (config.editorConfig.user.id) {
|
||||
<% if (!string.IsNullOrEmpty(History) && !string.IsNullOrEmpty(HistoryData))
|
||||
{ %>
|
||||
config.events['onRequestHistory'] = function () { // the user is trying to show the document version history
|
||||
docEditor.refreshHistory(<%= History %>); // show the document version history
|
||||
};
|
||||
config.events['onRequestHistoryData'] = function (event) { // the user is trying to click the specific document version in the document version history
|
||||
var ver = event.data;
|
||||
var histData = <%= HistoryData %>;
|
||||
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
|
||||
};
|
||||
config.events['onRequestHistoryClose '] = function () { // the user is trying to go back to the document from viewing the document version history
|
||||
document.location.reload();
|
||||
};
|
||||
<% } %>
|
||||
|
||||
<% if (!string.IsNullOrEmpty(UsersForMentions))
|
||||
{ %>
|
||||
// add mentions for not anonymous users
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
"users": <%= UsersForMentions %>
|
||||
});
|
||||
// add mentions for not anonymous users
|
||||
<% if (!string.IsNullOrEmpty(UsersForMentions))
|
||||
{ %>
|
||||
config.events['onRequestUsers'] = function () {
|
||||
docEditor.setUsers({ // set a list of users to mention in the comments
|
||||
"users": <%= UsersForMentions %>
|
||||
});
|
||||
};
|
||||
<% } %>
|
||||
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
event.data.actionLink = replaceActionLink(location.href, JSON.stringify(event.data.actionLink));
|
||||
var data = JSON.stringify(event.data);
|
||||
innerAlert("onRequestSendNotify: " + data);
|
||||
};
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
config.events.onRequestSaveAs = onRequestSaveAs;
|
||||
};
|
||||
// the user is mentioned in a comment
|
||||
config.events['onRequestSendNotify'] = function (event) {
|
||||
var actionLink = JSON.stringify(event.data.actionLink);
|
||||
console.log("onRequestSendNotify:");
|
||||
console.log(event.data);
|
||||
console.log("Link to comment: " + replaceActionLink(location.href, actionLink));
|
||||
};
|
||||
<% } %>
|
||||
|
||||
var сonnectEditor = function () {
|
||||
if ((config.document.fileType === "docxf" || config.document.fileType === "oform")
|
||||
&& DocsAPI.DocEditor.version().split(".")[0] < 7) {
|
||||
innerAlert("Please update ONLYOFFICE Docs to version 7.0 to work on fillable forms online.");
|
||||
return;
|
||||
}
|
||||
|
||||
docEditor = new DocsAPI.DocEditor("iframeEditor", config);
|
||||
};
|
||||
|
||||
|
||||
64
web/documentserver-example/csharp/DocEditor.aspx.cs
Normal file → Executable file
64
web/documentserver-example/csharp/DocEditor.aspx.cs
Normal file → Executable file
@ -41,7 +41,7 @@ namespace OnlineEditorsExample
|
||||
// get url to the original file for Document Server
|
||||
public static string FileUriUser
|
||||
{
|
||||
get { return _Default.FileUri(FileName, false); }
|
||||
get { return Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? getDownloadUrl(FileName) + "&dmode=emb" : _Default.FileUri(FileName, false); }
|
||||
}
|
||||
|
||||
protected string Key
|
||||
@ -100,20 +100,17 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
|
||||
// get url to download a file
|
||||
public static string getDownloadUrl
|
||||
public static string getDownloadUrl(string fileName)
|
||||
{
|
||||
get
|
||||
{
|
||||
var downloadUrl = new UriBuilder(_Default.GetServerUrl(true));
|
||||
var downloadUrl = new UriBuilder(_Default.GetServerUrl(true));
|
||||
downloadUrl.Path =
|
||||
HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx";
|
||||
downloadUrl.Query = "type=download"
|
||||
+ "&fileName=" + HttpUtility.UrlEncode(FileName)
|
||||
+ "&fileName=" + HttpUtility.UrlEncode(fileName)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress);
|
||||
return downloadUrl.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// loading a page
|
||||
@ -148,12 +145,17 @@ namespace OnlineEditorsExample
|
||||
var editorsMode = Request.GetOrDefault("editorsMode", "edit");
|
||||
|
||||
var canEdit = _Default.EditedExts.Contains(ext); // check if this file can be edited
|
||||
var mode = canEdit && editorsMode != "view" ? "edit" : "view"; // get the editor opening mode (edit or view)
|
||||
var submitForm = canEdit && (editorsMode.Equals("edit") || editorsMode.Equals("fillForms")); // check if the Submit form button is displayed or hidden
|
||||
var editorsType = Request.GetOrDefault("editorsType", "desktop");
|
||||
|
||||
var id = Request.Cookies.GetOrDefault("uid", null);
|
||||
var user = Users.getUser(id); // get the user
|
||||
|
||||
if ((!canEdit && editorsMode.Equals("edit") || editorsMode.Equals("fillForms")) && _Default.FillFormsExts.Contains(ext)) {
|
||||
editorsMode = "fillForms";
|
||||
canEdit = true;
|
||||
}
|
||||
var submitForm = editorsMode.Equals("fillForms") && id.Equals("uid-1") && false; // check if the Submit form button is displayed or hidden
|
||||
var mode = canEdit && editorsMode != "view" ? "edit" : "view"; // get the editor opening mode (edit or view)
|
||||
|
||||
var jss = new JavaScriptSerializer();
|
||||
|
||||
@ -190,7 +192,7 @@ namespace OnlineEditorsExample
|
||||
"document", new Dictionary<string, object>
|
||||
{
|
||||
{ "title", FileName },
|
||||
{ "url", getDownloadUrl },
|
||||
{ "url", getDownloadUrl(FileName) },
|
||||
{ "fileType", ext.Trim('.') },
|
||||
{ "key", Key },
|
||||
{
|
||||
@ -215,7 +217,8 @@ namespace OnlineEditorsExample
|
||||
{ "modifyContentControl", editorsMode != "blockcontent" },
|
||||
{ "review", canEdit && (editorsMode == "edit" || editorsMode == "review") },
|
||||
{ "reviewGroups", user.reviewGroups },
|
||||
{ "commentGroups", user.commentGroups }
|
||||
{ "commentGroups", user.commentGroups },
|
||||
{ "userInfoGroups", user.userInfoGroups }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -233,7 +236,7 @@ namespace OnlineEditorsExample
|
||||
// the user currently viewing or editing the document
|
||||
"user", new Dictionary<string, object>
|
||||
{
|
||||
{ "id", user.id },
|
||||
{ "id", !user.id.Equals("uid-0") ? user.id : null },
|
||||
{ "name", user.name },
|
||||
{ "group", user.group }
|
||||
}
|
||||
@ -253,6 +256,7 @@ namespace OnlineEditorsExample
|
||||
"customization", new Dictionary<string, object>
|
||||
{
|
||||
{ "about", true }, // the About section display
|
||||
{ "comments", true },
|
||||
{ "feedback", true }, // the Feedback & Support menu button display
|
||||
{ "forcesave", false }, // adds the request for the forced file saving to the callback handler
|
||||
{ "submitForm", submitForm }, // if the Submit form button is displayed or not
|
||||
@ -313,6 +317,7 @@ namespace OnlineEditorsExample
|
||||
// get the document history
|
||||
private void GetHistory(out Dictionary<string, object> history, out Dictionary<string, object> historyData)
|
||||
{
|
||||
var storagePath = WebConfigurationManager.AppSettings["storage-path"];
|
||||
var jss = new JavaScriptSerializer();
|
||||
var histDir = _Default.HistoryDir(_Default.StoragePath(FileName, null));
|
||||
|
||||
@ -350,8 +355,17 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
}
|
||||
|
||||
var ext = Path.GetExtension(FileName).ToLower();
|
||||
dataObj.Add("fileType", ext.Replace(".", ""));
|
||||
dataObj.Add("key", key);
|
||||
dataObj.Add("url", i == currentVersion ? FileUri : MakePublicUrl(Directory.GetFiles(verDir, "prev.*")[0])); // write file url to the data object
|
||||
// write file url to the data object
|
||||
var prevFileUrl = i == currentVersion ? FileUri : MakePublicHistoryUrl(FileName, i.ToString(), "prev" + ext);
|
||||
if (Path.IsPathRooted(storagePath))
|
||||
{
|
||||
prevFileUrl = i == currentVersion ? getDownloadUrl(FileName) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
|
||||
}
|
||||
|
||||
dataObj.Add("url", prevFileUrl); // write file url to the data object
|
||||
dataObj.Add("version", i);
|
||||
if (i > 1) // check if the version number is greater than 1 (the file was modified)
|
||||
{
|
||||
@ -370,11 +384,13 @@ namespace OnlineEditorsExample
|
||||
|
||||
var prev = (Dictionary<string, object>)histData[(i - 2).ToString()]; // get the history data from the previous file version
|
||||
dataObj.Add("previous", new Dictionary<string, object>() { // write information about previous file version to the data object
|
||||
{ "fileType", prev["fileType"] },
|
||||
{ "key", prev["key"] }, // write key and url information about previous file version
|
||||
{ "url", prev["url"] },
|
||||
});
|
||||
// write the path to the diff.zip archive with differences in this file version
|
||||
dataObj.Add("changesUrl", MakePublicUrl(Path.Combine(_Default.VersionDir(histDir, i - 1), "diff.zip")));
|
||||
var changesUrl = MakePublicHistoryUrl(FileName, (i - 1).ToString(), "diff.zip");
|
||||
dataObj.Add("changesUrl", changesUrl);
|
||||
}
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
@ -498,10 +514,25 @@ namespace OnlineEditorsExample
|
||||
// create the public url
|
||||
private string MakePublicUrl(string fullPath)
|
||||
{
|
||||
var root = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"];
|
||||
var root = Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? WebConfigurationManager.AppSettings["storage-path"]
|
||||
: HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"];
|
||||
return _Default.GetServerUrl(true) + fullPath.Substring(root.Length).Replace(Path.DirectorySeparatorChar, '/');
|
||||
}
|
||||
|
||||
|
||||
// create the public history url
|
||||
private string MakePublicHistoryUrl(string filename, string version, string file)
|
||||
{
|
||||
var fileUrl = new UriBuilder(_Default.GetServerUrl(true));
|
||||
fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx";
|
||||
fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename)
|
||||
+ "&ver=" + version + "&file=" + file
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress);
|
||||
return fileUrl.ToString();
|
||||
}
|
||||
|
||||
// create demo document
|
||||
private static void Try(string type, string sample, HttpRequest request)
|
||||
{
|
||||
@ -517,6 +548,9 @@ namespace OnlineEditorsExample
|
||||
case "slide":
|
||||
ext = ".pptx"; // .pptx for slide document type
|
||||
break;
|
||||
case "docxf":
|
||||
ext = ".docxf";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
@ -84,7 +84,8 @@ namespace ASC.Api.DocumentConverter
|
||||
string documentRevisionId,
|
||||
bool isAsync,
|
||||
out string convertedDocumentUri,
|
||||
string filePass = null)
|
||||
string filePass = null,
|
||||
string lang = null)
|
||||
{
|
||||
convertedDocumentUri = string.Empty;
|
||||
|
||||
@ -116,7 +117,8 @@ namespace ASC.Api.DocumentConverter
|
||||
{ "outputtype", toExtension.Trim('.') },
|
||||
{ "title", title },
|
||||
{ "url", documentUri },
|
||||
{ "password", filePass }
|
||||
{ "password", filePass },
|
||||
{ "region", lang }
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
@ -143,11 +145,7 @@ namespace ASC.Api.DocumentConverter
|
||||
requestStream.Write(bytes, 0, bytes.Length); // and write the serialized body object to it
|
||||
}
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (_Default.IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
_Default.VerifySSL();
|
||||
|
||||
string dataResponse;
|
||||
using (var response = request.GetResponse())
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>OnlineEditorsExample</RootNamespace>
|
||||
<AssemblyName>OnlineEditorsExample</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
@ -69,26 +69,35 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="App_Themes\images\block-content-24.png" />
|
||||
<Content Include="App_Themes\images\block-content.svg" />
|
||||
<Content Include="App_Themes\images\cell.ico" />
|
||||
<Content Include="App_Themes\images\comment-24.png" />
|
||||
<Content Include="App_Themes\images\delete-24.png" />
|
||||
<Content Include="App_Themes\images\desktop-24.png" />
|
||||
<Content Include="App_Themes\images\download-24.png" />
|
||||
<Content Include="App_Themes\images\embeded-24.png" />
|
||||
<Content Include="App_Themes\images\file_docx.png" />
|
||||
<Content Include="App_Themes\images\file_pptx.png" />
|
||||
<Content Include="App_Themes\images\file_upload.png" />
|
||||
<Content Include="App_Themes\images\file_xlsx.png" />
|
||||
<Content Include="App_Themes\images\fill-forms-24.png" />
|
||||
<Content Include="App_Themes\images\filter-24.png" />
|
||||
<Content Include="App_Themes\images\icon_docx.png" />
|
||||
<Content Include="App_Themes\images\icon_pptx.png" />
|
||||
<Content Include="App_Themes\images\icon_xlsx.png" />
|
||||
<Content Include="App_Themes\images\mobile-24.png" />
|
||||
<Content Include="App_Themes\images\review-24.png" />
|
||||
<Content Include="App_Themes\images\close.svg" />
|
||||
<Content Include="App_Themes\images\comment.svg" />
|
||||
<Content Include="App_Themes\images\delete.svg" />
|
||||
<Content Include="App_Themes\images\desktop.svg" />
|
||||
<Content Include="App_Themes\images\done.svg" />
|
||||
<Content Include="App_Themes\images\download.svg" />
|
||||
<Content Include="App_Themes\images\embeded.svg" />
|
||||
<Content Include="App_Themes\images\error.svg" />
|
||||
<Content Include="App_Themes\images\file_docx.svg" />
|
||||
<Content Include="App_Themes\images\file_docxf.svg" />
|
||||
<Content Include="App_Themes\images\file_pptx.svg" />
|
||||
<Content Include="App_Themes\images\file_upload.svg" />
|
||||
<Content Include="App_Themes\images\file_xlsx.svg" />
|
||||
<Content Include="App_Themes\images\fill-forms.svg" />
|
||||
<Content Include="App_Themes\images\filter.svg" />
|
||||
<Content Include="App_Themes\images\icon_docx.svg" />
|
||||
<Content Include="App_Themes\images\icon_pptx.svg" />
|
||||
<Content Include="App_Themes\images\icon_xlsx.svg" />
|
||||
<Content Include="App_Themes\images\info.svg" />
|
||||
<Content Include="App_Themes\images\logo.svg" />
|
||||
<Content Include="App_Themes\images\mobile-fill-forms.svg" />
|
||||
<Content Include="App_Themes\images\mobile.svg" />
|
||||
<Content Include="App_Themes\images\notdone.svg" />
|
||||
<Content Include="App_Themes\images\review.svg" />
|
||||
<Content Include="App_Themes\images\slide.ico" />
|
||||
<Content Include="App_Themes\images\word.ico" />
|
||||
<Content Include="App_Themes\media.css" />
|
||||
<Content Include="LICENSE" />
|
||||
<Content Include="licenses\jquery.license" />
|
||||
<Content Include="Web.config" />
|
||||
@ -126,13 +135,8 @@
|
||||
<Content Include="Default.aspx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="App_Themes\images\alert.png" />
|
||||
<Content Include="App_Themes\images\close.png" />
|
||||
<Content Include="App_Themes\images\corner.png" />
|
||||
<Content Include="App_Themes\images\done.png" />
|
||||
<Content Include="App_Themes\images\loader16.gif" />
|
||||
<Content Include="App_Themes\images\logo.png" />
|
||||
<Content Include="App_Themes\images\question_small.png" />
|
||||
<Content Include="App_Themes\jquery-ui.css" />
|
||||
<Content Include="App_Themes\stylesheet.css" />
|
||||
<Content Include="DocEditor.aspx" />
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
|
||||
This example will help you integrate ONLYOFFICE Docs into your web application written in .Net (C#).
|
||||
|
||||
It is aimed at testing the editors. Please, do not use it for production without proper modifications.
|
||||
**Please note**: It is intended for testing purposes and demonstrating functionality of the editors. Do NOT use this integration example on your own server without proper code modifications! In case you enabled the test example, disable it before going for production.
|
||||
|
||||
## Step 1. Install ONLYOFFICE Docs
|
||||
|
||||
Download and install ONLYOFFICE Docs (packaged as Document Server).
|
||||
Download and install ONLYOFFICE Docs (packaged as Document Server).
|
||||
|
||||
See the detailed guide to learn how to install Document Server [for Windows](https://helpcenter.onlyoffice.com/installation/docs-developer-install-windows.aspx), [for Linux](https://helpcenter.onlyoffice.com/installation/docs-developer-install-ubuntu.aspx), or [for Docker](https://helpcenter.onlyoffice.com/server/developer-edition/docker/docker-installation.aspx).
|
||||
|
||||
@ -14,11 +14,12 @@ See the detailed guide to learn how to install Document Server [for Windows](htt
|
||||
|
||||
Download the [.Net (C#) example](https://api.onlyoffice.com/editors/demopreview) from our site.
|
||||
|
||||
Connect the editors to your website by specifying the path to the editors installation in the *settings.config* file:
|
||||
To connect the editors to your website, specify the path to the editors installation and the path to the storage folder in the *settings.config* file:
|
||||
```
|
||||
<add key="storage-path" value=""/>
|
||||
<add key="files.docservice.url.site" value="https://documentserver/" />
|
||||
```
|
||||
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
|
||||
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **storage-path** is the path where files will be created and stored. You can set an absolute path.
|
||||
|
||||
If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) in the *DocEditor.aspx* file.
|
||||
|
||||
@ -28,13 +29,23 @@ Check that your system meets the requirements:
|
||||
* **Microsoft .NET Framework**: version 4.5 (download it from the [official Microsoft website](https://www.microsoft.com/en-US/download/details.aspx?id=30653));
|
||||
* **Internet Information Services**: version 7 or later.
|
||||
|
||||
Configure the IIS components for the server to work correctly:
|
||||
1. Open Windows features:
|
||||
|
||||
**Start** -> **Control Panel** -> **Programs** -> **Programs and Features** -> **Turn Windows features on or off**
|
||||
|
||||
2. In the opened window, find **Internet Information Services** and choose all the necessary features. To do this, open the **World Wide Web Services** list and check the following components:
|
||||
* **Application Development Features**: .NET Extensibility 4.8, ASP.NET 4.8, ISAPI Extensions, ISAPI Filters,
|
||||
* **Common HTTP Features**: Default Document,
|
||||
* **Security**: Request Filtering.
|
||||
|
||||
## Step 4. Run your website with the editors
|
||||
1. Run the Internet Information Service (IIS) Manager:
|
||||
|
||||
**Start** -> **Control Panel** -> **System and Security** -> **Administrative Tools** -> **Internet Information Services (IIS) Manager**
|
||||
|
||||
2. Add your website in the IIS Manager.
|
||||
|
||||
|
||||
On the **Connections** panel right-click the **Sites** node in the tree, then click **Add Website**.
|
||||
|
||||

|
||||
@ -46,7 +57,7 @@ Check that your system meets the requirements:
|
||||
|
||||

|
||||
4. Check for the .NET platform version specified in IIS Manager for you website. Choose **v4.0.** version.
|
||||
|
||||
|
||||
**Application Pools** -> right-click the platform name -> **Set application Pool defaults** -> **.NET CLR version**
|
||||
|
||||

|
||||
@ -61,3 +72,12 @@ Check that your system meets the requirements:
|
||||
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files.
|
||||
|
||||
Make sure that the Document Server in its turn has access to the server with the example installed with the address which you specify instead of **example.com** in the configuration files.
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
@ -78,7 +78,9 @@ namespace OnlineEditorsExample
|
||||
|
||||
if (token != null && !token.Equals("")) // invalid signature error
|
||||
{
|
||||
fileData = (Dictionary<string, object>)jss.Deserialize<Dictionary<string, object>>(token)["payload"];
|
||||
fileData = jss.Deserialize<Dictionary<string, object>>(token);
|
||||
if (fileData.ContainsKey("payload"))
|
||||
fileData = (Dictionary<string, object>)fileData["payload"];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -97,7 +99,11 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
var downloadUri = (string)fileData["url"];
|
||||
var curExt = Path.GetExtension(fileName).ToLower(); // get current file extension
|
||||
var downloadExt = Path.GetExtension(downloadUri).ToLower() ?? ""; // get the extension of the downloaded file
|
||||
|
||||
var downloadExt = fileData.ContainsKey("filetype")
|
||||
? "." + (string)fileData["filetype"]
|
||||
: Path.GetExtension(downloadUri).ToLower() ?? ""; // TODO: Delete in version 7.0 or higher. Support for versions below 7.0
|
||||
|
||||
var newFileName = fileName;
|
||||
|
||||
// convert downloaded file to the file with the current extension if these extensions aren't equal
|
||||
@ -124,11 +130,7 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
}
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (_Default.IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
_Default.VerifySSL();
|
||||
|
||||
var storagePath = _Default.StoragePath(newFileName, userAddress); // get the file path
|
||||
var histDir = _Default.HistoryDir(storagePath); // get the path to the history directory
|
||||
@ -175,7 +177,11 @@ namespace OnlineEditorsExample
|
||||
var downloadUri = (string)fileData["url"];
|
||||
|
||||
string curExt = Path.GetExtension(fileName).ToLower(); // get current file extension
|
||||
string downloadExt = Path.GetExtension(downloadUri).ToLower(); // get the extension of the downloaded file
|
||||
|
||||
var downloadExt = fileData.ContainsKey("filetype")
|
||||
? "." + (string)fileData["filetype"]
|
||||
: Path.GetExtension(downloadUri).ToLower(); // TODO: Delete in version 7.0 or higher. Support for versions below 7.0
|
||||
|
||||
Boolean newFileName = false;
|
||||
|
||||
// convert downloaded file to the file with the current extension if these extensions aren't equal
|
||||
@ -201,11 +207,7 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
}
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
if (_Default.IsMono)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
|
||||
}
|
||||
_Default.VerifySSL();
|
||||
|
||||
string forcesavePath = "";
|
||||
Boolean isSubmitForm = fileData["forcesavetype"].ToString().Equals("3"); // SubmitForm
|
||||
@ -250,8 +252,10 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
|
||||
// create a command request
|
||||
public static void commandRequest(string method, string key)
|
||||
public static void commandRequest(string method, string key, object meta = null)
|
||||
{
|
||||
_Default.VerifySSL();
|
||||
|
||||
string documentCommandUrl = WebConfigurationManager.AppSettings["files.docservice.url.site"] + WebConfigurationManager.AppSettings["files.docservice.url.command"];
|
||||
|
||||
var request = (HttpWebRequest)WebRequest.Create(documentCommandUrl);
|
||||
@ -263,13 +267,18 @@ namespace OnlineEditorsExample
|
||||
{ "key", key }
|
||||
};
|
||||
|
||||
if (meta != null)
|
||||
{
|
||||
body.Add("meta", meta);
|
||||
}
|
||||
|
||||
// check if a secret key to generate token exists or not
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
var payload = new Dictionary<string, object>
|
||||
{
|
||||
{ "payload", body }
|
||||
};
|
||||
{
|
||||
{ "payload", body }
|
||||
};
|
||||
|
||||
var payloadToken = JwtManager.Encode(payload); // encode a payload object into a header token
|
||||
var bodyToken = JwtManager.Encode(body); // encode body into a body token
|
||||
|
||||
@ -29,7 +29,8 @@ namespace OnlineEditorsExample
|
||||
"Can review all the changes",
|
||||
"Can perform all actions with comments",
|
||||
"The file favorite state is undefined",
|
||||
"Can create files from templates using data from the editor"
|
||||
"Can create files from templates using data from the editor",
|
||||
"Can see the information about all users"
|
||||
};
|
||||
|
||||
static List<string> descr_user_2 = new List<string>()
|
||||
@ -38,19 +39,21 @@ namespace OnlineEditorsExample
|
||||
"Can review only his own changes or changes made by users with no group",
|
||||
"Can view comments, edit his own comments and comments left by users with no group. Can remove his own comments only",
|
||||
"This file is marked as favorite",
|
||||
"Can create new files from the editor"
|
||||
"Can create new files from the editor",
|
||||
"Can see the information about users from Group2 and users who don’t belong to any group"
|
||||
};
|
||||
|
||||
static List<string> descr_user_3 = new List<string>()
|
||||
{
|
||||
"Belongs to Group3",
|
||||
"Can review changes made by Group2 users",
|
||||
"Can view comments left by Group2 and Group3 users. Can edit comments left by Group2 users",
|
||||
"Can view comments left by Group2 and Group3 users. Can edit comments left by the Group2 users",
|
||||
"This file isn’t marked as favorite",
|
||||
"Can’t copy data from the file to clipboard",
|
||||
"Can’t download the file",
|
||||
"Can’t print the file",
|
||||
"Can create new files from the editor"
|
||||
"Can create new files from the editor",
|
||||
"Can see the information about Group2 users"
|
||||
};
|
||||
|
||||
static List<string> descr_user_0 = new List<string>()
|
||||
@ -61,7 +64,9 @@ namespace OnlineEditorsExample
|
||||
"Can perform all actions with comments",
|
||||
"The file favorite state is undefined",
|
||||
"Can't mention others in comments",
|
||||
"Can't create new files from the editor"
|
||||
"Can't create new files from the editor",
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor"
|
||||
};
|
||||
|
||||
private static List<User> users = new List<User>() {
|
||||
@ -69,10 +74,11 @@ namespace OnlineEditorsExample
|
||||
"uid-1",
|
||||
"John Smith",
|
||||
"smith@example.com",
|
||||
null,
|
||||
"",
|
||||
null,
|
||||
new Dictionary<string, object>(),
|
||||
null,
|
||||
null,
|
||||
new List<string>(),
|
||||
descr_user_1,
|
||||
true
|
||||
@ -89,6 +95,7 @@ namespace OnlineEditorsExample
|
||||
{ "edit", new List<string>() { "group-2", "" } },
|
||||
{ "remove", new List<string>() { "group-2" } }
|
||||
},
|
||||
new List<string>() { "group-2", "" },
|
||||
true,
|
||||
new List<string>(),
|
||||
descr_user_2,
|
||||
@ -106,6 +113,7 @@ namespace OnlineEditorsExample
|
||||
{ "edit", new List<string>() { "group-2" } },
|
||||
{ "remove", new List<string>() { } }
|
||||
},
|
||||
new List<string>() { "group-2" },
|
||||
false,
|
||||
new List<string>() { "copy", "download", "print" },
|
||||
descr_user_3,
|
||||
@ -115,9 +123,10 @@ namespace OnlineEditorsExample
|
||||
"uid-0",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"",
|
||||
null,
|
||||
new Dictionary<string, object>(),
|
||||
new List<string>(),
|
||||
null,
|
||||
new List<string>(),
|
||||
descr_user_0,
|
||||
@ -173,8 +182,9 @@ namespace OnlineEditorsExample
|
||||
public List<string> deniedPermissions;
|
||||
public List<string> descriptions;
|
||||
public bool templates;
|
||||
public List<string> userInfoGroups;
|
||||
|
||||
public User(string id, string name, string email, string group, List<string> reviewGroups, Dictionary<string, object> commentGroups, bool? favorite, List<string> deniedPermissions, List<string> descriptions, bool templates)
|
||||
public User(string id, string name, string email, string group, List<string> reviewGroups, Dictionary<string, object> commentGroups, List<string> userInfoGroups, bool? favorite, List<string> deniedPermissions, List<string> descriptions, bool templates)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
@ -186,6 +196,7 @@ namespace OnlineEditorsExample
|
||||
this.deniedPermissions = deniedPermissions;
|
||||
this.descriptions = descriptions;
|
||||
this.templates = templates;
|
||||
this.userInfoGroups = userInfoGroups;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,26 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appSettings configSource="settings.config"/>
|
||||
<appSettings configSource="settings.config" />
|
||||
<system.web>
|
||||
<httpRuntime maxRequestLength="51200"/>
|
||||
<compilation debug="true" targetFramework="4.5"/>
|
||||
<authentication mode="Windows"/>
|
||||
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
|
||||
<httpRuntime maxRequestLength="51200" />
|
||||
<compilation debug="true" targetFramework="4.5" />
|
||||
<authentication mode="Windows" />
|
||||
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
<httpProtocol>
|
||||
<customHeaders>
|
||||
<add name="Access-Control-Allow-Origin" value="*" />
|
||||
</customHeaders>
|
||||
</httpProtocol>
|
||||
<httpProtocol>
|
||||
<customHeaders>
|
||||
<add name="Access-Control-Allow-Origin" value="*" />
|
||||
</customHeaders>
|
||||
</httpProtocol>
|
||||
<security>
|
||||
<requestFiltering>
|
||||
<requestLimits maxAllowedContentLength="1073741824"/>
|
||||
<requestLimits maxAllowedContentLength="52428800" />
|
||||
<denyUrlSequences>
|
||||
<add sequence=".."/>
|
||||
<add sequence=".." />
|
||||
</denyUrlSequences>
|
||||
<hiddenSegments>
|
||||
<remove segment="App_Data"/>
|
||||
<remove segment="App_Data" />
|
||||
</hiddenSegments>
|
||||
</requestFiltering>
|
||||
</security>
|
||||
|
||||
@ -44,6 +44,9 @@ namespace OnlineEditorsExample
|
||||
case "download":
|
||||
Download(context);
|
||||
break;
|
||||
case "downloadhistory":
|
||||
DownloadHistory(context);
|
||||
break;
|
||||
case "convert":
|
||||
Convert(context);
|
||||
break;
|
||||
@ -62,6 +65,26 @@ namespace OnlineEditorsExample
|
||||
case "files":
|
||||
Files(context);
|
||||
break;
|
||||
case "saveas":
|
||||
SaveAs(context);
|
||||
break;
|
||||
case "rename":
|
||||
Rename(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveAs(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "text/plain";
|
||||
try
|
||||
{
|
||||
var result = _Default.DoSaveAs(context);
|
||||
context.Response.Write(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"" + 1 + "\", \"message\": \"" + e.Message + "\"}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,7 +141,7 @@ namespace OnlineEditorsExample
|
||||
var userAddress = context.Request["userAddress"];
|
||||
var fileName = Path.GetFileName(context.Request["fileName"]);
|
||||
var status = (TrackerStatus) (int) fileData["status"]; // get status from the request body
|
||||
var saved = 1; // editing
|
||||
var saved = 0;
|
||||
switch (status)
|
||||
{
|
||||
case TrackerStatus.Editing:
|
||||
@ -174,7 +197,7 @@ namespace OnlineEditorsExample
|
||||
context.Response.Write("{\"error\":" + saved + "}");
|
||||
return;
|
||||
}
|
||||
context.Response.Write("{\"error\":0}");
|
||||
context.Response.Write("{\"error\":" + saved + "}");
|
||||
}
|
||||
|
||||
// remove a file
|
||||
@ -254,10 +277,11 @@ namespace OnlineEditorsExample
|
||||
{
|
||||
try
|
||||
{
|
||||
var fileName = Path.GetFileName(context.Request["fileName"]);
|
||||
var fileName = Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? context.Request["fileName"] : Path.GetFileName(context.Request["fileName"]);
|
||||
var userAddress = Path.GetFileName(context.Request["userAddress"]);
|
||||
var isEmbedded = context.Request["dmode"];
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && isEmbedded == null)
|
||||
{
|
||||
string JWTheader = WebConfigurationManager.AppSettings["files.docservice.header"].Equals("") ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
@ -304,5 +328,77 @@ namespace OnlineEditorsExample
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
private static void DownloadHistory(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fileName = Path.GetFileName(context.Request["fileName"]);
|
||||
var userAddress = Path.GetFileName(context.Request["userAddress"]);
|
||||
var version = Path.GetFileName(context.Request["ver"]);
|
||||
var file = Path.GetFileName(context.Request["file"]);
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
string JWTheader = WebConfigurationManager.AppSettings["files.docservice.header"].Equals("") ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
if (context.Request.Headers.AllKeys.Contains(JWTheader, StringComparer.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var headerToken = context.Request.Headers.Get(JWTheader).Substring("Bearer ".Length);
|
||||
string token = JwtManager.Decode(headerToken);
|
||||
|
||||
if (token == null || token.Equals(""))
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
context.Response.Write("JWT validation failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
context.Response.Write("JWT validation failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var filePath = _Default.HistoryPath(fileName, userAddress, version, file); // get the path to the force saved document version
|
||||
|
||||
download(filePath, context);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"File not found!\"}");
|
||||
}
|
||||
}
|
||||
|
||||
// rename a file
|
||||
private static void Rename(HttpContext context)
|
||||
{
|
||||
string fileData;
|
||||
try
|
||||
{
|
||||
using (var receiveStream = context.Request.InputStream)
|
||||
using (var readStream = new StreamReader(receiveStream))
|
||||
{
|
||||
fileData = readStream.ReadToEnd();
|
||||
if (string.IsNullOrEmpty(fileData)) return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
|
||||
}
|
||||
|
||||
var jss = new JavaScriptSerializer();
|
||||
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
|
||||
var newFileName = (string) body["newfilename"];
|
||||
var docKey = (string) body["dockey"];
|
||||
var meta = new Dictionary<string, object>() {
|
||||
{ "title", newFileName }
|
||||
};
|
||||
TrackManager.commandRequest("meta", docKey, meta);
|
||||
context.Response.Write("{ \"result\": \"OK\"}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Submodule web/documentserver-example/csharp/assets updated: f9fc118e43...1d601d84c4
@ -74,7 +74,8 @@ if (typeof jQuery != "undefined") {
|
||||
});
|
||||
|
||||
var timer = null;
|
||||
var checkConvert = function (filePass = null) {
|
||||
var checkConvert = function (filePass) {
|
||||
filePass = filePass ? filePass : null;
|
||||
if (timer != null) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
@ -167,7 +168,7 @@ if (typeof jQuery != "undefined") {
|
||||
var posExt = fileName.lastIndexOf('.');
|
||||
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : '';
|
||||
|
||||
if (EditedExtList.indexOf(posExt) != -1) {
|
||||
if (EditedExtList.indexOf(posExt) != -1 || FillFormExtList.indexOf(posExt) != -1) {
|
||||
jq("#beginEdit").removeClass("disable");
|
||||
}
|
||||
};
|
||||
@ -226,7 +227,7 @@ if (typeof jQuery != "undefined") {
|
||||
|
||||
jq(document).on("click", "#beginView:not(.disable)", function () {
|
||||
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
|
||||
var url = "doceditor.aspx?action=view&fileID=" + fileId;
|
||||
var url = "doceditor.aspx?editorsMode=view&fileID=" + fileId;
|
||||
window.open(url, "_blank");
|
||||
jq('#hiddenFileName').val("");
|
||||
jq.unblockUI();
|
||||
@ -288,10 +289,6 @@ if (typeof jQuery != "undefined") {
|
||||
};
|
||||
|
||||
var fileList = jq("tr.tableRow");
|
||||
if (fileList.length > 0) {
|
||||
console.log(jq("div#portal-info").is(":visible"));
|
||||
jq("div#portal-info").hide();
|
||||
}
|
||||
|
||||
var mouseIsOverTooltip = false;
|
||||
var hideTooltipTimeout = null;
|
||||
|
||||
@ -1,19 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<appSettings>
|
||||
<clear />
|
||||
<add key="version" value="1.0.0"/>
|
||||
<add key="version" value="1.2.0"/>
|
||||
|
||||
<add key="filesize-max" value="5242880"/>
|
||||
<add key="filesize-max" value="52428800"/>
|
||||
<add key="storage-path" value=""/>
|
||||
|
||||
<add key="files.docservice.fillform-docs" value=".oform|.docx"/>
|
||||
<add key="files.docservice.viewed-docs" value=".pdf|.djvu|.xps|.oxps"/>
|
||||
<add key="files.docservice.edited-docs" value=".docx|.xlsx|.csv|.pptx|.txt"/>
|
||||
<add key="files.docservice.convert-docs" value=".docm|.dotx|.dotm|.dot|.doc|.odt|.fodt|.ott|.xlsm|.xltx|.xltm|.xlt|.xls|.ods|.fods|.ots|.pptm|.ppt|.ppsx|.ppsm|.pps|.potx|.potm|.pot|.odp|.fodp|.otp|.rtf|.mht|.html|.htm|.xml|.epub|.fb2"/>
|
||||
<add key="files.docservice.edited-docs" value=".docx|.xlsx|.csv|.pptx|.txt|.docxf"/>
|
||||
<add key="files.docservice.convert-docs" value=".docm|.dotx|.dotm|.dot|.doc|.odt|.fodt|.ott|.xlsm|.xlsb|.xltx|.xltm|.xlt|.xls|.ods|.fods|.ots|.pptm|.ppt|.ppsx|.ppsm|.pps|.potx|.potm|.pot|.odp|.fodp|.otp|.rtf|.mht|.html|.htm|.xml|.epub|.fb2"/>
|
||||
<add key="files.docservice.timeout" value="120000" />
|
||||
<add key="files.docservice.secret" value="" />
|
||||
<add key="files.docservice.header" value="Authorization" />
|
||||
<add key="files.docservice.verify-peer-off" value="true"/>
|
||||
|
||||
<add key="files.docservice.url.site" value="https://documentserver/"/>
|
||||
<add key="files.docservice.languages" value="en:English|az:Azerbaijani|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese|cs:Czech|da:Danish|nl:Dutch|fi:Finnish|fr:French|gl:Galego|de:German|el:Greek|hu:Hungarian|id:Indonesian|it:Italian|ja:Japanese|ko:Korean|lv:Latvian|lo:Lao|nb:Norwegian|pl:Polish|pt:Portuguese|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese"/>
|
||||
|
||||
<add key="files.docservice.url.site" value="http://documentserver/"/>
|
||||
|
||||
<add key="files.docservice.url.converter" value="ConvertService.ashx"/>
|
||||
<add key="files.docservice.url.api" value="web-apps/apps/api/documents/api.js"/>
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
## Overview
|
||||
|
||||
This example will help you integrate ONLYOFFICE Docs into your web application written in Java
|
||||
with Spring Boot.
|
||||
with Spring Boot.
|
||||
|
||||
Spring Boot has a lot of functionality, but its most significant features are: dependency management,
|
||||
auto-configuration, and built-in servlet containers.
|
||||
|
||||
It is aimed at testing the editors. Please, do not use it for production without proper modifications.
|
||||
**Please note**: It is intended for testing purposes and demonstrating functionality of the editors. Do NOT use this integration example on your own server without proper code modifications! In case you enabled the test example, disable it before going for production.
|
||||
|
||||
## For Windows
|
||||
|
||||
### Step 1. Install ONLYOFFICE Docs
|
||||
|
||||
Download and install ONLYOFFICE Docs (packaged as Document Server).
|
||||
Download and install ONLYOFFICE Docs (packaged as Document Server).
|
||||
|
||||
See the detailed guide to learn how to install Document Server [for Windows](https://helpcenter.onlyoffice.com/installation/docs-developer-install-windows.aspx).
|
||||
|
||||
@ -19,16 +20,15 @@ See the detailed guide to learn how to install Document Server [for Windows](htt
|
||||
|
||||
Download the [Java-Spring example](https://api.onlyoffice.com/editors/demopreview) from our site.
|
||||
|
||||
To connect the editors to your website, specify the path to the editors installation, server address and port in the *\src\main\resources\application.properties* file:
|
||||
To connect the editors to your website, specify the path to the editors installation, server port and the path to the storage folder in the *\src\main\resources\application.properties* file:
|
||||
|
||||
```
|
||||
server.address=address
|
||||
files.storage=
|
||||
server.port=port
|
||||
files.docservice.url.site=https://documentserver/
|
||||
```
|
||||
|
||||
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
|
||||
**address** is the address of the server or comment this line to use localhost, **port** is the any available port.
|
||||
where the **documentserver** is the name of the server with the ONLYOFFICE Docs installed, **port** is any available port and **files.storage** is the path where files will be created and stored (in the project folder by default). You can set an absolute path. For example, *D:\\\\folder*. Please note that on Windows OS the double backslash must be used as a separator.
|
||||
|
||||
If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) it the *\src\main\resources\editor.html* file.
|
||||
|
||||
@ -65,11 +65,11 @@ To run the Java example code, install the Java version 11 appropriate for your O
|
||||
```
|
||||
echo %JAVA_HOME%
|
||||
```
|
||||
|
||||
|
||||
2. Set the **MAVEN_HOME** environment variable:
|
||||
|
||||
|
||||
Unzip the downloaded archive with the maven to any directory, it will be something like this:
|
||||
|
||||
|
||||
```
|
||||
C:\apache-maven-3.8.1
|
||||
```
|
||||
@ -87,7 +87,7 @@ To run the Java example code, install the Java version 11 appropriate for your O
|
||||
|
||||
Add C:\apache-maven-3.8.1\bin to the PATH system variable:
|
||||
In system variables, find PATH, clicks on the Edit... button. In “Edit environment variable” dialog, clicks on the New button and add this C:\apache-maven-3.8.1\bin
|
||||
|
||||
|
||||
Check if the variable created successfully by **echo** command in the **Command Prompt**:
|
||||
|
||||
```
|
||||
@ -112,8 +112,6 @@ To run the Java example code, install the Java version 11 appropriate for your O
|
||||
```
|
||||
http://server.address:server.port/
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Step 6. Check accessibility
|
||||
|
||||
@ -151,8 +149,8 @@ See the detailed guide to learn how to install Document Server [for Linux](https
|
||||
```
|
||||
git clone https://github.com/ONLYOFFICE/document-server-integration.git
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
3. Change the current directory for the project directory:
|
||||
|
||||
a) from archive
|
||||
@ -173,13 +171,13 @@ See the detailed guide to learn how to install Document Server [for Linux](https
|
||||
Edit the following lines:
|
||||
|
||||
```
|
||||
server.address=address
|
||||
files.storage=
|
||||
server.port=port
|
||||
files.docservice.url.site=https://documentserver/
|
||||
```
|
||||
|
||||
Where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
|
||||
**address** is the address of the server or comment this line to use localhost, **port** is the any available port.
|
||||
where the **documentserver** is the name of the server with the ONLYOFFICE Docs installed, **port** is any available port and **files.storage** is the path where files will be created and stored (in the project folder by default). You can set an absolute path.
|
||||
|
||||
|
||||
5. Install **Maven**:
|
||||
|
||||
@ -192,19 +190,18 @@ See the detailed guide to learn how to install Document Server [for Linux](https
|
||||
```
|
||||
mvn package
|
||||
```
|
||||
|
||||
|
||||
7. Start Java-Spring example:
|
||||
```
|
||||
./mvnw spring-boot:run
|
||||
```
|
||||
8. Open your browser using **server.address** and **server.port**:
|
||||
|
||||
|
||||
```
|
||||
http://server.address:server.port/
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Step 3. Check accessibility
|
||||
|
||||
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files.
|
||||
@ -222,13 +219,12 @@ Make sure that the Document Server has access to the server with the example ins
|
||||
2. Edit the following lines:
|
||||
|
||||
```
|
||||
server.address=address
|
||||
files.storage=
|
||||
server.port=port
|
||||
files.docservice.url.site=https://documentserver/
|
||||
```
|
||||
|
||||
Where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
|
||||
**address** is the address of the server or comment this line to use localhost, **port** is the any available port.
|
||||
|
||||
where the **documentserver** is the name of the server with the ONLYOFFICE Docs installed, **port** is any available port and **files.storage** is the path where files will be created and stored (in the project folder by default). You can set an absolute path.
|
||||
|
||||
3. Run the next command in the java example directory:
|
||||
|
||||
@ -236,7 +232,16 @@ Make sure that the Document Server has access to the server with the example ins
|
||||
docker-compose up
|
||||
```
|
||||
4. Open your browser using **server.address** and **server.port**:
|
||||
|
||||
|
||||
```
|
||||
http://server.address:server.port/
|
||||
```
|
||||
|
||||
## Important security info
|
||||
|
||||
Please keep in mind the following security aspects when you are using test examples:
|
||||
|
||||
* There is no protection of the storage from unauthorized access since there is no need for authorization.
|
||||
* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.
|
||||
* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server.
|
||||
* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain.
|
||||
@ -7,7 +7,9 @@ services:
|
||||
image: maven:3.8.1
|
||||
working_dir: /java-spring
|
||||
volumes:
|
||||
- .:/java-spring
|
||||
- .:/java-spring
|
||||
ports:
|
||||
- 4000:4000
|
||||
command: mvn clean spring-boot:run
|
||||
|
||||
|
||||
@ -33,31 +33,35 @@ public class ExampleData {
|
||||
private UserServices userService;
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
List<String> description_user_0=List.of(
|
||||
List<String> description_user_0=List.of( // the description for user 0
|
||||
"The name is requested when the editor is opened",
|
||||
"Doesn’t belong to any group",
|
||||
"Can review all the changes",
|
||||
"Can perform all actions with comments",
|
||||
"The file favorite state is undefined",
|
||||
"Can't mention others in comments",
|
||||
"Can't create new files from the editor"
|
||||
"Can't create new files from the editor",
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor"
|
||||
);
|
||||
List<String> description_user_1 = List.of(
|
||||
List<String> description_user_1 = List.of( // the description for user 1
|
||||
"File author by default",
|
||||
"He doesn’t belong to any of the groups",
|
||||
"He can review all the changes",
|
||||
"He can do everything with the comments",
|
||||
"The file favorite state is undefined",
|
||||
"Can create a file from a template with data from the editor"
|
||||
"Can create a file from a template with data from the editor",
|
||||
"Can see the information about all users"
|
||||
);
|
||||
List<String> description_user_2 = List.of(
|
||||
List<String> description_user_2 = List.of( // the description for user 2
|
||||
"He belongs to Group2",
|
||||
"He can review only his own changes or the changes made by the users who don’t belong to any of the groups",
|
||||
"He can view every comment, edit his comments and the comments left by the users who don't belong to any of the groups and remove only his comments",
|
||||
"This file is favorite",
|
||||
"Can create a file from an editor"
|
||||
"Can create a file from an editor",
|
||||
"Can see the information about users from Group2 and users who don’t belong to any group"
|
||||
);
|
||||
List<String> description_user_3 = List.of(
|
||||
List<String> description_user_3 = List.of( // the description for user 3
|
||||
"He belongs to Group3",
|
||||
"He can review only the changes made by the users from Group2",
|
||||
"He can view the comments left by the users from Group2 and Group3 and edit the comments left by the users from Group2",
|
||||
@ -65,21 +69,24 @@ public class ExampleData {
|
||||
"He can’t copy data from the file into the clipboard",
|
||||
"He can’t download the file",
|
||||
"He can’t print the file",
|
||||
"Can create a file from an editor"
|
||||
"Can create a file from an editor",
|
||||
"Can see the information about Group2 users"
|
||||
);
|
||||
userService.createUser("John Smith", "smith@example.com",
|
||||
description_user_1, null, List.of(FilterState.NULL.toString()),
|
||||
userService.createUser("John Smith", "smith@example.com", // create user 1 with the specified parameters
|
||||
description_user_1, "", List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()));
|
||||
userService.createUser("Mark Pottato", "pottato@example.com",
|
||||
List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()),
|
||||
null);
|
||||
userService.createUser("Mark Pottato", "pottato@example.com", // create user 2 with the specified parameters
|
||||
description_user_2, "group-2", List.of("","group-2"), List.of(FilterState.NULL.toString()),
|
||||
List.of("group-2", ""), List.of("group-2"));
|
||||
userService.createUser("Hamish Mitchell", "mitchell@example.com",
|
||||
List.of("group-2", ""), List.of("group-2"), List.of("group-2", ""), true);
|
||||
userService.createUser("Hamish Mitchell", "mitchell@example.com", // create user 3 with the specified parameters
|
||||
description_user_3, "group-3", List.of("group-2"), List.of("group-2", "group-3"),
|
||||
List.of("group-2"), new ArrayList<>());
|
||||
userService.createUser("Anonymous",null,
|
||||
description_user_0,null, List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()));
|
||||
List.of("group-2"), new ArrayList<>(), List.of("group-2"), false);
|
||||
userService.createUser("Anonymous",null, // create user 0 with the specified parameters
|
||||
description_user_0,"", List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), new ArrayList<>(),null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@SpringBootApplication
|
||||
public class IntegrationApplication {
|
||||
|
||||
// run the SpringApplication from the IntagrationApplication with the specified parameters
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(IntegrationApplication.class, args);
|
||||
}
|
||||
|
||||
@ -30,38 +30,57 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.onlyoffice.integration.documentserver.util.SSLUtils;
|
||||
|
||||
@Configuration
|
||||
public class IntegrationConfiguration {
|
||||
|
||||
@Value("${files.storage}")
|
||||
private String storageAddress;
|
||||
|
||||
@Value("${files.docservice.verify-peer-off}")
|
||||
private String verifyPerrOff;
|
||||
|
||||
@Autowired
|
||||
private FileStoragePathBuilder storagePathBuilder;
|
||||
|
||||
@Autowired
|
||||
private SSLUtils ssl;
|
||||
|
||||
@Bean
|
||||
public ModelMapper mapper(){
|
||||
public ModelMapper mapper(){ // create the model mapper
|
||||
ModelMapper mapper = new ModelMapper();
|
||||
mapper.getConfiguration()
|
||||
.setMatchingStrategy(MatchingStrategies.STRICT)
|
||||
.setFieldMatchingEnabled(true)
|
||||
.setSkipNullEnabled(true)
|
||||
.setFieldAccessLevel(org.modelmapper.config.Configuration.AccessLevel.PRIVATE);
|
||||
mapper.getConfiguration() // get the mapper configuration and set new parameters to it
|
||||
.setMatchingStrategy(MatchingStrategies.STRICT) // specify the STRICT matching strategy
|
||||
.setFieldMatchingEnabled(true) // define if the field matching is enabled or not
|
||||
.setSkipNullEnabled(true) // define if null value will be skipped or not
|
||||
.setFieldAccessLevel(org.modelmapper.config.Configuration.AccessLevel.PRIVATE); // specify the PRIVATE field access level
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JSONParser jsonParser(){
|
||||
public JSONParser jsonParser(){ // create JSON parser
|
||||
return new JSONParser();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
public void init(){ // initialize the storage path builder
|
||||
storagePathBuilder.configure(storageAddress.isBlank() ? null : storageAddress);
|
||||
if(!verifyPerrOff.isEmpty()) {
|
||||
try{
|
||||
if(verifyPerrOff.equals("true")) {
|
||||
ssl.turnOffSslChecking(); //the certificate will be ignored
|
||||
} else {
|
||||
ssl.turnOnSslChecking(); //the certificate will be verified
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper(){
|
||||
public ObjectMapper objectMapper(){ // create the object mapper
|
||||
return new ObjectMapper();
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,6 +72,7 @@ public class EditorController {
|
||||
private FileConfigurer<DefaultFileWrapper> fileConfigurer;
|
||||
|
||||
@GetMapping(path = "${url.editor}")
|
||||
// process request to open the editor page
|
||||
public String index(@RequestParam("fileName") String fileName,
|
||||
@RequestParam(value = "action", required = false) String actionParam,
|
||||
@RequestParam(value = "type", required = false) String typeParam,
|
||||
@ -89,10 +90,12 @@ public class EditorController {
|
||||
|
||||
Optional<User> optionalUser = userService.findUserById(Integer.parseInt(uid));
|
||||
|
||||
// if the user is not present, return the ONLYOFFICE start page
|
||||
if(!optionalUser.isPresent()) return "index.html";
|
||||
|
||||
User user = optionalUser.get();
|
||||
|
||||
// get file model with the default file parameters
|
||||
FileModel fileModel = fileConfigurer.getFileModel(
|
||||
DefaultFileWrapper
|
||||
.builder()
|
||||
@ -105,23 +108,24 @@ public class EditorController {
|
||||
.build()
|
||||
);
|
||||
|
||||
model.addAttribute("model", fileModel);
|
||||
model.addAttribute("fileHistory", historyManager.getHistory(fileModel.getDocument()));
|
||||
model.addAttribute("docserviceApiUrl",docserviceSite + docserviceApiUrl);
|
||||
model.addAttribute("dataInsertImage", getInsertImage());
|
||||
model.addAttribute("dataCompareFile", getCompareFile());
|
||||
model.addAttribute("dataMailMergeRecipients", getMailMerge());
|
||||
model.addAttribute("usersForMentions", getUserMentions(uid));
|
||||
// add attributes to the specified model
|
||||
model.addAttribute("model", fileModel); // add file model with the default parameters to the original model
|
||||
model.addAttribute("fileHistory", historyManager.getHistory(fileModel.getDocument())); // get file history and add it to the model
|
||||
model.addAttribute("docserviceApiUrl",docserviceSite + docserviceApiUrl); // create the document service api URL and add it to the model
|
||||
model.addAttribute("dataInsertImage", getInsertImage()); // get an image and add it to the model
|
||||
model.addAttribute("dataCompareFile", getCompareFile()); // get a document for comparison and add it to the model
|
||||
model.addAttribute("dataMailMergeRecipients", getMailMerge()); // get recipients data for mail merging and add it to the model
|
||||
model.addAttribute("usersForMentions", getUserMentions(uid)); // get user data for mentions and add it to the model
|
||||
return "editor.html";
|
||||
}
|
||||
|
||||
private List<Mentions> getUserMentions(String uid){
|
||||
private List<Mentions> getUserMentions(String uid){ // get user data for mentions
|
||||
List<Mentions> usersForMentions=new ArrayList<>();
|
||||
if(uid!=null && !uid.equals("4")) {
|
||||
List<User> list = userService.findAll();
|
||||
for (User u : list) {
|
||||
if (u.getId()!=Integer.parseInt(uid) && u.getId()!=4) {
|
||||
usersForMentions.add(new Mentions(u.getName(),u.getEmail()));
|
||||
usersForMentions.add(new Mentions(u.getName(),u.getEmail())); // user data includes user names and emails
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,26 +134,28 @@ public class EditorController {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private String getInsertImage() {
|
||||
private String getInsertImage() { // get an image that will be inserted into the document
|
||||
Map<String, Object> dataInsertImage = new HashMap<>();
|
||||
dataInsertImage.put("fileType", "png");
|
||||
dataInsertImage.put("url", storagePathBuilder.getServerUrl(true) + "/css/img/logo.png");
|
||||
|
||||
// check if the document token is enabled
|
||||
if(jwtManager.tokenEnabled()){
|
||||
dataInsertImage.put("token", jwtManager.createToken(dataInsertImage));
|
||||
dataInsertImage.put("token", jwtManager.createToken(dataInsertImage)); // create token from the dataInsertImage object
|
||||
}
|
||||
|
||||
return objectMapper.writeValueAsString(dataInsertImage).substring(1, objectMapper.writeValueAsString(dataInsertImage).length()-1);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private String getCompareFile(){
|
||||
private String getCompareFile(){ // get a document that will be compared with the current document
|
||||
Map<String, Object> dataCompareFile = new HashMap<>();
|
||||
dataCompareFile.put("fileType", "docx");
|
||||
dataCompareFile.put("url", storagePathBuilder.getServerUrl(true) + "/assets?name=sample.docx");
|
||||
|
||||
// check if the document token is enabled
|
||||
if(jwtManager.tokenEnabled()){
|
||||
dataCompareFile.put("token", jwtManager.createToken(dataCompareFile));
|
||||
dataCompareFile.put("token", jwtManager.createToken(dataCompareFile)); // create token from the dataCompareFile object
|
||||
}
|
||||
|
||||
return objectMapper.writeValueAsString(dataCompareFile);
|
||||
@ -157,12 +163,13 @@ public class EditorController {
|
||||
|
||||
@SneakyThrows
|
||||
private String getMailMerge(){
|
||||
Map<String, Object> dataMailMergeRecipients = new HashMap<>();
|
||||
Map<String, Object> dataMailMergeRecipients = new HashMap<>(); // get recipients data for mail merging
|
||||
dataMailMergeRecipients.put("fileType", "csv");
|
||||
dataMailMergeRecipients.put("url", storagePathBuilder.getServerUrl(true) + "/csv");
|
||||
|
||||
// check if the document token is enabled
|
||||
if(jwtManager.tokenEnabled()){
|
||||
dataMailMergeRecipients.put("token", jwtManager.createToken(dataMailMergeRecipients));
|
||||
dataMailMergeRecipients.put("token", jwtManager.createToken(dataMailMergeRecipients)); // create token from the dataMailMergeRecipients object
|
||||
}
|
||||
|
||||
return objectMapper.writeValueAsString(dataMailMergeRecipients);
|
||||
|
||||
@ -31,6 +31,7 @@ import com.onlyoffice.integration.services.UserServices;
|
||||
import com.onlyoffice.integration.documentserver.util.file.FileUtility;
|
||||
import com.onlyoffice.integration.documentserver.util.service.ServiceConverter;
|
||||
import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
|
||||
import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -58,6 +59,15 @@ public class FileController {
|
||||
@Value("${files.docservice.header}")
|
||||
private String documentJwtHeader;
|
||||
|
||||
@Value("${filesize-max}")
|
||||
private String filesizeMax;
|
||||
|
||||
@Value("${files.docservice.url.site}")
|
||||
private String docserviceUrlSite;
|
||||
|
||||
@Value("${files.docservice.url.command}")
|
||||
private String docserviceUrlCommand;
|
||||
|
||||
@Autowired
|
||||
private FileUtility fileUtility;
|
||||
@Autowired
|
||||
@ -76,22 +86,39 @@ public class FileController {
|
||||
private ObjectMapper objectMapper;
|
||||
@Autowired
|
||||
private ServiceConverter serviceConverter;
|
||||
@Autowired
|
||||
private CallbackManager callbackManager;
|
||||
|
||||
// create user metadata
|
||||
private String createUserMetadata(String uid, String fullFileName) {
|
||||
Optional<User> optionalUser = userService.findUserById(Integer.parseInt(uid));
|
||||
String documentType = fileUtility.getDocumentType(fullFileName).toString().toLowerCase();
|
||||
Optional<User> optionalUser = userService.findUserById(Integer.parseInt(uid)); // find a user by their ID
|
||||
String documentType = fileUtility.getDocumentType(fullFileName).toString().toLowerCase(); // get document type
|
||||
if(optionalUser.isPresent()){
|
||||
User user = optionalUser.get();
|
||||
storageMutator.createMeta(fullFileName,
|
||||
storageMutator.createMeta(fullFileName, // create meta information with the user ID and name specified
|
||||
String.valueOf(user.getId()), user.getName());
|
||||
}
|
||||
return "{ \"filename\": \"" + fullFileName + "\", \"documentType\": \"" + documentType + "\" }";
|
||||
}
|
||||
|
||||
// download data from the specified file
|
||||
private ResponseEntity<Resource> downloadFile(String fileName){
|
||||
Resource resource = storageMutator.loadFileAsResource(fileName);
|
||||
Resource resource = storageMutator.loadFileAsResource(fileName); // load the specified file as a resource
|
||||
String contentType = "application/octet-stream";
|
||||
|
||||
// create a response with the content type, header and body with the file data
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(contentType))
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
|
||||
.body(resource);
|
||||
}
|
||||
|
||||
// download data from the specified history file
|
||||
private ResponseEntity<Resource> downloadFileHistory(String fileName, String version, String file){
|
||||
Resource resource = storageMutator.loadFileAsResourceHistory(fileName,version,file); // load the specified file as a resource
|
||||
String contentType = "application/octet-stream";
|
||||
|
||||
// create a response with the content type, header and body with the file data
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(contentType))
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
|
||||
@ -100,130 +127,159 @@ public class FileController {
|
||||
|
||||
@PostMapping("/upload")
|
||||
@ResponseBody
|
||||
public String upload(@RequestParam("file") MultipartFile file,
|
||||
public String upload(@RequestParam("file") MultipartFile file, // upload a file
|
||||
@CookieValue("uid") String uid){
|
||||
try {
|
||||
String fullFileName = file.getOriginalFilename();
|
||||
String fileExtension = fileUtility.getFileExtension(fullFileName);
|
||||
long fileSize = file.getSize();
|
||||
byte[] bytes = file.getBytes();
|
||||
String fullFileName = file.getOriginalFilename(); // get file name
|
||||
String fileExtension = fileUtility.getFileExtension(fullFileName); // get file extension
|
||||
long fileSize = file.getSize(); // get file size
|
||||
byte[] bytes = file.getBytes(); // get file in bytes
|
||||
|
||||
// check if the file size exceeds the maximum file size or is less than 0
|
||||
if(fileUtility.getMaxFileSize() < fileSize || fileSize <= 0){
|
||||
return "{ \"error\": \"File size is incorrect\"}";
|
||||
return "{ \"error\": \"File size is incorrect\"}"; // if so, write an error message to the response
|
||||
}
|
||||
|
||||
// check if file extension is supported by the editor
|
||||
if(!fileUtility.getFileExts().contains(fileExtension)){
|
||||
return "{ \"error\": \"File type is not supported\"}";
|
||||
return "{ \"error\": \"File type is not supported\"}"; // if not, write an error message to the response
|
||||
}
|
||||
|
||||
String fileNamePath = storageMutator.updateFile(fullFileName, bytes);
|
||||
String fileNamePath = storageMutator.updateFile(fullFileName, bytes); // update a file
|
||||
if (fileNamePath.isBlank()){
|
||||
throw new IOException("Could not update a file");
|
||||
throw new IOException("Could not update a file"); // if the file cannot be updated, an error occurs
|
||||
}
|
||||
|
||||
fullFileName = fileUtility.getFileNameWithoutExtension(fileNamePath) + fileExtension;
|
||||
fullFileName = fileUtility.getFileNameWithoutExtension(fileNamePath) + fileExtension; // get full file name
|
||||
|
||||
return createUserMetadata(uid, fullFileName);
|
||||
return createUserMetadata(uid, fullFileName); // create user metadata and return it
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "{ \"error\": \"Something went wrong when uploading the file.\"}";
|
||||
return "{ \"error\": \"Something went wrong when uploading the file.\"}"; // if the operation of file uploading is unsuccessful, an error occurs
|
||||
}
|
||||
|
||||
@PostMapping(path = "${url.converter}")
|
||||
@ResponseBody
|
||||
public String convert(@RequestBody Converter body,
|
||||
@CookieValue("uid") String uid){
|
||||
String fileName = body.getFileName();
|
||||
String fileUri = documentManager.getDownloadUrl(fileName);
|
||||
String filePass = body.getFilePass() != null ? body.getFilePass() : null;
|
||||
String fileExt = fileUtility.getFileExtension(fileName);
|
||||
DocumentType type = fileUtility.getDocumentType(fileName);
|
||||
String internalFileExt = fileUtility.getInternalExtension(type);
|
||||
public String convert(@RequestBody Converter body, // convert a file
|
||||
@CookieValue("uid") String uid, @CookieValue("ulang") String lang){
|
||||
String fileName = body.getFileName(); // get file name
|
||||
String fileUri = documentManager.getDownloadUrl(fileName); // get URL for downloading a file with the specified name
|
||||
String filePass = body.getFilePass() != null ? body.getFilePass() : null; // get file password if it exists
|
||||
String fileExt = fileUtility.getFileExtension(fileName); // get file extension
|
||||
DocumentType type = fileUtility.getDocumentType(fileName); // get document type (word, cell or slide)
|
||||
String internalFileExt = fileUtility.getInternalExtension(type); // get an editor internal extension (".docx", ".xlsx" or ".pptx")
|
||||
|
||||
try{
|
||||
if(fileUtility.getConvertExts().contains(fileExt)){
|
||||
String key = serviceConverter.generateRevisionId(fileUri);
|
||||
String newFileUri = serviceConverter
|
||||
.getConvertedUri(fileUri, fileExt, internalFileExt, key, filePass, true);
|
||||
if(fileUtility.getConvertExts().contains(fileExt)){ // check if the file with such an extension can be converted
|
||||
String key = serviceConverter.generateRevisionId(fileUri); // generate document key
|
||||
String newFileUri = serviceConverter // get the URL to the converted file
|
||||
.getConvertedUri(fileUri, fileExt, internalFileExt, key, filePass, true, lang);
|
||||
|
||||
if(newFileUri.isEmpty()){
|
||||
return "{ \"step\" : \"0\", \"filename\" : \"" + fileName + "\"}";
|
||||
}
|
||||
|
||||
// get a file name of an internal file extension with an index if the file with such a name already exists
|
||||
String nameWithInternalExt = fileUtility.getFileNameWithoutExtension(fileName) + internalFileExt;
|
||||
String correctedName = documentManager.getCorrectName(nameWithInternalExt);
|
||||
|
||||
URL url = new URL(newFileUri);
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
InputStream stream = connection.getInputStream();
|
||||
InputStream stream = connection.getInputStream(); // get input stream of the converted file
|
||||
|
||||
if (stream == null){
|
||||
connection.disconnect();
|
||||
throw new RuntimeException("Input stream is null");
|
||||
}
|
||||
|
||||
// create the converted file with input stream
|
||||
storageMutator.createFile(Path.of(storagePathBuilder.getFileLocation(correctedName)), stream);
|
||||
fileName = correctedName;
|
||||
}
|
||||
|
||||
// create meta information about the converted file with the user ID and name specified
|
||||
return createUserMetadata(uid, fileName);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "{ \"error\": \"" + "The file can't be converted.\"}";
|
||||
return "{ \"error\": \"" + "The file can't be converted.\"}"; // if the operation of file converting is unsuccessful, an error occurs
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@ResponseBody
|
||||
public String delete(@RequestBody Converter body){
|
||||
public String delete(@RequestBody Converter body){ // delete a file
|
||||
try
|
||||
{
|
||||
String fullFileName = fileUtility.getFileName(body.getFileName());
|
||||
boolean fileSuccess = storageMutator.deleteFile(fullFileName);
|
||||
boolean historySuccess = storageMutator.deleteFileHistory(fullFileName);
|
||||
String fullFileName = fileUtility.getFileName(body.getFileName()); // get full file name
|
||||
boolean fileSuccess = storageMutator.deleteFile(fullFileName); // delete a file from the storage and return the status of this operation (true or false)
|
||||
boolean historySuccess = storageMutator.deleteFileHistory(fullFileName); // delete file history and return the status of this operation (true or false)
|
||||
|
||||
return "{ \"success\": \""+ (fileSuccess && historySuccess) +"\"}";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return "{ \"error\": \"" + e.getMessage() + "\"}";
|
||||
return "{ \"error\": \"" + e.getMessage() + "\"}"; // if the operation of file deleting is unsuccessful, an error occurs
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/downloadhistory")
|
||||
public ResponseEntity<Resource> downloadHistory(HttpServletRequest request,// download a file
|
||||
@RequestParam("fileName") String fileName,
|
||||
@RequestParam("ver") String version,
|
||||
@RequestParam("file") String file){ // history file
|
||||
try{
|
||||
// check if a token is enabled or not
|
||||
if(jwtManager.tokenEnabled()){
|
||||
String header = request.getHeader(documentJwtHeader == null // get the document JWT header
|
||||
|| documentJwtHeader.isEmpty() ? "Authorization" : documentJwtHeader);
|
||||
if(header != null && !header.isEmpty()){
|
||||
String token = header.replace("Bearer ", ""); // token is the header without the Bearer prefix
|
||||
jwtManager.readToken(token); // read the token
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return downloadFileHistory(fileName,version,file); // download data from the specified file
|
||||
} catch(Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(path = "${url.download}")
|
||||
public ResponseEntity<Resource> download(HttpServletRequest request,
|
||||
public ResponseEntity<Resource> download(HttpServletRequest request, // download a file
|
||||
@RequestParam("fileName") String fileName){
|
||||
try{
|
||||
// check if a token is enabled or not
|
||||
if(jwtManager.tokenEnabled()){
|
||||
String header = request.getHeader(documentJwtHeader == null
|
||||
String header = request.getHeader(documentJwtHeader == null // get the document JWT header
|
||||
|| documentJwtHeader.isEmpty() ? "Authorization" : documentJwtHeader);
|
||||
if(header != null && !header.isEmpty()){
|
||||
String token = header.replace("Bearer ", "");
|
||||
jwtManager.readToken(token);
|
||||
String token = header.replace("Bearer ", ""); // token is the header without the Bearer prefix
|
||||
jwtManager.readToken(token); // read the token
|
||||
}
|
||||
}
|
||||
return downloadFile(fileName);
|
||||
return downloadFile(fileName); // download data from the specified file
|
||||
} catch(Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/create")
|
||||
public String create(@RequestParam("fileExt") String fileExt,
|
||||
public String create(@RequestParam("fileExt") String fileExt, // create a sample file of the specified extension
|
||||
@RequestParam(value = "sample", required = false) Optional<Boolean> isSample,
|
||||
@CookieValue(value = "uid", required = false) String uid,
|
||||
Model model){
|
||||
Boolean sampleData = (isSample.isPresent() && !isSample.isEmpty()) && isSample.get();
|
||||
Boolean sampleData = (isSample.isPresent() && !isSample.isEmpty()) && isSample.get(); // specify if the sample data exists or not
|
||||
if(fileExt != null){
|
||||
try{
|
||||
Optional<User> user = userService.findUserById(Integer.parseInt(uid));
|
||||
if (!user.isPresent()) throw new RuntimeException("Could not fine any user with id = "+uid);
|
||||
String fileName = documentManager.createDemo(fileExt, sampleData, uid, user.get().getName());
|
||||
Optional<User> user = userService.findUserById(Integer.parseInt(uid)); // find a user by their ID
|
||||
if (!user.isPresent()) throw new RuntimeException("Could not fine any user with id = "+uid); // if the user with the specified ID doesn't exist, an error occurs
|
||||
String fileName = documentManager.createDemo(fileExt, sampleData, uid, user.get().getName()); // create a demo document with the sample data
|
||||
if (fileName.isBlank() || fileName == null) {
|
||||
throw new RuntimeException("You must have forgotten to add asset files");
|
||||
}
|
||||
return "redirect:editor?fileName=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8);
|
||||
return "redirect:editor?fileName=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8); // redirect the request
|
||||
}catch (Exception ex){
|
||||
model.addAttribute("error", ex.getMessage());
|
||||
return "error.html";
|
||||
@ -233,14 +289,14 @@ public class FileController {
|
||||
}
|
||||
|
||||
@GetMapping("/assets")
|
||||
public ResponseEntity<Resource> assets(@RequestParam("name") String name)
|
||||
public ResponseEntity<Resource> assets(@RequestParam("name") String name) // get sample files from the assests
|
||||
{
|
||||
String fileName = Path.of("assets", "sample", fileUtility.getFileName(name)).toString();
|
||||
return downloadFile(fileName);
|
||||
}
|
||||
|
||||
@GetMapping("/csv")
|
||||
public ResponseEntity<Resource> csv()
|
||||
public ResponseEntity<Resource> csv() // download a csv file
|
||||
{
|
||||
String fileName = Path.of("assets", "sample", "csv.csv").toString();
|
||||
return downloadFile(fileName);
|
||||
@ -248,27 +304,27 @@ public class FileController {
|
||||
|
||||
@GetMapping("/files")
|
||||
@ResponseBody
|
||||
public ArrayList<Map<String, Object>> files(@RequestParam(value = "fileId", required = false) String fileId){
|
||||
public ArrayList<Map<String, Object>> files(@RequestParam(value = "fileId", required = false) String fileId){ // get files information
|
||||
return fileId == null ? documentManager.getFilesInfo() : documentManager.getFilesInfo(fileId);
|
||||
}
|
||||
|
||||
@PostMapping(path = "${url.track}")
|
||||
@ResponseBody
|
||||
public String track(HttpServletRequest request,
|
||||
public String track(HttpServletRequest request, // track file changes
|
||||
@RequestParam("fileName") String fileName,
|
||||
@RequestParam("userAddress") String userAddress,
|
||||
@RequestBody Track body){
|
||||
try {
|
||||
String bodyString = objectMapper.writeValueAsString(body);
|
||||
String header = request.getHeader(documentJwtHeader == null
|
||||
String bodyString = objectMapper.writeValueAsString(body); // write the request body to the object mapper as a string
|
||||
String header = request.getHeader(documentJwtHeader == null // get the request header
|
||||
|| documentJwtHeader.isEmpty() ? "Authorization" : documentJwtHeader);
|
||||
|
||||
if (bodyString.isEmpty()) {
|
||||
if (bodyString.isEmpty()) { // if the request body is empty, an error occurs
|
||||
throw new RuntimeException("{\"error\":1,\"message\":\"Request payload is empty\"}");
|
||||
}
|
||||
|
||||
JSONObject bodyCheck = jwtManager.parseBody(bodyString, header);
|
||||
body = objectMapper.readValue(bodyCheck.toJSONString(), Track.class);
|
||||
JSONObject bodyCheck = jwtManager.parseBody(bodyString, header); // parse the request body
|
||||
body = objectMapper.readValue(bodyCheck.toJSONString(), Track.class); // read the request body
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
@ -278,4 +334,53 @@ public class FileController {
|
||||
|
||||
return"{\"error\":" + error + "}";
|
||||
}
|
||||
|
||||
@PostMapping("/saveas")
|
||||
@ResponseBody
|
||||
public String saveAs(@RequestBody JSONObject body, @CookieValue("uid") String uid) {
|
||||
String title = (String) body.get("title");
|
||||
String saveAsFileUrl = (String) body.get("url");
|
||||
|
||||
try {
|
||||
String fileName = documentManager.getCorrectName(title);
|
||||
String curExt = fileUtility.getFileExtension(fileName);
|
||||
|
||||
if (!fileUtility.getFileExts().contains(curExt)) {
|
||||
return "{\"error\":\"File type is not supported\"}";
|
||||
}
|
||||
|
||||
URL url = new URL(saveAsFileUrl);
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
InputStream stream = connection.getInputStream();
|
||||
|
||||
if (Integer.parseInt(filesizeMax) < stream.available() || stream.available() <= 0) {
|
||||
return "{\"error\":\"File size is incorrect\"}";
|
||||
}
|
||||
storageMutator.createFile(Path.of(storagePathBuilder.getFileLocation(fileName)), stream);
|
||||
createUserMetadata(uid, fileName);
|
||||
|
||||
return "{\"file\": \"" + fileName + "\"}";
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
@ResponseBody
|
||||
public String rename(@RequestBody JSONObject body) {
|
||||
String newfilename = (String) body.get("newfilename");
|
||||
String dockey = (String) body.get("dockey");
|
||||
|
||||
HashMap<String, String> meta = new HashMap<>();
|
||||
meta.put("title", newfilename);
|
||||
|
||||
try {
|
||||
callbackManager.commandRequest("meta", dockey, meta);
|
||||
return "result ok";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,26 +64,41 @@ public class IndexController {
|
||||
@Value("${url.editor}")
|
||||
private String urlEditor;
|
||||
|
||||
@Value("${files.docservice.languages}")
|
||||
private String langs;
|
||||
|
||||
@GetMapping("${url.index}")
|
||||
public String index(Model model){
|
||||
java.io.File[] files = storageMutator.getStoredFiles();
|
||||
java.io.File[] files = storageMutator.getStoredFiles(); // get all the stored files from the storage
|
||||
List<String> docTypes = new ArrayList<>();
|
||||
List<Boolean> filesEditable = new ArrayList<>();
|
||||
List<String> versions = new ArrayList<>();
|
||||
List<Boolean> isFillFormDoc = new ArrayList<>();
|
||||
List<String> langsAndKeys = Arrays.asList(langs.split("\\|"));
|
||||
|
||||
List<User> users = userService.findAll();
|
||||
Map<String, String> languages = new HashMap<>();
|
||||
|
||||
String tooltip = users.stream()
|
||||
.map(user -> mistUtility.convertUserDescriptions(user.getName(), user.getDescriptions()))
|
||||
langsAndKeys.forEach((str) -> {
|
||||
String[] couple = str.split(":");
|
||||
languages.put(couple[0], couple[1]);
|
||||
});
|
||||
|
||||
List<User> users = userService.findAll(); // get a list of all the users
|
||||
|
||||
String tooltip = users.stream() // get the tooltip with the user descriptions
|
||||
.map(user -> mistUtility.convertUserDescriptions(user.getName(), user.getDescriptions())) // convert user descriptions to the specified format
|
||||
.collect(Collectors.joining());
|
||||
|
||||
for(java.io.File file:files){
|
||||
String fileName = file.getName();
|
||||
docTypes.add(fileUtility.getDocumentType(fileName).toString().toLowerCase());
|
||||
filesEditable.add(fileUtility.getEditedExts().contains(fileUtility.getFileExtension(fileName)));
|
||||
versions.add(" ["+storagePathBuilder.getFileVersion(fileName, true)+"]");
|
||||
for(java.io.File file:files){ // run through all the files
|
||||
String fileName = file.getName(); // get file name
|
||||
docTypes.add(fileUtility.getDocumentType(fileName).toString().toLowerCase()); // add a document type of each file to the list
|
||||
filesEditable.add(fileUtility.getEditedExts().contains(fileUtility.getFileExtension(fileName))); // specify if a file is editable or not
|
||||
versions.add(" ["+storagePathBuilder.getFileVersion(fileName, true)+"]"); // add a file version to the list
|
||||
isFillFormDoc.add(fileUtility.getFillExts().contains(fileUtility.getFileExtension(fileName)));
|
||||
}
|
||||
|
||||
// add all the parameters to the model
|
||||
model.addAttribute("isFillFormDoc", isFillFormDoc);
|
||||
model.addAttribute("versions",versions);
|
||||
model.addAttribute("files", files);
|
||||
model.addAttribute("docTypes", docTypes);
|
||||
@ -91,17 +106,19 @@ public class IndexController {
|
||||
model.addAttribute("datadocs", docserviceSite+docservicePreloader);
|
||||
model.addAttribute("tooltip", tooltip);
|
||||
model.addAttribute("users", users);
|
||||
model.addAttribute("languages", languages);
|
||||
|
||||
return "index.html";
|
||||
}
|
||||
|
||||
@PostMapping("/config")
|
||||
@ResponseBody
|
||||
public HashMap<String, String> configParameters(){
|
||||
public HashMap<String, String> configParameters(){ // get configuration parameters
|
||||
HashMap<String, String> configuration = new HashMap<>();
|
||||
|
||||
configuration.put("ConverExtList", String.join(",",fileUtility.getConvertExts()));
|
||||
configuration.put("EditedExtList", String.join(",",fileUtility.getEditedExts()));
|
||||
configuration.put("FillExtList", String.join(",", fileUtility.getFillExts())); // put a list of the extensions that can be filled to config
|
||||
configuration.put("ConverExtList", String.join(",", fileUtility.getConvertExts())); // put a list of the extensions that can be converted to config
|
||||
configuration.put("EditedExtList", String.join(",", fileUtility.getEditedExts())); // put a list of the extensions that can be edited to config
|
||||
configuration.put("UrlConverter", urlConverter);
|
||||
configuration.put("UrlEditor", urlEditor);
|
||||
|
||||
|
||||
@ -21,11 +21,12 @@ package com.onlyoffice.integration.documentserver.callbacks;
|
||||
import com.onlyoffice.integration.dto.Track;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
// specify the callback handler functions
|
||||
public interface Callback {
|
||||
int handle(Track body, String fileName);
|
||||
int getStatus();
|
||||
int handle(Track body, String fileName); // handle the callback
|
||||
int getStatus(); // get document status
|
||||
@Autowired
|
||||
default void selfRegistration(CallbackHandler callbackHandler){
|
||||
default void selfRegistration(CallbackHandler callbackHandler){ // register a callback handler
|
||||
callbackHandler.register(getStatus(), this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,11 +33,11 @@ public class CallbackHandler {
|
||||
|
||||
private Map<Integer, Callback> callbackHandlers = new HashMap<>();
|
||||
|
||||
public void register(int code, Callback callback){
|
||||
public void register(int code, Callback callback){ // register a callback handler
|
||||
callbackHandlers.put(code, callback);
|
||||
}
|
||||
|
||||
public int handle(Track body, String fileName){
|
||||
public int handle(Track body, String fileName){ // handle a callback
|
||||
Callback callback = callbackHandlers.get(body.getStatus());
|
||||
if (callback == null){
|
||||
logger.warn("Callback status "+body.getStatus()+" is not supported yet");
|
||||
|
||||
@ -18,17 +18,18 @@
|
||||
|
||||
package com.onlyoffice.integration.documentserver.callbacks;
|
||||
|
||||
// document status
|
||||
public enum Status {
|
||||
EDITING(1),
|
||||
SAVE(2),
|
||||
CORRUPTED(3),
|
||||
MUST_FORCE_SAVE(6),
|
||||
CORRUPTED_FORCE_SAVE(7);
|
||||
EDITING(1), // 1 - document is being edited
|
||||
SAVE(2), // 2 - document is ready for saving
|
||||
CORRUPTED(3), // 3 - document saving error has occurred
|
||||
MUST_FORCE_SAVE(6), // 6 - document is being edited, but the current document state is saved
|
||||
CORRUPTED_FORCE_SAVE(7); // 7 - error has occurred while force saving the document
|
||||
private int code;
|
||||
Status(int code){
|
||||
this.code = code;
|
||||
}
|
||||
public int getCode(){
|
||||
public int getCode(){ // get document status
|
||||
return this.code;
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,15 +31,15 @@ public class EditCallback implements Callback {
|
||||
@Autowired
|
||||
private CallbackManager callbackManager;
|
||||
@Override
|
||||
public int handle(Track body, String fileName) {
|
||||
public int handle(Track body, String fileName) { // handle the callback when the document is being edited
|
||||
int result = 0;
|
||||
Action action = body.getActions().get(0);
|
||||
if (action.getType().equals(com.onlyoffice.integration.documentserver.models.enums.Action.edit)) {
|
||||
String user = action.getUserid();
|
||||
if (!body.getUsers().contains(user)) {
|
||||
String key = body.getKey();
|
||||
Action action = body.getActions().get(0); // get the user ID who is editing the document
|
||||
if (action.getType().equals(com.onlyoffice.integration.documentserver.models.enums.Action.edit)) { // if this value is not equal to the user ID
|
||||
String user = action.getUserid(); // get user ID
|
||||
if (!body.getUsers().contains(user)) { // if this user is not specified in the body
|
||||
String key = body.getKey(); // get document key
|
||||
try {
|
||||
callbackManager.commandRequest("forcesave", key);
|
||||
callbackManager.commandRequest("forcesave", key, null); // create a command request to forcibly save the document being edited without closing it
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
result = 1;
|
||||
@ -50,7 +50,7 @@ public class EditCallback implements Callback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatus() {
|
||||
return Status.EDITING.getCode();
|
||||
public int getStatus() { // get document status
|
||||
return Status.EDITING.getCode(); // return status 1 - document is being edited
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,10 +30,10 @@ public class ForcesaveCallback implements Callback {
|
||||
@Autowired
|
||||
private CallbackManager callbackManager;
|
||||
@Override
|
||||
public int handle(Track body, String fileName) {
|
||||
public int handle(Track body, String fileName) { // handle the callback when the force saving request is performed
|
||||
int result = 0;
|
||||
try {
|
||||
callbackManager.processForceSave(body, fileName);
|
||||
callbackManager.processForceSave(body, fileName); // file force saving process
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
result = 1;
|
||||
@ -42,7 +42,7 @@ public class ForcesaveCallback implements Callback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatus() {
|
||||
return Status.MUST_FORCE_SAVE.getCode();
|
||||
public int getStatus() { // get document status
|
||||
return Status.MUST_FORCE_SAVE.getCode(); // return status 6 - document is being edited, but the current document state is saved
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,10 +30,10 @@ public class SaveCallback implements Callback {
|
||||
@Autowired
|
||||
private CallbackManager callbackManager;
|
||||
@Override
|
||||
public int handle(Track body, String fileName) {
|
||||
public int handle(Track body, String fileName) { // handle the callback when the saving request is performed
|
||||
int result = 0;
|
||||
try {
|
||||
callbackManager.processSave(body, fileName);
|
||||
callbackManager.processSave(body, fileName); // file saving process
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
result = 1;
|
||||
@ -43,7 +43,7 @@ public class SaveCallback implements Callback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatus() {
|
||||
return Status.SAVE.getCode();
|
||||
public int getStatus() { // get document status
|
||||
return Status.SAVE.getCode(); // return status 2 - document is ready for saving
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,9 +19,10 @@
|
||||
package com.onlyoffice.integration.documentserver.managers.callback;
|
||||
|
||||
import com.onlyoffice.integration.dto.Track;
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface CallbackManager {
|
||||
void processSave(Track body, String fileName);
|
||||
void commandRequest(String method, String key);
|
||||
void processForceSave(Track body, String fileName);
|
||||
public interface CallbackManager { // specify the callback manager functions
|
||||
void processSave(Track body, String fileName); // file saving process
|
||||
void commandRequest(String method, String key, HashMap meta); // create a command request
|
||||
void processForceSave(Track body, String fileName); // file force saving process
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
@ -68,36 +69,40 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
@Autowired
|
||||
private ServiceConverter serviceConverter;
|
||||
|
||||
// save file information from the URL to the file specified
|
||||
private void downloadToFile(String url, Path path) throws Exception {
|
||||
if (url == null || url.isEmpty()) throw new RuntimeException("Url argument is not specified");
|
||||
if (path == null) throw new RuntimeException("Path argument is not specified");
|
||||
if (url == null || url.isEmpty()) throw new RuntimeException("Url argument is not specified"); // URL isn't specified
|
||||
if (path == null) throw new RuntimeException("Path argument is not specified"); // file isn't specified
|
||||
|
||||
URL uri = new URL(url);
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) uri.openConnection();
|
||||
InputStream stream = connection.getInputStream();
|
||||
InputStream stream = connection.getInputStream(); // get input stream of the file information from the URL
|
||||
|
||||
if (stream == null) {
|
||||
connection.disconnect();
|
||||
throw new RuntimeException("Input stream is null");
|
||||
}
|
||||
|
||||
storageMutator.createFile(path, stream);
|
||||
storageMutator.createOrUpdateFile(path, stream); // update a file or create a new one
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void processSave(Track body, String fileName) {
|
||||
public void processSave(Track body, String fileName) { // file saving process
|
||||
String downloadUri = body.getUrl();
|
||||
String changesUri = body.getChangesurl();
|
||||
String key = body.getKey();
|
||||
String newFileName = fileName;
|
||||
|
||||
String curExt = fileUtility.getFileExtension(fileName);
|
||||
String downloadExt = fileUtility.getFileExtension(downloadUri);
|
||||
String curExt = fileUtility.getFileExtension(fileName); // get current file extension
|
||||
String downloadExt = "." + body.getFiletype(); // get an extension of the downloaded file
|
||||
|
||||
// Todo [Delete in version 7.0 or higher]
|
||||
if (downloadExt != "." + null) downloadExt = fileUtility.getFileExtension(downloadUri); // Support for versions below 7.0
|
||||
|
||||
//TODO: Refactoring
|
||||
if (!curExt.equals(downloadExt)) {
|
||||
if (!curExt.equals(downloadExt)) { // convert downloaded file to the file with the current extension if these extensions aren't equal
|
||||
try {
|
||||
String newFileUri = serviceConverter.getConvertedUri(downloadUri, downloadExt, curExt, serviceConverter.generateRevisionId(downloadUri), null, false); // convert file and get url to a new file
|
||||
String newFileUri = serviceConverter.getConvertedUri(downloadUri, downloadExt, curExt, serviceConverter.generateRevisionId(downloadUri), null, false, null); // convert a file and get URL to a new file
|
||||
if (newFileUri.isEmpty()) {
|
||||
newFileName = documentManager
|
||||
.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + downloadExt); // get the correct file name if it already exists
|
||||
@ -109,61 +114,68 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
}
|
||||
}
|
||||
|
||||
String storagePath = storagePathBuilder.getFileLocation(newFileName);
|
||||
Path histDir = Paths.get(storagePathBuilder.getHistoryDir(storagePath));
|
||||
storageMutator.createDirectory(histDir);
|
||||
String storagePath = storagePathBuilder.getFileLocation(newFileName); // get the path to a new file
|
||||
Path lastVersion = Paths.get(storagePathBuilder.getFileLocation(fileName)); // get the path to the last file version
|
||||
|
||||
String versionDir = documentManager.versionDir(histDir.toAbsolutePath().toString(),
|
||||
storagePathBuilder.getFileVersion(histDir.toAbsolutePath().toString(), false), true);
|
||||
if (lastVersion.toFile().exists()) { // if the last file version exists
|
||||
Path histDir = Paths.get(storagePathBuilder.getHistoryDir(storagePath)); // get the history directory
|
||||
storageMutator.createDirectory(histDir); // and create it
|
||||
|
||||
Path ver = Paths.get(versionDir);
|
||||
Path lastVersion = Paths.get(storagePathBuilder.getFileLocation(fileName));
|
||||
Path toSave = Paths.get(storagePath);
|
||||
String versionDir = documentManager.versionDir(histDir.toAbsolutePath().toString(), // get the file version directory
|
||||
storagePathBuilder.getFileVersion(histDir.toAbsolutePath().toString(), false), true);
|
||||
|
||||
storageMutator.createDirectory(ver);
|
||||
storageMutator.moveFile(lastVersion, Paths.get(versionDir + File.separator + "prev" + curExt));
|
||||
Path ver = Paths.get(versionDir);
|
||||
Path toSave = Paths.get(storagePath);
|
||||
|
||||
downloadToFile(downloadUri, toSave);
|
||||
downloadToFile(changesUri, Path.of(versionDir + File.separator + "diff.zip"));
|
||||
storageMutator.createDirectory(ver); // create the file version directory
|
||||
storageMutator.moveFile(lastVersion, Paths.get(versionDir + File.separator + "prev" + curExt)); // move the last file version to the file version directory with the "prev" postfix
|
||||
|
||||
JSONObject jsonChanges = new JSONObject();
|
||||
jsonChanges.put("changes", body.getHistory().getChanges());
|
||||
jsonChanges.put("serverVersion", body.getHistory().getServerVersion());
|
||||
String history = objectMapper.writeValueAsString(jsonChanges);
|
||||
downloadToFile(downloadUri, toSave); // save file to the storage path
|
||||
downloadToFile(changesUri, Path.of(versionDir + File.separator + "diff.zip")); // save file changes to the diff.zip archive
|
||||
|
||||
if(history==null && body.getHistory()!=null){
|
||||
history = objectMapper.writeValueAsString(body.getHistory());
|
||||
JSONObject jsonChanges = new JSONObject(); // create a json object for document changes
|
||||
jsonChanges.put("changes", body.getHistory().getChanges()); // put the changes to the json object
|
||||
jsonChanges.put("serverVersion", body.getHistory().getServerVersion()); // put the server version to the json object
|
||||
String history = objectMapper.writeValueAsString(jsonChanges);
|
||||
|
||||
if (history == null && body.getHistory() != null) {
|
||||
history = objectMapper.writeValueAsString(body.getHistory());
|
||||
}
|
||||
|
||||
if (history != null && !history.isEmpty()) {
|
||||
storageMutator.writeToFile(versionDir + File.separator + "changes.json", history); // write the history changes to the changes.json file
|
||||
}
|
||||
|
||||
storageMutator.writeToFile(versionDir + File.separator + "key.txt", key); // write the key value to the key.txt file
|
||||
storageMutator.deleteFile(storagePathBuilder.getForcesavePath(newFileName, false)); // get the path to the forcesaved file version and remove it
|
||||
}
|
||||
|
||||
if (history != null && !history.isEmpty()) {
|
||||
storageMutator.writeToFile(versionDir + File.separator + "changes.json", history);
|
||||
}
|
||||
|
||||
storageMutator.writeToFile(versionDir + File.separator + "key.txt", key);
|
||||
storageMutator.deleteFile(storagePathBuilder.getForcesavePath(newFileName, false));
|
||||
}
|
||||
|
||||
//TODO: Replace (String method) with (Enum method)
|
||||
@SneakyThrows
|
||||
public void commandRequest(String method, String key) {
|
||||
public void commandRequest(String method, String key, HashMap meta) { // create a command request
|
||||
String DocumentCommandUrl = docserviceUrlSite + docserviceUrlCommand;
|
||||
|
||||
URL url = new URL(DocumentCommandUrl);
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
|
||||
HashMap<String, Object> params = new HashMap<>();
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("c", method);
|
||||
params.put("key", key);
|
||||
|
||||
if (meta != null) {
|
||||
params.put("meta", meta);
|
||||
}
|
||||
|
||||
String headerToken;
|
||||
if (jwtManager.tokenEnabled())
|
||||
if (jwtManager.tokenEnabled()) // check if a secret key to generate token exists or not
|
||||
{
|
||||
Map<String, Object> payloadMap = new HashMap<>();
|
||||
payloadMap.put("payload", params);
|
||||
headerToken = jwtManager.createToken(payloadMap);
|
||||
connection.setRequestProperty(documentJwtHeader.equals("") ? "Authorization" : documentJwtHeader, "Bearer " + headerToken);
|
||||
headerToken = jwtManager.createToken(payloadMap); // encode a payload object into a header token
|
||||
connection.setRequestProperty(documentJwtHeader.equals("") ? "Authorization" : documentJwtHeader, "Bearer " + headerToken); // add a header Authorization with a header token and Authorization prefix in it
|
||||
|
||||
String token = jwtManager.createToken(params);
|
||||
String token = jwtManager.createToken(params); // encode a payload object into a body token
|
||||
params.put("token", token);
|
||||
}
|
||||
|
||||
@ -171,36 +183,47 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
|
||||
byte[] bodyByte = bodyString.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestMethod("POST"); // set the request method
|
||||
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); // set the Content-Type header
|
||||
connection.setDoOutput(true); // set the doOutput field to true
|
||||
connection.connect();
|
||||
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
os.write(bodyByte);
|
||||
os.write(bodyByte); // write bytes to the output stream
|
||||
}
|
||||
|
||||
InputStream stream = connection.getInputStream();
|
||||
InputStream stream = connection.getInputStream(); // get input stream
|
||||
|
||||
if (stream == null) throw new RuntimeException("Could not get an answer");
|
||||
|
||||
String jsonString = serviceConverter.convertStreamToString(stream);
|
||||
String jsonString = serviceConverter.convertStreamToString(stream); // convert stream to json string
|
||||
connection.disconnect();
|
||||
|
||||
JSONObject response = serviceConverter.convertStringToJSON(jsonString);
|
||||
JSONObject response = serviceConverter.convertStringToJSON(jsonString); // convert json string to json object
|
||||
//TODO: Add errors ENUM
|
||||
if (!response.get("error").toString().equals("0")){
|
||||
throw new RuntimeException(response.toJSONString());
|
||||
String responseCode = response.get("error").toString();
|
||||
switch(responseCode) {
|
||||
case "0":
|
||||
case "4": {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new RuntimeException(response.toJSONString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void processForceSave(Track body, String fileName) {
|
||||
public void processForceSave(Track body, String fileName) { // file force saving process
|
||||
|
||||
String downloadUri = body.getUrl();
|
||||
|
||||
String curExt = fileUtility.getFileExtension(fileName);
|
||||
String downloadExt = fileUtility.getFileExtension(downloadUri);
|
||||
String curExt = fileUtility.getFileExtension(fileName); // get current file extension
|
||||
String downloadExt = "."+body.getFiletype(); // get an extension of the downloaded file
|
||||
|
||||
// Todo [Delete in version 7.0 or higher]
|
||||
if (downloadExt != "."+null) downloadExt = fileUtility.getFileExtension(downloadUri); // Support for versions below 7.0
|
||||
|
||||
Boolean newFileName = false;
|
||||
|
||||
// convert downloaded file to the file with the current extension if these extensions aren't equal
|
||||
@ -208,7 +231,7 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
if (!curExt.equals(downloadExt)) {
|
||||
try {
|
||||
String newFileUri = serviceConverter.getConvertedUri(downloadUri, downloadExt,
|
||||
curExt, serviceConverter.generateRevisionId(downloadUri), null, false); // convert file and get url to a new file
|
||||
curExt, serviceConverter.generateRevisionId(downloadUri), null, false, null); // convert file and get URL to a new file
|
||||
if (newFileUri.isEmpty()) {
|
||||
newFileName = true;
|
||||
} else {
|
||||
@ -226,18 +249,18 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
boolean isSubmitForm = body.getForcesavetype().toString().equals("3");
|
||||
|
||||
//TODO: Extract function
|
||||
if (isSubmitForm) {
|
||||
if (isSubmitForm) { // if the form is submitted
|
||||
if (newFileName){
|
||||
fileName = documentManager
|
||||
.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + "-form" + downloadExt); // get the correct file name if it already exists
|
||||
} else {
|
||||
fileName = documentManager.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + "-form" + curExt);
|
||||
}
|
||||
forcesavePath = storagePathBuilder.getFileLocation(fileName);
|
||||
forcesavePath = storagePathBuilder.getFileLocation(fileName); // create forcesave path if it doesn't exist
|
||||
List<Action> actions = body.getActions();
|
||||
Action action = actions.get(0);
|
||||
String user = action.getUserid();
|
||||
storageMutator.createMeta(fileName, user, "Filling Form");
|
||||
String user = action.getUserid(); // get the user ID
|
||||
storageMutator.createMeta(fileName, user, "Filling Form"); // create meta data for the forcesaved file
|
||||
} else {
|
||||
if (newFileName){
|
||||
fileName = documentManager.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName) + downloadExt);
|
||||
|
||||
@ -45,6 +45,8 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
|
||||
@Value("${files.storage.folder}")
|
||||
private String storageFolder;
|
||||
@Value("${files.storage}")
|
||||
private String filesStorage;
|
||||
@Value("${url.track}")
|
||||
private String trackUrl;
|
||||
@Value("${url.download}")
|
||||
@ -59,37 +61,43 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
@Autowired
|
||||
private ServiceConverter serviceConverter;
|
||||
|
||||
// get URL to the created file
|
||||
public String getCreateUrl(String fileName, Boolean sample){
|
||||
String fileExt = fileName.substring(fileName.length() - 4);
|
||||
String url = storagePathBuilder.getServerUrl(true) + "/create?fileExt=" + fileExt + "&sample=" + sample;
|
||||
return url;
|
||||
}
|
||||
|
||||
// get a file name with an index if the file with such a name already exists
|
||||
public String getCorrectName(String fileName)
|
||||
{
|
||||
String baseName = fileUtility.getFileNameWithoutExtension(fileName);
|
||||
String ext = fileUtility.getFileExtension(fileName);
|
||||
String name = baseName + ext;
|
||||
String baseName = fileUtility.getFileNameWithoutExtension(fileName); // get file name without extension
|
||||
String ext = fileUtility.getFileExtension(fileName); // get file extension
|
||||
String name = baseName + ext; // create a full file name
|
||||
|
||||
Path path = Paths.get(storagePathBuilder.getFileLocation(name));
|
||||
|
||||
for (int i = 1; Files.exists(path); i++)
|
||||
for (int i = 1; Files.exists(path); i++) // run through all the files with such a name in the storage directory
|
||||
{
|
||||
name = baseName + " (" + i + ")" + ext;
|
||||
name = baseName + " (" + i + ")" + ext; // and add an index to the base name
|
||||
path = Paths.get(storagePathBuilder.getFileLocation(name));
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
// get file URL
|
||||
public String getFileUri(String fileName, Boolean forDocumentServer)
|
||||
{
|
||||
try
|
||||
{
|
||||
String serverPath = storagePathBuilder.getServerUrl(forDocumentServer);
|
||||
String hostAddress = storagePathBuilder.getStorageLocation();
|
||||
String serverPath = storagePathBuilder.getServerUrl(forDocumentServer); // get server URL
|
||||
String hostAddress = storagePathBuilder.getStorageLocation(); // get the storage directory
|
||||
String filePathDownload = !fileName.contains(InetAddress.getLocalHost().getHostAddress()) ? fileName
|
||||
: fileName.substring(fileName.indexOf(InetAddress.getLocalHost().getHostAddress()) + InetAddress.getLocalHost().getHostAddress().length() + 1);
|
||||
if (!filesStorage.isEmpty() && filePathDownload.contains(filesStorage)) {
|
||||
filePathDownload = filePathDownload.substring(filesStorage.length() + 1);
|
||||
}
|
||||
|
||||
String filePath = serverPath + "/download?fileName=" + URLEncoder.encode(filePathDownload, java.nio.charset.StandardCharsets.UTF_8.toString())
|
||||
+ "&userAddress" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString());
|
||||
@ -101,6 +109,28 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
}
|
||||
}
|
||||
|
||||
// get file URL
|
||||
public String getHistoryFileUrl(String fileName, Integer version, String file, Boolean forDocumentServer)
|
||||
{
|
||||
try
|
||||
{
|
||||
String serverPath = storagePathBuilder.getServerUrl(forDocumentServer); // get server URL
|
||||
String hostAddress = storagePathBuilder.getStorageLocation(); // get the storage directory
|
||||
String filePathDownload = !fileName.contains(InetAddress.getLocalHost().getHostAddress()) ? fileName
|
||||
: fileName.substring(fileName.indexOf(InetAddress.getLocalHost().getHostAddress()) + InetAddress.getLocalHost().getHostAddress().length() + 1);
|
||||
|
||||
String filePath = serverPath + "/downloadhistory?fileName=" + URLEncoder.encode(filePathDownload, java.nio.charset.StandardCharsets.UTF_8.toString())
|
||||
+ "&ver=" + version + "&file="+file
|
||||
+ "&userAddress" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString());
|
||||
return filePath;
|
||||
}
|
||||
catch (UnsupportedEncodingException | UnknownHostException e)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// get the callback URL
|
||||
public String getCallback(String fileName)
|
||||
{
|
||||
String serverPath = storagePathBuilder.getServerUrl(true);
|
||||
@ -118,6 +148,7 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
}
|
||||
}
|
||||
|
||||
// get URL to download a file
|
||||
public String getDownloadUrl(String fileName) {
|
||||
String serverPath = storagePathBuilder.getServerUrl(true);
|
||||
String storageAddress = storagePathBuilder.getStorageLocation();
|
||||
@ -136,11 +167,13 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
}
|
||||
}
|
||||
|
||||
// get file information
|
||||
public ArrayList<Map<String, Object>> getFilesInfo(){
|
||||
ArrayList<Map<String, Object>> files = new ArrayList<>();
|
||||
|
||||
// run through all the stored files
|
||||
for(File file : storageMutator.getStoredFiles()){
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
Map<String, Object> map = new LinkedHashMap<>(); // write all the parameters to the map
|
||||
map.put("version", storagePathBuilder.getFileVersion(file.getName(), false));
|
||||
map.put("id", serviceConverter
|
||||
.generateRevisionId(storagePathBuilder.getStorageLocation() +
|
||||
@ -159,6 +192,7 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
return files;
|
||||
}
|
||||
|
||||
// get file information by its ID
|
||||
public ArrayList<Map<String, Object>> getFilesInfo(String fileId){
|
||||
ArrayList<Map<String, Object>> file = new ArrayList<>();
|
||||
|
||||
@ -172,6 +206,7 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
return file;
|
||||
}
|
||||
|
||||
// get the path to the file version by the history path and file version
|
||||
public String versionDir(String path, Integer version, boolean historyPath) {
|
||||
if (!historyPath){
|
||||
return storagePathBuilder.getHistoryDir(storagePathBuilder.getFileLocation(path)) + version;
|
||||
@ -179,19 +214,20 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
return path + File.separator + version;
|
||||
}
|
||||
|
||||
// create demo document
|
||||
public String createDemo(String fileExt,Boolean sample,String uid,String uname) {
|
||||
String demoName = (sample ?"sample.":"new." + fileExt);
|
||||
String demoPath = "assets" + File.separator + (sample ? "sample" : "new") + File.separator + demoName;
|
||||
String fileName = getCorrectName(demoName);
|
||||
String demoName = (sample ? "sample." : "new.") + fileExt; // create sample or new template file with the necessary extension
|
||||
String demoPath = "assets" + File.separator + (sample ? "sample" : "new") + File.separator + demoName; // get the path to the sample document
|
||||
String fileName = getCorrectName(demoName); // get a file name with an index if the file with such a name already exists
|
||||
|
||||
InputStream stream = Thread.currentThread()
|
||||
.getContextClassLoader()
|
||||
.getResourceAsStream(demoPath);
|
||||
.getResourceAsStream(demoPath); // get the input file stream
|
||||
|
||||
if (stream == null) return null;
|
||||
|
||||
storageMutator.createFile(Path.of(storagePathBuilder.getFileLocation(fileName)), stream);
|
||||
storageMutator.createMeta(fileName, uid, uname);
|
||||
storageMutator.createFile(Path.of(storagePathBuilder.getFileLocation(fileName)), stream); // create a file in the specified directory
|
||||
storageMutator.createMeta(fileName, uid, uname); // create meta information of the demo file
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@ -21,14 +21,16 @@ package com.onlyoffice.integration.documentserver.managers.document;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
// specify the document manager functions
|
||||
public interface DocumentManager {
|
||||
String getCorrectName(String fileName);
|
||||
String getFileUri(String fileName, Boolean forDocumentServer);
|
||||
String getCallback(String fileName);
|
||||
String getDownloadUrl(String fileName);
|
||||
ArrayList<Map<String, Object>> getFilesInfo();
|
||||
ArrayList<Map<String, Object>> getFilesInfo(String fileId);
|
||||
String versionDir(String path, Integer version, boolean historyPath);
|
||||
String createDemo(String fileExt,Boolean sample,String uid,String uname) throws Exception;
|
||||
String getCreateUrl(String fileName, Boolean sample);
|
||||
String getCorrectName(String fileName); // get a file name with an index if the file with such a name already exists
|
||||
String getFileUri(String fileName, Boolean forDocumentServer); // get file URL
|
||||
String getHistoryFileUrl(String fileName, Integer version, String file, Boolean forDocumentServer); // get file URL
|
||||
String getCallback(String fileName); // get the callback URL
|
||||
String getDownloadUrl(String fileName); // get URL to download a file
|
||||
ArrayList<Map<String, Object>> getFilesInfo(); // get file information
|
||||
ArrayList<Map<String, Object>> getFilesInfo(String fileId); // get file information by its ID
|
||||
String versionDir(String path, Integer version, boolean historyPath); // get the path to the file version by the history path and file version
|
||||
String createDemo(String fileExt,Boolean sample,String uid,String uname) throws Exception; // create demo document
|
||||
String getCreateUrl(String fileName, Boolean sample); // get URL to the created file
|
||||
}
|
||||
|
||||
@ -58,27 +58,28 @@ public class DefaultHistoryManager implements HistoryManager {
|
||||
|
||||
//TODO: Refactoring
|
||||
@SneakyThrows
|
||||
public String[] getHistory(Document document) {
|
||||
String histDir = storagePathBuilder.getHistoryDir(storagePathBuilder.getFileLocation(document.getTitle()));
|
||||
Integer curVer = storagePathBuilder.getFileVersion(histDir, false);
|
||||
public String[] getHistory(Document document) { // get document history
|
||||
String histDir = storagePathBuilder.getHistoryDir(storagePathBuilder.getFileLocation(document.getTitle())); // get history directory
|
||||
Integer curVer = storagePathBuilder.getFileVersion(histDir, false); // get current file version
|
||||
|
||||
if (curVer > 0) {
|
||||
if (curVer > 0) { // check if the current file version is greater than 0
|
||||
List<Object> hist = new ArrayList<>();
|
||||
Map<String, Object> histData = new HashMap<>();
|
||||
|
||||
for (Integer i = 1; i <= curVer; i++) {
|
||||
for (Integer i = 1; i <= curVer; i++) { // run through all the file versions
|
||||
Map<String, Object> obj = new HashMap<String, Object>();
|
||||
Map<String, Object> dataObj = new HashMap<String, Object>();
|
||||
String verDir = documentManager.versionDir(histDir, i, true);
|
||||
String verDir = documentManager.versionDir(histDir, i, true); // get the path to the given file version
|
||||
|
||||
String key = i == curVer ? document.getKey() : readFileToEnd(new File(verDir + File.separator + "key.txt"));
|
||||
String key = i == curVer ? document.getKey() : readFileToEnd(new File(verDir + File.separator + "key.txt")); // get document key
|
||||
obj.put("key", key);
|
||||
obj.put("version", i);
|
||||
|
||||
if (i == 1) {
|
||||
String createdInfo = readFileToEnd(new File(histDir + File.separator + "createdInfo.json"));
|
||||
JSONObject json = (JSONObject) parser.parse(createdInfo);
|
||||
if (i == 1) { // check if the version number is equal to 1
|
||||
String createdInfo = readFileToEnd(new File(histDir + File.separator + "createdInfo.json")); // get file with meta data
|
||||
JSONObject json = (JSONObject) parser.parse(createdInfo); // and turn it into json object
|
||||
|
||||
// write meta information to the object (user information and creation date)
|
||||
obj.put("created", json.get("created"));
|
||||
Map<String, Object> user = new HashMap<String, Object>();
|
||||
user.put("id", json.get("id"));
|
||||
@ -86,26 +87,32 @@ public class DefaultHistoryManager implements HistoryManager {
|
||||
obj.put("user", user);
|
||||
}
|
||||
|
||||
dataObj.put("fileType", fileUtility.getFileExtension(document.getTitle()).replace(".", ""));
|
||||
dataObj.put("key", key);
|
||||
dataObj.put("url", i == curVer ? document.getUrl() :
|
||||
documentManager.getFileUri(documentManager.versionDir(histDir, i, true) + File.separator + "prev" + fileUtility.getFileExtension(document.getTitle()), true));
|
||||
documentManager.getHistoryFileUrl(document.getTitle(), i, "prev" + fileUtility.getFileExtension(document.getTitle()), true));
|
||||
dataObj.put("version", i);
|
||||
|
||||
if (i > 1) {
|
||||
if (i > 1) { //check if the version number is greater than 1
|
||||
// if so, get the path to the changes.json file
|
||||
JSONObject changes = (JSONObject) parser.parse(readFileToEnd(new File(documentManager.versionDir(histDir, i - 1, true) + File.separator + "changes.json")));
|
||||
JSONObject change = (JSONObject) ((JSONArray) changes.get("changes")).get(0);
|
||||
|
||||
// write information about changes to the object
|
||||
obj.put("changes", changes.get("changes"));
|
||||
obj.put("serverVersion", changes.get("serverVersion"));
|
||||
obj.put("created", change.get("created"));
|
||||
obj.put("user", change.get("user"));
|
||||
|
||||
Map<String, Object> prev = (Map<String, Object>) histData.get(Integer.toString(i - 2));
|
||||
Map<String, Object> prev = (Map<String, Object>) histData.get(Integer.toString(i - 2)); // get the history data from the previous file version
|
||||
Map<String, Object> prevInfo = new HashMap<String, Object>();
|
||||
prevInfo.put("key", prev.get("key"));
|
||||
prevInfo.put("fileType", prev.get("fileType"));
|
||||
prevInfo.put("key", prev.get("key")); // write key and URL information about previous file version
|
||||
prevInfo.put("url", prev.get("url"));
|
||||
dataObj.put("previous", prevInfo);
|
||||
dataObj.put("changesUrl", documentManager.getFileUri(documentManager.versionDir(histDir, i - 1, true) + File.separator + "diff.zip", true));
|
||||
dataObj.put("previous", prevInfo); // write information about previous file version to the data object
|
||||
// write the path to the diff.zip archive with differences in this file version
|
||||
Integer verdiff = i - 1;
|
||||
dataObj.put("changesUrl", documentManager.getHistoryFileUrl(document.getTitle(), verdiff, "diff.zip", true));
|
||||
}
|
||||
|
||||
if (jwtManager.tokenEnabled()) dataObj.put("token", jwtManager.createToken(dataObj));
|
||||
@ -114,6 +121,7 @@ public class DefaultHistoryManager implements HistoryManager {
|
||||
histData.put(Integer.toString(i - 1), dataObj);
|
||||
}
|
||||
|
||||
// write history information about the current file version to the history object
|
||||
Map<String, Object> histObj = new HashMap<String, Object>();
|
||||
histObj.put("currentVersion", curVer);
|
||||
histObj.put("history", hist);
|
||||
@ -127,11 +135,12 @@ public class DefaultHistoryManager implements HistoryManager {
|
||||
return new String[]{"", ""};
|
||||
}
|
||||
|
||||
// read a file
|
||||
private String readFileToEnd(File file) {
|
||||
String output = "";
|
||||
try {
|
||||
try (FileInputStream is = new FileInputStream(file)) {
|
||||
Scanner scanner = new Scanner(is);
|
||||
Scanner scanner = new Scanner(is); // read data from the source
|
||||
scanner.useDelimiter("\\A");
|
||||
while (scanner.hasNext()) {
|
||||
output += scanner.next();
|
||||
|
||||
@ -20,6 +20,7 @@ package com.onlyoffice.integration.documentserver.managers.history;
|
||||
|
||||
import com.onlyoffice.integration.documentserver.models.filemodel.Document;
|
||||
|
||||
// specify the history manager functions
|
||||
public interface HistoryManager {
|
||||
String[] getHistory(Document document);
|
||||
String[] getHistory(Document document); // get document history
|
||||
}
|
||||
|
||||
@ -42,56 +42,62 @@ public class DefaultJwtManager implements JwtManager {
|
||||
@Autowired
|
||||
private JSONParser parser;
|
||||
|
||||
// create document token
|
||||
public String createToken(Map<String, Object> payloadClaims) {
|
||||
try {
|
||||
// build a HMAC signer using a SHA-256 hash
|
||||
Signer signer = HMACSigner.newSHA256Signer(tokenSecret);
|
||||
JWT jwt = new JWT();
|
||||
for (String key : payloadClaims.keySet()) {
|
||||
jwt.addClaim(key, payloadClaims.get(key));
|
||||
for (String key : payloadClaims.keySet()) { // run through all the keys from the payload
|
||||
jwt.addClaim(key, payloadClaims.get(key)); // and write each claim to the jwt
|
||||
}
|
||||
return JWT.getEncoder().encode(jwt, signer);
|
||||
return JWT.getEncoder().encode(jwt, signer); // sign and encode the JWT to a JSON string representation
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// check if the token is enabled
|
||||
public boolean tokenEnabled() {
|
||||
return tokenSecret != null && !tokenSecret.isEmpty();
|
||||
}
|
||||
|
||||
// read document token
|
||||
public JWT readToken(String token) {
|
||||
try {
|
||||
// build a HMAC verifier using the token secret
|
||||
Verifier verifier = HMACVerifier.newVerifier(tokenSecret);
|
||||
return JWT.getDecoder().decode(token, verifier);
|
||||
return JWT.getDecoder().decode(token, verifier); // verify and decode the encoded string JWT to a rich object
|
||||
} catch (Exception exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// parse the body
|
||||
public JSONObject parseBody(String payload, String header) {
|
||||
JSONObject body;
|
||||
try {
|
||||
Object obj = parser.parse(payload);
|
||||
Object obj = parser.parse(payload); // get body parameters by parsing the payload
|
||||
body = (JSONObject) obj;
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("{\"error\":1,\"message\":\"JSON Parsing error\"}");
|
||||
}
|
||||
if (tokenEnabled()) {
|
||||
String token = (String) body.get("token");
|
||||
if (token == null) {
|
||||
if (header != null && !header.isBlank()) {
|
||||
token = header.startsWith("Bearer ") ? header.substring(7) : header;
|
||||
if (tokenEnabled()) { // check if the token is enabled
|
||||
String token = (String) body.get("token"); // get token from the body
|
||||
if (token == null) { // if token is empty
|
||||
if (header != null && !header.isBlank()) { // and the header is defined
|
||||
token = header.startsWith("Bearer ") ? header.substring(7) : header; // get token from the header (it is placed after the Bearer prefix if it exists)
|
||||
}
|
||||
}
|
||||
if (token == null || token.isBlank()) {
|
||||
throw new RuntimeException("{\"error\":1,\"message\":\"JWT expected\"}");
|
||||
}
|
||||
|
||||
JWT jwt = readToken(token);
|
||||
JWT jwt = readToken(token); // read token
|
||||
if (jwt == null) {
|
||||
throw new RuntimeException("{\"error\":1,\"message\":\"JWT validation failed\"}");
|
||||
}
|
||||
if (jwt.getObject("payload") != null) {
|
||||
if (jwt.getObject("payload") != null) { // get payload from the token and check if it is not empty
|
||||
try {
|
||||
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> jwtPayload =
|
||||
(LinkedHashMap<String, Object>)jwt.getObject("payload");
|
||||
|
||||
@ -23,9 +23,10 @@ import org.primeframework.jwt.domain.JWT;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
// specify the jwt manager functions
|
||||
public interface JwtManager {
|
||||
boolean tokenEnabled();
|
||||
String createToken(Map<String, Object> payloadClaims);
|
||||
JWT readToken(String token);
|
||||
JSONObject parseBody(String payload, String header);
|
||||
boolean tokenEnabled(); // check if the token is enabled
|
||||
String createToken(Map<String, Object> payloadClaims); // create document token
|
||||
JWT readToken(String token); // read document token
|
||||
JSONObject parseBody(String payload, String header); // parse the body
|
||||
}
|
||||
|
||||
@ -41,25 +41,27 @@ public class SampleTemplateManager implements TemplateManager {
|
||||
@Autowired
|
||||
private FileUtility fileUtility;
|
||||
|
||||
// create a template document with the specified name
|
||||
public List<Template> createTemplates(String fileName){
|
||||
List<Template> templates = List.of(
|
||||
new Template("", "Blank", documentManager.getCreateUrl(fileName, false)),
|
||||
new Template(getTemplateImageUrl(fileName), "With sample content", documentManager.getCreateUrl(fileName, true))
|
||||
new Template("", "Blank", documentManager.getCreateUrl(fileName, false)), // create a blank template
|
||||
new Template(getTemplateImageUrl(fileName), "With sample content", documentManager.getCreateUrl(fileName, true)) // create a template with sample content using the template image
|
||||
);
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
// get the template image URL for the specified file
|
||||
public String getTemplateImageUrl(String fileName){
|
||||
DocumentType fileType = fileUtility.getDocumentType(fileName);
|
||||
String path = storagePathBuilder.getServerUrl(true);
|
||||
if(fileType.equals(DocumentType.word)){
|
||||
DocumentType fileType = fileUtility.getDocumentType(fileName); // get the file type
|
||||
String path = storagePathBuilder.getServerUrl(true); // get server URL
|
||||
if(fileType.equals(DocumentType.word)){ // get URL to the template image for the word document type
|
||||
return path + "/css/img/file_docx.svg";
|
||||
} else if(fileType.equals(DocumentType.slide)){
|
||||
} else if(fileType.equals(DocumentType.slide)){ // get URL to the template image for the slide document type
|
||||
return path + "/css/img/file_pptx.svg";
|
||||
} else if(fileType.equals(DocumentType.cell)){
|
||||
} else if(fileType.equals(DocumentType.cell)){ // get URL to the template image for the cell document type
|
||||
return path + "/css/img/file_xlsx.svg";
|
||||
}
|
||||
return path + "/css/img/file_docx.svg";
|
||||
return path + "/css/img/file_docx.svg"; // get URL to the template image for the default document type (word)
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,8 @@ package com.onlyoffice.integration.documentserver.managers.template;
|
||||
import com.onlyoffice.integration.documentserver.models.filemodel.Template;
|
||||
import java.util.List;
|
||||
|
||||
// specify the template manager functions
|
||||
public interface TemplateManager {
|
||||
List<Template> createTemplates(String fileName);
|
||||
String getTemplateImageUrl(String fileName);
|
||||
List<Template> createTemplates(String fileName); // create a template document with the specified name
|
||||
String getTemplateImageUrl(String fileName); // get the template image URL for the specified file
|
||||
}
|
||||
|
||||
@ -28,20 +28,21 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("prototype")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Customization {
|
||||
public class Customization { // the parameters which allow to customize the editor interface so that it looked like your other products (if there are any) and change the presence or absence of the additional buttons, links, change logos and editor owner details
|
||||
@Autowired
|
||||
private Logo logo;
|
||||
private Logo logo; // the image file at the top left corner of the Editor header
|
||||
@Autowired
|
||||
private Goback goback;
|
||||
private Boolean autosave = true;
|
||||
private Boolean chat = true;
|
||||
private Boolean comments = true;
|
||||
private Boolean compactHeader = false;
|
||||
private Boolean compactToolbar = false;
|
||||
private Boolean compatibleFeatures = false;
|
||||
private Boolean forcesave = false;
|
||||
private Boolean help = true;
|
||||
private Boolean hideRightMenu = false;
|
||||
private Boolean hideRulers = false;
|
||||
private Boolean submitForm = false;
|
||||
private Goback goback; // the settings for the Open file location menu button and upper right corner button
|
||||
private Boolean autosave = true; // if the Autosave menu option is enabled or disabled
|
||||
private Boolean comments = true; // if the Comments menu button is displayed or hidden
|
||||
private Boolean compactHeader = false; // if the additional action buttons are displayed in the upper part of the editor window header next to the logo (false) or in the toolbar (true)
|
||||
private Boolean compactToolbar = false; // if the top toolbar type displayed is full (false) or compact (true)
|
||||
private Boolean compatibleFeatures = false; // the use of functionality only compatible with the OOXML format
|
||||
private Boolean forcesave = false; // add the request for the forced file saving to the callback handler when saving the document within the document editing service
|
||||
private Boolean help = true; // if the Help menu button is displayed or hidden
|
||||
private Boolean hideRightMenu = false; // if the right menu is displayed or hidden on first loading
|
||||
private Boolean hideRulers = false; // if the editor rulers are displayed or hidden
|
||||
private Boolean submitForm = false; // if the Submit form button is displayed or hidden
|
||||
private Boolean about = true;
|
||||
private Boolean feedback =true;
|
||||
}
|
||||
|
||||
@ -28,9 +28,9 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("prototype")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Embedded {
|
||||
private String embedUrl;
|
||||
private String saveUrl;
|
||||
private String shareUrl;
|
||||
private ToolbarDocked toolbarDocked;
|
||||
public class Embedded { // the parameters which allow to change the settings which define the behavior of the buttons in the embedded mode
|
||||
private String embedUrl; // the absolute URL to the document serving as a source file for the document embedded into the web page
|
||||
private String saveUrl; // the absolute URL that will allow the document to be saved onto the user personal computer
|
||||
private String shareUrl; // the absolute URL that will allow other users to share this document
|
||||
private ToolbarDocked toolbarDocked; // the place for the embedded viewer toolbar, can be either top or bottom
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@ package com.onlyoffice.integration.documentserver.models.configurations;
|
||||
|
||||
import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@ -30,19 +29,19 @@ import javax.annotation.PostConstruct;
|
||||
|
||||
@Component
|
||||
@Scope("prototype")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Goback {
|
||||
public class Goback { // the settings for the Open file location menu button and upper right corner button
|
||||
|
||||
@Autowired
|
||||
private FileStoragePathBuilder storagePathBuilder;
|
||||
|
||||
@Value("${url.index}")
|
||||
private String indexMapping;
|
||||
private String url;
|
||||
|
||||
@Getter
|
||||
private String url; // the absolute URL to the website address which will be opened when clicking the Open file location menu button
|
||||
|
||||
@PostConstruct
|
||||
private void init(){
|
||||
this.url = storagePathBuilder.getServerUrl(false)+indexMapping;
|
||||
private void init() {
|
||||
this.url = storagePathBuilder.getServerUrl(false) + indexMapping;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,10 +23,21 @@ import lombok.Setter;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
@Component
|
||||
@Scope("prototype")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Info {
|
||||
private Boolean favorite = null;
|
||||
public class Info { // the additional parameters for the document (document owner, folder where the document is stored, uploading date, sharing settings)
|
||||
private String owner = "Me"; // the name of the document owner/creator
|
||||
private Boolean favorite = null; // the highlighting state of the Favorite icon
|
||||
private String uploaded = getDate(); // the document uploading date
|
||||
|
||||
private String getDate() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd yyyy", Locale.US);
|
||||
return simpleDateFormat.format(new Date());
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,11 +28,11 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("prototype")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Logo {
|
||||
public class Logo { // the image file at the top left corner of the Editor header
|
||||
@Value("${logo.image}")
|
||||
private String image;
|
||||
private String image; // the path to the image file used to show in common work mode
|
||||
@Value("${logo.imageEmbedded}")
|
||||
private String imageEmbedded;
|
||||
private String imageEmbedded; // the path to the image file used to show in the embedded mode
|
||||
@Value("${logo.url}")
|
||||
private String url;
|
||||
private String url; // the absolute URL which will be used when someone clicks the logo image
|
||||
}
|
||||
|
||||
@ -49,5 +49,7 @@ public enum Language {
|
||||
es,
|
||||
tr,
|
||||
uk,
|
||||
vi
|
||||
vi,
|
||||
gl,
|
||||
az
|
||||
}
|
||||
|
||||
@ -33,9 +33,9 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
public class CommentGroup {
|
||||
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
|
||||
private List<String> view;
|
||||
private List<String> view; // define a list of groups whose comments the user can view
|
||||
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
|
||||
private List<String> edit;
|
||||
private List<String> edit; // define a list of groups whose comments the user can edit
|
||||
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
|
||||
private List<String> remove;
|
||||
private List<String> remove; // define a list of groups whose comments the user can remove
|
||||
}
|
||||
|
||||
@ -29,14 +29,14 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("prototype")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Document {
|
||||
public class Document { // the parameters pertaining to the document (title, url, file type, etc.)
|
||||
@Autowired
|
||||
private Info info;
|
||||
private Info info; // additional parameters for the document (document owner, folder where the document is stored, uploading date, sharing settings)
|
||||
@Autowired
|
||||
private Permission permissions;
|
||||
private String fileType;
|
||||
private String key;
|
||||
private String urlUser;
|
||||
private String title;
|
||||
private String url;
|
||||
private Permission permissions; // the permission for the document to be edited and downloaded or not
|
||||
private String fileType; // the file type for the source viewed or edited document
|
||||
private String key; // the unique document identifier used by the service to recognize the document
|
||||
private String urlUser; // the absolute URL that will allow the document to be saved onto the user personal computer
|
||||
private String title; // the desired file name for the viewed or edited document which will also be used as file name when the document is downloaded
|
||||
private String url; // the absolute URL where the source viewed or edited document is stored
|
||||
}
|
||||
|
||||
@ -35,17 +35,17 @@ import java.util.List;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EditorConfig {
|
||||
private HashMap<String, Object> actionLink = null;
|
||||
private String callbackUrl;
|
||||
private String createUrl;
|
||||
public class EditorConfig { // the parameters pertaining to the editor interface: opening mode (viewer or editor), interface language, additional buttons, etc.
|
||||
private HashMap<String, Object> actionLink = null; // the data which contains the information about the action in the document that will be scrolled to
|
||||
private String callbackUrl; // the absolute URL to the document storage service
|
||||
private String createUrl; // the absolute URL of the document where it will be created and available after creation
|
||||
@Autowired
|
||||
private Customization customization;
|
||||
private Customization customization; // the parameters which allow to customize the editor interface so that it looked like your other products (if there are any) and change the presence or absence of the additional buttons, links, change logos and editor owner details
|
||||
@Autowired
|
||||
private Embedded embedded;
|
||||
private Language lang;
|
||||
private Mode mode;
|
||||
private Embedded embedded; // the parameters which allow to change the settings which define the behavior of the buttons in the embedded mode
|
||||
private Language lang; // the editor interface language
|
||||
private Mode mode; // the editor opening mode
|
||||
@Autowired
|
||||
private User user;
|
||||
private List<Template> templates;
|
||||
private User user; // the user currently viewing or editing the document
|
||||
private List<Template> templates; // the presence or absence of the templates in the <b>Create New...</b> menu option
|
||||
}
|
||||
|
||||
@ -30,12 +30,12 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("prototype")
|
||||
@Getter
|
||||
@Setter
|
||||
public class FileModel {
|
||||
public class FileModel { // the file base parameters which include the platform type used, document display size (width and height) and type of the document opened
|
||||
@Autowired
|
||||
private Document document;
|
||||
private DocumentType documentType;
|
||||
private Document document; // the parameters pertaining to the document (title, url, file type, etc.)
|
||||
private DocumentType documentType; // the document type to be opened
|
||||
@Autowired
|
||||
private EditorConfig editorConfig;
|
||||
private String token;
|
||||
private Type type;
|
||||
private EditorConfig editorConfig; // the parameters pertaining to the editor interface: opening mode (viewer or editor), interface language, additional buttons, etc.
|
||||
private String token; // the encrypted signature added to the Document Server config
|
||||
private Type type; // the platform type used to access the document
|
||||
}
|
||||
|
||||
@ -33,18 +33,20 @@ import java.util.List;
|
||||
@Scope("prototype")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Permission extends AbstractModel {
|
||||
private Boolean comment = true;
|
||||
private Boolean copy = true;
|
||||
private Boolean download = true;
|
||||
private Boolean edit = true;
|
||||
private Boolean print = true;
|
||||
private Boolean fillForms = true;
|
||||
private Boolean modifyFilter = true;
|
||||
private Boolean modifyContentControl = true;
|
||||
private Boolean review = true;
|
||||
public class Permission extends AbstractModel { // the permission for the document to be edited and downloaded or not
|
||||
private Boolean comment = true; // if the document can be commented or not
|
||||
private Boolean copy = true; // if the content can be copied to the clipboard or not
|
||||
private Boolean download = true; // if the document can be downloaded or only viewed or edited online
|
||||
private Boolean edit = true; // if the document can be edited or only viewed
|
||||
private Boolean print = true; // if the document can be printed or not
|
||||
private Boolean fillForms = true; // if the forms can be filled
|
||||
private Boolean modifyFilter = true; // if the filter can applied globally (true) affecting all the other users, or locally (false)
|
||||
private Boolean modifyContentControl = true; // if the content control settings can be changed
|
||||
private Boolean review = true; // if the document can be reviewed or not
|
||||
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
|
||||
private List<String> reviewGroups;
|
||||
private List<String> reviewGroups; // the groups whose changes the user can accept/reject
|
||||
@Autowired
|
||||
private CommentGroup commentGroups;
|
||||
private CommentGroup commentGroups; // the groups whose comments the user can edit, remove and/or view
|
||||
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SerializerFilter.class)
|
||||
private List<String> userInfoGroups;
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class Template {
|
||||
private String image;
|
||||
private String title;
|
||||
private String url;
|
||||
public class Template { // the document template parameters
|
||||
private String image; // the absolute URL to the image for template
|
||||
private String title; // the template title that will be displayed in the <b>Create New...</b> menu option
|
||||
private String url; // the absolute URL to the document where it will be created and available after creation
|
||||
}
|
||||
|
||||
@ -33,9 +33,10 @@ public class User extends AbstractModel {
|
||||
private String name;
|
||||
private String group;
|
||||
|
||||
// the user configuration parameters
|
||||
public void configure(int id, String name, String group){
|
||||
this.id = "uid-"+id;
|
||||
this.name = name;
|
||||
this.group = group;
|
||||
this.id = "uid-"+id; // the user id
|
||||
this.name = name; // the user name
|
||||
this.group = group; // the group the user belongs to
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,15 +6,18 @@ import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
|
||||
// specify the file storage mutator functions
|
||||
public interface FileStorageMutator {
|
||||
void createDirectory(Path path);
|
||||
boolean createFile(Path path, InputStream stream);
|
||||
boolean deleteFile(String fileName);
|
||||
boolean deleteFileHistory(String fileName);
|
||||
String updateFile(String fileName, byte[] bytes);
|
||||
boolean writeToFile(String pathName, String payload);
|
||||
boolean moveFile(Path source, Path destination);
|
||||
Resource loadFileAsResource(String fileName);
|
||||
File[] getStoredFiles();
|
||||
void createMeta(String fileName, String uid, String uname);
|
||||
void createDirectory(Path path); // create a new directory if it does not exist
|
||||
boolean createFile(Path path, InputStream stream); // create a new file if it does not exist
|
||||
boolean deleteFile(String fileName); // delete a file
|
||||
boolean deleteFileHistory(String fileName); // delete file history
|
||||
String updateFile(String fileName, byte[] bytes); // update a file
|
||||
boolean writeToFile(String pathName, String payload); // write the payload to the file
|
||||
boolean moveFile(Path source, Path destination); // move a file to the specified destination
|
||||
Resource loadFileAsResource(String fileName); // load file as a resource
|
||||
Resource loadFileAsResourceHistory(String fileName,String version,String file); // load file as a resource
|
||||
File[] getStoredFiles(); // get a collection of all the stored files
|
||||
void createMeta(String fileName, String uid, String uname); // create the file meta information
|
||||
boolean createOrUpdateFile(Path path, InputStream stream); // create or update a file
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.onlyoffice.integration.documentserver.storage;
|
||||
|
||||
// specify the file storage path builder functions
|
||||
public interface FileStoragePathBuilder {
|
||||
void configure(String address);
|
||||
String getStorageLocation();
|
||||
String getFileLocation(String fileName);
|
||||
String getServerUrl(Boolean forDocumentServer);
|
||||
String getHistoryDir(String fileName);
|
||||
int getFileVersion(String historyPath, Boolean ifIndexPage);
|
||||
String getForcesavePath(String fileName, Boolean create);
|
||||
void configure(String address); // create a new storage folder
|
||||
String getStorageLocation(); // get the storage directory
|
||||
String getFileLocation(String fileName); // get the directory of the specified file
|
||||
String getServerUrl(Boolean forDocumentServer); // get the server URL
|
||||
String getHistoryDir(String fileName); // get the history directory
|
||||
int getFileVersion(String historyPath, Boolean ifIndexPage); // get the file version
|
||||
String getForcesavePath(String fileName, Boolean create); // get the path where all the forcely saved file versions are saved or create it
|
||||
}
|
||||
|
||||
@ -32,9 +32,8 @@ import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@ -83,16 +82,26 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
createDirectory(Paths.get(getStorageLocation()));
|
||||
}
|
||||
|
||||
// get the storage directory
|
||||
public String getStorageLocation(){
|
||||
String serverPath = System.getProperty("user.dir");
|
||||
String directory = serverPath
|
||||
+ File.separator + storageFolder
|
||||
+ File.separator + this.storageAddress
|
||||
+ File.separator;
|
||||
String serverPath = System.getProperty("user.dir"); // get the path to the server
|
||||
String directory; // create the storage directory
|
||||
if (Paths.get(this.storageAddress).isAbsolute()) {
|
||||
directory = this.storageAddress + File.separator;
|
||||
} else {
|
||||
directory = serverPath
|
||||
+ File.separator + storageFolder
|
||||
+ File.separator + this.storageAddress
|
||||
+ File.separator;
|
||||
}
|
||||
if (!Files.exists(Paths.get(directory))) {
|
||||
createDirectory(Paths.get(directory));
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
// get the directory of the specified file
|
||||
public String getFileLocation(String fileName){
|
||||
if (fileName.contains(File.separator)) {
|
||||
return getStorageLocation() + fileName;
|
||||
@ -100,6 +109,7 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
return getStorageLocation() + fileUtility.getFileName(fileName);
|
||||
}
|
||||
|
||||
// create a new directory if it does not exist
|
||||
public void createDirectory(Path path){
|
||||
if (Files.exists(path)) return;
|
||||
try {
|
||||
@ -109,21 +119,22 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
}
|
||||
}
|
||||
|
||||
// create a new file if it does not exist
|
||||
public boolean createFile(Path path, InputStream stream){
|
||||
if (Files.exists(path)){
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
File file = Files.createFile(path).toFile();
|
||||
File file = Files.createFile(path).toFile(); // create a new file in the specified path
|
||||
try (FileOutputStream out = new FileOutputStream(file))
|
||||
{
|
||||
int read;
|
||||
final byte[] bytes = new byte[1024];
|
||||
while ((read = stream.read(bytes)) != -1)
|
||||
{
|
||||
out.write(bytes, 0, read);
|
||||
out.write(bytes, 0, read); // write bytes to the output stream
|
||||
}
|
||||
out.flush();
|
||||
out.flush(); // force write data to the output stream that can be cached in the current thread
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -131,36 +142,41 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
return false;
|
||||
}
|
||||
|
||||
// delete a file
|
||||
public boolean deleteFile(String fileName){
|
||||
fileName = URLDecoder.decode(fileName, StandardCharsets.UTF_8); // decode a x-www-form-urlencoded string
|
||||
if (fileName.isBlank()) return false;
|
||||
|
||||
String filenameWithoutExt = fileUtility.getFileNameWithoutExtension(fileName);
|
||||
String filenameWithoutExt = fileUtility.getFileNameWithoutExtension(fileName); // get file name without extension
|
||||
|
||||
Path filePath = Paths.get(getFileLocation(fileName));
|
||||
Path filePathWithoutExt = Paths.get(getStorageLocation() + filenameWithoutExt);
|
||||
Path filePath = fileName.contains(File.separator) ? Paths.get(fileName) : Paths.get(getFileLocation(fileName)); // get the path to the file
|
||||
Path filePathWithoutExt = fileName.contains(File.separator) ? Paths.get(filenameWithoutExt) : Paths.get(getStorageLocation() + filenameWithoutExt); // get the path to the file without extension
|
||||
|
||||
boolean fileDeleted = FileSystemUtils.deleteRecursively(filePath.toFile());
|
||||
boolean fileWithoutExtDeleted = FileSystemUtils.deleteRecursively(filePathWithoutExt.toFile());
|
||||
boolean fileDeleted = FileSystemUtils.deleteRecursively(filePath.toFile()); // delete the specified file; for directories, recursively delete any nested directories or files as well
|
||||
boolean fileWithoutExtDeleted = FileSystemUtils.deleteRecursively(filePathWithoutExt.toFile()); // delete the specified file without extension; for directories, recursively delete any nested directories or files as well
|
||||
|
||||
return fileDeleted && fileWithoutExtDeleted;
|
||||
}
|
||||
|
||||
// delete file history
|
||||
public boolean deleteFileHistory(String fileName) {
|
||||
fileName = URLDecoder.decode(fileName, StandardCharsets.UTF_8); // decode a x-www-form-urlencoded string
|
||||
if (fileName.isBlank()) return false;
|
||||
|
||||
Path fileHistoryPath = Paths.get(getStorageLocation() + getHistoryDir(fileName));
|
||||
Path fileHistoryPathWithoutExt = Paths.get(getStorageLocation() + getHistoryDir(fileUtility.getFileNameWithoutExtension(fileName)));
|
||||
Path fileHistoryPath = Paths.get(getStorageLocation() + getHistoryDir(fileName)); // get the path to the history file
|
||||
Path fileHistoryPathWithoutExt = Paths.get(getStorageLocation() + getHistoryDir(fileUtility.getFileNameWithoutExtension(fileName))); // get the path to the history file without extension
|
||||
|
||||
boolean historyDeleted = FileSystemUtils.deleteRecursively(fileHistoryPath.toFile());
|
||||
boolean historyWithoutExtDeleted = FileSystemUtils.deleteRecursively(fileHistoryPathWithoutExt.toFile());
|
||||
boolean historyDeleted = FileSystemUtils.deleteRecursively(fileHistoryPath.toFile()); // delete the specified history file; for directories, recursively delete any nested directories or files as well
|
||||
boolean historyWithoutExtDeleted = FileSystemUtils.deleteRecursively(fileHistoryPathWithoutExt.toFile()); // delete the specified history file without extension; for directories, recursively delete any nested directories or files as well
|
||||
|
||||
return historyDeleted || historyWithoutExtDeleted;
|
||||
}
|
||||
|
||||
// update a file
|
||||
public String updateFile(String fileName, byte[] bytes) {
|
||||
Path path = fileUtility.generateFilepath(getStorageLocation(), fileName);
|
||||
Path path = fileUtility.generateFilepath(getStorageLocation(), fileName); // generate the path to the specified file
|
||||
try {
|
||||
Files.write(path, bytes);
|
||||
Files.write(path, bytes); // write new information in the bytes format to the file
|
||||
return path.getFileName().toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -168,6 +184,7 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
return "";
|
||||
}
|
||||
|
||||
// move a file to the specified destination
|
||||
public boolean moveFile(Path source, Path destination){
|
||||
try {
|
||||
Files.move(source, destination,
|
||||
@ -179,6 +196,7 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
return false;
|
||||
}
|
||||
|
||||
// write the payload to the file
|
||||
public boolean writeToFile(String pathName, String payload){
|
||||
try (FileWriter fw = new FileWriter(pathName)) {
|
||||
fw.write(payload);
|
||||
@ -189,18 +207,19 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the path where all the forcely saved file versions are saved or create it
|
||||
public String getForcesavePath(String fileName, Boolean create) {
|
||||
String directory = getStorageLocation();
|
||||
|
||||
Path path = Paths.get(directory);
|
||||
Path path = Paths.get(directory); // get the storage directory
|
||||
if (!Files.exists(path)) return "";
|
||||
|
||||
directory = getFileLocation(fileName) + historyPostfix + File.separator;
|
||||
|
||||
path = Paths.get(directory);
|
||||
path = Paths.get(directory); // get the history file directory
|
||||
if (!create && !Files.exists(path)) return "";
|
||||
|
||||
createDirectory(path);
|
||||
createDirectory(path); // create a new directory where all the forcely saved file versions will be saved
|
||||
|
||||
directory = directory + fileName;
|
||||
path = Paths.get(directory);
|
||||
@ -211,14 +230,15 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
return directory;
|
||||
}
|
||||
|
||||
// load file as a resource
|
||||
public Resource loadFileAsResource(String fileName){
|
||||
String fileLocation = getForcesavePath(fileName, false);
|
||||
if (fileLocation.isBlank()){
|
||||
fileLocation = getFileLocation(fileName);
|
||||
String fileLocation = getForcesavePath(fileName, false); // get the path where all the forcely saved file versions are saved
|
||||
if (fileLocation.isBlank()){ // if file location is empty
|
||||
fileLocation = getFileLocation(fileName); // get it by the file name
|
||||
}
|
||||
try {
|
||||
Path filePath = Paths.get(fileLocation);
|
||||
Resource resource = new UrlResource(filePath.toUri());
|
||||
Path filePath = Paths.get(fileLocation); // get the path to the file location
|
||||
Resource resource = new UrlResource(filePath.toUri()); // convert the file path to URL
|
||||
if(resource.exists()) return resource;
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
@ -226,6 +246,21 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
return null;
|
||||
}
|
||||
|
||||
public Resource loadFileAsResourceHistory(String fileName,String version,String file){
|
||||
|
||||
String fileLocation = getStorageLocation() + fileName + "-hist" + File.separator + version + File.separator + file; // get it by the file name
|
||||
|
||||
try {
|
||||
Path filePath = Paths.get(fileLocation); // get the path to the file location
|
||||
Resource resource = new UrlResource(filePath.toUri()); // convert the file path to URL
|
||||
if(resource.exists()) return resource;
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// get a collection of all the stored files
|
||||
public File[] getStoredFiles()
|
||||
{
|
||||
File file = new File(getStorageLocation());
|
||||
@ -233,18 +268,19 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void createMeta(String fileName, String uid, String uname) {
|
||||
String histDir = getHistoryDir(getFileLocation(fileName));
|
||||
public void createMeta(String fileName, String uid, String uname) { // create the file meta information
|
||||
String histDir = getHistoryDir(getFileLocation(fileName)); // get the history directory
|
||||
|
||||
Path path = Paths.get(histDir);
|
||||
createDirectory(path);
|
||||
Path path = Paths.get(histDir); // get the path to the history directory
|
||||
createDirectory(path); // create the history directory
|
||||
|
||||
// create the json object with the file metadata
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
json.put("id", uid);
|
||||
json.put("name", uname);
|
||||
json.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); // put the file creation date to the json object
|
||||
json.put("id", uid); // put the user ID to the json object
|
||||
json.put("name", uname); // put the user name to the json object
|
||||
|
||||
File meta = Files.createFile(Paths.get(histDir + File.separator + "createdInfo.json")).toFile();
|
||||
File meta = new File(histDir + File.separator + "createdInfo.json"); // create the createdInfo.json file with the file meta information
|
||||
try (FileWriter writer = new FileWriter(meta)) {
|
||||
json.writeJSONString(writer);
|
||||
} catch (IOException ex){
|
||||
@ -252,6 +288,22 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
}
|
||||
}
|
||||
|
||||
// create or update a file
|
||||
public boolean createOrUpdateFile(Path path, InputStream stream) {
|
||||
if (!Files.exists(path)){ // if the specified file does not exist
|
||||
return createFile(path, stream); // create it in the specified directory
|
||||
} else {
|
||||
try {
|
||||
Files.write(path, stream.readAllBytes()); // otherwise, write new information in the bytes format to the file
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the server URL
|
||||
public String getServerUrl(Boolean forDocumentServer) {
|
||||
if (forDocumentServer && !docserviceUrlExample.equals("")) {
|
||||
return docserviceUrlExample;
|
||||
@ -260,27 +312,29 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
}
|
||||
}
|
||||
|
||||
// get the history directory
|
||||
public String getHistoryDir(String path)
|
||||
{
|
||||
return path + historyPostfix;
|
||||
}
|
||||
|
||||
// get the file version
|
||||
public int getFileVersion(String historyPath, Boolean ifIndexPage)
|
||||
{
|
||||
Path path;
|
||||
if (ifIndexPage) {
|
||||
path = Paths.get(getStorageLocation() + getHistoryDir(historyPath));
|
||||
if (ifIndexPage) { // if the start page is opened
|
||||
path = Paths.get(getStorageLocation() + getHistoryDir(historyPath)); // get the storage directory and add the history directory to it
|
||||
} else {
|
||||
path = Paths.get(historyPath);
|
||||
if (!Files.exists(path)) return 1;
|
||||
path = Paths.get(historyPath); // otherwise, get the path to the history directory
|
||||
if (!Files.exists(path)) return 1; // if the history directory does not exist, then the file version is 1
|
||||
}
|
||||
|
||||
try (Stream<Path> stream = Files.walk(path, 1)) {
|
||||
try (Stream<Path> stream = Files.walk(path, 1)) { // run through all the files in the history directory
|
||||
return stream
|
||||
.filter(file -> Files.isDirectory(file))
|
||||
.map(Path::getFileName)
|
||||
.map(Path::toString)
|
||||
.collect(Collectors.toSet()).size();
|
||||
.filter(file -> Files.isDirectory(file)) // take only directories from the history folder
|
||||
.map(Path::getFileName) // get file names
|
||||
.map(Path::toString) // and convert them into strings
|
||||
.collect(Collectors.toSet()).size(); // convert stream into set and get its size which specifies the file version
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
|
||||
@ -7,7 +7,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class Misc {
|
||||
public String convertUserDescriptions(String username, List<String> description){
|
||||
public String convertUserDescriptions(String username, List<String> description){ // cenvert user descriptions to the specified format
|
||||
String result = "<div class=\"user-descr\"><b>"+username+"</b><br/><ul>"+description.
|
||||
stream().map(text -> "<li>"+text+"</li>")
|
||||
.collect(Collectors.joining()) + "</ul></div>";
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
package com.onlyoffice.integration.documentserver.util;
|
||||
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* Disables and enables certificate and host-name checking in
|
||||
* HttpsURLConnection, the default JVM implementation of the HTTPS/TLS protocol.
|
||||
* Has no effect on implementations such as Apache Http Client, Ok Http.
|
||||
*/
|
||||
@Component
|
||||
public final class SSLUtils {
|
||||
|
||||
private final HostnameVerifier jvmHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
|
||||
|
||||
private final HostnameVerifier trivialHostnameVerifier = new HostnameVerifier() {
|
||||
public boolean verify(String hostname, SSLSession sslSession) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
private final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[] { new X509TrustManager() {
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||
}
|
||||
} };
|
||||
|
||||
public void turnOffSslChecking() throws NoSuchAlgorithmException, KeyManagementException {
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(trivialHostnameVerifier);
|
||||
// Install the all-trusting trust manager
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, UNQUESTIONING_TRUST_MANAGER, null);
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
|
||||
public void turnOnSslChecking() throws KeyManagementException, NoSuchAlgorithmException {
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(jvmHostnameVerifier);
|
||||
// Return it to the initial state (discovered by reflection, now hardcoded)
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, null, null);
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
|
||||
}
|
||||
@ -46,48 +46,62 @@ public class DefaultFileUtility implements FileUtility {
|
||||
@Value("${files.docservice.convert-docs}")
|
||||
private String docserviceConvertDocs;
|
||||
|
||||
@Value("${files.docservice.fillforms-docs}")
|
||||
private String docserviceFillDocs;
|
||||
|
||||
// document extensions
|
||||
private List<String> ExtsDocument = Arrays.asList(
|
||||
".doc", ".docx", ".docm",
|
||||
".dot", ".dotx", ".dotm",
|
||||
".odt", ".fodt", ".ott", ".rtf", ".txt",
|
||||
".html", ".htm", ".mht", ".xml",
|
||||
".pdf", ".djvu", ".fb2", ".epub", ".xps");
|
||||
".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oform");
|
||||
|
||||
// spreadsheet extensions
|
||||
private List<String> ExtsSpreadsheet = Arrays.asList(
|
||||
".xls", ".xlsx", ".xlsm",
|
||||
".xls", ".xlsx", ".xlsm", ".xlsb",
|
||||
".xlt", ".xltx", ".xltm",
|
||||
".ods", ".fods", ".ots", ".csv");
|
||||
|
||||
// presentation extensions
|
||||
private List<String> ExtsPresentation = Arrays.asList(
|
||||
".pps", ".ppsx", ".ppsm",
|
||||
".ppt", ".pptx", ".pptm",
|
||||
".pot", ".potx", ".potm",
|
||||
".odp", ".fodp", ".otp");
|
||||
|
||||
// get the document type
|
||||
public DocumentType getDocumentType(String fileName)
|
||||
{
|
||||
String ext = getFileExtension(fileName).toLowerCase();
|
||||
String ext = getFileExtension(fileName).toLowerCase(); // get file extension from its name
|
||||
// word type for document extensions
|
||||
if (ExtsDocument.contains(ext))
|
||||
return DocumentType.word;
|
||||
|
||||
// cell type for spreadsheet extensions
|
||||
if (ExtsSpreadsheet.contains(ext))
|
||||
return DocumentType.cell;
|
||||
|
||||
// slide type for presentation extensions
|
||||
if (ExtsPresentation.contains(ext))
|
||||
return DocumentType.slide;
|
||||
|
||||
// default file type is word
|
||||
return DocumentType.word;
|
||||
}
|
||||
|
||||
// get file name from its URL
|
||||
public String getFileName(String url)
|
||||
{
|
||||
if (url == null) return "";
|
||||
|
||||
// get file name from the last part of URL
|
||||
String fileName = url.substring(url.lastIndexOf('/') + 1);
|
||||
fileName = fileName.split("\\?")[0];
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// get file name without extension
|
||||
public String getFileNameWithoutExtension(String url)
|
||||
{
|
||||
String fileName = getFileName(url);
|
||||
@ -96,6 +110,7 @@ public class DefaultFileUtility implements FileUtility {
|
||||
return fileNameWithoutExt;
|
||||
}
|
||||
|
||||
// get file extension from URL
|
||||
public String getFileExtension(String url)
|
||||
{
|
||||
String fileName = getFileName(url);
|
||||
@ -104,59 +119,76 @@ public class DefaultFileUtility implements FileUtility {
|
||||
return fileExt.toLowerCase();
|
||||
}
|
||||
|
||||
// get an editor internal extension
|
||||
public String getInternalExtension(DocumentType type)
|
||||
{
|
||||
// .docx for word file type
|
||||
if (type.equals(DocumentType.word))
|
||||
return ".docx";
|
||||
|
||||
// .xlsx for cell file type
|
||||
if (type.equals(DocumentType.cell))
|
||||
return ".xlsx";
|
||||
|
||||
// .pptx for slide file type
|
||||
if (type.equals(DocumentType.slide))
|
||||
return ".pptx";
|
||||
|
||||
// the default file type is .docx
|
||||
return ".docx";
|
||||
}
|
||||
|
||||
public List<String> getFillExts()
|
||||
{
|
||||
return Arrays.asList(docserviceFillDocs.split("\\|"));
|
||||
}
|
||||
|
||||
// get file extensions that can be viewed
|
||||
public List<String> getViewedExts()
|
||||
{
|
||||
return Arrays.asList(docserviceViewedDocs.split("\\|"));
|
||||
}
|
||||
|
||||
// get file extensions that can be edited
|
||||
public List<String> getEditedExts()
|
||||
{
|
||||
return Arrays.asList(docserviceEditedDocs.split("\\|"));
|
||||
}
|
||||
|
||||
// get file extensions that can be converted
|
||||
public List<String> getConvertExts()
|
||||
{
|
||||
return Arrays.asList(docserviceConvertDocs.split("\\|"));
|
||||
}
|
||||
|
||||
// get all the supported file extensions
|
||||
public List<String> getFileExts() {
|
||||
List<String> res = new ArrayList<>();
|
||||
|
||||
res.addAll(getViewedExts());
|
||||
res.addAll(getEditedExts());
|
||||
res.addAll(getConvertExts());
|
||||
res.addAll(getFillExts());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// generate the file path from file directory and name
|
||||
public Path generateFilepath(String directory, String fullFileName){
|
||||
String fileName = getFileNameWithoutExtension(fullFileName);
|
||||
String fileExtension = getFileExtension(fullFileName);
|
||||
Path path = Paths.get(directory+fullFileName);
|
||||
String fileName = getFileNameWithoutExtension(fullFileName); // get file name without extension
|
||||
String fileExtension = getFileExtension(fullFileName); // get file extension
|
||||
Path path = Paths.get(directory+fullFileName); // get the path to the files with the specified name
|
||||
|
||||
for(int i = 1; Files.exists(path); i++){
|
||||
fileName = getFileNameWithoutExtension(fullFileName) + "("+i+")";
|
||||
path = Paths.get(directory+fileName+fileExtension);
|
||||
for(int i = 1; Files.exists(path); i++){ // run through all the files with the specified name
|
||||
fileName = getFileNameWithoutExtension(fullFileName) + "("+i+")"; // get a name of each file without extension and add an index to it
|
||||
path = Paths.get(directory+fileName+fileExtension); // create a new path for this file with the correct name and extension
|
||||
}
|
||||
|
||||
path = Paths.get(directory+fileName+fileExtension);
|
||||
return path;
|
||||
}
|
||||
|
||||
// get maximum file size
|
||||
public long getMaxFileSize(){
|
||||
long size = Long.parseLong(filesizeMax);
|
||||
return size > 0 ? size : 5 * 1024 * 1024;
|
||||
|
||||
@ -23,16 +23,18 @@ import com.onlyoffice.integration.documentserver.models.enums.DocumentType;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
// specify the file utility functions
|
||||
public interface FileUtility {
|
||||
DocumentType getDocumentType(String fileName);
|
||||
String getFileName(String url);
|
||||
String getFileNameWithoutExtension(String url);
|
||||
String getFileExtension(String url);
|
||||
String getInternalExtension(DocumentType type);
|
||||
List<String> getFileExts();
|
||||
List<String> getViewedExts();
|
||||
List<String> getEditedExts();
|
||||
List<String> getConvertExts();
|
||||
Path generateFilepath(String directory, String fullFileName);
|
||||
long getMaxFileSize();
|
||||
DocumentType getDocumentType(String fileName); // get the document type
|
||||
String getFileName(String url); // get file name from its URL
|
||||
String getFileNameWithoutExtension(String url); // get file name without extension
|
||||
String getFileExtension(String url); // get file extension from URL
|
||||
String getInternalExtension(DocumentType type); // get an editor internal extension
|
||||
List<String> getFileExts(); // get all the supported file extensions
|
||||
List<String> getFillExts(); // get file extensions that can be filled
|
||||
List<String> getViewedExts(); // get file extensions that can be viewed
|
||||
List<String> getEditedExts(); // get file extensions that can be edited
|
||||
List<String> getConvertExts(); // get file extensions that can be converted
|
||||
Path generateFilepath(String directory, String fullFileName); // generate the file path from file directory and name
|
||||
long getMaxFileSize(); // get maximum file size
|
||||
}
|
||||
|
||||
@ -62,20 +62,21 @@ public class DefaultServiceConverter implements ServiceConverter
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
int timeout = Integer.parseInt(docserviceTimeout);
|
||||
int timeout = Integer.parseInt(docserviceTimeout); // parse the dcoument service timeout value
|
||||
if (timeout > 0) convertTimeout = timeout;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private String postToServer(Convert body, String headerToken){
|
||||
String bodyString = objectMapper.writeValueAsString(body);
|
||||
private String postToServer(Convert body, String headerToken){ // send the POST request to the server
|
||||
String bodyString = objectMapper.writeValueAsString(body); // write the body request to the object mapper in the string format
|
||||
URL url = null;
|
||||
java.net.HttpURLConnection connection = null;
|
||||
InputStream response = null;
|
||||
String jsonString = null;
|
||||
|
||||
byte[] bodyByte = bodyString.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] bodyByte = bodyString.getBytes(StandardCharsets.UTF_8); // convert body string into bytes
|
||||
try{
|
||||
// set the request parameters
|
||||
url = new URL(docServiceUrl+docServiceUrlConverter);
|
||||
connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
@ -85,33 +86,38 @@ public class DefaultServiceConverter implements ServiceConverter
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
connection.setConnectTimeout(convertTimeout);
|
||||
|
||||
// check if the token is enabled
|
||||
if (jwtManager.tokenEnabled())
|
||||
{
|
||||
// set the JWT header to the request
|
||||
connection.setRequestProperty(documentJwtHeader.isBlank() ?
|
||||
"Authorization" : documentJwtHeader, "Bearer " + headerToken);
|
||||
}
|
||||
|
||||
connection.connect();
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
os.write(bodyByte);
|
||||
os.flush();
|
||||
os.write(bodyByte); // write bytes to the output stream
|
||||
os.flush(); // force write data to the output stream that can be cached in the current thread
|
||||
}
|
||||
|
||||
response = connection.getInputStream();
|
||||
jsonString = convertStreamToString(response);
|
||||
response = connection.getInputStream(); // get the input stream
|
||||
jsonString = convertStreamToString(response); // convert the response stream into a string
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
return jsonString;
|
||||
}
|
||||
}
|
||||
|
||||
// get the URL to the converted file
|
||||
public String getConvertedUri(String documentUri, String fromExtension,
|
||||
String toExtension, String documentRevisionId,
|
||||
String filePass, Boolean isAsync)
|
||||
String filePass, Boolean isAsync, String lang)
|
||||
{
|
||||
// check if the fromExtension parameter is defined; if not, get it from the document url
|
||||
fromExtension = fromExtension == null || fromExtension.isEmpty() ?
|
||||
fileUtility.getFileExtension(documentUri) : fromExtension;
|
||||
|
||||
// check if the file name parameter is defined; if not, get random uuid for this file
|
||||
String title = fileUtility.getFileName(documentUri);
|
||||
title = title == null || title.isEmpty() ? UUID.randomUUID().toString() : title;
|
||||
|
||||
@ -119,7 +125,9 @@ public class DefaultServiceConverter implements ServiceConverter
|
||||
|
||||
documentRevisionId = generateRevisionId(documentRevisionId); // create document token
|
||||
|
||||
// write all the necessary parameters to the body object
|
||||
Convert body = new Convert();
|
||||
body.setLang(lang);
|
||||
body.setUrl(documentUri);
|
||||
body.setOutputtype(toExtension.replace(".", ""));
|
||||
body.setFiletype(fromExtension.replace(".", ""));
|
||||
@ -133,6 +141,7 @@ public class DefaultServiceConverter implements ServiceConverter
|
||||
if (jwtManager.tokenEnabled())
|
||||
{
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("region", lang);
|
||||
map.put("url", body.getUrl());
|
||||
map.put("outputtype", body.getOutputtype());
|
||||
map.put("filetype", body.getFiletype());
|
||||
@ -156,22 +165,24 @@ public class DefaultServiceConverter implements ServiceConverter
|
||||
return getResponseUri(jsonString);
|
||||
}
|
||||
|
||||
// generate document key
|
||||
public String generateRevisionId(String expectedKey)
|
||||
{
|
||||
if (expectedKey.length() > 20)
|
||||
expectedKey = Integer.toString(expectedKey.hashCode());
|
||||
if (expectedKey.length() > 20) // if the expected key length is greater than 20
|
||||
expectedKey = Integer.toString(expectedKey.hashCode()); // the expected key is hashed and a fixed length value is stored in the string format
|
||||
|
||||
String key = expectedKey.replace("[^0-9-.a-zA-Z_=]", "_");
|
||||
|
||||
return key.substring(0, Math.min(key.length(), 20));
|
||||
return key.substring(0, Math.min(key.length(), 20)); // the resulting key length is 20 or less
|
||||
}
|
||||
|
||||
//TODO: Replace with a registry (callbacks package for reference)
|
||||
private void processConvertServiceResponceError(int errorCode)
|
||||
private void processConvertServiceResponceError(int errorCode) // create an error message for an error code
|
||||
{
|
||||
String errorMessage = "";
|
||||
String errorMessageTemplate = "Error occurred in the ConvertService: ";
|
||||
|
||||
// add the error message to the error message template depending on the error code
|
||||
switch (errorCode)
|
||||
{
|
||||
case -8:
|
||||
@ -198,10 +209,10 @@ public class DefaultServiceConverter implements ServiceConverter
|
||||
case -1:
|
||||
errorMessage = errorMessageTemplate + "Error convertation unknown";
|
||||
break;
|
||||
case 0:
|
||||
case 0: // if the error code is equal to 0, the error message is empty
|
||||
break;
|
||||
default:
|
||||
errorMessage = "ErrorCode = " + errorCode;
|
||||
errorMessage = "ErrorCode = " + errorCode; // default value for the error message
|
||||
break;
|
||||
}
|
||||
|
||||
@ -209,44 +220,45 @@ public class DefaultServiceConverter implements ServiceConverter
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private String getResponseUri(String jsonString)
|
||||
private String getResponseUri(String jsonString) // get the response URL
|
||||
{
|
||||
JSONObject jsonObj = convertStringToJSON(jsonString);
|
||||
|
||||
Object error = jsonObj.get("error");
|
||||
if (error != null)
|
||||
processConvertServiceResponceError(Math.toIntExact((long)error));
|
||||
if (error != null) // if an error occurs
|
||||
processConvertServiceResponceError(Math.toIntExact((long)error)); // then get an error message
|
||||
|
||||
// check if the conversion is completed and save the result to a variable
|
||||
Boolean isEndConvert = (Boolean) jsonObj.get("endConvert");
|
||||
|
||||
Long resultPercent = 0l;
|
||||
String responseUri = null;
|
||||
|
||||
if (isEndConvert)
|
||||
if (isEndConvert) // if the conversion is completed
|
||||
{
|
||||
resultPercent = 100l;
|
||||
responseUri = (String) jsonObj.get("fileUrl");
|
||||
responseUri = (String) jsonObj.get("fileUrl"); // get the file URL
|
||||
}
|
||||
else
|
||||
else // if the conversion isn't completed
|
||||
{
|
||||
resultPercent = (Long) jsonObj.get("percent");
|
||||
resultPercent = resultPercent >= 100l ? 99l : resultPercent;
|
||||
resultPercent = resultPercent >= 100l ? 99l : resultPercent; // get the percentage value of the conversion process
|
||||
}
|
||||
|
||||
return resultPercent >= 100l ? responseUri : "";
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public String convertStreamToString(InputStream stream)
|
||||
public String convertStreamToString(InputStream stream) // convert stream to string
|
||||
{
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(stream);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||
String line = bufferedReader.readLine();
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(stream); // create an object to get incoming stream
|
||||
StringBuilder stringBuilder = new StringBuilder(); // create a string builder object
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader); // create an object to read incoming streams
|
||||
String line = bufferedReader.readLine(); // get incoming streams by lines
|
||||
|
||||
while (line != null)
|
||||
{
|
||||
stringBuilder.append(line);
|
||||
stringBuilder.append(line); // concatenate strings using the string builder
|
||||
line = bufferedReader.readLine();
|
||||
}
|
||||
|
||||
@ -256,10 +268,10 @@ public class DefaultServiceConverter implements ServiceConverter
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public JSONObject convertStringToJSON(String jsonString)
|
||||
public JSONObject convertStringToJSON(String jsonString) // convert string to json
|
||||
{
|
||||
Object obj = parser.parse(jsonString);
|
||||
JSONObject jsonObj = (JSONObject) obj;
|
||||
Object obj = parser.parse(jsonString); // parse json string
|
||||
JSONObject jsonObj = (JSONObject) obj; // and turn it into a json object
|
||||
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
@ -24,11 +24,13 @@ import org.json.simple.parser.ParseException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
// specify the converter service functions
|
||||
public interface ServiceConverter {
|
||||
String getConvertedUri(String documentUri, String fromExtension,
|
||||
String getConvertedUri(String documentUri, String fromExtension, // get the URL to the converted file
|
||||
String toExtension, String documentRevisionId,
|
||||
String filePass, Boolean isAsync);
|
||||
String generateRevisionId(String expectedKey);
|
||||
String convertStreamToString(InputStream stream);
|
||||
JSONObject convertStringToJSON(String jsonString);
|
||||
String filePass, Boolean isAsync, String lang);
|
||||
String generateRevisionId(String expectedKey); // generate document key
|
||||
String convertStreamToString(InputStream stream); // convert stream to string
|
||||
JSONObject convertStringToJSON(String jsonString); // convert string to json
|
||||
}
|
||||
|
||||
@ -36,4 +36,5 @@ public class Convert {
|
||||
private String filePass;
|
||||
private Boolean async;
|
||||
private String token;
|
||||
private String lang;
|
||||
}
|
||||
|
||||
@ -31,4 +31,6 @@ public class Converter {
|
||||
private String fileName;
|
||||
@JsonProperty("filePass")
|
||||
private String filePass;
|
||||
@JsonProperty("lang")
|
||||
private String lang;
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Track {
|
||||
private String filetype;
|
||||
private String url;
|
||||
private String key;
|
||||
private String changesurl;
|
||||
|
||||
@ -47,4 +47,6 @@ public class Permission extends AbstractEntity {
|
||||
private List<Group> commentsEditGroups;
|
||||
@ManyToMany
|
||||
private List<Group> commentsRemoveGroups;
|
||||
@ManyToMany
|
||||
private List<Group> userInfoGroups;
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ import java.util.List;
|
||||
public class User extends AbstractEntity {
|
||||
private String name;
|
||||
private String email;
|
||||
private Boolean favorite;
|
||||
@ManyToOne
|
||||
private Group group;
|
||||
@OneToOne
|
||||
|
||||
@ -37,17 +37,17 @@ public abstract class AbstractMapper<E extends AbstractEntity, M extends Abstrac
|
||||
}
|
||||
|
||||
@Override
|
||||
public M toModel(E entity) {
|
||||
return Objects.isNull(entity)
|
||||
public M toModel(E entity) { // convert the entity to the model
|
||||
return Objects.isNull(entity) // check if an entity is not empty
|
||||
? null
|
||||
: mapper.map(entity, modelClass);
|
||||
: mapper.map(entity, modelClass); // and add it to the model mapper
|
||||
}
|
||||
|
||||
Converter<E, M> modelConverter() {
|
||||
Converter<E, M> modelConverter() { // specify the model converter
|
||||
return context -> {
|
||||
E source = context.getSource();
|
||||
M destination = context.getDestination();
|
||||
handleSpecificFields(source, destination);
|
||||
E source = context.getSource(); // get the source entity
|
||||
M destination = context.getDestination(); // get the destination model
|
||||
handleSpecificFields(source, destination); // map the entity to the model
|
||||
return context.getDestination();
|
||||
};
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ package com.onlyoffice.integration.mappers;
|
||||
import com.onlyoffice.integration.entities.AbstractEntity;
|
||||
import com.onlyoffice.integration.documentserver.models.AbstractModel;
|
||||
|
||||
// specify the model mapper functions
|
||||
public interface Mapper<E extends AbstractEntity, M extends AbstractModel> {
|
||||
M toModel(E entity);
|
||||
M toModel(E entity); // convert the entity to the model
|
||||
}
|
||||
|
||||
@ -39,20 +39,21 @@ public class PermissionsMapper extends AbstractMapper<Permission, com.onlyoffice
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void configure() {
|
||||
mapper.createTypeMap(Permission.class, com.onlyoffice.integration.documentserver.models.filemodel.Permission.class)
|
||||
.setPostConverter(modelConverter());
|
||||
public void configure() { // configure the permission mapper
|
||||
mapper.createTypeMap(Permission.class, com.onlyoffice.integration.documentserver.models.filemodel.Permission.class) // create the type map
|
||||
.setPostConverter(modelConverter()); // and apply the post converter to it
|
||||
}
|
||||
|
||||
@Override
|
||||
void handleSpecificFields(Permission source, com.onlyoffice.integration.documentserver.models.filemodel.Permission destination) {
|
||||
destination.setReviewGroups(source.getReviewGroups().stream().map(g -> g.getName()).collect(Collectors.toList()));
|
||||
destination.setCommentGroups(
|
||||
void handleSpecificFields(Permission source, com.onlyoffice.integration.documentserver.models.filemodel.Permission destination) { // handle specific permission fields
|
||||
destination.setReviewGroups(source.getReviewGroups().stream().map(g -> g.getName()).collect(Collectors.toList())); // set the reviewGroups parameter
|
||||
destination.setCommentGroups( // set the commentGroups parameter
|
||||
new CommentGroup(
|
||||
source.getCommentsViewGroups().stream().map(g -> g.getName()).collect(Collectors.toList()),
|
||||
source.getCommentsEditGroups().stream().map(g -> g.getName()).collect(Collectors.toList()),
|
||||
source.getCommentsRemoveGroups().stream().map(g -> g.getName()).collect(Collectors.toList())
|
||||
)
|
||||
);
|
||||
destination.setUserInfoGroups(source.getUserInfoGroups().stream().map(g -> g.getName()).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,13 +37,13 @@ public class UsersMapper extends AbstractMapper<User, com.onlyoffice.integration
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void configure() {
|
||||
mapper.createTypeMap(User.class, com.onlyoffice.integration.documentserver.models.filemodel.User.class)
|
||||
.setPostConverter(modelConverter());
|
||||
public void configure() { // configure the users mapper
|
||||
mapper.createTypeMap(User.class, com.onlyoffice.integration.documentserver.models.filemodel.User.class) // create the type map
|
||||
.setPostConverter(modelConverter()); // and apply the post converter to it
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSpecificFields(User source, com.onlyoffice.integration.documentserver.models.filemodel.User destination) {
|
||||
destination.setGroup(source.getGroup() != null ? source.getGroup().getName() : null);
|
||||
public void handleSpecificFields(User source, com.onlyoffice.integration.documentserver.models.filemodel.User destination) { // handle specific users fields
|
||||
destination.setGroup(source.getGroup() != null ? source.getGroup().getName() : null); // set the Group parameter
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,21 +32,23 @@ public class GroupServices {
|
||||
@Autowired
|
||||
private GroupRepository groupRepository;
|
||||
|
||||
// create a new group with the specified name
|
||||
public Group createGroup(String name){
|
||||
if(name == null) return null;
|
||||
Optional<Group> group = groupRepository.findGroupByName(name);
|
||||
if(group.isPresent()) return group.get();
|
||||
if(name == null) return null; // check if a name is specified
|
||||
Optional<Group> group = groupRepository.findGroupByName(name); // check if group with such a name already exists
|
||||
if(group.isPresent()) return group.get(); // if it exists, return it
|
||||
Group newGroup = new Group();
|
||||
newGroup.setName(name);
|
||||
newGroup.setName(name); // otherwise, create a new group with the specified name
|
||||
|
||||
groupRepository.save(newGroup);
|
||||
groupRepository.save(newGroup); // save a new group
|
||||
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
// create a list of groups from the reviewGroups permission parameter
|
||||
public List<Group> createGroups(List<String> reviewGroups){
|
||||
if(reviewGroups == null) return null;
|
||||
return reviewGroups.stream()
|
||||
if(reviewGroups == null) return null; // check if the reviewGroups permission exists
|
||||
return reviewGroups.stream() // convert this parameter to a list of groups whose changes the user can accept/reject
|
||||
.map(group -> createGroup(group))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@ -32,24 +32,28 @@ public class PermissionServices {
|
||||
@Autowired
|
||||
private PermissionRepository permissionRepository;
|
||||
|
||||
// create permissions with the specified parameters
|
||||
public Permission createPermission(List<Group> reviewGroups,
|
||||
List<Group> commentViewGroups,
|
||||
List<Group> commentEditGroups,
|
||||
List<Group> commentRemoveGroups){
|
||||
List<Group> commentRemoveGroups,
|
||||
List<Group> userInfoGroups){
|
||||
|
||||
Permission permission = new Permission();
|
||||
permission.setReviewGroups(reviewGroups);
|
||||
permission.setCommentsViewGroups(commentViewGroups);
|
||||
permission.setCommentsEditGroups(commentEditGroups);
|
||||
permission.setCommentsRemoveGroups(commentRemoveGroups);
|
||||
permission.setReviewGroups(reviewGroups); // define the groups whose changes the user can accept/reject
|
||||
permission.setCommentsViewGroups(commentViewGroups); // defines the groups whose comments the user can view
|
||||
permission.setCommentsEditGroups(commentEditGroups); // defines the groups whose comments the user can edit
|
||||
permission.setCommentsRemoveGroups(commentRemoveGroups); // defines the groups whose comments the user can remove
|
||||
permission.setUserInfoGroups(userInfoGroups);
|
||||
|
||||
permissionRepository.save(permission);
|
||||
permissionRepository.save(permission); // save new permissions
|
||||
|
||||
return permission;
|
||||
}
|
||||
|
||||
// update permissions
|
||||
public Permission updatePermission(Permission newPermission){
|
||||
permissionRepository.save(newPermission);
|
||||
permissionRepository.save(newPermission); // save new permissions
|
||||
|
||||
return newPermission;
|
||||
}
|
||||
|
||||
@ -40,36 +40,41 @@ public class UserServices {
|
||||
@Autowired
|
||||
private PermissionServices permissionService;
|
||||
|
||||
// get a list of all users
|
||||
public List<User> findAll(){
|
||||
return userRepository.findAll();
|
||||
}
|
||||
|
||||
// get a user by their ID
|
||||
public Optional<User> findUserById(Integer id){
|
||||
return userRepository.findById(id);
|
||||
}
|
||||
|
||||
// create a user with the specified parameters
|
||||
public User createUser(String name, String email,
|
||||
List<String> description, String group,
|
||||
List<String> reviewGroups,
|
||||
List<String> viewGroups,
|
||||
List<String> editGroups,
|
||||
List<String> removeGroups){
|
||||
List<String> removeGroups, List<String> userInfoGroups, Boolean favoriteDoc){
|
||||
User newUser = new User();
|
||||
newUser.setName(name);
|
||||
newUser.setEmail(email);
|
||||
newUser.setGroup(groupServices.createGroup(group));
|
||||
newUser.setDescriptions(description);
|
||||
newUser.setName(name); // set the user name
|
||||
newUser.setEmail(email); // set the user email
|
||||
newUser.setGroup(groupServices.createGroup(group)); // set the user group
|
||||
newUser.setDescriptions(description); // set the user description
|
||||
newUser.setFavorite(favoriteDoc); // specify if the user has the favorite documents or not
|
||||
|
||||
List<Group> groupsReview = groupServices.createGroups(reviewGroups);
|
||||
List<Group> commentGroupsView = groupServices.createGroups(viewGroups);
|
||||
List<Group> commentGroupsEdit = groupServices.createGroups(editGroups);
|
||||
List<Group> commentGroupsRemove = groupServices.createGroups(removeGroups);
|
||||
List<Group> groupsReview = groupServices.createGroups(reviewGroups); // define the groups whose changes the user can accept/reject
|
||||
List<Group> commentGroupsView = groupServices.createGroups(viewGroups); // defines the groups whose comments the user can view
|
||||
List<Group> commentGroupsEdit = groupServices.createGroups(editGroups); // defines the groups whose comments the user can edit
|
||||
List<Group> commentGroupsRemove = groupServices.createGroups(removeGroups); // defines the groups whose comments the user can remove
|
||||
List<Group> usInfoGroups = groupServices.createGroups(userInfoGroups);
|
||||
|
||||
Permission permission = permissionService
|
||||
.createPermission(groupsReview, commentGroupsView, commentGroupsEdit, commentGroupsRemove);
|
||||
.createPermission(groupsReview, commentGroupsView, commentGroupsEdit, commentGroupsRemove, usInfoGroups); // specify permissions for the current user
|
||||
newUser.setPermissions(permission);
|
||||
|
||||
userRepository.save(newUser);
|
||||
userRepository.save(newUser); // save a new user
|
||||
|
||||
return newUser;
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ package com.onlyoffice.integration.services.configurers.implementations;
|
||||
|
||||
import com.onlyoffice.integration.documentserver.models.enums.Action;
|
||||
import com.onlyoffice.integration.documentserver.models.configurations.Customization;
|
||||
import com.onlyoffice.integration.entities.User;
|
||||
import com.onlyoffice.integration.services.configurers.CustomizationConfigurer;
|
||||
import com.onlyoffice.integration.services.configurers.wrappers.DefaultCustomizationWrapper;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
@ -29,9 +30,9 @@ import org.springframework.stereotype.Service;
|
||||
@Primary
|
||||
public class DefaultCustomizationConfigurer implements CustomizationConfigurer<DefaultCustomizationWrapper> {
|
||||
@Override
|
||||
public void configure(Customization customization, DefaultCustomizationWrapper wrapper){
|
||||
Action action = wrapper.getAction();
|
||||
Boolean canEdit = wrapper.getCanEdit();
|
||||
customization.setSubmitForm(canEdit && (action.equals(Action.edit) || action.equals(Action.fillForms)));
|
||||
public void configure(Customization customization, DefaultCustomizationWrapper wrapper) { // define the customization configurer
|
||||
Action action = wrapper.getAction(); // get the action parameter from the customization wrapper
|
||||
User user = wrapper.getUser();
|
||||
customization.setSubmitForm(action.equals(Action.fillForms) && user.getId() == 1 && false); // set the submitForm parameter to the customization config
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Random;
|
||||
|
||||
@Service
|
||||
@Primary
|
||||
@ -49,24 +48,22 @@ public class DefaultDocumentConfigurer implements DocumentConfigurer<DefaultDocu
|
||||
@Autowired
|
||||
private ServiceConverter serviceConverter;
|
||||
|
||||
private Random rnd = new Random();
|
||||
public void configure(Document document, DefaultDocumentWrapper wrapper){ // define the document configurer
|
||||
String fileName = wrapper.getFileName(); // get the fileName parameter from the document wrapper
|
||||
Permission permission = wrapper.getPermission(); // get the permission parameter from the document wrapper
|
||||
|
||||
public void configure(Document document, DefaultDocumentWrapper wrapper){
|
||||
String fileName = wrapper.getFileName();
|
||||
Permission permission = wrapper.getPermission();
|
||||
document.setTitle(fileName); // set the title to the document config
|
||||
document.setUrl(documentManager.getDownloadUrl(fileName)); // set the URL to download a file to the document config
|
||||
document.setUrlUser(documentManager.getFileUri(fileName, false)); // set the file URL to the document config
|
||||
document.setFileType(fileUtility.getFileExtension(fileName).replace(".","")); // set the file type to the document config
|
||||
document.getInfo().setFavorite(wrapper.getFavorite()); // set the favorite parameter to the document config
|
||||
|
||||
document.setTitle(fileName);
|
||||
document.setUrl(documentManager.getDownloadUrl(fileName));
|
||||
document.setUrlUser(documentManager.getFileUri(fileName, false));
|
||||
document.setFileType(fileUtility.getInternalExtension(fileUtility.getDocumentType(fileName)).replace(".",""));
|
||||
document.getInfo().setFavorite(rnd.nextBoolean());
|
||||
|
||||
String key = serviceConverter.
|
||||
String key = serviceConverter. // get the document key
|
||||
generateRevisionId(storagePathBuilder.getStorageLocation()
|
||||
+ "/" + fileName + "/"
|
||||
+ new File(storagePathBuilder.getFileLocation(fileName)).lastModified());
|
||||
|
||||
document.setKey(key);
|
||||
document.setPermissions(permission);
|
||||
document.setKey(key); // set the key to the document config
|
||||
document.setPermissions(permission); // set the permission parameters to the document config
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user