Compare commits
781 Commits
feature/cs
...
v7.5.0.112
| Author | SHA1 | Date | |
|---|---|---|---|
| 847e4ce6d9 | |||
| 152083ed4e | |||
| d594870c87 | |||
| ce0bbca5b2 | |||
| e6831fa52f | |||
| ffa686e0a2 | |||
| 730cc09520 | |||
| 35613ddccb | |||
| 2fa83dcc94 | |||
| c1af2ba5b4 | |||
| fa84f451c2 | |||
| 87e9da1212 | |||
| 22dbacaa63 | |||
| d192d1e0e8 | |||
| 5b115f7dbc | |||
| 41a22934a0 | |||
| 94f4e83d79 | |||
| 8ed0c4771d | |||
| 0445184cbc | |||
| e4750e7a61 | |||
| a78450453d | |||
| ca139938e9 | |||
| 8ae9dc6fff | |||
| 9c0121e69f | |||
| e11861b30f | |||
| 21842b772d | |||
| 17a1485d52 | |||
| 07c752ed81 | |||
| 8c704687a7 | |||
| b691eb5717 | |||
| dc35b240d1 | |||
| 527e5053e6 | |||
| 1839a5c26b | |||
| ccb81a60e1 | |||
| b73a70e6d0 | |||
| 89e64fe71e | |||
| 2ffc44f339 | |||
| 4e515a66ef | |||
| a758f9a6d8 | |||
| 0131724cab | |||
| a178dbc612 | |||
| 4064f73c89 | |||
| 561af8444c | |||
| 091bf10374 | |||
| 63461b3eb6 | |||
| bd20af2096 | |||
| 2611fae25c | |||
| c740e21e83 | |||
| 8193d5b9f2 | |||
| 1f109c2b88 | |||
| a676da0a61 | |||
| 5f0fcfebd2 | |||
| 292640aa95 | |||
| 9aedba8be3 | |||
| c98e8d03d2 | |||
| 5951870870 | |||
| 9bc6964274 | |||
| 2051f3028e | |||
| 869f8e7ba7 | |||
| 815b5fb428 | |||
| 13a1a6ba2c | |||
| a3b93fee99 | |||
| 36cca57dd8 | |||
| 53f315c5ee | |||
| 7c0d8cd59d | |||
| 3405af796c | |||
| b4905eb94e | |||
| 5a3330beb2 | |||
| 5d16a50f0f | |||
| d8b6b0bbb5 | |||
| 7b6c9b5683 | |||
| d4bed077e0 | |||
| 8aba537cea | |||
| 9cc6612bb2 | |||
| 4bae7d8bf5 | |||
| 59c9061306 | |||
| 2fb011185a | |||
| 49a58e687d | |||
| 42e1b0635a | |||
| e9d8b60c13 | |||
| 33119ca2ad | |||
| 913c1350c2 | |||
| fa34f5a44e | |||
| 5784171806 | |||
| 8829f969d3 | |||
| ab48645ba8 | |||
| 5d0f1b62d0 | |||
| 78747c1cae | |||
| 2955dc004f | |||
| 85981abd00 | |||
| 7542c6ca6e | |||
| ab0553d988 | |||
| 57e498ebba | |||
| ce1052139e | |||
| 350ea4e678 | |||
| 979391e413 | |||
| 2b454e23d5 | |||
| 9ed5f19d6b | |||
| 851b2e48c7 | |||
| be40222d1a | |||
| d701f1565b | |||
| 2f39fb3bc6 | |||
| 626f051aab | |||
| acd4bf87e7 | |||
| 9a9e122eec | |||
| 340eaa31f4 | |||
| 6433f502ad | |||
| cbfbf77f0f | |||
| 173641a7af | |||
| ce37d1de20 | |||
| ce80e89028 | |||
| 63365e176e | |||
| 32a60c09aa | |||
| 5a03024cd3 | |||
| cb6416c481 | |||
| 55e4247687 | |||
| a0620905b2 | |||
| 3fcef4096a | |||
| 4e5349c1c4 | |||
| 538eec1ff3 | |||
| 10e67c787c | |||
| 565a27d981 | |||
| 7304c1e67a | |||
| f9ba90d3ac | |||
| d2f40c5395 | |||
| ca0b7adcee | |||
| df7cfda2fb | |||
| 9ebef04f3d | |||
| a6ed970bca | |||
| 7f659bc95e | |||
| 3c4a1c1c31 | |||
| 2bae0567ad | |||
| 419fbf90f9 | |||
| 2d637b88df | |||
| 13e2d5b33c | |||
| f208fe1939 | |||
| b3cc35cb5e | |||
| 8b316b0786 | |||
| c57fcbfd90 | |||
| 1939b85c8c | |||
| ee0ac33820 | |||
| c93579d98f | |||
| 61a9e122cd | |||
| e88a9f5bed | |||
| f1ce0fb415 | |||
| 3b142d92fc | |||
| 1898da660e | |||
| 0629cf0797 | |||
| 7737670a6d | |||
| 5bdcac42e3 | |||
| 4b8ffa26cc | |||
| a4b6fcb512 | |||
| 523b10c979 | |||
| 1d4bc95c29 | |||
| e94a4863aa | |||
| edda981ab7 | |||
| 65ebf9a5b1 | |||
| a081cd1f06 | |||
| 04c5ee8cd7 | |||
| 3ebf3fabee | |||
| 403efc1325 | |||
| 7deedcaa5e | |||
| 161e26dd8a | |||
| 09804349fa | |||
| 83a83f4f5d | |||
| 79ee987003 | |||
| 434484cac3 | |||
| a0bafb0e4b | |||
| 184aded727 | |||
| 7db708e559 | |||
| 3b3116f56e | |||
| 15c70f43d7 | |||
| 39af4be045 | |||
| c9dc4862ed | |||
| 122d41e307 | |||
| 2880db7383 | |||
| c0f23a4fc2 | |||
| 1a49d8dd03 | |||
| 180f287c07 | |||
| 37c33965c8 | |||
| 0861732dbe | |||
| d3220c7a91 | |||
| 450cafdae3 | |||
| 62abe3e569 | |||
| 8b2fbff3b7 | |||
| acf243ee3e | |||
| 66c38ded4a | |||
| 58a73190d4 | |||
| ae7a208831 | |||
| 2d83f3f39c | |||
| 2aed1e3a83 | |||
| 001a99b502 | |||
| a7a9f997d5 | |||
| 4c3dc96e30 | |||
| 7fe1ae27b4 | |||
| dce840c627 | |||
| 4f832ac2f7 | |||
| e7623e29d7 | |||
| 16dd8a55e5 | |||
| dca68bf0d1 | |||
| f028f1ba2f | |||
| 5c8867dd20 | |||
| 27eea60fc3 | |||
| c285b49d3b | |||
| 70c86f3054 | |||
| 00e5466a0c | |||
| 12a366a28a | |||
| b4918cf493 | |||
| b2b21980d1 | |||
| 09a97c0f66 | |||
| 5db65ef062 | |||
| 5164380336 | |||
| 26c5cd0a83 | |||
| bff8c83283 | |||
| 827bd3981f | |||
| e8599c7c56 | |||
| 0a3b951eb6 | |||
| 988da27e3f | |||
| a697219dcf | |||
| 7649e7f51e | |||
| 108b5ea317 | |||
| 4ea0760803 | |||
| c558098deb | |||
| 4a61093343 | |||
| 2af1f56aa7 | |||
| 6780feafa6 | |||
| 23b4ffc104 | |||
| 7304166d8f | |||
| 46a9fffb0e | |||
| 0ccc98e83f | |||
| 7f59c15112 | |||
| 455f2ee823 | |||
| 3076a9bc0e | |||
| c605607b5e | |||
| e05afc931a | |||
| 53aeb19e2f | |||
| 14a557be69 | |||
| 666b6f8a03 | |||
| ebddc8114a | |||
| fa76819b2d | |||
| 69aa25880a | |||
| 7cd79280ff | |||
| 4535bfe661 | |||
| 01cabdf1e5 | |||
| 8b15a0e417 | |||
| 451b3b7a38 | |||
| 952b495c4d | |||
| 1cd3642de8 | |||
| a4f49cb86b | |||
| 9ca722329f | |||
| 496a150620 | |||
| 983a92d9e0 | |||
| ad94016a85 | |||
| fcb807471f | |||
| 50a4ddbd11 | |||
| 01d1dc4274 | |||
| 1447b304eb | |||
| 8e79c6448f | |||
| badf3c7d49 | |||
| 342b31f7d7 | |||
| 0ae8f5d396 | |||
| 7a238c2b73 | |||
| 0b4c67e552 | |||
| f5391051b1 | |||
| 01c8a940d4 | |||
| 579992e40b | |||
| 3a2218a466 | |||
| 0ea28f525f | |||
| 33363f6144 | |||
| da8bdca022 | |||
| c4eccc5ee8 | |||
| ab13745cf6 | |||
| 97f07e4275 | |||
| 7c3e250797 | |||
| 32ab794f11 | |||
| 800ef84f84 | |||
| a7e4036667 | |||
| 4f589a7394 | |||
| a3abb58d72 | |||
| 17536df8e5 | |||
| 2e8a483a0c | |||
| a0aa7b4fd0 | |||
| 8b720beffa | |||
| a1c286cbaa | |||
| fc377b967d | |||
| b2de5eff4c | |||
| 02439f3699 | |||
| 2429f21a84 | |||
| aa0a4b5400 | |||
| a28300848b | |||
| fec0e87218 | |||
| efbace1e8b | |||
| 35e479355a | |||
| 32c91b9016 | |||
| 183d165c00 | |||
| a996f2c3c3 | |||
| 782243eb86 | |||
| f058d68126 | |||
| a8f07fce4d | |||
| 025bd1068d | |||
| 75b22614cf | |||
| 6cb15697ab | |||
| 1da93ce071 | |||
| 837e34de37 | |||
| 20c4ec1b78 | |||
| 39bab74422 | |||
| 665ab6a77d | |||
| 5663227c55 | |||
| 42ac89e5e5 | |||
| c95499536d | |||
| 5659756c07 | |||
| 038b3b3049 | |||
| 6b555c4d0d | |||
| 44d49bed62 | |||
| 517b130db6 | |||
| 0ff435b9bd | |||
| 56bc372140 | |||
| 0068b6d87d | |||
| 4679804774 | |||
| d03f74087c | |||
| e3a088ccaf | |||
| 5865fedbe7 | |||
| 68390aa26c | |||
| 744e5203cb | |||
| 7df7af3f47 | |||
| bf40cd1249 | |||
| f3cb5adb22 | |||
| c8d44199c2 | |||
| 12bcc0009b | |||
| be1ea81f82 | |||
| 668df46ec3 | |||
| 43905695e0 | |||
| 4a49becea1 | |||
| c91d3a24b9 | |||
| d6a4984b84 | |||
| f1dae06746 | |||
| 3cf3bcf2c8 | |||
| aa6e19ebaa | |||
| 24a26fd530 | |||
| a5f91bc14f | |||
| d7034c72c9 | |||
| c0437b152f | |||
| b72b2c6619 | |||
| c516631360 | |||
| 5cc8d7c094 | |||
| 5f4764060c | |||
| 44832008a8 | |||
| d86e737493 | |||
| 07a1e3101b | |||
| 1ebfe49916 | |||
| b1d6f8d652 | |||
| 8f0edf90e6 | |||
| 7c77389550 | |||
| 637731a4d7 | |||
| 6fc98a025b | |||
| f123cbcce3 | |||
| 11f166525e | |||
| 68db498dfd | |||
| f914afcc53 | |||
| 8dcf75f3fb | |||
| 3d9e091882 | |||
| a9ca4b3272 | |||
| a722b04226 | |||
| 9a1110a56e | |||
| 707122013f | |||
| f9ed5edf89 | |||
| dbf6766897 | |||
| a60c594505 | |||
| 2d0e6c0d3f | |||
| 63e7461995 | |||
| d2491ae6b7 | |||
| 35798a7916 | |||
| f7000b51a7 | |||
| 7e36939392 | |||
| afec51b296 | |||
| 66faaab294 | |||
| 7be2a5a507 | |||
| 8cf26de5e2 | |||
| 016611ba52 | |||
| 73d1011e8a | |||
| f2a11a5894 | |||
| c6043d4428 | |||
| c37ba28ad3 | |||
| 53f810fc54 | |||
| a55875ae1e | |||
| 707a634823 | |||
| b511fa872a | |||
| 4a2e7d9a9e | |||
| e4d5de2c0e | |||
| 50dca2e2c0 | |||
| 893303c27f | |||
| b543392c62 | |||
| adf52c756e | |||
| 693cc5a951 | |||
| ff9ba7fbf1 | |||
| c2b87959a2 | |||
| 18ee7776ef | |||
| c99efda67a | |||
| d65f970255 | |||
| f5442a8a89 | |||
| e347ea36ce | |||
| f0651dabf0 | |||
| ccf85c1c0f | |||
| 6ea35bf55c | |||
| f6afde346a | |||
| ce4074bcce | |||
| 5697b58aa2 | |||
| d5e6301211 | |||
| 9048082cb7 | |||
| 63526226be | |||
| fb07785b0e | |||
| 91638382d3 | |||
| 56e46466b2 | |||
| fa9731ab57 | |||
| c2ba46ce85 | |||
| 4c5780f1d6 | |||
| 0419611a62 | |||
| bcc1011ddd | |||
| 91a4fe1e52 | |||
| 21fed8a81e | |||
| f2fc63c24f | |||
| 521608fa15 | |||
| e16ad4e53d | |||
| 7205e383c8 | |||
| 9bf317b3e0 | |||
| ac668a41c5 | |||
| 606f4255dc | |||
| 22a64dd932 | |||
| dd3255779f | |||
| 89c7e63ab8 | |||
| 447c604fe9 | |||
| dff9602852 | |||
| f4d7915dd6 | |||
| 01204d544e | |||
| a06aa8c8b3 | |||
| 7977427038 | |||
| 0b8d0ed10a | |||
| efec141039 | |||
| 6736555ff3 | |||
| d94fe30a3e | |||
| 3079320534 | |||
| 4f3af51e54 | |||
| d19c81c944 | |||
| bc3cbbbb82 | |||
| 8ee3ddc925 | |||
| 173c05dbf3 | |||
| b13c548c4d | |||
| ef8237adfd | |||
| c80379da31 | |||
| a54c43c0c2 | |||
| 5e524aa148 | |||
| e84ee9e01b | |||
| 27ceb1e6c6 | |||
| 508b0d913c | |||
| 5999b070dc | |||
| 3ed13f3975 | |||
| 1789f7c9fd | |||
| a05ea11dd7 | |||
| c6dd46a004 | |||
| bf04979c31 | |||
| e9274b7303 | |||
| 03022c5b45 | |||
| ce4ccdd5b0 | |||
| 07eba65458 | |||
| 072b082240 | |||
| c664bc4ee9 | |||
| f113d7eeb1 | |||
| 9409bf0785 | |||
| d51e724130 | |||
| 9489b4dcde | |||
| d9c139a42b | |||
| 534f1d8284 | |||
| f177af8791 | |||
| 0b1a100be7 | |||
| 3932aeabed | |||
| be1dd93627 | |||
| fd75d3ce17 | |||
| eac69c683d | |||
| 4351de8ec7 | |||
| 4c4092634a | |||
| efac4d4a66 | |||
| 1afb1db3d5 | |||
| 6b63d8298c | |||
| c76d93966f | |||
| a74fef732e | |||
| 06a692326e | |||
| cc73e6b42b | |||
| 7b926f1e11 | |||
| bbb81f9bf1 | |||
| 2b19d96646 | |||
| bfae48f32f | |||
| a2a9fb3d25 | |||
| 5b9d4a7eb2 | |||
| 0f9144bb12 | |||
| 76dde2fac8 | |||
| 75f44a79d3 | |||
| d874ba0096 | |||
| 7495ae9c15 | |||
| ee5c892e2d | |||
| c464e658fc | |||
| 575b68a8cf | |||
| dcf0b500ec | |||
| e76f06fbd7 | |||
| dcac8cbbde | |||
| 497a7dc98f | |||
| a3db74a449 | |||
| 7d74726b07 | |||
| 36169cbaa8 | |||
| 1dcc0cb3b9 | |||
| 69cc5de02a | |||
| a2cacd983e | |||
| be1616d6b6 | |||
| d9a79e20d7 | |||
| 6aa80c4a8c | |||
| 8bf38e39ac | |||
| 35017c341d | |||
| 2f91bdd1b8 | |||
| f5c6fe76d3 | |||
| e1d6bac33a | |||
| 49084614cd | |||
| e5b8628760 | |||
| f0dbf0f9a0 | |||
| 072ba012ab | |||
| 01f7f18cd4 | |||
| e6511a5b69 | |||
| 43b9f31aa6 | |||
| eb5b4f42c7 | |||
| 12f5528d90 | |||
| ae58966ef0 | |||
| a0e22c1304 | |||
| 3fc916e8da | |||
| 084e9cfca2 | |||
| d943bf26cc | |||
| 1983f170d3 | |||
| 22a3608238 | |||
| 40c4a37e4a | |||
| 03d0068038 | |||
| d8771a877b | |||
| 1e2ac3e23c | |||
| 459c7cd233 | |||
| c0241a84be | |||
| 0df40f97ea | |||
| b7aa93e628 | |||
| d47ec1820a | |||
| 3952663302 | |||
| 9e39adddcc | |||
| f79fb213f1 | |||
| c236f2902e | |||
| 96368f871c | |||
| 5831c7f651 | |||
| 52706402a2 | |||
| 90be38c240 | |||
| 19f75a0646 | |||
| 4fd38856fd | |||
| 593ad9559f | |||
| 8d06c0afcb | |||
| 4b3b44d828 | |||
| bb9d73610e | |||
| 8468c87170 | |||
| 976dfc9276 | |||
| da7cc3e65d | |||
| 3d7ea8715a | |||
| 487467cbed | |||
| cb71e3fb35 | |||
| 5749ad8db2 | |||
| f3d03c6011 | |||
| 16b1a90cb1 | |||
| a29d98eb10 | |||
| 82cb492bb7 | |||
| 6fde4de187 | |||
| ad073bb2f8 | |||
| 827b315bff | |||
| 855dfb4736 | |||
| 50eeaf0db4 | |||
| 8d3afb7ad0 | |||
| 830fa87e27 | |||
| 4d8a893326 | |||
| 7f371699b1 | |||
| 76a2bfd9f9 | |||
| 9c88f86e80 | |||
| 4d4951f184 | |||
| 251f48ee1e | |||
| bdca343550 | |||
| dcc7bdfcae | |||
| 469a8c087b | |||
| 61a8490d4f | |||
| 4fa2049adc | |||
| 060f28e404 | |||
| 82bc0e6496 | |||
| beaab91223 | |||
| 49953199d4 | |||
| 9c7b39bd5a | |||
| c2f653bbde | |||
| d3d3121d51 | |||
| ebd252f42c | |||
| 586d7767b4 | |||
| ea8b0c0fa3 | |||
| 055f548056 | |||
| 78752275fd | |||
| c26a17f29e | |||
| 61d64e909b | |||
| 21d1fd962f | |||
| 4eff2e7d89 | |||
| 2b6b48720e | |||
| 4f26ff64c6 | |||
| d23e139272 | |||
| e6ec9acc96 | |||
| 9d54ec748a | |||
| 8d2cbca12f | |||
| 20c51ea577 | |||
| 23f2837c66 | |||
| 9faf540f8c | |||
| 5bb8719e00 | |||
| 2bb01fbfff | |||
| 66ab02199b | |||
| d77be1fcbd | |||
| e729afdd05 | |||
| e88c2e9c68 | |||
| 63b7641c47 | |||
| 54f501c82b | |||
| c291b1059c | |||
| ee0a167708 | |||
| f76c611033 | |||
| 7d1c3a994d | |||
| 42b7c8353e | |||
| 584dd720de | |||
| aa5d6fce47 | |||
| 32c64daa4d | |||
| 1b1d07ebc5 | |||
| 55734a1458 | |||
| 43875b06bf | |||
| 97ba0da3c2 | |||
| 8147608d3b | |||
| 9213143e14 | |||
| f1a9a84777 | |||
| 75046b80c6 | |||
| 69caf53646 | |||
| 6f69350183 | |||
| 2e75037b4e | |||
| bba6473b95 | |||
| 2aaa32449a | |||
| 1a44d6d415 | |||
| 7a3025c548 | |||
| cdd816ef35 | |||
| f69097b209 | |||
| 9896be023e | |||
| 1d99c8f58e | |||
| 835e10ed4b | |||
| e4439bfc3e | |||
| 5ad77a855b | |||
| 5933aa83ad | |||
| 78bd037486 | |||
| 17beef45f4 | |||
| 37f49af588 | |||
| f86c09b19d | |||
| b11a1be481 | |||
| a3e140981d | |||
| 3112be387e | |||
| 383d7c27c0 | |||
| 7190725726 | |||
| 065da92d65 | |||
| 5c877cf902 | |||
| 726808813a | |||
| 7af4c16b35 | |||
| e7fc9bb8c2 | |||
| baf429a0d0 | |||
| 00b2d948dc | |||
| 81258cc717 | |||
| 9db426ffe5 | |||
| a6ee7d28d0 | |||
| 7a50b8fda2 | |||
| 5f7f8d66d5 | |||
| d514acf32e | |||
| d3df1499d2 | |||
| f7682b12ae | |||
| 8c2d62d917 | |||
| f0d9c54038 | |||
| fbe5b1de37 | |||
| dccfbb2edf | |||
| 0f2b5305e3 | |||
| c69a7c92a5 | |||
| 6fa3aab99c | |||
| 02f4777058 | |||
| e0386f7cf9 | |||
| 0521f20413 | |||
| 61b5746ddf | |||
| 57d823acb1 | |||
| 4d99e2e406 | |||
| bec48ed834 | |||
| e856f5bcb1 | |||
| c57a710bca | |||
| 248e9213a1 | |||
| a035adcbd9 | |||
| 7fd1b65fec | |||
| 8ee0aa45b9 | |||
| dfcf244dc8 | |||
| 0563795494 | |||
| b6b6e80ffb | |||
| bd3b91d02f | |||
| 555f8d43cd | |||
| 3f48a8d492 | |||
| bb921e7eff | |||
| 13d5e6fa94 | |||
| cbfcf5de96 | |||
| 4771d96819 | |||
| d2aa6f0653 | |||
| cf2a00a374 | |||
| bdfb75dc84 | |||
| 66cbb64039 | |||
| 879ee1f750 | |||
| 90449fff3a | |||
| 893c6306f2 | |||
| aa3806f1dd | |||
| 4000117811 | |||
| 3319e6428a | |||
| 9e21ca625c | |||
| 02def07f23 | |||
| fc4dac6c4b | |||
| 486a09f3b2 | |||
| 9a22fc854b | |||
| ac4d5561a2 | |||
| 98cdda06c4 | |||
| 744fccf913 | |||
| 349ff5d61d | |||
| dbba22df23 | |||
| 2ddd822b24 | |||
| 6b4d6baf4b | |||
| 2c8d151cc7 | |||
| 60c7c025a3 | |||
| 7aaf5243cb | |||
| 44b0f4d53d | |||
| 70b63636e3 | |||
| 8d4582e379 | |||
| a1ec2cf366 | |||
| 4907e9d3c8 | |||
| 88f3d6da59 | |||
| 481b111cb2 | |||
| a1e13f3315 | |||
| d1dd289c77 | |||
| 7b4e40c4e4 | |||
| 6d4cad2215 | |||
| f43a4471ef | |||
| 0cf90e86c7 | |||
| 406de99b01 | |||
| f4bcb15d33 | |||
| d2a0164738 | |||
| a49ef4cc13 | |||
| 3ca29cd402 | |||
| c398b30e33 | |||
| 8caea9fab0 | |||
| f44c62540c | |||
| 7644db80e3 | |||
| 880497cd01 | |||
| 34f8174d9d | |||
| 99bc9d3fdf | |||
| 165c292ab8 | |||
| 8fe41cd8e6 | |||
| 705ea097e2 | |||
| f4799bebb4 | |||
| 4ffa524de0 | |||
| cd055317e0 | |||
| b1941c5980 | |||
| 83bc0fed5e | |||
| 5620f49f8f | |||
| d9fefef834 | |||
| 37591d847c | |||
| 77290d88f3 | |||
| 6befd87761 | |||
| f3e270c1ad | |||
| f5f1e4b391 | |||
| 8ba389d02f | |||
| 45910ff1f3 | |||
| 7ec969f4d9 | |||
| c7e13ef8a8 | |||
| 3d488f89b2 | |||
| cc00af1510 | |||
| f8aa55143c | |||
| 1b44c04893 | |||
| 1a51759154 | |||
| 8807328180 | |||
| ca49e5bdda |
6
.github/workflows/lint-php.yml
vendored
@ -22,8 +22,8 @@ jobs:
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
php-version: '8.2'
|
||||
tools: cs2pr, phpcs
|
||||
|
||||
- name: Run phpcs
|
||||
run: phpcs -q --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml --ignore=node_modules,bower_components,vendor ./
|
||||
- name: Lint
|
||||
run: phpcs src index.php
|
||||
|
||||
5
.gitignore
vendored
@ -22,8 +22,3 @@
|
||||
/web/documentserver-example/csharp/packages
|
||||
/web/documentserver-example/csharp-mvc/packages
|
||||
/web/documentserver-example/java-spring/documents/
|
||||
/web/documentserver-example/ruby/.bundle
|
||||
/web/documentserver-example/ruby/db/*.sqlite3
|
||||
/web/documentserver-example/ruby/db/*.sqlite3-journal
|
||||
/web/documentserver-example/ruby/log/*
|
||||
/web/documentserver-example/ruby/tmp
|
||||
|
||||
56
.gitmodules
vendored
@ -1,19 +1,3 @@
|
||||
[submodule "web/documentserver-example/nodejs/public/assets"]
|
||||
path = web/documentserver-example/nodejs/public/assets
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/java/src/main/resources/assets"]
|
||||
path = web/documentserver-example/java/src/main/resources/assets
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/php/assets"]
|
||||
path = web/documentserver-example/php/assets
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/python/assets"]
|
||||
path = web/documentserver-example/python/assets
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/csharp-mvc/assets"]
|
||||
path = web/documentserver-example/csharp-mvc/assets
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
@ -22,11 +6,43 @@
|
||||
path = web/documentserver-example/csharp/assets
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/ruby/public/assets"]
|
||||
path = web/documentserver-example/ruby/public/assets
|
||||
[submodule "web/documentserver-example/nodejs/public/assets/document-templates"]
|
||||
path = web/documentserver-example/nodejs/public/assets/document-templates
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/java-spring/src/main/resources/assets"]
|
||||
path = web/documentserver-example/java-spring/src/main/resources/assets
|
||||
[submodule "web/documentserver-example/nodejs/public/assets/document-formats"]
|
||||
path = web/documentserver-example/nodejs/public/assets/document-formats
|
||||
url = https://github.com/ONLYOFFICE/document-formats
|
||||
branch = master
|
||||
[submodule "web/documentserver-example/php/assets/document-templates"]
|
||||
path = web/documentserver-example/php/assets/document-templates
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/php/assets/document-formats"]
|
||||
path = web/documentserver-example/php/assets/document-formats
|
||||
url = https://github.com/ONLYOFFICE/document-formats
|
||||
branch = master
|
||||
[submodule "web/documentserver-example/python/assets/document-templates"]
|
||||
path = web/documentserver-example/python/assets/document-templates
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/java/src/main/resources/assets/document-templates"]
|
||||
path = web/documentserver-example/java/src/main/resources/assets/document-templates
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/ruby/assets/document-templates"]
|
||||
path = web/documentserver-example/ruby/assets/document-templates
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/java-spring/src/main/resources/assets/document-templates"]
|
||||
path = web/documentserver-example/java-spring/src/main/resources/assets/document-templates
|
||||
url = https://github.com/ONLYOFFICE/document-templates
|
||||
branch = main/en
|
||||
[submodule "web/documentserver-example/python/assets/document-formats"]
|
||||
path = web/documentserver-example/python/assets/document-formats
|
||||
url = https://github.com/ONLYOFFICE/document-formats
|
||||
branch = master
|
||||
[submodule "web/documentserver-example/ruby/assets/document-formats"]
|
||||
path = web/documentserver-example/ruby/assets/document-formats
|
||||
url = https://github.com/ONLYOFFICE/document-formats
|
||||
branch = master
|
||||
|
||||
@ -3,10 +3,6 @@ Document Server integration example uses code from the following 3rd party proje
|
||||
|
||||
web/documentserver-example/csharp
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -19,14 +15,26 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JWT - JWT (JSON Web Token) Implementation for .NET (Public Domain) (https://github.com/jwt-dotnet/jwt/)
|
||||
License: MIT
|
||||
License File: JWT.license
|
||||
|
||||
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://github.com/JamesNK/Newtonsoft.Json)
|
||||
License: MIT
|
||||
License File: Newtonsoft.Json.license
|
||||
|
||||
|
||||
web/documentserver-example/csharp-mvc
|
||||
|
||||
@ -34,10 +42,6 @@ Entity Framework - Entity Framework is an object-relational mapper that enables
|
||||
License: MICROSOFT SOFTWARE SUPPLEMENTAL TERMS, MICROSOFT SOFTWARE LICENSE TERMS
|
||||
License File: EntityFramework.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -50,19 +54,27 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JWT - JWT (JSON Web Token) Implementation for .NET (Public Domain) (https://github.com/jwt-dotnet/jwt/)
|
||||
License: MIT
|
||||
License File: JWT.license
|
||||
|
||||
Microsoft.Web.Infrastructure - This package contains the Microsoft.Web.Infrastructure assembly that lets you dynamically register HTTP modules at run time. (https://www.microsoft.com/web/webpi/eula/aspnetmvc3update-eula.htm)
|
||||
License: MS-EULA License
|
||||
License File: Microsoft.Web.Infrastructure.license
|
||||
|
||||
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://licenses.nuget.org/MIT)
|
||||
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://github.com/JamesNK/Newtonsoft.Json)
|
||||
License: MIT
|
||||
License File: Newtonsoft.Json.license
|
||||
|
||||
@ -73,10 +85,6 @@ License File: WebGrease.license
|
||||
|
||||
web/documentserver-example/java
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -89,9 +97,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
@ -104,9 +116,17 @@ License File: prime-jwt.license
|
||||
|
||||
web/documentserver-example/java-spring
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: gson.license
|
||||
|
||||
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
|
||||
License: MPL 2.0 or EPL 1.0
|
||||
License File: h2database.license
|
||||
|
||||
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: jackson-databind.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
@ -120,14 +140,30 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
|
||||
License: Apache 2.0
|
||||
License File: JSON.simple.license
|
||||
|
||||
Project Lombok - Project Lombok is a java library that automatically plugs into your editor and build tools. (https://mvnrepository.com/artifact/org.projectlombok/lombok).
|
||||
License: MIT
|
||||
License File lombok.license
|
||||
|
||||
ModelMapper - ModelMapper is an intelligent object mapping library that automatically maps objects to each other. (https://github.com/modelmapper/modelmapper)
|
||||
License: Apache 2.0
|
||||
License File modelmapper.license
|
||||
|
||||
Prime JWT - is intended to be fast and easy to use. Prime JWT has a single external dependency on Jackson. (https://github.com/ws-apps/prime-jwt/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: prime-jwt.license
|
||||
@ -148,22 +184,6 @@ Spring Data JPA - Persist data in SQL stores with Java Persistence API using Spr
|
||||
License: Apache 2.0
|
||||
License File: spring-data-jpa.license
|
||||
|
||||
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
|
||||
License: MPL 2.0 or EPL 1.0
|
||||
License File: h2database.license
|
||||
|
||||
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
|
||||
License: Apache 2.0
|
||||
License File: JSON.simple.license
|
||||
|
||||
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: gson.license
|
||||
|
||||
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: jackson-databind.license
|
||||
|
||||
|
||||
web/documentserver-example/nodejs
|
||||
|
||||
@ -199,10 +219,6 @@ he - a robust HTML entity encoder/decoder written in JavaScript. (htt
|
||||
License: MIT
|
||||
License File: he.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -215,9 +231,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
@ -248,11 +268,8 @@ License: MIT
|
||||
License File: urllib.license
|
||||
|
||||
|
||||
web/documentserver-example/php
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
web/documentserver-example/php
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
@ -266,24 +283,52 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JWT - JSON Web Token implementation (https://github.com/firebase/php-jwt/blob/master/LICENSE)
|
||||
License: BSD-3-Clause
|
||||
License File: jwt.license
|
||||
|
||||
PHP_CodeSniffer - PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent. (https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt)
|
||||
License: BSD-3-Clause
|
||||
License File: PHP_CodeSniffer.license
|
||||
|
||||
PHPUnit - The PHP Unit Testing framework. (https://github.com/sebastianbergmann/phpunit/blob/main/LICENSE)
|
||||
License: BSD 3-Clause
|
||||
License File: phpunit.license
|
||||
|
||||
property-access - Provides functions to read and write from/to an object or array using a simple string notation. (https://github.com/symfony/property-access/blob/6.3/LICENSE)
|
||||
License: MIT
|
||||
License File: property-access.license
|
||||
|
||||
serializer - Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON. (https://github.com/symfony/serializer/blob/6.3/LICENSE)
|
||||
License: MIT
|
||||
License File: serializer.license
|
||||
|
||||
|
||||
web/documentserver-example/python
|
||||
|
||||
django-stubs - PEP-484 stubs for Django. (https://github.com/typeddjango/django-stubs/blob/master/LICENSE.md)
|
||||
License: MIT
|
||||
License File: django-stubs.license
|
||||
|
||||
Django - Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Thanks for checking it out. (https://github.com/django/django/blob/main/LICENSE)
|
||||
License: BSD-3-Clause
|
||||
License File: Django.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
flake8 - flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code. (https://github.com/PyCQA/flake8/blob/main/LICENSE)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
License File: flake8.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
@ -297,14 +342,26 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
msgspec - A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML. (https://github.com/jcrist/msgspec/blob/0.18.1/LICENSE)
|
||||
License: BSD 3-Clause
|
||||
License File: msgspec.license
|
||||
|
||||
mypy - Optional static typing for Python. (https://github.com/python/mypy/blob/master/LICENSE)
|
||||
License: MIT
|
||||
License File: mypy.license
|
||||
|
||||
PyJWT - A Python implementation of RFC 7519. (https://github.com/jpadilla/pyjwt/blob/master/LICENSE)
|
||||
License: MIT
|
||||
License File: PyJWT.license
|
||||
@ -317,6 +374,10 @@ requests - Requests allows you to send HTTP/1.1 requests extremely easily.
|
||||
License: Apache 2.0
|
||||
License File: requests.license
|
||||
|
||||
typeshed - Collection of library stubs for Python, with static types. (https://github.com/python/typeshed/blob/main/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: typeshed.license
|
||||
|
||||
|
||||
web/documentserver-example/ruby
|
||||
|
||||
@ -328,14 +389,14 @@ coffee-rails - CoffeeScript adapter for the Rails asset pipeline. (https://gith
|
||||
License: MIT
|
||||
License File: coffee-rails.license
|
||||
|
||||
dalli - High performance memcached client for Ruby. (https://github.com/petergoldstein/dalli/blob/v3.2.0/LICENSE)
|
||||
License: MIT
|
||||
License File: dalli.license
|
||||
|
||||
jbuilder - Create JSON structures via a Builder-style DSL (https://github.com/rails/jbuilder/blob/master/MIT-LICENSE)
|
||||
License: MIT
|
||||
License File: jbuilder.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -348,9 +409,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
@ -360,10 +425,18 @@ jquery-rails - This gem provides jQuery and the jQuery-ujs driver for your Rail
|
||||
License: MIT
|
||||
License File: jquery-rails.license
|
||||
|
||||
mimemagic - А library to detect the mime type of a file by extension or by content. (https://github.com/mimemagicrb/mimemagic/blob/master/LICENSE)
|
||||
License: MIT
|
||||
License File: mimemagic.license
|
||||
|
||||
rails - Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern. (https://github.com/rails/rails/blob/v6.0.3.2/MIT-LICENSE)
|
||||
License: MIT
|
||||
License File: rails.license
|
||||
|
||||
rubocop - A Ruby static code analyzer and formatter, based on the community Ruby style guide. (https://github.com/rubocop/rubocop/blob/v1.52.0/LICENSE.txt)
|
||||
License: MIT
|
||||
License File: rubocop.license
|
||||
|
||||
sass-rails - This gem provides official integration for Ruby on Rails projects with the Sass stylesheet language. (https://github.com/rails/sass-rails/blob/master/MIT-LICENSE)
|
||||
License: MIT
|
||||
License File: sass-rails.license
|
||||
@ -372,9 +445,13 @@ sdoc - rdoc generator html with javascript search index. (https://githu
|
||||
License: MIT
|
||||
License File: sdoc.license
|
||||
|
||||
sqlite3 - This module allows Ruby programs to interface with the SQLite3 database engine (www.sqlite.org). (https://github.com/sparklemotion/sqlite3-ruby/blob/master/LICENSE)
|
||||
License: BSD-3-Clause
|
||||
License File: sqlite3.license
|
||||
sorbet - A fast, powerful type checker designed for Ruby. (https://github.com/sorbet/sorbet/blob/0.5.10871.20230607144259-d9000e2ba/LICENSE)
|
||||
License: Apache License 2.0
|
||||
License File: sorbet.license
|
||||
|
||||
tapioca - The swiss army knife of RBI generation. (https://github.com/Shopify/tapioca/blob/v0.11.6/LICENSE.txt)
|
||||
License: MIT
|
||||
License File: tapioca.license
|
||||
|
||||
turbolinks - Rails engine for Turbolinks 5 support (https://github.com/turbolinks/turbolinks-rails/blob/master/LICENSE)
|
||||
License: MIT
|
||||
|
||||
32
CHANGELOG.md
@ -1,5 +1,37 @@
|
||||
# Change Log
|
||||
|
||||
- nodejs: onRequestSelectDocument method
|
||||
- nodejs: onRequestSelectSpreadsheet method
|
||||
- nodejs: onRequestOpen
|
||||
- nodejs: submitForm
|
||||
- nodejs: key in referenceData
|
||||
- nodejs: change reference source
|
||||
- php: using a repo with a list of formats
|
||||
- nodejs: using a repo with a list of formats
|
||||
- nodejs: delete file without reloading the page
|
||||
- nodejs: getting history by a separate request
|
||||
- nodejs: restore from history
|
||||
- python: restore from history
|
||||
- ruby: restore from history
|
||||
- php: restore from history
|
||||
- csharp-mvc: getting history by a separate request
|
||||
- csharp-mvc: restore from history
|
||||
- csharp: getting history by a separate request
|
||||
- csharp: restore from history
|
||||
|
||||
## 1.6.0
|
||||
- nodejs: setUsers for region protection
|
||||
- si skin languages
|
||||
- fix "no" skin languages
|
||||
- anonymous can't change viewer to edit
|
||||
- referenceData
|
||||
- anonymous can't protect file
|
||||
- separate setting for checking the token in requests
|
||||
- php: linter refactoring
|
||||
- horizontal scroll fix for Internet Explorer
|
||||
- save file with extension from response after conversation
|
||||
- conversation to ooxml
|
||||
|
||||
## 1.5.1
|
||||
- update jquery
|
||||
|
||||
|
||||
@ -26,13 +26,13 @@
|
||||
<RemoveDir Directories="$(To)" ContinueOnError="true" />
|
||||
|
||||
<ItemGroup>
|
||||
<ZipFilesCSharp Include="$(DirCSharp)**" Exclude="$(DirCSharp)obj\**;$(DirCSharp)**\.git" />
|
||||
<ZipFilesCSharp Include="$(DirCSharp)**" Exclude="$(DirCSharp).vs\**;$(DirCSharp)bin\*.pdb;$(DirCSharp)bin\*.xml;$(DirCSharp)obj\**;$(DirCSharp)packages\**;$(DirCSharp)**\.git" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(ZipFilesCSharp)" DestinationFiles="@(ZipFilesCSharp->'$(NameCSharp)\%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<Zip Files="$(NameCSharp)" WorkingDirectory="$(To)" ZipFileName="$(NameCSharp).zip" />
|
||||
|
||||
<ItemGroup>
|
||||
<ZipFilesMVC Include="$(DirMvc)**" Exclude="$(DirMvc)obj\**;$(DirMvc)**\.git" />
|
||||
<ZipFilesMVC Include="$(DirMvc)**" Exclude="$(DirMvc).vs\**;$(DirMvc)bin\*.pdb;$(DirMvc)bin\*.xml;$(DirMvc)obj\**;$(DirMvc)packages\**;$(DirMvc)**\.git" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(ZipFilesMVC)" DestinationFiles="@(ZipFilesMVC->'$(NameMvc)\%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<Zip Files="$(NameMvc)" WorkingDirectory="$(To)" ZipFileName="$(NameMvc).zip" />
|
||||
|
||||
@ -4,10 +4,6 @@ Entity Framework - Entity Framework is an object-relational mapper that enables
|
||||
License: MICROSOFT SOFTWARE SUPPLEMENTAL TERMS, MICROSOFT SOFTWARE LICENSE TERMS
|
||||
License File: EntityFramework.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -20,9 +16,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
|
||||
@ -682,3 +682,8 @@
|
||||
max-width:15%;
|
||||
}
|
||||
}
|
||||
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
|
||||
.tableRow td:first-child{
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,6 +220,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
var fileName = GetCorrectName(demoName); // get a file name with an index if the file with such a name already exists
|
||||
|
||||
File.Copy(HttpRuntime.AppDomainAppPath + demoPath + demoName, StoragePath(fileName)); // copy file to the storage directory
|
||||
File.SetLastWriteTime(StoragePath(fileName), DateTime.Now);
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@ -68,24 +68,24 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
/// <param name="toExtension">Extension to which to convert</param>
|
||||
/// <param name="documentRevisionId">Key for caching on service</param>
|
||||
/// <param name="isAsync">Perform conversions asynchronously</param>
|
||||
/// <param name="convertedDocumentUri">Uri to the converted document</param>
|
||||
/// <param name="convertedDocumentData">Uri and file type of the converted document</param>
|
||||
/// <returns>The percentage of conversion completion</returns>
|
||||
/// <example>
|
||||
/// string convertedDocumentUri;
|
||||
/// GetConvertedUri("http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", ".pdf", ".docx", "http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", false, out convertedDocumentUri);
|
||||
/// Dictionary<string, string> convertedDocumentData;
|
||||
/// GetConvertedData("http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", ".pdf", ".docx", "http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", false, out convertedDocumentData);
|
||||
/// </example>
|
||||
/// <exception>
|
||||
/// </exception>
|
||||
public static int GetConvertedUri(string documentUri,
|
||||
public static int GetConvertedData(string documentUri,
|
||||
string fromExtension,
|
||||
string toExtension,
|
||||
string documentRevisionId,
|
||||
bool isAsync,
|
||||
out string convertedDocumentUri,
|
||||
out Dictionary<string, string> convertedDocumentData,
|
||||
string filePass = null,
|
||||
string lang = null)
|
||||
{
|
||||
convertedDocumentUri = string.Empty;
|
||||
convertedDocumentData = new Dictionary<string, string>();
|
||||
|
||||
// check if the fromExtension parameter is defined; if not, get it from the document url
|
||||
fromExtension = string.IsNullOrEmpty(fromExtension) ? Path.GetExtension(documentUri).ToLower() : fromExtension;
|
||||
@ -119,7 +119,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{ "region", lang }
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
// create payload object
|
||||
var payload = new Dictionary<string, object>
|
||||
@ -157,7 +157,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
return GetResponseUri(dataResponse, out convertedDocumentUri);
|
||||
return GetResponseData(dataResponse, out convertedDocumentData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -181,9 +181,9 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
/// Processing document received from the editing service
|
||||
/// </summary>
|
||||
/// <param name="jsonDocumentResponse">The resulting json from editing service</param>
|
||||
/// <param name="responseUri">Uri to the converted document</param>
|
||||
/// <param name="responseData">Uri and file type of the converted document</param>
|
||||
/// <returns>The percentage of conversion completion</returns>
|
||||
private static int GetResponseUri(string jsonDocumentResponse, out string responseUri)
|
||||
private static int GetResponseData(string jsonDocumentResponse, out Dictionary<string, string> responseData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonDocumentResponse)) throw new ArgumentException("Invalid param", "jsonDocumentResponse");
|
||||
|
||||
@ -197,14 +197,20 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
var isEndConvert = responseFromService.endConvert;
|
||||
|
||||
int resultPercent;
|
||||
responseUri = string.Empty;
|
||||
responseData = new Dictionary<string, string>();
|
||||
var responseUri = string.Empty;
|
||||
var responseFileType = string.Empty;
|
||||
if (isEndConvert) // if the conversion is completed
|
||||
{
|
||||
responseUri = responseFromService.fileUrl; // get the file url
|
||||
responseFileType = responseFromService.fileType; // get the file type
|
||||
responseData.Add("fileUrl", responseUri);
|
||||
responseData.Add("fileType", responseFileType);
|
||||
resultPercent = 100;
|
||||
}
|
||||
else // if the conversion isn't completed
|
||||
{
|
||||
responseData.Add("fileUrl", "");
|
||||
resultPercent = responseFromService.percent; // get the percentage value
|
||||
if (resultPercent >= 100) resultPercent = 99;
|
||||
}
|
||||
|
||||
@ -29,11 +29,13 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
{
|
||||
private static readonly string Secret;
|
||||
public static readonly bool Enabled;
|
||||
public static readonly bool SignatureUseForRequest;
|
||||
|
||||
static JwtManager()
|
||||
{
|
||||
Secret = WebConfigurationManager.AppSettings["files.docservice.secret"] ?? ""; // get token secret from the config parameters
|
||||
Enabled = !string.IsNullOrEmpty(Secret); // check if the token is enabled
|
||||
SignatureUseForRequest = bool.Parse(WebConfigurationManager.AppSettings["files.docservice.token.useforrequest"]);
|
||||
}
|
||||
|
||||
// encode a payload object into a token using a secret key
|
||||
|
||||
@ -53,7 +53,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
var fileData = jss.Deserialize<Dictionary<string, object>>(body);
|
||||
|
||||
// check if the document token is enabled
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
string JWTheader = string.IsNullOrEmpty(WebConfigurationManager.AppSettings["files.docservice.header"]) ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
@ -108,8 +108,9 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
try
|
||||
{
|
||||
// convert file and give url to a new file
|
||||
string newFileUri;
|
||||
var result = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), false, out newFileUri);
|
||||
Dictionary<string, string> newFileData;
|
||||
var result = ServiceConverter.GetConvertedData(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), false, out newFileData);
|
||||
var newFileUri = newFileData["fileUrl"];
|
||||
if (string.IsNullOrEmpty(newFileUri))
|
||||
{
|
||||
// get the correct file name if it already exists
|
||||
@ -128,37 +129,48 @@ 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);
|
||||
|
||||
var versionDir = DocManagerHelper.VersionDir(histDir, DocManagerHelper.GetFileVersion(histDir)); // get the path to the file version
|
||||
if (!Directory.Exists(versionDir)) Directory.CreateDirectory(versionDir); // if the path doesn't exist, create it
|
||||
|
||||
// get the path to the previous file version and move it to the storage directory
|
||||
File.Move(DocManagerHelper.StoragePath(fileName, userAddress), Path.Combine(versionDir, "prev" + curExt));
|
||||
|
||||
DownloadToFile(downloadUri, storagePath); // save file to the storage directory
|
||||
DownloadToFile((string)fileData["changesurl"], Path.Combine(versionDir, "diff.zip")); // save file changes to the diff.zip archive
|
||||
|
||||
var hist = fileData.ContainsKey("changeshistory") ? (string)fileData["changeshistory"] : null;
|
||||
if (string.IsNullOrEmpty(hist) && fileData.ContainsKey("history"))
|
||||
try
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
hist = jss.Serialize(fileData["history"]);
|
||||
}
|
||||
var bytesFile = DownloadFile(downloadUri); // download document file
|
||||
var storagePath = DocManagerHelper.StoragePath(newFileName, userAddress); // get the file path
|
||||
|
||||
if (!string.IsNullOrEmpty(hist))
|
||||
var histDir = DocManagerHelper.HistoryDir(storagePath); // get the path to the history directory
|
||||
if (!Directory.Exists(histDir)) Directory.CreateDirectory(histDir);
|
||||
|
||||
var versionDir = DocManagerHelper.VersionDir(histDir, DocManagerHelper.GetFileVersion(histDir)); // get the path to the file version
|
||||
if (!Directory.Exists(versionDir)) Directory.CreateDirectory(versionDir); // if the path doesn't exist, create it
|
||||
|
||||
// get the path to the previous file version and move it to the storage directory
|
||||
File.Move(DocManagerHelper.StoragePath(fileName, userAddress), Path.Combine(versionDir, "prev" + curExt));
|
||||
|
||||
SaveFile(bytesFile, storagePath);// save document file
|
||||
|
||||
byte[] bytesChanges = DownloadFile((string)fileData["changesurl"]); // download changes file
|
||||
SaveFile(bytesChanges, Path.Combine(versionDir, "diff.zip")); // save file changes to the diff.zip archive
|
||||
|
||||
var hist = fileData.ContainsKey("changeshistory") ? (string)fileData["changeshistory"] : null;
|
||||
if (string.IsNullOrEmpty(hist) && fileData.ContainsKey("history"))
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
hist = jss.Serialize(fileData["history"]);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(hist))
|
||||
{
|
||||
File.WriteAllText(Path.Combine(versionDir, "changes.json"), hist); // write the history changes to the changes.json file
|
||||
}
|
||||
|
||||
File.WriteAllText(Path.Combine(versionDir, "key.txt"), (string)fileData["key"]); // write the key value to the key.txt file
|
||||
|
||||
string forcesavePath = DocManagerHelper.ForcesavePath(newFileName, userAddress, false); // get the path to the forcesaved file version
|
||||
if (!forcesavePath.Equals("")) // if the forcesaved file version exists
|
||||
{
|
||||
File.Delete(forcesavePath); // remove it
|
||||
}
|
||||
|
||||
} catch (Exception)
|
||||
{
|
||||
File.WriteAllText(Path.Combine(versionDir, "changes.json"), hist); // write the history changes to the changes.json file
|
||||
}
|
||||
|
||||
File.WriteAllText(Path.Combine(versionDir, "key.txt"), (string)fileData["key"]); // write the key value to the key.txt file
|
||||
|
||||
string forcesavePath = DocManagerHelper.ForcesavePath(newFileName, userAddress, false); // get the path to the forcesaved file version
|
||||
if (!forcesavePath.Equals("")) // if the forcesaved file version exists
|
||||
{
|
||||
File.Delete(forcesavePath); // remove it
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -184,8 +196,9 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
try
|
||||
{
|
||||
// convert file and give url to a new file
|
||||
string newFileUri;
|
||||
var result = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), false, out newFileUri);
|
||||
Dictionary<string, string> newFileData;
|
||||
var result = ServiceConverter.GetConvertedData(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), false, out newFileData);
|
||||
var newFileUri = newFileData["fileUrl"];
|
||||
if (string.IsNullOrEmpty(newFileUri))
|
||||
{
|
||||
newFileName = true;
|
||||
@ -202,43 +215,51 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
|
||||
DocManagerHelper.VerifySSL();
|
||||
|
||||
string forcesavePath = "";
|
||||
Boolean isSubmitForm = fileData["forcesavetype"].ToString().Equals("3"); // SubmitForm
|
||||
|
||||
if (isSubmitForm) // if the form is submitted
|
||||
try
|
||||
{
|
||||
if (newFileName)
|
||||
var bytesFile = DownloadFile(downloadUri); // download document file
|
||||
|
||||
string forcesavePath = "";
|
||||
Boolean isSubmitForm = fileData["forcesavetype"].ToString().Equals("3"); // SubmitForm
|
||||
|
||||
if (isSubmitForm) // if the form is submitted
|
||||
{
|
||||
fileName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "-form" + downloadExt, userAddress); // get the correct file name if it already exists
|
||||
if (newFileName)
|
||||
{
|
||||
fileName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "-form" + downloadExt, userAddress); // get the correct file name if it already exists
|
||||
} else
|
||||
{
|
||||
fileName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "-form" + curExt, userAddress);
|
||||
{
|
||||
fileName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "-form" + curExt, userAddress);
|
||||
}
|
||||
forcesavePath = DocManagerHelper.StoragePath(fileName, userAddress);
|
||||
}
|
||||
forcesavePath = DocManagerHelper.StoragePath(fileName, userAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newFileName)
|
||||
else
|
||||
{
|
||||
fileName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + downloadExt, userAddress);
|
||||
}
|
||||
forcesavePath = DocManagerHelper.ForcesavePath(fileName, userAddress, false);
|
||||
if (newFileName)
|
||||
{
|
||||
fileName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + downloadExt, userAddress);
|
||||
}
|
||||
forcesavePath = DocManagerHelper.ForcesavePath(fileName, userAddress, false);
|
||||
if (string.IsNullOrEmpty(forcesavePath)) // create forcesave path if it doesn't exist
|
||||
{
|
||||
forcesavePath = DocManagerHelper.ForcesavePath(fileName, userAddress, true);
|
||||
{
|
||||
forcesavePath = DocManagerHelper.ForcesavePath(fileName, userAddress, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DownloadToFile(downloadUri, forcesavePath);
|
||||
SaveFile(bytesFile, forcesavePath);// save document file
|
||||
|
||||
if (isSubmitForm)
|
||||
if (isSubmitForm)
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
var actions = jss.Deserialize<List<object>>(jss.Serialize(fileData["actions"]));
|
||||
var action = jss.Deserialize<Dictionary<string, object>>(jss.Serialize(actions[0]));
|
||||
var user = action["userid"].ToString(); // get the user id
|
||||
DocManagerHelper.CreateMeta(fileName, user, "Filling Form", userAddress); // create meta data for the forcesaved file
|
||||
}
|
||||
} catch (Exception)
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
var actions = jss.Deserialize<List<object>>(jss.Serialize(fileData["actions"]));
|
||||
var action = jss.Deserialize<Dictionary<string, object>>(jss.Serialize(actions[0]));
|
||||
var user = action["userid"].ToString(); // get the user id
|
||||
DocManagerHelper.CreateMeta(fileName, user, "Filling Form", userAddress); // create meta data for the forcesaved file
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -266,7 +287,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
|
||||
// check if a secret key to generate token exists or not
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
var payload = new Dictionary<string, object>
|
||||
{
|
||||
@ -310,27 +331,30 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
// save file
|
||||
private static void SaveFile(byte[] data, string path)
|
||||
{
|
||||
using (var fs = File.Open(path, FileMode.Create))
|
||||
{
|
||||
fs.Write(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
|
||||
// save file information from the url to the file specified
|
||||
private static void DownloadToFile(string url, string path)
|
||||
private static byte[] DownloadFile(string url)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url)) throw new ArgumentException("url"); // url isn't specified
|
||||
if (string.IsNullOrEmpty(path)) throw new ArgumentException("path"); // file isn't specified
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Timeout = 5000;
|
||||
using (var stream = req.GetResponse().GetResponseStream()) // get input stream of the file information from the url
|
||||
{
|
||||
if (stream == null) throw new Exception("stream is null");
|
||||
const int bufferSize = 4096;
|
||||
|
||||
using (var fs = File.Open(path, FileMode.Create))
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
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
|
||||
}
|
||||
stream.CopyTo(memoryStream);
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +69,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor",
|
||||
"Can't view chat",
|
||||
"Can't protect file",
|
||||
"View file without collaboration",
|
||||
};
|
||||
|
||||
@ -131,7 +132,7 @@ namespace OnlineEditorsExampleMVC.Helpers
|
||||
new Dictionary<string,object>(),
|
||||
new List<string>(),
|
||||
null,
|
||||
new List<string>(),
|
||||
new List<string>() { "protect" },
|
||||
descr_user_0,
|
||||
false
|
||||
)
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
@ -138,6 +137,17 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
{ "favorite", favorite}
|
||||
}
|
||||
},
|
||||
{
|
||||
"referenceData", new Dictionary<string, string>()
|
||||
{
|
||||
{ "fileKey", !user.id.Equals("uid-0") ?
|
||||
jss.Serialize(new Dictionary<string, object>{
|
||||
{"fileName", FileName},
|
||||
{"userAddress", HttpUtility.UrlEncode(DocManagerHelper.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
|
||||
}) : null },
|
||||
{"instanceId", DocManagerHelper.GetServerUrl(false) }
|
||||
}
|
||||
},
|
||||
{
|
||||
// the permission for the document to be edited and downloaded or not
|
||||
"permissions", new Dictionary<string, object>
|
||||
@ -154,7 +164,8 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
{ "chat", !user.id.Equals("uid-0") },
|
||||
{ "reviewGroups", user.reviewGroups },
|
||||
{ "commentGroups", user.commentGroups },
|
||||
{ "userInfoGroups", user.userInfoGroups }
|
||||
{ "userInfoGroups", user.userInfoGroups },
|
||||
{ "protect", !user.deniedPermissions.Contains("protect") }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -224,123 +235,6 @@ namespace OnlineEditorsExampleMVC.Models
|
||||
return jss.Serialize(config);
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
||||
history = null;
|
||||
historyData = null;
|
||||
|
||||
if (DocManagerHelper.GetFileVersion(histDir) > 0) // if the file was modified (the file version is greater than 0)
|
||||
{
|
||||
var currentVersion = DocManagerHelper.GetFileVersion(histDir);
|
||||
var hist = new List<Dictionary<string, object>>();
|
||||
var histData = new Dictionary<string, object>();
|
||||
|
||||
for (var i = 1; i <= currentVersion; i++) // run through all the file versions
|
||||
{
|
||||
var obj = new Dictionary<string, object>();
|
||||
var dataObj = new Dictionary<string, object>();
|
||||
var verDir = DocManagerHelper.VersionDir(histDir, i); // get the path to the given file version
|
||||
|
||||
var key = i == currentVersion ? Key : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key
|
||||
|
||||
obj.Add("key", key);
|
||||
obj.Add("version", i);
|
||||
|
||||
if (i == 1) // check if the version number is equal to 1
|
||||
{
|
||||
var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file
|
||||
|
||||
if (File.Exists(infoPath))
|
||||
{
|
||||
var info = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(infoPath));
|
||||
obj.Add("created", info["created"]); // write meta information to the object (user information and creation date)
|
||||
obj.Add("user", new Dictionary<string, object>() {
|
||||
{ "id", info["id"] },
|
||||
{ "name", info["name"] },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var ext = Path.GetExtension(FileName).ToLower();
|
||||
dataObj.Add("fileType", ext.Replace(".", ""));
|
||||
dataObj.Add("key", key);
|
||||
// write file url to the data object
|
||||
string prevFileUrl;
|
||||
string directPrevFileUrl;
|
||||
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 + "\\", ""));
|
||||
directPrevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext, false)
|
||||
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
|
||||
}
|
||||
else {
|
||||
prevFileUrl = i == currentVersion ? FileUri
|
||||
: DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext);
|
||||
directPrevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext, false)
|
||||
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
|
||||
}
|
||||
|
||||
dataObj.Add("url", prevFileUrl);
|
||||
if (IsEnabledDirectUrl)
|
||||
{
|
||||
dataObj.Add("directUrl", directPrevFileUrl);
|
||||
}
|
||||
dataObj.Add("version", i);
|
||||
if (i > 1) // check if the version number is greater than 1 (the file was modified)
|
||||
{
|
||||
// get the path to the changes.json file
|
||||
var changes = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "changes.json")));
|
||||
var changesArray = (ArrayList)changes["changes"];
|
||||
var change = changesArray.Count > 0
|
||||
? (Dictionary<string, object>)changesArray[0]
|
||||
: new Dictionary<string, object>();
|
||||
|
||||
// write information about changes to the object
|
||||
obj.Add("changes", change.Count > 0 ? changes["changes"] : null);
|
||||
obj.Add("serverVersion", changes["serverVersion"]);
|
||||
obj.Add("created", change.Count > 0 ? change["created"] : null);
|
||||
obj.Add("user", change.Count > 0 ? change["user"] : null);
|
||||
|
||||
var prev = (Dictionary<string, object>)histData[(i - 2).ToString()]; // get the history data from the previous file version
|
||||
dataObj.Add("previous", IsEnabledDirectUrl ? new Dictionary<string, object>() { // write information about previous file version to the data object with direct url
|
||||
{ "fileType", prev["fileType"] },
|
||||
{ "key", prev["key"] }, // write key and url information about previous file version
|
||||
{ "url", prev["url"] },
|
||||
{ "directUrl", prev["directUrl"] },
|
||||
} : new Dictionary<string, object>() { // write information about previous file version to the data object without direct url
|
||||
{ "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
|
||||
var changesUrl = DocManagerHelper.GetHistoryDownloadUrl(FileName, (i - 1).ToString(), "diff.zip");
|
||||
dataObj.Add("changesUrl", changesUrl);
|
||||
}
|
||||
if(JwtManager.Enabled)
|
||||
{
|
||||
var token = JwtManager.Encode(dataObj);
|
||||
dataObj.Add("token", token);
|
||||
}
|
||||
hist.Add(obj); // add object dictionary to the hist list
|
||||
histData.Add((i - 1).ToString(), dataObj); // write data object information to the history data
|
||||
}
|
||||
|
||||
// write history information about the current file version to the history object
|
||||
history = jss.Serialize(new Dictionary<string, object>()
|
||||
{
|
||||
{ "currentVersion", currentVersion },
|
||||
{ "history", hist }
|
||||
});
|
||||
historyData = jss.Serialize(histData);
|
||||
}
|
||||
}
|
||||
|
||||
// get a document which will be compared with the current document
|
||||
public void GetCompareFileData(out string compareConfig)
|
||||
{
|
||||
|
||||
@ -236,6 +236,7 @@ if (typeof jQuery != "undefined") {
|
||||
window.open(url, "_blank");
|
||||
jq('#hiddenFileName').val("");
|
||||
jq.unblockUI();
|
||||
document.location.reload();
|
||||
});
|
||||
|
||||
jq(document).on("click", "#beginView:not(.disable)", function () {
|
||||
@ -244,6 +245,7 @@ if (typeof jQuery != "undefined") {
|
||||
window.open(url, "_blank");
|
||||
jq('#hiddenFileName').val("");
|
||||
jq.unblockUI();
|
||||
document.location.reload();
|
||||
});
|
||||
|
||||
jq(document).on("click", "#beginEmbedded:not(.disable)", function () {
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
-->
|
||||
<link rel="icon" href="<%= "content/images/" + Model.DocumentType + ".ico" %>" type="image/x-icon" />
|
||||
<title><%= Model.FileName + " - ONLYOFFICE" %></title>
|
||||
|
||||
|
||||
<%: Styles.Render("~/Content/editor") %>
|
||||
|
||||
</head>
|
||||
@ -40,7 +40,7 @@
|
||||
<div id="iframeEditor">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<%: Scripts.Render(new []{ WebConfigurationManager.AppSettings["files.docservice.url.site"] + WebConfigurationManager.AppSettings["files.docservice.url.api"] }) %>
|
||||
|
||||
<script type="text/javascript" language="javascript">
|
||||
@ -141,7 +141,7 @@
|
||||
<% 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;
|
||||
@ -178,6 +178,59 @@
|
||||
}
|
||||
};
|
||||
|
||||
var onRequestReferenceData = function (event) { // user refresh external data source
|
||||
event.data.directUrl = !!config.document.directUrl;
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=reference");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(JSON.stringify(event.data));
|
||||
xhr.onload = function () {
|
||||
console.log(xhr.responseText);
|
||||
docEditor.setReferenceData(JSON.parse(xhr.responseText));
|
||||
}
|
||||
};
|
||||
|
||||
var onRequestHistory = function () {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "webeditor.ashx?type=gethistory&filename=<%= Model.FileName %>");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send();
|
||||
xhr.onload = function () {
|
||||
console.log(xhr.responseText);
|
||||
docEditor.refreshHistory(JSON.parse(xhr.responseText));
|
||||
}
|
||||
};
|
||||
|
||||
var onRequestHistoryData = function (event) {
|
||||
var ver = event.data;
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "webeditor.ashx?type=getversiondata&filename=<%= Model.FileName %>&version=" + ver + "&directUrl=" + !!config.document.directUrl);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send();
|
||||
xhr.onload = function () {
|
||||
console.log(xhr.responseText);
|
||||
docEditor.setHistoryData(JSON.parse(xhr.responseText)); // send the link to the document for viewing the version history
|
||||
}
|
||||
};
|
||||
|
||||
var onRequestRestore = function (event) {
|
||||
var fileName = "<%= Model.FileName %>";
|
||||
var version = event.data.version;
|
||||
var data = {
|
||||
fileName: fileName,
|
||||
version: version
|
||||
};
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=restore&directUrl=" + !!config.document.directUrl);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
docEditor.refreshHistory(JSON.parse(xhr.responseText));
|
||||
}
|
||||
}
|
||||
|
||||
config = <%= Model.GetDocConfig(Request, Url) %>;
|
||||
|
||||
config.width = "100%";
|
||||
@ -186,7 +239,6 @@
|
||||
config.events = {
|
||||
'onAppReady': onAppReady,
|
||||
'onDocumentStateChange': onDocumentStateChange,
|
||||
'onRequestEditRights': onRequestEditRights,
|
||||
'onError': onError,
|
||||
'onOutdatedVersion': onOutdatedVersion,
|
||||
"onMakeActionLink": onMakeActionLink,
|
||||
@ -196,30 +248,19 @@
|
||||
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
|
||||
};
|
||||
|
||||
<% string hist, histData; %>
|
||||
<% Model.GetHistory(out hist, out histData); %>
|
||||
|
||||
<% string usersForMentions; %>
|
||||
<% Model.GetUsersMentions(Request, out 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();
|
||||
};
|
||||
<% } %>
|
||||
// the user is trying to show the document version history
|
||||
config.events['onRequestHistory'] = onRequestHistory;
|
||||
// the user is trying to click the specific document version in the document version history
|
||||
config.events['onRequestHistoryData'] = onRequestHistoryData;
|
||||
// the user is trying to go back to the document from viewing the document version history
|
||||
config.events['onRequestHistoryClose'] = function () {
|
||||
document.location.reload();
|
||||
};
|
||||
config.events['onRequestRestore'] = onRequestRestore;
|
||||
|
||||
// add mentions for not anonymous users
|
||||
<% if (!string.IsNullOrEmpty(usersForMentions))
|
||||
@ -239,6 +280,9 @@
|
||||
};
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
config.events['onRequestReferenceData'] = onRequestReferenceData;
|
||||
// prevent switch the document from the viewing into the editing mode for anonymous users
|
||||
config.events['onRequestEditRights'] = onRequestEditRights;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@ -50,6 +51,15 @@ namespace OnlineEditorsExampleMVC
|
||||
case "downloadhistory":
|
||||
DownloadHistory(context);
|
||||
break;
|
||||
case "gethistory":
|
||||
GetHistory(context);
|
||||
break;
|
||||
case "getversiondata":
|
||||
GetVersionData(context);
|
||||
break;
|
||||
case "restore":
|
||||
Restore(context);
|
||||
break;
|
||||
case "convert":
|
||||
Convert(context);
|
||||
break;
|
||||
@ -74,6 +84,9 @@ namespace OnlineEditorsExampleMVC
|
||||
case "rename":
|
||||
Rename(context);
|
||||
break;
|
||||
case "reference":
|
||||
Reference(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,11 +240,10 @@ namespace OnlineEditorsExampleMVC
|
||||
var fileUri = DocManagerHelper.GetDownloadUrl(fileName);
|
||||
|
||||
var extension = (Path.GetExtension(fileName).ToLower() ?? "").Trim('.');
|
||||
var internalExtension = DocManagerHelper.GetInternalExtension(FileUtility.GetFileType(fileName)).Trim('.');
|
||||
var internalExtension = "ooxml";
|
||||
|
||||
// check if the file with such an extension can be converted
|
||||
if (DocManagerHelper.ConvertExts.Contains("." + extension)
|
||||
&& !string.IsNullOrEmpty(internalExtension))
|
||||
if (DocManagerHelper.ConvertExts.Contains("." + extension))
|
||||
{
|
||||
// generate document key
|
||||
var key = ServiceConverter.GenerateRevisionId(fileUri);
|
||||
@ -244,17 +256,19 @@ namespace OnlineEditorsExampleMVC
|
||||
Query = "type=download&fileName=" + HttpUtility.UrlEncode(fileName)
|
||||
};
|
||||
|
||||
// get the url to the converted file
|
||||
string newFileUri;
|
||||
var result = ServiceConverter.GetConvertedUri(downloadUri.ToString(), extension, internalExtension, key, true, out newFileUri, filePass, lang);
|
||||
// get the url and file type of the converted file
|
||||
Dictionary<string, string> newFileData;
|
||||
var result = ServiceConverter.GetConvertedData(downloadUri.ToString(), extension, internalExtension, key, true, out newFileData, filePass, lang);
|
||||
if (result != 100)
|
||||
{
|
||||
context.Response.Write("{ \"step\" : \"" + result + "\", \"filename\" : \"" + fileName + "\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var newFileUri = newFileData["fileUrl"];
|
||||
var newFileType = "." + newFileData["fileType"];
|
||||
// get a file name of an internal file extension with an index if the file with such a name already exists
|
||||
var correctName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "." + internalExtension);
|
||||
var correctName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + newFileType);
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(newFileUri);
|
||||
|
||||
@ -461,20 +475,21 @@ namespace OnlineEditorsExampleMVC
|
||||
var userAddress = context.Request["userAddress"];
|
||||
var isEmbedded = context.Request["dmode"];
|
||||
|
||||
if (JwtManager.Enabled && isEmbedded == null)
|
||||
if (JwtManager.Enabled && isEmbedded == null && userAddress != null && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
string JWTheader = string.IsNullOrEmpty(WebConfigurationManager.AppSettings["files.docservice.header"]) ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
string token = "";
|
||||
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 (string.IsNullOrEmpty(token))
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
context.Response.Write("JWT validation failed");
|
||||
return;
|
||||
}
|
||||
token = JwtManager.Decode(headerToken);
|
||||
}
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
context.Response.Write("JWT validation failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -508,6 +523,173 @@ namespace OnlineEditorsExampleMVC
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
private static void GetHistory(HttpContext context)
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
var fileName = context.Request["filename"];
|
||||
|
||||
var history = GetHistory(fileName);
|
||||
|
||||
context.Response.Write(jss.Serialize(history));
|
||||
}
|
||||
|
||||
private static void GetVersionData(HttpContext context)
|
||||
{
|
||||
var storagePath = WebConfigurationManager.AppSettings["storage-path"];
|
||||
var jss = new JavaScriptSerializer();
|
||||
|
||||
var fileName = context.Request["filename"];
|
||||
int version;
|
||||
|
||||
if (!int.TryParse(context.Request["version"], out version))
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"Version number invalid!\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var versionData = new Dictionary<string, object>();
|
||||
|
||||
var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, null));
|
||||
var lastVersion = DocManagerHelper.GetFileVersion(histDir);
|
||||
|
||||
var verDir = DocManagerHelper.VersionDir(histDir, version);
|
||||
|
||||
var key = version == lastVersion
|
||||
? ServiceConverter.GenerateRevisionId(DocManagerHelper.CurUserHostAddress()
|
||||
+ "/" + fileName + "/"
|
||||
+ File.GetLastWriteTime(DocManagerHelper.StoragePath(fileName, null)).GetHashCode())
|
||||
: File.ReadAllText(Path.Combine(verDir, "key.txt"));
|
||||
|
||||
|
||||
var ext = Path.GetExtension(fileName).ToLower();
|
||||
versionData.Add("fileType", ext.Replace(".", ""));
|
||||
versionData.Add("key", key);
|
||||
|
||||
// write file url to the data object
|
||||
string prevFileUrl;
|
||||
string directPrevFileUrl;
|
||||
if (Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath))
|
||||
{
|
||||
prevFileUrl = version == lastVersion ? DocManagerHelper.GetDownloadUrl(fileName)
|
||||
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
|
||||
directPrevFileUrl = version == lastVersion ? DocManagerHelper.GetDownloadUrl(fileName, false)
|
||||
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
prevFileUrl = version == lastVersion ? DocManagerHelper.GetFileUri(fileName, true)
|
||||
: DocManagerHelper.GetHistoryDownloadUrl(fileName, version.ToString(), "prev" + ext);
|
||||
directPrevFileUrl = version == lastVersion ? DocManagerHelper.GetFileUri(fileName, false)
|
||||
: DocManagerHelper.GetHistoryDownloadUrl(fileName, version.ToString(), "prev" + ext, false);
|
||||
}
|
||||
|
||||
versionData.Add("url", prevFileUrl);
|
||||
|
||||
var isEnableDirectUrl = string.Equals(DocManagerHelper.GetDirectUrl(), "true");
|
||||
if (isEnableDirectUrl)
|
||||
{
|
||||
versionData.Add("directUrl", directPrevFileUrl); // write direct url to the data object
|
||||
}
|
||||
|
||||
versionData.Add("version", version);
|
||||
if (version > 1)
|
||||
{
|
||||
var prevVerDir = DocManagerHelper.VersionDir(histDir, version - 1);
|
||||
|
||||
var prevUrl = Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath)
|
||||
? DocManagerHelper.GetDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""))
|
||||
: DocManagerHelper.GetHistoryDownloadUrl(fileName, (version - 1).ToString(), "prev" + ext);
|
||||
|
||||
var prevKey = File.ReadAllText(Path.Combine(prevVerDir, "key.txt"));
|
||||
|
||||
Dictionary<string, object> dataPrev = new Dictionary<string, object>() { // write information about previous file version to the data object
|
||||
{ "fileType", ext.Replace(".", "") },
|
||||
{ "key", prevKey }, // write key and url information about previous file version
|
||||
{ "url", prevUrl }
|
||||
};
|
||||
|
||||
string directPrevUrl;
|
||||
if (isEnableDirectUrl)
|
||||
{
|
||||
directPrevUrl = Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath)
|
||||
? DocManagerHelper.GetDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""), false)
|
||||
: DocManagerHelper.GetHistoryDownloadUrl(fileName, version.ToString(), "prev" + ext, false);
|
||||
|
||||
dataPrev.Add("directUrl", directPrevUrl);
|
||||
}
|
||||
|
||||
versionData.Add("previous", dataPrev);
|
||||
|
||||
if (File.Exists(Path.Combine(prevVerDir, "diff.zip")))
|
||||
{
|
||||
var changesUrl = DocManagerHelper.GetHistoryDownloadUrl(fileName, (version - 1).ToString(), "diff.zip");
|
||||
versionData.Add("changesUrl", changesUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
var token = JwtManager.Encode(versionData);
|
||||
versionData.Add("token", token);
|
||||
}
|
||||
|
||||
context.Response.Write(jss.Serialize(versionData));
|
||||
}
|
||||
|
||||
private static void Restore(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 fileName = (string)body["fileName"];
|
||||
var version = (int)body["version"];
|
||||
|
||||
var key = ServiceConverter.GenerateRevisionId(DocManagerHelper.CurUserHostAddress()
|
||||
+ "/" + fileName + "/"
|
||||
+ File.GetLastWriteTime(DocManagerHelper.StoragePath(fileName, null)).GetHashCode());
|
||||
|
||||
var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, null));
|
||||
var currentVersionDir = DocManagerHelper.VersionDir(histDir, DocManagerHelper.GetFileVersion(histDir));
|
||||
var verDir = DocManagerHelper.VersionDir(histDir, version);
|
||||
|
||||
if (!Directory.Exists(currentVersionDir)) Directory.CreateDirectory(currentVersionDir);
|
||||
|
||||
var ext = Path.GetExtension(fileName).ToLower();
|
||||
File.Copy(DocManagerHelper.StoragePath(fileName, null), Path.Combine(currentVersionDir, "prev" + ext));
|
||||
|
||||
File.WriteAllText(Path.Combine(currentVersionDir, "key.txt"), key);
|
||||
|
||||
var changesPath = Path.Combine(DocManagerHelper.VersionDir(histDir, version - 1), "changes.json");
|
||||
if (File.Exists(changesPath))
|
||||
{
|
||||
File.Copy(changesPath, Path.Combine(currentVersionDir, "changes.json"));
|
||||
}
|
||||
|
||||
File.Copy(Path.Combine(verDir, "prev" + ext), DocManagerHelper.StoragePath(fileName, null), true);
|
||||
|
||||
var fileInfo = new FileInfo(DocManagerHelper.StoragePath(fileName, null));
|
||||
fileInfo.LastWriteTimeUtc = DateTime.UtcNow;
|
||||
|
||||
var history = GetHistory(fileName);
|
||||
|
||||
context.Response.Write(jss.Serialize(history));
|
||||
}
|
||||
|
||||
// download a history file
|
||||
private static void DownloadHistory(HttpContext context)
|
||||
{
|
||||
@ -518,7 +700,7 @@ namespace OnlineEditorsExampleMVC
|
||||
var version = System.Convert.ToInt32(context.Request["ver"]);
|
||||
var file = Path.GetFileName(context.Request["file"]);
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
string JWTheader = string.IsNullOrEmpty(WebConfigurationManager.AppSettings["files.docservice.header"]) ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
@ -590,5 +772,162 @@ namespace OnlineEditorsExampleMVC
|
||||
TrackManager.commandRequest("meta", docKey, meta);
|
||||
context.Response.Write("{ \"result\": \"OK\"}");
|
||||
}
|
||||
|
||||
private static void Reference(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);
|
||||
Dictionary<string, object> referenceData = null;
|
||||
var fileName = "";
|
||||
var userAddress = "";
|
||||
|
||||
if (body.ContainsKey("referenceData"))
|
||||
{
|
||||
referenceData = jss.Deserialize<Dictionary<string, object>>(jss.Serialize(body["referenceData"]));
|
||||
var instanceId = (string)referenceData["instanceId"];
|
||||
var fileKey = (string)referenceData["fileKey"];
|
||||
if (instanceId == DocManagerHelper.GetServerUrl(false))
|
||||
{
|
||||
var fileKeyObj = jss.Deserialize<Dictionary<string, object>>(fileKey);
|
||||
userAddress = (string)fileKeyObj["userAddress"];
|
||||
if (userAddress == HttpUtility.UrlEncode(DocManagerHelper.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)))
|
||||
{
|
||||
fileName = (string)fileKeyObj["fileName"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName == "")
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = (string)body["path"];
|
||||
path = Path.GetFileName(path);
|
||||
if (File.Exists(DocManagerHelper.StoragePath(path, null)))
|
||||
{
|
||||
fileName = path;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"Path not found!\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName == "")
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"File not found!\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var directUrl = (bool)body["directUrl"];
|
||||
|
||||
var data = new Dictionary<string, object>() {
|
||||
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower().Trim('.') },
|
||||
{ "url", DocManagerHelper.GetDownloadUrl(fileName)},
|
||||
{ "directUrl", directUrl ? DocManagerHelper.GetDownloadUrl(fileName, false) : null },
|
||||
{ "referenceData", new Dictionary<string, string>()
|
||||
{
|
||||
{ "fileKey", jss.Serialize(new Dictionary<string, object>{
|
||||
{"fileName", fileName},
|
||||
{"userAddress", HttpUtility.UrlEncode(DocManagerHelper.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
|
||||
})
|
||||
},
|
||||
{ "instanceId", DocManagerHelper.GetServerUrl(false) }
|
||||
}
|
||||
},
|
||||
{ "path", fileName }
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
var token = JwtManager.Encode(data);
|
||||
data.Add("token", token);
|
||||
}
|
||||
|
||||
context.Response.Write(jss.Serialize(data));
|
||||
}
|
||||
|
||||
// get the document history
|
||||
private static Dictionary<string, object> GetHistory(string fileName)
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, null));
|
||||
|
||||
var history = new Dictionary<string, object>();
|
||||
|
||||
var currentVersion = DocManagerHelper.GetFileVersion(histDir);
|
||||
var currentKey = ServiceConverter.GenerateRevisionId(DocManagerHelper.CurUserHostAddress()
|
||||
+ "/" + fileName + "/"
|
||||
+ File.GetLastWriteTime(DocManagerHelper.StoragePath(fileName, null)).GetHashCode());
|
||||
|
||||
var versionList = new List<Dictionary<string, object>>();
|
||||
for (var versionNum = 1; versionNum <= currentVersion; versionNum++)
|
||||
{
|
||||
var versionObj = new Dictionary<string, object>();
|
||||
var verDir = DocManagerHelper.VersionDir(histDir, versionNum); // get the path to the given file version
|
||||
|
||||
var key = versionNum == currentVersion ? currentKey : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key
|
||||
|
||||
versionObj.Add("key", key);
|
||||
versionObj.Add("version", versionNum);
|
||||
|
||||
var changesPath = Path.Combine(DocManagerHelper.VersionDir(histDir, versionNum - 1), "changes.json");
|
||||
if (versionNum == 1 || !File.Exists(changesPath)) // check if the version number is equal to 1
|
||||
{
|
||||
var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file
|
||||
if (File.Exists(infoPath))
|
||||
{
|
||||
var info = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(infoPath));
|
||||
versionObj.Add("created", info["created"]); // write meta information to the object (user information and creation date)
|
||||
versionObj.Add("user", new Dictionary<string, object>()
|
||||
{
|
||||
{ "id", info["id"] },
|
||||
{ "name", info["name"] },
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (versionNum > 1) // check if the version number is greater than 1 (the file was modified)
|
||||
{
|
||||
// get the path to the changes.json file
|
||||
var changes = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(changesPath));
|
||||
var changesArray = (ArrayList)changes["changes"];
|
||||
var change = changesArray.Count > 0
|
||||
? (Dictionary<string, object>)changesArray[0]
|
||||
: new Dictionary<string, object>();
|
||||
|
||||
// write information about changes to the object
|
||||
versionObj.Add("changes", change.Count > 0 ? changes["changes"] : null);
|
||||
versionObj.Add("serverVersion", changes["serverVersion"]);
|
||||
versionObj.Add("created", change.Count > 0 ? change["created"] : null);
|
||||
versionObj.Add("user", change.Count > 0 ? change["user"] : null);
|
||||
}
|
||||
|
||||
versionList.Add(versionObj);
|
||||
}
|
||||
|
||||
history.Add("currentVersion", currentVersion);
|
||||
history.Add("history", versionList);
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -4,10 +4,6 @@ Entity Framework - Entity Framework is an object-relational mapper that enables
|
||||
License: MICROSOFT SOFTWARE SUPPLEMENTAL TERMS, MICROSOFT SOFTWARE LICENSE TERMS
|
||||
License File: EntityFramework.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -20,9 +16,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
|
||||
@ -1,22 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
<appSettings>
|
||||
<clear />
|
||||
<add key="version" value="1.5.1"/>
|
||||
<add key="version" value="1.6.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|.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.fillform-docs" value=".docx|.oform"/>
|
||||
<add key="files.docservice.viewed-docs" value=".djvu|.oxps|.pdf|.xps"/>
|
||||
<add key="files.docservice.edited-docs" value=".csv|.docm|.docx|.docxf|.dotm|.dotx|.epub|.fb2|.html|.odp|.ods|.odt|.otp|.ots|.ott|.potm|.potx|.ppsm|.ppsx|.pptm|.pptx|.rtf|.txt|.xlsm|.xlsx|.xltm|.xltx"/>
|
||||
<add key="files.docservice.convert-docs" value=".doc|.dot|.dps|.dpt|.epub|.et|.ett|.fb2|.fodp|.fods|.fodt|.htm|.html|.mht|.mhtml|.odp|.ods|.odt|.otp|.ots|.ott|.pot|.pps|.ppt|.rtf|.stw|.sxc|.sxi|.sxw|.wps|.wpt|.xls|.xlsb|.xlt|.xml"/>
|
||||
<add key="files.docservice.timeout" value="120000" />
|
||||
<add key="files.docservice.secret" value="" />
|
||||
<add key="files.docservice.header" value="Authorization" />
|
||||
|
||||
<add key="files.docservice.token.useforrequest" value="true" />
|
||||
|
||||
<add key="files.docservice.verify-peer-off" value="true"/>
|
||||
|
||||
<add key="files.docservice.languages" value="en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (People's Republic of China)|zh-TW:Chinese (Traditional, Taiwan)|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|ms:Malay (Malaysia)|nb:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA: Test Language"/>
|
||||
<add key="files.docservice.languages" value="en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (Simplified)|zh-TW:Chinese (Traditional)|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|lo:Lao|lv:Latvian|ms:Malay (Malaysia)|no:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|si:Sinhala (Sri Lanka)|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA: Test Language"/>
|
||||
|
||||
<add key="files.docservice.url.site" value="http://documentserver/"/>
|
||||
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
ONLYOFFICE Applications example uses code from the following 3rd party projects:
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
|
||||
@ -682,3 +682,8 @@
|
||||
max-width:15%;
|
||||
}
|
||||
}
|
||||
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
|
||||
.tableRow td:first-child{
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,11 +471,10 @@ namespace OnlineEditorsExample
|
||||
var lang = context.Request.Cookies.GetOrDefault("ulang", null);
|
||||
|
||||
var extension = (Path.GetExtension(_fileName).ToLower() ?? "").Trim('.');
|
||||
var internalExtension = FileType.GetInternalExtension(_fileName).Trim('.');
|
||||
var internalExtension = "ooxml";
|
||||
|
||||
// check if the file with such an extension can be converted
|
||||
if (ConvertExts.Contains("." + extension)
|
||||
&& !string.IsNullOrEmpty(internalExtension))
|
||||
if (ConvertExts.Contains("." + extension))
|
||||
{
|
||||
// generate document key
|
||||
var key = ServiceConverter.GenerateRevisionId(FileUri(_fileName, true));
|
||||
@ -487,16 +486,18 @@ namespace OnlineEditorsExample
|
||||
fileUrl.Query = "type=download&fileName=" + HttpUtility.UrlEncode(_fileName)
|
||||
+ "&userAddress=" + HttpUtility.UrlEncode(CurUserHostAddress(HttpContext.Current.Request.UserHostAddress));
|
||||
|
||||
// get the url to the converted file
|
||||
string newFileUri;
|
||||
var result = ServiceConverter.GetConvertedUri(fileUrl.ToString() , extension, internalExtension, key, true, out newFileUri, filePass, lang);
|
||||
// get the url and file type of the converted file
|
||||
Dictionary<string, string> newFileData;
|
||||
var result = ServiceConverter.GetConvertedData(fileUrl.ToString() , extension, internalExtension, key, true, out newFileData, filePass, lang);
|
||||
if (result != 100)
|
||||
{
|
||||
return "{ \"step\" : \"" + result + "\", \"filename\" : \"" + _fileName + "\"}";
|
||||
}
|
||||
|
||||
var newFileUri = newFileData["fileUrl"];
|
||||
var newFileType = "." + newFileData["fileType"];
|
||||
// get a file name of an internal file extension with an index if the file with such a name already exists
|
||||
var fileName = GetCorrectName(Path.GetFileNameWithoutExtension(_fileName) + "." + internalExtension);
|
||||
var fileName = GetCorrectName(Path.GetFileNameWithoutExtension(_fileName) + newFileType);
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(newFileUri);
|
||||
|
||||
@ -632,5 +633,12 @@ namespace OnlineEditorsExample
|
||||
string isEnabledDirectUrl = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query).Get("directUrl");
|
||||
return "&directUrl=" + (isEnabledDirectUrl != null ? isEnabledDirectUrl : "false");
|
||||
}
|
||||
|
||||
// get direct url flag
|
||||
public static bool IsEnabledDirectUrl()
|
||||
{
|
||||
string isEnabledDirectUrl = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query).Get("directUrl");
|
||||
return isEnabledDirectUrl != null ? Convert.ToBoolean(isEnabledDirectUrl) : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -153,7 +153,7 @@
|
||||
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;
|
||||
@ -190,6 +190,19 @@
|
||||
}
|
||||
};
|
||||
|
||||
var onRequestReferenceData = function (event) { // user refresh external data source
|
||||
|
||||
event.data.directUrl = !!config.document.directUrl;
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=reference");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(JSON.stringify(event.data));
|
||||
xhr.onload = function () {
|
||||
console.log(xhr.responseText);
|
||||
docEditor.setReferenceData(JSON.parse(xhr.responseText));
|
||||
}
|
||||
};
|
||||
|
||||
config = <%= DocConfig %>;
|
||||
|
||||
config.width = "100%";
|
||||
@ -198,7 +211,6 @@
|
||||
config.events = {
|
||||
'onAppReady': onAppReady,
|
||||
'onDocumentStateChange': onDocumentStateChange,
|
||||
'onRequestEditRights': onRequestEditRights,
|
||||
'onError': onError,
|
||||
'onOutdatedVersion': onOutdatedVersion,
|
||||
'onMakeActionLink': onMakeActionLink,
|
||||
@ -209,20 +221,49 @@
|
||||
};
|
||||
|
||||
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['onRequestHistory'] = function (event) { // the user is trying to show the document version history
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "webeditor.ashx?type=gethistory&filename=<%= FileName %>");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send();
|
||||
xhr.onload = function () {
|
||||
console.log(xhr.responseText);
|
||||
docEditor.refreshHistory(JSON.parse(xhr.responseText));
|
||||
}
|
||||
};
|
||||
config.events['onRequestHistoryData'] = function (event) { // the user is trying to click the specific document version in the document version history
|
||||
var ver = event.data;
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "webeditor.ashx?type=getversiondata&filename=<%= FileName %>&version=" + ver + "&directUrl=" + !!config.document.directUrl);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send();
|
||||
xhr.onload = function () {
|
||||
console.log(xhr.responseText);
|
||||
docEditor.setHistoryData(JSON.parse(xhr.responseText)); // 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();
|
||||
};
|
||||
config.events['onRequestRestore'] = function (event) {
|
||||
var fileName = "<%= FileName %>";
|
||||
var version = event.data.version;
|
||||
var data = {
|
||||
fileName: fileName,
|
||||
version: version
|
||||
};
|
||||
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();
|
||||
};
|
||||
<% } %>
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "webeditor.ashx?type=restore&directUrl=" + !!config.document.directUrl);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.send(JSON.stringify(data));
|
||||
xhr.onload = function () {
|
||||
docEditor.refreshHistory(JSON.parse(xhr.responseText));
|
||||
}
|
||||
};
|
||||
|
||||
// add mentions for not anonymous users
|
||||
<% if (!string.IsNullOrEmpty(UsersForMentions))
|
||||
@ -242,6 +283,9 @@
|
||||
};
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
config.events['onRequestReferenceData'] = onRequestReferenceData;
|
||||
// prevent switch the document from the viewing into the editing mode for anonymous users
|
||||
config.events['onRequestEditRights'] = onRequestEditRights;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
@ -61,8 +60,6 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
|
||||
protected string DocConfig { get; private set; }
|
||||
protected string History { get; private set; }
|
||||
protected string HistoryData { get; private set; }
|
||||
protected string InsertImageConfig { get; private set; }
|
||||
protected string CompareFileData { get; private set; }
|
||||
protected string DataMailMergeRecipients { get; private set; }
|
||||
@ -195,7 +192,7 @@ namespace OnlineEditorsExample
|
||||
{
|
||||
{ "title", FileName },
|
||||
{ "url", getDownloadUrl(FileName) },
|
||||
{ "directUrl", IsEnabledDirectUrl() ? directUrl : "" },
|
||||
{ "directUrl", _Default.IsEnabledDirectUrl() ? directUrl : "" },
|
||||
{ "fileType", ext.Trim('.') },
|
||||
{ "key", Key },
|
||||
{
|
||||
@ -206,6 +203,17 @@ namespace OnlineEditorsExample
|
||||
{ "favorite", favorite }
|
||||
}
|
||||
},
|
||||
{
|
||||
"referenceData", new Dictionary<string, string>()
|
||||
{
|
||||
{ "fileKey", !user.id.Equals("uid-0") ?
|
||||
jss.Serialize(new Dictionary<string, object>{
|
||||
{"fileName", FileName},
|
||||
{"userAddress", HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
|
||||
}) : null },
|
||||
{"instanceId", _Default.GetServerUrl(false) }
|
||||
}
|
||||
},
|
||||
{
|
||||
// the permission for the document to be edited and downloaded or not
|
||||
"permissions", new Dictionary<string, object>
|
||||
@ -222,7 +230,8 @@ namespace OnlineEditorsExample
|
||||
{ "chat", !user.id.Equals("uid-0") },
|
||||
{ "reviewGroups", user.reviewGroups },
|
||||
{ "commentGroups", user.commentGroups },
|
||||
{ "userInfoGroups", user.userInfoGroups }
|
||||
{ "userInfoGroups", user.userInfoGroups },
|
||||
{ "protect", !user.deniedPermissions.Contains("protect") }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,134 +317,10 @@ namespace OnlineEditorsExample
|
||||
// get users for mentions
|
||||
List<Dictionary<string, object>> usersData = Users.getUsersForMentions(user.id);
|
||||
UsersForMentions = !user.id.Equals("uid-0") ? jss.Serialize(usersData) : null;
|
||||
|
||||
Dictionary<string, object> hist;
|
||||
Dictionary<string, object> histData;
|
||||
|
||||
// get the document history
|
||||
GetHistory(out hist, out histData);
|
||||
if (hist != null && histData != null)
|
||||
{
|
||||
History = jss.Serialize(hist);
|
||||
HistoryData = jss.Serialize(histData);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
||||
history = null;
|
||||
historyData = null;
|
||||
|
||||
if (_Default.GetFileVersion(histDir) > 0) // if the file was modified (the file version is greater than 0)
|
||||
{
|
||||
var currentVersion = _Default.GetFileVersion(histDir);
|
||||
var hist = new List<Dictionary<string, object>>();
|
||||
var histData = new Dictionary<string, object>();
|
||||
|
||||
for (var i = 1; i <= currentVersion; i++) // run through all the file versions
|
||||
{
|
||||
var obj = new Dictionary<string, object>();
|
||||
var dataObj = new Dictionary<string, object>();
|
||||
var verDir = _Default.VersionDir(histDir, i); // get the path to the given file version
|
||||
|
||||
var key = i == currentVersion ? Key : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key
|
||||
|
||||
obj.Add("key", key);
|
||||
obj.Add("version", i);
|
||||
|
||||
if (i == 1) // check if the version number is equal to 1
|
||||
{
|
||||
var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file
|
||||
|
||||
if (File.Exists(infoPath)) {
|
||||
var info = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(infoPath));
|
||||
obj.Add("created", info["created"]); // write meta information to the object (user information and creation date)
|
||||
obj.Add("user", new Dictionary<string, object>() {
|
||||
{ "id", info["id"] },
|
||||
{ "name", info["name"] },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var ext = Path.GetExtension(FileName).ToLower();
|
||||
dataObj.Add("fileType", ext.Replace(".", ""));
|
||||
dataObj.Add("key", key);
|
||||
// write file url to the data object
|
||||
var directPrevFileUrl = i == currentVersion ? _Default.FileUri(FileName, false) : MakePublicHistoryUrl(FileName, i.ToString(), "prev" + ext, false);
|
||||
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 + "\\", ""));
|
||||
directPrevFileUrl = i == currentVersion ? getDownloadUrl(FileName, false) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
|
||||
}
|
||||
|
||||
dataObj.Add("url", prevFileUrl); // write file url to the data object
|
||||
|
||||
if (IsEnabledDirectUrl())
|
||||
{
|
||||
dataObj.Add("directUrl", directPrevFileUrl); // write direct 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)
|
||||
{
|
||||
// get the path to the changes.json file
|
||||
var changes = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(Path.Combine(_Default.VersionDir(histDir, i - 1), "changes.json")));
|
||||
var changesArray = (ArrayList)changes["changes"];
|
||||
var change = changesArray.Count > 0
|
||||
? (Dictionary<string, object>)changesArray[0]
|
||||
: new Dictionary<string, object>();
|
||||
|
||||
// write information about changes to the object
|
||||
obj.Add("changes", change.Count > 0 ? changes["changes"] : null);
|
||||
obj.Add("serverVersion", changes["serverVersion"]);
|
||||
obj.Add("created", change.Count > 0 ? change["created"] : null);
|
||||
obj.Add("user", change.Count > 0 ? change["user"] : null);
|
||||
|
||||
var prev = (Dictionary<string, object>)histData[(i - 2).ToString()]; // get the history data from the previous file version
|
||||
|
||||
Dictionary<string, object> dataPrev = 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"] }
|
||||
};
|
||||
|
||||
if (IsEnabledDirectUrl())
|
||||
{
|
||||
dataPrev.Add("directUrl", prev["directUrl"]);
|
||||
}
|
||||
|
||||
dataObj.Add("previous", dataPrev);
|
||||
// write the path to the diff.zip archive with differences in this file version
|
||||
var changesUrl = MakePublicHistoryUrl(FileName, (i - 1).ToString(), "diff.zip");
|
||||
dataObj.Add("changesUrl", changesUrl);
|
||||
}
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
var token = JwtManager.Encode(dataObj);
|
||||
dataObj.Add("token", token);
|
||||
}
|
||||
hist.Add(obj); // add object dictionary to the hist list
|
||||
histData.Add((i - 1).ToString(), dataObj); // write data object information to the history data
|
||||
}
|
||||
|
||||
// write history information about the current file version to the history object
|
||||
history = new Dictionary<string, object>()
|
||||
{
|
||||
{ "currentVersion", currentVersion },
|
||||
{ "history", hist }
|
||||
};
|
||||
historyData = histData;
|
||||
}
|
||||
}
|
||||
|
||||
// get a logo config
|
||||
private Dictionary<string, object> GetLogoConfig()
|
||||
{
|
||||
@ -457,7 +342,7 @@ namespace OnlineEditorsExample
|
||||
{ "url", InsertImageUrl.ToString()}
|
||||
};
|
||||
|
||||
if (IsEnabledDirectUrl())
|
||||
if (_Default.IsEnabledDirectUrl())
|
||||
{
|
||||
logoConfig.Add("directUrl", DirectImageUrl.ToString());
|
||||
}
|
||||
@ -494,7 +379,7 @@ namespace OnlineEditorsExample
|
||||
{ "url", compareFileUrl.ToString() }
|
||||
};
|
||||
|
||||
if (IsEnabledDirectUrl())
|
||||
if (_Default.IsEnabledDirectUrl())
|
||||
{
|
||||
dataCompareFile.Add("directUrl", DirectFileUrl.ToString());
|
||||
}
|
||||
@ -533,7 +418,7 @@ namespace OnlineEditorsExample
|
||||
{ "url", mailmergeUrl.ToString() }
|
||||
};
|
||||
|
||||
if (IsEnabledDirectUrl())
|
||||
if (_Default.IsEnabledDirectUrl())
|
||||
{
|
||||
mailMergeConfig.Add("directUrl", DirectMailMergeUrl.ToString());
|
||||
}
|
||||
@ -577,21 +462,6 @@ namespace OnlineEditorsExample
|
||||
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, Boolean isServer = true)
|
||||
{
|
||||
var userAddress = isServer ? "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)) : "";
|
||||
var fileUrl = new UriBuilder(_Default.GetServerUrl(isServer));
|
||||
fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx";
|
||||
fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename)
|
||||
+ "&ver=" + version + "&file=" + file
|
||||
+ userAddress;
|
||||
return fileUrl.ToString();
|
||||
}
|
||||
|
||||
// create demo document
|
||||
private static void Try(string type, string sample, HttpRequest request)
|
||||
{
|
||||
@ -620,6 +490,7 @@ namespace OnlineEditorsExample
|
||||
|
||||
var filePath = _Default.StoragePath(FileName, null);
|
||||
File.Copy(HttpRuntime.AppDomainAppPath + demoPath + demoName, filePath); // copy this file to the storage directory
|
||||
File.SetLastWriteTime(filePath, DateTime.Now);
|
||||
|
||||
// create a json file with file meta data
|
||||
var id = request.Cookies.GetOrDefault("uid", null);
|
||||
@ -639,12 +510,5 @@ namespace OnlineEditorsExample
|
||||
{ "name", uname }
|
||||
}));
|
||||
}
|
||||
|
||||
// get direct url flag
|
||||
private static bool IsEnabledDirectUrl()
|
||||
{
|
||||
string isEnabledDirectUrl = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query).Get("directUrl");
|
||||
return isEnabledDirectUrl != null ? Convert.ToBoolean(isEnabledDirectUrl) : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -70,24 +70,24 @@ namespace ASC.Api.DocumentConverter
|
||||
/// <param name="toExtension">Extension to which to convert</param>
|
||||
/// <param name="documentRevisionId">Key for caching on service</param>
|
||||
/// <param name="isAsync">Perform conversions asynchronously</param>
|
||||
/// <param name="convertedDocumentUri">Uri to the converted document</param>
|
||||
/// <param name="convertedDocumentData">Uri and file type of the converted document</param>
|
||||
/// <returns>The percentage of conversion completion</returns>
|
||||
/// <example>
|
||||
/// string convertedDocumentUri;
|
||||
/// GetConvertedUri("http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", ".pdf", ".docx", "http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", false, out convertedDocumentUri);
|
||||
/// Dictionary<string, string> convertedDocumentData;
|
||||
/// GetConvertedData("http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", ".pdf", ".docx", "http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", false, out convertedDocumentData);
|
||||
/// </example>
|
||||
/// <exception>
|
||||
/// </exception>
|
||||
public static int GetConvertedUri(string documentUri,
|
||||
public static int GetConvertedData(string documentUri,
|
||||
string fromExtension,
|
||||
string toExtension,
|
||||
string documentRevisionId,
|
||||
bool isAsync,
|
||||
out string convertedDocumentUri,
|
||||
out Dictionary<string, string> convertedDocumentData,
|
||||
string filePass = null,
|
||||
string lang = null)
|
||||
{
|
||||
convertedDocumentUri = string.Empty;
|
||||
convertedDocumentData = new Dictionary<string, string>();
|
||||
|
||||
// check if the fromExtension parameter is defined; if not, get it from the document url
|
||||
fromExtension = string.IsNullOrEmpty(fromExtension) ? Path.GetExtension(documentUri).ToLower() : fromExtension;
|
||||
@ -121,7 +121,7 @@ namespace ASC.Api.DocumentConverter
|
||||
{ "region", lang }
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
// create payload object
|
||||
var payload = new Dictionary<string, object>
|
||||
@ -159,7 +159,7 @@ namespace ASC.Api.DocumentConverter
|
||||
}
|
||||
}
|
||||
|
||||
return GetResponseUri(dataResponse, out convertedDocumentUri);
|
||||
return GetResponseData(dataResponse, out convertedDocumentData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -183,9 +183,9 @@ namespace ASC.Api.DocumentConverter
|
||||
/// Processing document received from the editing service
|
||||
/// </summary>
|
||||
/// <param name="jsonDocumentResponse">The resulting json from editing service</param>
|
||||
/// <param name="responseUri">Uri to the converted document</param>
|
||||
/// <param name="responseData">Uri and file type of the converted document</param>
|
||||
/// <returns>The percentage of conversion completion</returns>
|
||||
private static int GetResponseUri(string jsonDocumentResponse, out string responseUri)
|
||||
private static int GetResponseData(string jsonDocumentResponse, out Dictionary<string, string> responseData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonDocumentResponse)) throw new ArgumentException("Invalid param", "jsonDocumentResponse");
|
||||
|
||||
@ -199,14 +199,20 @@ namespace ASC.Api.DocumentConverter
|
||||
var isEndConvert = responseFromService.endConvert;
|
||||
|
||||
int resultPercent;
|
||||
responseUri = string.Empty;
|
||||
responseData = new Dictionary<string, string>();
|
||||
var responseUri = string.Empty;
|
||||
var responseFileType = string.Empty;
|
||||
if (isEndConvert) // if the conversion is completed
|
||||
{
|
||||
responseUri = responseFromService.fileUrl; // get the file url
|
||||
responseFileType = responseFromService.fileType; // get the file type
|
||||
responseData.Add("fileUrl", responseUri);
|
||||
responseData.Add("fileType", responseFileType);
|
||||
resultPercent = 100;
|
||||
}
|
||||
else // if the conversion isn't completed
|
||||
{
|
||||
responseData.Add("fileUrl", "");
|
||||
resultPercent = responseFromService.percent; // get the percentage value
|
||||
if (resultPercent >= 100) resultPercent = 99;
|
||||
}
|
||||
|
||||
@ -29,11 +29,13 @@ namespace OnlineEditorsExample
|
||||
{
|
||||
private static readonly string Secret;
|
||||
public static readonly bool Enabled;
|
||||
public static readonly bool SignatureUseForRequest;
|
||||
|
||||
static JwtManager()
|
||||
{
|
||||
Secret = WebConfigurationManager.AppSettings["files.docservice.secret"] ?? ""; // get token secret from the config parameters
|
||||
Enabled = !string.IsNullOrEmpty(Secret); // check if the token is enabled
|
||||
SignatureUseForRequest = bool.Parse(WebConfigurationManager.AppSettings["files.docservice.token.useforrequest"]);
|
||||
}
|
||||
|
||||
// encode a payload object into a token using a secret key
|
||||
|
||||
@ -55,7 +55,7 @@ namespace OnlineEditorsExample
|
||||
var fileData = jss.Deserialize<Dictionary<string, object>>(body);
|
||||
|
||||
// check if the document token is enabled
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
string JWTheader = string.IsNullOrEmpty(WebConfigurationManager.AppSettings["files.docservice.header"]) ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
@ -110,8 +110,9 @@ namespace OnlineEditorsExample
|
||||
try
|
||||
{
|
||||
// convert file and give url to a new file
|
||||
string newFileUri;
|
||||
ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), false, out newFileUri);
|
||||
Dictionary<string, string> newFileData;
|
||||
ServiceConverter.GetConvertedData(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), false, out newFileData);
|
||||
var newFileUri = newFileData["fileUrl"];
|
||||
if (string.IsNullOrEmpty(newFileUri))
|
||||
{
|
||||
// get the correct file name if it already exists
|
||||
@ -130,37 +131,48 @@ namespace OnlineEditorsExample
|
||||
|
||||
_Default.VerifySSL();
|
||||
|
||||
var storagePath = _Default.StoragePath(newFileName, userAddress); // get the file path
|
||||
var histDir = _Default.HistoryDir(storagePath); // get the path to the history directory
|
||||
if (!Directory.Exists(histDir)) Directory.CreateDirectory(histDir);
|
||||
|
||||
var versionDir = _Default.VersionDir(histDir, _Default.GetFileVersion(histDir)); // get the path to the file version
|
||||
if (!Directory.Exists(versionDir)) Directory.CreateDirectory(versionDir); // if the path doesn't exist, create it
|
||||
|
||||
// get the path to the previous file version and rename the storage path with it
|
||||
File.Copy(_Default.StoragePath(fileName, userAddress), Path.Combine(versionDir, "prev" + curExt));
|
||||
|
||||
DownloadToFile(downloadUri, storagePath); // save file to the storage directory
|
||||
DownloadToFile((string)fileData["changesurl"], Path.Combine(versionDir, "diff.zip")); // save file changes to the diff.zip archive
|
||||
|
||||
var hist = fileData.ContainsKey("changeshistory") ? (string)fileData["changeshistory"] : null;
|
||||
if (string.IsNullOrEmpty(hist) && fileData.ContainsKey("history"))
|
||||
try
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
hist = jss.Serialize(fileData["history"]);
|
||||
}
|
||||
var bytesFile = DownloadFile(downloadUri); // download document file
|
||||
var storagePath = _Default.StoragePath(newFileName, userAddress); // get the file path
|
||||
|
||||
if (!string.IsNullOrEmpty(hist))
|
||||
{
|
||||
File.WriteAllText(Path.Combine(versionDir, "changes.json"), hist); // write the history changes to the changes.json file
|
||||
}
|
||||
var histDir = _Default.HistoryDir(storagePath); // get the path to the history directory
|
||||
if (!Directory.Exists(histDir)) Directory.CreateDirectory(histDir);
|
||||
|
||||
File.WriteAllText(Path.Combine(versionDir, "key.txt"), (string)fileData["key"]); // write the key value to the key.txt file
|
||||
var versionDir = _Default.VersionDir(histDir, _Default.GetFileVersion(histDir)); // get the path to the file version
|
||||
if (!Directory.Exists(versionDir)) Directory.CreateDirectory(versionDir); // if the path doesn't exist, create it
|
||||
|
||||
string forcesavePath = _Default.ForcesavePath(newFileName, userAddress, false); // get the path to the forcesaved file version
|
||||
// get the path to the previous file version and rename the storage path with it
|
||||
File.Copy(_Default.StoragePath(fileName, userAddress), Path.Combine(versionDir, "prev" + curExt));
|
||||
|
||||
SaveFile(bytesFile, storagePath);// save document file
|
||||
|
||||
var bytesChanges = DownloadFile((string)fileData["changesurl"]); // download changes file
|
||||
SaveFile(bytesChanges, Path.Combine(versionDir, "diff.zip")); // save file changes to the diff.zip archive
|
||||
|
||||
var hist = fileData.ContainsKey("changeshistory") ? (string)fileData["changeshistory"] : null;
|
||||
if (string.IsNullOrEmpty(hist) && fileData.ContainsKey("history"))
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
hist = jss.Serialize(fileData["history"]);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(hist))
|
||||
{
|
||||
File.WriteAllText(Path.Combine(versionDir, "changes.json"), hist); // write the history changes to the changes.json file
|
||||
}
|
||||
|
||||
File.WriteAllText(Path.Combine(versionDir, "key.txt"), (string)fileData["key"]); // write the key value to the key.txt file
|
||||
|
||||
string forcesavePath = _Default.ForcesavePath(newFileName, userAddress, false); // get the path to the forcesaved file version
|
||||
if (!string.IsNullOrEmpty(forcesavePath)) // if the forcesaved file version exists
|
||||
{
|
||||
File.Delete(forcesavePath); // remove it
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
File.Delete(forcesavePath); // remove it
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -186,8 +198,9 @@ namespace OnlineEditorsExample
|
||||
try
|
||||
{
|
||||
// convert file and give url to a new file
|
||||
string newFileUri;
|
||||
var result = ServiceConverter.GetConvertedUri(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), false, out newFileUri);
|
||||
Dictionary<string, string> newFileData;
|
||||
var result = ServiceConverter.GetConvertedData(downloadUri, downloadExt, curExt, ServiceConverter.GenerateRevisionId(downloadUri), false, out newFileData);
|
||||
var newFileUri = newFileData["fileUrl"];
|
||||
if (string.IsNullOrEmpty(newFileUri))
|
||||
{
|
||||
newFileName = true;
|
||||
@ -205,43 +218,51 @@ namespace OnlineEditorsExample
|
||||
|
||||
_Default.VerifySSL();
|
||||
|
||||
string forcesavePath = "";
|
||||
Boolean isSubmitForm = fileData["forcesavetype"].ToString().Equals("3"); // SubmitForm
|
||||
|
||||
if (isSubmitForm) // if the form is submitted
|
||||
try
|
||||
{
|
||||
if (newFileName)
|
||||
var bytesFile = DownloadFile(downloadUri); // download document file
|
||||
string forcesavePath = "";
|
||||
Boolean isSubmitForm = fileData["forcesavetype"].ToString().Equals("3"); // SubmitForm
|
||||
|
||||
if (isSubmitForm) // if the form is submitted
|
||||
{
|
||||
fileName = _Default.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "-form" + downloadExt, userAddress); // get the correct file name if it already exists
|
||||
if (newFileName)
|
||||
{
|
||||
fileName = _Default.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "-form" + downloadExt, userAddress); // get the correct file name if it already exists
|
||||
} else
|
||||
{
|
||||
fileName = _Default.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "-form" + curExt, userAddress);
|
||||
{
|
||||
fileName = _Default.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + "-form" + curExt, userAddress);
|
||||
}
|
||||
forcesavePath = _Default.StoragePath(fileName, userAddress);
|
||||
}
|
||||
forcesavePath = _Default.StoragePath(fileName, userAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newFileName)
|
||||
else
|
||||
{
|
||||
fileName = _Default.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + downloadExt, userAddress);
|
||||
}
|
||||
if (newFileName)
|
||||
{
|
||||
fileName = _Default.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + downloadExt, userAddress);
|
||||
}
|
||||
|
||||
forcesavePath = _Default.ForcesavePath(fileName, userAddress, false);
|
||||
forcesavePath = _Default.ForcesavePath(fileName, userAddress, false);
|
||||
if (string.IsNullOrEmpty(forcesavePath)) // create forcesave path if it doesn't exist
|
||||
{
|
||||
forcesavePath = _Default.ForcesavePath(fileName, userAddress, true);
|
||||
}
|
||||
}
|
||||
|
||||
SaveFile(bytesFile, forcesavePath);// save document file
|
||||
|
||||
if (isSubmitForm)
|
||||
{
|
||||
forcesavePath = _Default.ForcesavePath(fileName, userAddress, true);
|
||||
var jss = new JavaScriptSerializer();
|
||||
var actions = jss.Deserialize<List<object>>(jss.Serialize(fileData["actions"]));
|
||||
var action = jss.Deserialize<Dictionary<string, object>>(jss.Serialize(actions[0]));
|
||||
var user = action["userid"].ToString(); // get the user id
|
||||
DocEditor.CreateMeta(fileName, user, "Filling Form", userAddress); // create meta data for the forcesaved file
|
||||
}
|
||||
}
|
||||
|
||||
DownloadToFile(downloadUri, forcesavePath);
|
||||
|
||||
if (isSubmitForm)
|
||||
catch (Exception)
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
var actions = jss.Deserialize<List<object>>(jss.Serialize(fileData["actions"]));
|
||||
var action = jss.Deserialize<Dictionary<string, object>>(jss.Serialize(actions[0]));
|
||||
var user = action["userid"].ToString(); // get the user id
|
||||
DocEditor.CreateMeta(fileName, user, "Filling Form", userAddress); // create meta data for the forcesaved file
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -269,7 +290,7 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
|
||||
// check if a secret key to generate token exists or not
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
var payload = new Dictionary<string, object>
|
||||
{
|
||||
@ -313,27 +334,29 @@ namespace OnlineEditorsExample
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveFile(byte[] data, string path)
|
||||
{
|
||||
using (var fs = File.Open(path, FileMode.Create))
|
||||
{
|
||||
fs.Write(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
|
||||
// save file information from the url to the file specified
|
||||
private static void DownloadToFile(string url, string path)
|
||||
private static byte[] DownloadFile(string url)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url)) throw new ArgumentException("url"); // url isn't specified
|
||||
if (string.IsNullOrEmpty(path)) throw new ArgumentException("path"); // file isn't specified
|
||||
|
||||
var req = (HttpWebRequest)WebRequest.Create(url);
|
||||
req.Timeout = 5000;
|
||||
using (var stream = req.GetResponse().GetResponseStream()) // get input stream of the file information from the url
|
||||
{
|
||||
if (stream == null) throw new Exception("stream is null");
|
||||
const int bufferSize = 4096;
|
||||
|
||||
using (var fs = File.Open(path, FileMode.Create))
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
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
|
||||
}
|
||||
stream.CopyTo(memoryStream);
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,6 +68,7 @@ namespace OnlineEditorsExample
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor",
|
||||
"Can't view chat",
|
||||
"Can't protect file",
|
||||
"View file without collaboration",
|
||||
};
|
||||
|
||||
@ -130,7 +131,7 @@ namespace OnlineEditorsExample
|
||||
new Dictionary<string, object>(),
|
||||
new List<string>(),
|
||||
null,
|
||||
new List<string>(),
|
||||
new List<string>() { "protect" },
|
||||
descr_user_0,
|
||||
false
|
||||
)
|
||||
|
||||
@ -26,6 +26,9 @@ using System.Diagnostics;
|
||||
using System.Web.Configuration;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Collections;
|
||||
using System.Net.Sockets;
|
||||
using ASC.Api.DocumentConverter;
|
||||
|
||||
namespace OnlineEditorsExample
|
||||
{
|
||||
@ -47,6 +50,15 @@ namespace OnlineEditorsExample
|
||||
case "downloadhistory":
|
||||
DownloadHistory(context);
|
||||
break;
|
||||
case "gethistory":
|
||||
GetHistory(context);
|
||||
break;
|
||||
case "getversiondata":
|
||||
GetVersionData(context);
|
||||
break;
|
||||
case "restore":
|
||||
Restore(context);
|
||||
break;
|
||||
case "convert":
|
||||
Convert(context);
|
||||
break;
|
||||
@ -71,6 +83,9 @@ namespace OnlineEditorsExample
|
||||
case "rename":
|
||||
Rename(context);
|
||||
break;
|
||||
case "reference":
|
||||
Reference(context);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,21 +296,21 @@ namespace OnlineEditorsExample
|
||||
var userAddress = Path.GetFileName(context.Request["userAddress"]);
|
||||
var isEmbedded = context.Request["dmode"];
|
||||
|
||||
if (JwtManager.Enabled && isEmbedded == null)
|
||||
if (JwtManager.Enabled && isEmbedded == null && userAddress != null && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
string JWTheader = string.IsNullOrEmpty(WebConfigurationManager.AppSettings["files.docservice.header"]) ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
string token = "";
|
||||
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 (string.IsNullOrEmpty(token))
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
context.Response.Write("JWT validation failed");
|
||||
return;
|
||||
}
|
||||
token = JwtManager.Decode(headerToken);
|
||||
}
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
context.Response.Write("JWT validation failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,6 +344,164 @@ namespace OnlineEditorsExample
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
private static void GetHistory(HttpContext context)
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
var fileName = context.Request["filename"];
|
||||
|
||||
var history = GetHistory(fileName);
|
||||
|
||||
context.Response.Write(jss.Serialize(history));
|
||||
}
|
||||
|
||||
private static void GetVersionData(HttpContext context)
|
||||
{
|
||||
var storagePath = WebConfigurationManager.AppSettings["storage-path"];
|
||||
var jss = new JavaScriptSerializer();
|
||||
|
||||
var fileName = context.Request["filename"];
|
||||
int version;
|
||||
|
||||
if (!int.TryParse(context.Request["version"], out version))
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"Version number invalid!\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var versionData = new Dictionary<string, object>();
|
||||
|
||||
var histDir = _Default.HistoryDir(_Default.StoragePath(fileName, null));
|
||||
var lastVersion = _Default.GetFileVersion(histDir);
|
||||
|
||||
var verDir = _Default.VersionDir(histDir, version);
|
||||
|
||||
var lastVersionUri = _Default.FileUri(fileName, true);
|
||||
var key = version == lastVersion
|
||||
? ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null)
|
||||
+ "/" + Path.GetFileName(lastVersionUri)
|
||||
+ "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode())
|
||||
: File.ReadAllText(Path.Combine(verDir, "key.txt"));
|
||||
|
||||
|
||||
var ext = Path.GetExtension(fileName).ToLower();
|
||||
versionData.Add("fileType", ext.Replace(".", ""));
|
||||
versionData.Add("key", key);
|
||||
|
||||
var directPrevFileUrl = version == lastVersion ? _Default.FileUri(fileName, false) : MakePublicHistoryUrl(fileName, version.ToString(), "prev" + ext, false);
|
||||
var prevFileUrl = version == lastVersion ? lastVersionUri : MakePublicHistoryUrl(fileName, version.ToString(), "prev" + ext);
|
||||
if (Path.IsPathRooted(storagePath))
|
||||
{
|
||||
prevFileUrl = version == lastVersion ? DocEditor.getDownloadUrl(fileName) : DocEditor.getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
|
||||
directPrevFileUrl = version == lastVersion ? DocEditor.getDownloadUrl(fileName, false) : DocEditor.getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
|
||||
}
|
||||
|
||||
versionData.Add("url", prevFileUrl);
|
||||
|
||||
if (_Default.IsEnabledDirectUrl())
|
||||
{
|
||||
versionData.Add("directUrl", directPrevFileUrl); // write direct url to the data object
|
||||
}
|
||||
|
||||
versionData.Add("version", version);
|
||||
if (version > 1)
|
||||
{
|
||||
var prevVerDir = _Default.VersionDir(histDir, version - 1);
|
||||
|
||||
var prevUrl = MakePublicHistoryUrl(fileName, (version - 1).ToString(), "prev" + ext);
|
||||
if (Path.IsPathRooted(storagePath))
|
||||
prevUrl = DocEditor.getDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""));
|
||||
|
||||
var prevKey = File.ReadAllText(Path.Combine(prevVerDir, "key.txt"));
|
||||
|
||||
Dictionary<string, object> dataPrev = new Dictionary<string, object>() { // write information about previous file version to the data object
|
||||
{ "fileType", ext.Replace(".", "") },
|
||||
{ "key", prevKey }, // write key and url information about previous file version
|
||||
{ "url", prevUrl }
|
||||
};
|
||||
|
||||
string directPrevUrl;
|
||||
if (_Default.IsEnabledDirectUrl())
|
||||
{
|
||||
directPrevUrl = Path.IsPathRooted(storagePath)
|
||||
? DocEditor.getDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""), false)
|
||||
: MakePublicHistoryUrl(fileName, (version - 1).ToString(), "prev" + ext, false);
|
||||
|
||||
dataPrev.Add("directUrl", directPrevUrl); // write direct url to the data object
|
||||
}
|
||||
|
||||
versionData.Add("previous", dataPrev);
|
||||
|
||||
if (File.Exists(Path.Combine(prevVerDir, "diff.zip")))
|
||||
{
|
||||
var changesUrl = MakePublicHistoryUrl(fileName, (version - 1).ToString(), "diff.zip");
|
||||
versionData.Add("changesUrl", changesUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
var token = JwtManager.Encode(versionData);
|
||||
versionData.Add("token", token);
|
||||
}
|
||||
|
||||
context.Response.Write(jss.Serialize(versionData));
|
||||
}
|
||||
|
||||
private void Restore(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 fileName = (string)body["fileName"];
|
||||
var version = (int)body["version"];
|
||||
|
||||
var lastVersionUri = _Default.FileUri(fileName, true);
|
||||
var key = ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null)
|
||||
+ "/" + Path.GetFileName(lastVersionUri)
|
||||
+ "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode());
|
||||
|
||||
var histDir = _Default.HistoryDir(_Default.StoragePath(fileName, null));
|
||||
var currentVersionDir = _Default.VersionDir(histDir, _Default.GetFileVersion(histDir));
|
||||
var verDir = _Default.VersionDir(histDir, version);
|
||||
|
||||
if (!Directory.Exists(currentVersionDir)) Directory.CreateDirectory(currentVersionDir);
|
||||
|
||||
var ext = Path.GetExtension(fileName).ToLower();
|
||||
File.Copy(_Default.StoragePath(fileName, null), Path.Combine(currentVersionDir, "prev" + ext));
|
||||
|
||||
File.WriteAllText(Path.Combine(currentVersionDir, "key.txt"), key);
|
||||
|
||||
var changesPath = Path.Combine(_Default.VersionDir(histDir, version - 1), "changes.json");
|
||||
if (File.Exists(changesPath))
|
||||
{
|
||||
File.Copy(changesPath, Path.Combine(currentVersionDir, "changes.json"));
|
||||
}
|
||||
|
||||
File.Copy(Path.Combine(verDir, "prev" + ext), _Default.StoragePath(fileName, null), true);
|
||||
|
||||
var fileInfo = new FileInfo(_Default.StoragePath(fileName, null));
|
||||
fileInfo.LastWriteTimeUtc = DateTime.UtcNow;
|
||||
|
||||
var history = GetHistory(fileName);
|
||||
|
||||
context.Response.Write(jss.Serialize(history));
|
||||
}
|
||||
|
||||
private static void DownloadHistory(HttpContext context)
|
||||
{
|
||||
try
|
||||
@ -338,7 +511,7 @@ namespace OnlineEditorsExample
|
||||
var version = Path.GetFileName(context.Request["ver"]);
|
||||
var file = Path.GetFileName(context.Request["file"]);
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
if (JwtManager.Enabled && JwtManager.SignatureUseForRequest)
|
||||
{
|
||||
string JWTheader = string.IsNullOrEmpty(WebConfigurationManager.AppSettings["files.docservice.header"]) ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"];
|
||||
|
||||
@ -409,5 +582,175 @@ namespace OnlineEditorsExample
|
||||
TrackManager.commandRequest("meta", docKey, meta);
|
||||
context.Response.Write("{ \"result\": \"OK\"}");
|
||||
}
|
||||
|
||||
private static void Reference(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);
|
||||
Dictionary<string, object> referenceData = null;
|
||||
var fileName = "";
|
||||
var userAddress = "";
|
||||
|
||||
if (body.ContainsKey("referenceData"))
|
||||
{
|
||||
referenceData = jss.Deserialize<Dictionary<string, object>>(jss.Serialize(body["referenceData"]));
|
||||
var instanceId = (string)referenceData["instanceId"];
|
||||
var fileKey = (string)referenceData["fileKey"];
|
||||
if (instanceId == _Default.GetServerUrl(false))
|
||||
{
|
||||
var fileKeyObj = jss.Deserialize<Dictionary<string, object>>(fileKey);
|
||||
userAddress = (string)fileKeyObj["userAddress"];
|
||||
if (userAddress == HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)))
|
||||
{
|
||||
fileName = (string)fileKeyObj["fileName"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName == "")
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = (string)body["path"];
|
||||
path = Path.GetFileName(path);
|
||||
if (File.Exists(_Default.StoragePath(path, null)))
|
||||
{
|
||||
fileName = path;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"Path not found!\"}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName == "")
|
||||
{
|
||||
context.Response.Write("{ \"error\": \"File not found!\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
var directUrl = (bool) body["directUrl"];
|
||||
|
||||
var data = new Dictionary<string, object>() {
|
||||
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower().Trim('.') },
|
||||
{ "url", DocEditor.getDownloadUrl(fileName)},
|
||||
{ "directUrl", directUrl ? DocEditor.getDownloadUrl(fileName, false) : null},
|
||||
{ "referenceData", new Dictionary<string, string>()
|
||||
{
|
||||
{ "fileKey", jss.Serialize(new Dictionary<string, object>{
|
||||
{"fileName", fileName},
|
||||
{"userAddress", HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
|
||||
})
|
||||
},
|
||||
{"instanceId", _Default.GetServerUrl(false) }
|
||||
}
|
||||
},
|
||||
{ "path", fileName }
|
||||
};
|
||||
|
||||
if (JwtManager.Enabled)
|
||||
{
|
||||
var token = JwtManager.Encode(data);
|
||||
data.Add("token", token);
|
||||
}
|
||||
|
||||
context.Response.Write(jss.Serialize(data));
|
||||
}
|
||||
|
||||
// get the document history
|
||||
private static Dictionary<string, object> GetHistory(string fileName)
|
||||
{
|
||||
var jss = new JavaScriptSerializer();
|
||||
var histDir = _Default.HistoryDir(_Default.StoragePath(fileName, null));
|
||||
|
||||
var history = new Dictionary<string, object>();
|
||||
|
||||
var currentVersion = _Default.GetFileVersion(histDir);
|
||||
var currentFileUri = _Default.FileUri(fileName, true);
|
||||
var currentKey = ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null)
|
||||
+ "/" + Path.GetFileName(currentFileUri)
|
||||
+ "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode());
|
||||
|
||||
var versionList = new List<Dictionary<string, object>>();
|
||||
for (var versionNum = 1; versionNum <= currentVersion; versionNum++)
|
||||
{
|
||||
var versionObj = new Dictionary<string, object>();
|
||||
var verDir = _Default.VersionDir(histDir, versionNum); // get the path to the given file version
|
||||
|
||||
var key = versionNum == currentVersion ? currentKey : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key
|
||||
|
||||
versionObj.Add("key", key);
|
||||
versionObj.Add("version", versionNum);
|
||||
|
||||
var changesPath = Path.Combine(_Default.VersionDir(histDir, versionNum - 1), "changes.json");
|
||||
if (versionNum == 1 || !File.Exists(changesPath)) // check if the version number is equal to 1
|
||||
{
|
||||
var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file
|
||||
if (File.Exists(infoPath))
|
||||
{
|
||||
var info = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(infoPath));
|
||||
versionObj.Add("created", info["created"]); // write meta information to the object (user information and creation date)
|
||||
versionObj.Add("user", new Dictionary<string, object>()
|
||||
{
|
||||
{ "id", info["id"] },
|
||||
{ "name", info["name"] },
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (versionNum > 1) // check if the version number is greater than 1 (the file was modified)
|
||||
{
|
||||
// get the path to the changes.json file
|
||||
var changes = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(changesPath));
|
||||
var changesArray = (ArrayList)changes["changes"];
|
||||
var change = changesArray.Count > 0
|
||||
? (Dictionary<string, object>)changesArray[0]
|
||||
: new Dictionary<string, object>();
|
||||
|
||||
// write information about changes to the object
|
||||
versionObj.Add("changes", change.Count > 0 ? changes["changes"] : null);
|
||||
versionObj.Add("serverVersion", changes["serverVersion"]);
|
||||
versionObj.Add("created", change.Count > 0 ? change["created"] : null);
|
||||
versionObj.Add("user", change.Count > 0 ? change["user"] : null);
|
||||
}
|
||||
|
||||
versionList.Add(versionObj);
|
||||
}
|
||||
|
||||
history.Add("currentVersion", currentVersion);
|
||||
history.Add("history", versionList);
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
// create the public history url
|
||||
private static string MakePublicHistoryUrl(string filename, string version, string file, Boolean isServer = true)
|
||||
{
|
||||
var userAddress = isServer ? "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)) : "";
|
||||
var fileUrl = new UriBuilder(_Default.GetServerUrl(isServer));
|
||||
fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath
|
||||
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
|
||||
+ "webeditor.ashx";
|
||||
fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename)
|
||||
+ "&ver=" + version + "&file=" + file
|
||||
+ userAddress;
|
||||
return fileUrl.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,5 @@
|
||||
ONLYOFFICE Applications example uses code from the following 3rd party projects:
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
|
||||
@ -236,6 +236,7 @@ if (typeof jQuery != "undefined") {
|
||||
window.open(url, "_blank");
|
||||
jq('#hiddenFileName').val("");
|
||||
jq.unblockUI();
|
||||
document.location.reload();
|
||||
});
|
||||
|
||||
jq(document).on("click", "#beginView:not(.disable)", function () {
|
||||
@ -244,6 +245,7 @@ if (typeof jQuery != "undefined") {
|
||||
window.open(url, "_blank");
|
||||
jq('#hiddenFileName').val("");
|
||||
jq.unblockUI();
|
||||
document.location.reload();
|
||||
});
|
||||
|
||||
jq(document).on("click", "#beginEmbedded:not(.disable)", function () {
|
||||
|
||||
@ -1,21 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<appSettings>
|
||||
<clear />
|
||||
<add key="version" value="1.5.1"/>
|
||||
<add key="version" value="1.6.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|.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.fillform-docs" value=".docx|.oform"/>
|
||||
<add key="files.docservice.viewed-docs" value=".djvu|.oxps|.pdf|.xps"/>
|
||||
<add key="files.docservice.edited-docs" value=".csv|.docm|.docx|.docxf|.dotm|.dotx|.epub|.fb2|.html|.odp|.ods|.odt|.otp|.ots|.ott|.potm|.potx|.ppsm|.ppsx|.pptm|.pptx|.rtf|.txt|.xlsm|.xlsx|.xltm|.xltx"/>
|
||||
<add key="files.docservice.convert-docs" value=".doc|.dot|.dps|.dpt|.epub|.et|.ett|.fb2|.fodp|.fods|.fodt|.htm|.html|.mht|.mhtml|.odp|.ods|.odt|.otp|.ots|.ott|.pot|.pps|.ppt|.rtf|.stw|.sxc|.sxi|.sxw|.wps|.wpt|.xls|.xlsb|.xlt|.xml"/>
|
||||
<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.languages" value="en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (People's Republic of China)|zh-TW:Chinese (Traditional, Taiwan)|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|ms:Malay (Malaysia)|nb:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA: Test Language"/>
|
||||
<add key="files.docservice.token.useforrequest" value="true" />
|
||||
|
||||
<add key="files.docservice.languages" value="en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (Simplified)|zh-TW:Chinese (Traditional)|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|lo:Lao|lv:Latvian|ms:Malay (Malaysia)|no:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|si:Sinhala (Sri Lanka)|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA: Test Language"/>
|
||||
|
||||
<add key="files.docservice.url.site" value="http://documentserver/"/>
|
||||
|
||||
|
||||
@ -1,8 +1,17 @@
|
||||
ONLYOFFICE Applications example uses code from the following 3rd party projects:
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: gson.license
|
||||
|
||||
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
|
||||
License: MPL 2.0 or EPL 1.0
|
||||
License File: h2database.license
|
||||
|
||||
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: jackson-databind.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
@ -16,14 +25,30 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
|
||||
License: Apache 2.0
|
||||
License File: JSON.simple.license
|
||||
|
||||
Project Lombok - Project Lombok is a java library that automatically plugs into your editor and build tools. (https://mvnrepository.com/artifact/org.projectlombok/lombok).
|
||||
License: MIT
|
||||
License File lombok.license
|
||||
|
||||
ModelMapper - ModelMapper is an intelligent object mapping library that automatically maps objects to each other. (https://github.com/modelmapper/modelmapper)
|
||||
License: Apache 2.0
|
||||
License File modelmapper.license
|
||||
|
||||
Prime JWT - is intended to be fast and easy to use. Prime JWT has a single external dependency on Jackson. (https://github.com/ws-apps/prime-jwt/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: prime-jwt.license
|
||||
@ -43,27 +68,3 @@ License File: spring-boot.license
|
||||
Spring Data JPA - Persist data in SQL stores with Java Persistence API using Spring Data and Hibernate. (https://github.com/spring-projects/spring-data-jpa/blob/main/LICENSE.txt)
|
||||
License: Apache 2.0
|
||||
License File: spring-data-jpa.license
|
||||
|
||||
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
|
||||
License: MPL 2.0 or EPL 1.0
|
||||
License File: h2database.license
|
||||
|
||||
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
|
||||
License: Apache 2.0
|
||||
License File: JSON.simple.license
|
||||
|
||||
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: gson.license
|
||||
|
||||
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: jackson-databind.license
|
||||
|
||||
ModelMapper - ModelMapper is an intelligent object mapping library that automatically maps objects to each other. (https://github.com/modelmapper/modelmapper)
|
||||
License: Apache 2.0
|
||||
License File modelmapper.license
|
||||
|
||||
Project Lombok - Project Lombok is a java library that automatically plugs into your editor and build tools. (https://mvnrepository.com/artifact/org.projectlombok/lombok).
|
||||
License: MIT
|
||||
License File lombok.license
|
||||
|
||||
@ -1,8 +1,17 @@
|
||||
ONLYOFFICE Applications example uses code from the following 3rd party projects:
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: gson.license
|
||||
|
||||
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
|
||||
License: MPL 2.0 or EPL 1.0
|
||||
License File: h2database.license
|
||||
|
||||
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: jackson-databind.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
@ -16,14 +25,30 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.UI.license
|
||||
|
||||
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
|
||||
License: Apache 2.0
|
||||
License File: JSON.simple.license
|
||||
|
||||
Project Lombok - Project Lombok is a java library that automatically plugs into your editor and build tools. (https://mvnrepository.com/artifact/org.projectlombok/lombok).
|
||||
License: MIT
|
||||
License File lombok.license
|
||||
|
||||
ModelMapper - ModelMapper is an intelligent object mapping library that automatically maps objects to each other. (https://github.com/modelmapper/modelmapper)
|
||||
License: Apache 2.0
|
||||
License File modelmapper.license
|
||||
|
||||
Prime JWT - is intended to be fast and easy to use. Prime JWT has a single external dependency on Jackson. (https://github.com/ws-apps/prime-jwt/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: prime-jwt.license
|
||||
@ -43,19 +68,3 @@ License File: spring-boot.license
|
||||
Spring Data JPA - Persist data in SQL stores with Java Persistence API using Spring Data and Hibernate. (https://github.com/spring-projects/spring-data-jpa/blob/main/LICENSE.txt)
|
||||
License: Apache 2.0
|
||||
License File: spring-data-jpa.license
|
||||
|
||||
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
|
||||
License: MPL 2.0 or EPL 1.0
|
||||
License File: h2database.license
|
||||
|
||||
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
|
||||
License: Apache 2.0
|
||||
License File: JSON.simple.license
|
||||
|
||||
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: gson.license
|
||||
|
||||
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
|
||||
License: Apache 2.0
|
||||
License File: jackson-databind.license
|
||||
@ -45,6 +45,7 @@ public class ExampleData {
|
||||
"Can’t see anyone’s information",
|
||||
"Can't rename files from the editor",
|
||||
"Can't view chat",
|
||||
"Can't protect file",
|
||||
"View file without collaboration"
|
||||
);
|
||||
|
||||
@ -92,22 +93,23 @@ public class ExampleData {
|
||||
userService.createUser("John Smith", "smith@example.com", descriptionUserFirst,
|
||||
"", List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()), null, true);
|
||||
List.of(FilterState.NULL.toString()), null, true, true);
|
||||
|
||||
// create user 2 with the specified parameters
|
||||
userService.createUser("Mark Pottato", "pottato@example.com", descriptionUserSecond,
|
||||
"group-2", List.of("", "group-2"), List.of(FilterState.NULL.toString()),
|
||||
List.of("group-2", ""), List.of("group-2"), List.of("group-2", ""), true, true);
|
||||
List.of("group-2", ""), List.of("group-2"), List.of("group-2", ""), true, true,
|
||||
true);
|
||||
|
||||
// create user 3 with the specified parameters
|
||||
userService.createUser("Hamish Mitchell", "mitchell@example.com", descriptionUserThird,
|
||||
"group-3", List.of("group-2"), List.of("group-2", "group-3"), List.of("group-2"),
|
||||
new ArrayList<>(), List.of("group-2"), false, true);
|
||||
new ArrayList<>(), List.of("group-2"), false, true, true);
|
||||
|
||||
// create user 0 with the specified parameters
|
||||
userService.createUser("Anonymous", null, descriptionUserZero, "",
|
||||
List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
|
||||
List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()),
|
||||
new ArrayList<>(), null, false);
|
||||
new ArrayList<>(), null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,11 +19,14 @@
|
||||
package com.onlyoffice.integration.controllers;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.onlyoffice.integration.documentserver.callbacks.CallbackHandler;
|
||||
import com.onlyoffice.integration.documentserver.managers.jwt.JwtManager;
|
||||
import com.onlyoffice.integration.documentserver.storage.FileStorageMutator;
|
||||
import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
|
||||
import com.onlyoffice.integration.dto.Converter;
|
||||
import com.onlyoffice.integration.dto.ConvertedData;
|
||||
import com.onlyoffice.integration.dto.Track;
|
||||
import com.onlyoffice.integration.entities.User;
|
||||
import com.onlyoffice.integration.documentserver.models.enums.DocumentType;
|
||||
@ -32,7 +35,10 @@ 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.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
@ -45,20 +51,30 @@ import org.springframework.web.bind.annotation.CookieValue;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -198,15 +214,18 @@ public class FileController {
|
||||
// get document type (word, cell or slide)
|
||||
DocumentType type = fileUtility.getDocumentType(fileName);
|
||||
|
||||
// get an editor internal extension (".docx", ".xlsx" or ".pptx")
|
||||
String internalFileExt = fileUtility.getInternalExtension(type);
|
||||
// convert to .ooxml
|
||||
String internalFileExt = "ooxml";
|
||||
|
||||
try {
|
||||
// check if the file with such an extension can be converted
|
||||
if (fileUtility.getConvertExts().contains(fileExt)) {
|
||||
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);
|
||||
ConvertedData response = serviceConverter // get the URL to the converted file
|
||||
.getConvertedData(fileUri, fileExt, internalFileExt, key, filePass, true, lang);
|
||||
|
||||
String newFileUri = response.getUri();
|
||||
String newFileType = "." + response.getFileType();
|
||||
|
||||
if (newFileUri.isEmpty()) {
|
||||
return "{ \"step\" : \"0\", \"filename\" : \"" + fileName + "\"}";
|
||||
@ -214,7 +233,7 @@ public class FileController {
|
||||
|
||||
/* 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 nameWithInternalExt = fileUtility.getFileNameWithoutExtension(fileName) + newFileType;
|
||||
String correctedName = documentManager.getCorrectName(nameWithInternalExt);
|
||||
|
||||
URL url = new URL(newFileUri);
|
||||
@ -226,6 +245,9 @@ public class FileController {
|
||||
throw new RuntimeException("Input stream is null");
|
||||
}
|
||||
|
||||
// remove source file
|
||||
storageMutator.deleteFile(fileName);
|
||||
|
||||
// create the converted file with input stream
|
||||
storageMutator.createFile(Path.of(storagePathBuilder.getFileLocation(correctedName)), stream);
|
||||
fileName = correctedName;
|
||||
@ -266,7 +288,7 @@ public class FileController {
|
||||
@RequestParam("file") final String file) { // history file
|
||||
try {
|
||||
// check if a token is enabled or not
|
||||
if (jwtManager.tokenEnabled()) {
|
||||
if (jwtManager.tokenEnabled() && jwtManager.tokenUseForRequest()) {
|
||||
String header = request.getHeader(documentJwtHeader == null // get the document JWT header
|
||||
|| documentJwtHeader.isEmpty() ? "Authorization" : documentJwtHeader);
|
||||
if (header != null && !header.isEmpty()) {
|
||||
@ -285,16 +307,20 @@ public class FileController {
|
||||
|
||||
@GetMapping(path = "${url.download}")
|
||||
public ResponseEntity<Resource> download(final HttpServletRequest request, // download a file
|
||||
@RequestParam("fileName") final String fileName) {
|
||||
@RequestParam("fileName") final String fileName,
|
||||
@RequestParam(value = "userAddress", required = false)
|
||||
final String userAddress) {
|
||||
try {
|
||||
// check if a token is enabled or not
|
||||
if (jwtManager.tokenEnabled()) {
|
||||
String header = request.getHeader(documentJwtHeader == null // get the document JWT header
|
||||
if (jwtManager.tokenEnabled() && userAddress != null && jwtManager.tokenUseForRequest()) {
|
||||
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 downloadFile(fileName); // download data from the specified file
|
||||
@ -338,13 +364,13 @@ public class FileController {
|
||||
@GetMapping("/assets")
|
||||
public ResponseEntity<Resource> assets(@RequestParam("name")
|
||||
final String name) { // get sample files from the assests
|
||||
String fileName = Path.of("assets", "sample", fileUtility.getFileName(name)).toString();
|
||||
String fileName = Path.of("assets", "document-templates", "sample", fileUtility.getFileName(name)).toString();
|
||||
return downloadFile(fileName);
|
||||
}
|
||||
|
||||
@GetMapping("/csv")
|
||||
public ResponseEntity<Resource> csv() { // download a csv file
|
||||
String fileName = Path.of("assets", "sample", "csv.csv").toString();
|
||||
String fileName = Path.of("assets", "document-templates", "sample", "csv.csv").toString();
|
||||
return downloadFile(fileName);
|
||||
}
|
||||
|
||||
@ -442,4 +468,157 @@ public class FileController {
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/reference")
|
||||
@ResponseBody
|
||||
public String reference(@RequestBody final JSONObject body) {
|
||||
try {
|
||||
JSONParser parser = new JSONParser();
|
||||
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
String userAddress = "";
|
||||
String fileName = "";
|
||||
|
||||
if (body.containsKey("referenceData")) {
|
||||
LinkedHashMap referenceDataObj = (LinkedHashMap) body.get("referenceData");
|
||||
String instanceId = (String) referenceDataObj.get("instanceId");
|
||||
|
||||
if (instanceId.equals(storagePathBuilder.getServerUrl(false))) {
|
||||
JSONObject fileKey = (JSONObject) parser.parse((String) referenceDataObj.get("fileKey"));
|
||||
userAddress = (String) fileKey.get("userAddress");
|
||||
if (userAddress.equals(InetAddress.getLocalHost().getHostAddress())) {
|
||||
fileName = (String) fileKey.get("fileName");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (fileName.equals("")) {
|
||||
try {
|
||||
String path = (String) body.get("path");
|
||||
path = fileUtility.getFileName(path);
|
||||
File f = new File(storagePathBuilder.getFileLocation(path));
|
||||
if (f.exists()) {
|
||||
fileName = path;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName.equals("")) {
|
||||
return "{ \"error\": \"File not found\"}";
|
||||
}
|
||||
|
||||
boolean directUrl = (boolean) body.get("directUrl");
|
||||
|
||||
HashMap<String, Object> fileKey = new HashMap<>();
|
||||
fileKey.put("fileName", fileName);
|
||||
fileKey.put("userAddress", InetAddress.getLocalHost().getHostAddress());
|
||||
|
||||
HashMap<String, Object> referenceData = new HashMap<>();
|
||||
referenceData.put("instanceId", storagePathBuilder.getServerUrl(true));
|
||||
referenceData.put("fileKey", gson.toJson(fileKey));
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("fileType", fileUtility.getFileExtension(fileName).replace(".", ""));
|
||||
data.put("url", documentManager.getDownloadUrl(fileName, true));
|
||||
data.put("directUrl", directUrl ? documentManager.getDownloadUrl(fileName, false) : null);
|
||||
data.put("referenceData", referenceData);
|
||||
data.put("path", fileName);
|
||||
|
||||
if (jwtManager.tokenEnabled()) {
|
||||
String token = jwtManager.createToken(data);
|
||||
data.put("token", token);
|
||||
}
|
||||
return gson.toJson(data);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/restore")
|
||||
@ResponseBody
|
||||
public String restore(@RequestBody final JSONObject body) {
|
||||
try {
|
||||
String sourceBasename = (String) body.get("fileName");
|
||||
Integer version = (Integer) body.get("version");
|
||||
String userID = (String) body.get("userId");
|
||||
|
||||
String sourceStringFile = storagePathBuilder.getFileLocation(sourceBasename);
|
||||
File sourceFile = new File(sourceStringFile);
|
||||
Path sourcePathFile = sourceFile.toPath();
|
||||
String historyDirectory = storagePathBuilder.getHistoryDir(sourcePathFile.toString());
|
||||
|
||||
Integer bumpedVersion = storagePathBuilder.getFileVersion(historyDirectory, false);
|
||||
String bumpedVersionStringDirectory = documentManager.versionDir(historyDirectory, bumpedVersion, true);
|
||||
File bumpedVersionDirectory = new File(bumpedVersionStringDirectory);
|
||||
if (!bumpedVersionDirectory.exists()) {
|
||||
bumpedVersionDirectory.mkdir();
|
||||
}
|
||||
|
||||
Path bumpedKeyPathFile = Paths.get(bumpedVersionStringDirectory, "key.txt");
|
||||
String bumpedKeyStringFile = bumpedKeyPathFile.toString();
|
||||
File bumpedKeyFile = new File(bumpedKeyStringFile);
|
||||
String bumpedKey = serviceConverter.generateRevisionId(
|
||||
storagePathBuilder.getStorageLocation()
|
||||
+ "/"
|
||||
+ sourceBasename
|
||||
+ "/"
|
||||
+ Long.toString(sourceFile.lastModified())
|
||||
);
|
||||
FileWriter bumpedKeyFileWriter = new FileWriter(bumpedKeyFile);
|
||||
bumpedKeyFileWriter.write(bumpedKey);
|
||||
bumpedKeyFileWriter.close();
|
||||
|
||||
Integer userInnerID = Integer.parseInt(userID.replace("uid-", ""));
|
||||
User user = userService.findUserById(userInnerID).get();
|
||||
|
||||
Path bumpedChangesPathFile = Paths.get(bumpedVersionStringDirectory, "changes.json");
|
||||
String bumpedChangesStringFile = bumpedChangesPathFile.toString();
|
||||
File bumpedChangesFile = new File(bumpedChangesStringFile);
|
||||
JSONObject bumpedChangesUser = new JSONObject();
|
||||
// Don't add the `uid-` prefix.
|
||||
// https://github.com/ONLYOFFICE/document-server-integration/issues/437#issuecomment-1663526562
|
||||
bumpedChangesUser.put("id", user.getId());
|
||||
bumpedChangesUser.put("name", user.getName());
|
||||
JSONObject bumpedChangesChangesItem = new JSONObject();
|
||||
bumpedChangesChangesItem.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
bumpedChangesChangesItem.put("user", bumpedChangesUser);
|
||||
JSONArray bumpedChangesChanges = new JSONArray();
|
||||
bumpedChangesChanges.add(bumpedChangesChangesItem);
|
||||
JSONObject bumpedChanges = new JSONObject();
|
||||
bumpedChanges.put("serverVersion", null);
|
||||
bumpedChanges.put("changes", bumpedChangesChanges);
|
||||
String bumpedChangesContent = bumpedChanges.toJSONString();
|
||||
FileWriter bumpedChangesFileWriter = new FileWriter(bumpedChangesFile);
|
||||
bumpedChangesFileWriter.write(bumpedChangesContent);
|
||||
bumpedChangesFileWriter.close();
|
||||
|
||||
String sourceExtension = fileUtility.getFileExtension(sourceBasename);
|
||||
String previousBasename = "prev" + sourceExtension;
|
||||
|
||||
Path bumpedFile = Paths.get(bumpedVersionStringDirectory, previousBasename);
|
||||
Files.move(sourcePathFile, bumpedFile);
|
||||
|
||||
String recoveryVersionStringDirectory = documentManager.versionDir(historyDirectory, version, true);
|
||||
Path recoveryPathFile = Paths.get(recoveryVersionStringDirectory, previousBasename);
|
||||
String recoveryStringFile = recoveryPathFile.toString();
|
||||
FileInputStream recoveryStream = new FileInputStream(recoveryStringFile);
|
||||
storageMutator.createFile(sourcePathFile, recoveryStream);
|
||||
recoveryStream.close();
|
||||
|
||||
JSONObject responseBody = new JSONObject();
|
||||
responseBody.put("error", null);
|
||||
responseBody.put("success", true);
|
||||
return responseBody.toJSONString();
|
||||
} catch (Exception error) {
|
||||
error.printStackTrace();
|
||||
JSONObject responseBody = new JSONObject();
|
||||
responseBody.put("error", error.getMessage());
|
||||
responseBody.put("success", false);
|
||||
return responseBody.toJSONString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -75,14 +76,12 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
@Autowired
|
||||
private ServiceConverter serviceConverter;
|
||||
|
||||
// save file information from the URL to the file specified
|
||||
private void downloadToFile(final String url, final Path path) throws Exception {
|
||||
// download file from url
|
||||
@SneakyThrows
|
||||
private byte[] getDownloadFile(final String url) {
|
||||
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();
|
||||
@ -100,7 +99,17 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
throw new RuntimeException("Input stream is null");
|
||||
}
|
||||
|
||||
storageMutator.createOrUpdateFile(path, stream); // update a file or create a new one
|
||||
return stream.readAllBytes();
|
||||
}
|
||||
|
||||
// file saving
|
||||
@SneakyThrows
|
||||
private void saveFile(final byte[] byteArray, final Path path) {
|
||||
if (path == null) {
|
||||
throw new RuntimeException("Path argument is not specified"); // file isn't specified
|
||||
}
|
||||
// update a file or create a new one
|
||||
storageMutator.createOrUpdateFile(path, new ByteArrayInputStream(byteArray));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@ -118,9 +127,9 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
if (!curExt.equals(downloadExt)) {
|
||||
try {
|
||||
String newFileUri = serviceConverter
|
||||
.getConvertedUri(downloadUri, downloadExt, curExt,
|
||||
.getConvertedData(downloadUri, downloadExt, curExt,
|
||||
serviceConverter.generateRevisionId(downloadUri), null, false,
|
||||
null); // convert a file and get URL to a new file
|
||||
null).getUri(); // convert a file and get URL to a new file
|
||||
if (newFileUri.isEmpty()) {
|
||||
newFileName = documentManager
|
||||
.getCorrectName(fileUtility.getFileNameWithoutExtension(fileName)
|
||||
@ -134,6 +143,8 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
}
|
||||
}
|
||||
|
||||
byte[] byteArrayFile = getDownloadFile(downloadUri); // download document file
|
||||
|
||||
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
|
||||
@ -152,12 +163,13 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
|
||||
storageMutator.createDirectory(ver); // create the file version directory
|
||||
|
||||
// move the last file version to the file version directory with the "prev" postfix
|
||||
storageMutator.moveFile(lastVersion, Paths.get(versionDir + File.separator + "prev" + curExt));
|
||||
lastVersion.toFile().renameTo(new File(versionDir + File.separator + "prev" + curExt));
|
||||
|
||||
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
|
||||
saveFile(byteArrayFile, toSave); // save document file
|
||||
|
||||
byte[] byteArrayChanges = getDownloadFile(changesUri); // download file changes
|
||||
saveFile(byteArrayChanges, Path
|
||||
.of(versionDir + File.separator + "diff.zip")); // save file changes to the diff.zip archive
|
||||
|
||||
JSONObject jsonChanges = new JSONObject(); // create a json object for document changes
|
||||
jsonChanges.put("changes", body.getHistory().getChanges()); // put the changes to the json object
|
||||
@ -201,7 +213,8 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
}
|
||||
|
||||
String headerToken;
|
||||
if (jwtManager.tokenEnabled()) { // check if a secret key to generate token exists or not
|
||||
// check if a secret key to generate token exists or not
|
||||
if (jwtManager.tokenEnabled() && jwtManager.tokenUseForRequest()) {
|
||||
Map<String, Object> payloadMap = new HashMap<>();
|
||||
payloadMap.put("payload", params);
|
||||
headerToken = jwtManager.createToken(payloadMap); // encode a payload object into a header token
|
||||
@ -246,8 +259,8 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(response.toJSONString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void processForceSave(final Track body, final String fileNameParam) { // file force saving process
|
||||
@ -266,8 +279,8 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
try {
|
||||
// convert file and get URL to a new file
|
||||
String newFileUri = serviceConverter
|
||||
.getConvertedUri(downloadUri, downloadExt, curExt, serviceConverter
|
||||
.generateRevisionId(downloadUri), null, false, null);
|
||||
.getConvertedData(downloadUri, downloadExt, curExt, serviceConverter
|
||||
.generateRevisionId(downloadUri), null, false, null).getUri();
|
||||
if (newFileUri.isEmpty()) {
|
||||
newFileName = true;
|
||||
} else {
|
||||
@ -278,6 +291,7 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
}
|
||||
}
|
||||
|
||||
byte[] byteArrayFile = getDownloadFile(downloadUri); // download document file
|
||||
String forcesavePath = "";
|
||||
|
||||
// todo: Use ENUMS
|
||||
@ -313,6 +327,6 @@ public class DefaultCallbackManager implements CallbackManager {
|
||||
}
|
||||
}
|
||||
|
||||
downloadToFile(downloadUri, Path.of(forcesavePath));
|
||||
saveFile(byteArrayFile, Path.of(forcesavePath));
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,8 +217,14 @@ public class DefaultDocumentManager implements DocumentManager {
|
||||
public String createDemo(final String fileExt, final Boolean sample, final String uid, final String uname) {
|
||||
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 demoPath =
|
||||
"assets"
|
||||
+ File.separator
|
||||
+ "document-templates"
|
||||
+ File.separator
|
||||
+ (sample ? "sample" : "new")
|
||||
+ File.separator
|
||||
+ demoName;
|
||||
|
||||
// get a file name with an index if the file with such a name already exists
|
||||
String fileName = getCorrectName(demoName);
|
||||
|
||||
@ -37,6 +37,8 @@ import java.util.Map;
|
||||
public class DefaultJwtManager implements JwtManager {
|
||||
@Value("${files.docservice.secret}")
|
||||
private String tokenSecret;
|
||||
@Value("${files.docservice.token-use-for-request}")
|
||||
private String tokenUseForRequest;
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
@Autowired
|
||||
@ -62,6 +64,10 @@ public class DefaultJwtManager implements JwtManager {
|
||||
return tokenSecret != null && !tokenSecret.isEmpty();
|
||||
}
|
||||
|
||||
public boolean tokenUseForRequest() {
|
||||
return Boolean.parseBoolean(tokenUseForRequest) && !tokenUseForRequest.isEmpty();
|
||||
}
|
||||
|
||||
// read document token
|
||||
public JWT readToken(final String token) {
|
||||
try {
|
||||
@ -84,7 +90,7 @@ public class DefaultJwtManager implements JwtManager {
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("{\"error\":1,\"message\":\"JSON Parsing error\"}");
|
||||
}
|
||||
if (tokenEnabled()) { // check if the token is enabled
|
||||
if (tokenEnabled() && tokenUseForRequest()) { // 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
|
||||
|
||||
@ -26,6 +26,7 @@ import java.util.Map;
|
||||
// specify the jwt manager functions
|
||||
public interface JwtManager {
|
||||
boolean tokenEnabled(); // check if the token is enabled
|
||||
boolean tokenUseForRequest(); // 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
|
||||
|
||||
@ -27,5 +27,6 @@ public enum Action {
|
||||
comment,
|
||||
chat,
|
||||
fillForms,
|
||||
blockcontent
|
||||
blockcontent,
|
||||
protect
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Component
|
||||
@Scope("prototype")
|
||||
@Getter
|
||||
@ -43,4 +45,5 @@ public class Document { // the parameters pertaining to the document (title, ur
|
||||
as file name when the document is downloaded */
|
||||
private String url; // the absolute URL where the source viewed or edited document is stored
|
||||
private String directUrl;
|
||||
private HashMap<String, Object> referenceData;
|
||||
}
|
||||
|
||||
@ -51,4 +51,5 @@ public class Permission extends AbstractModel { // the permission for the docum
|
||||
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;
|
||||
private Boolean protect = true;
|
||||
}
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2023
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.onlyoffice.integration.documentserver.models.filemodel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class ReferenceData {
|
||||
@Autowired
|
||||
private FileStoragePathBuilder storagePathBuilder;
|
||||
private final String instanceId;
|
||||
private final Map<String, String> fileKey;
|
||||
public ReferenceData(final String fileName, final String curUserHostAddress, final User user) {
|
||||
instanceId = storagePathBuilder.getServerUrl(true);
|
||||
Map<String, String> fileKeyList = new HashMap<>();
|
||||
if (!user.getId().equals("uid-0")) {
|
||||
fileKeyList.put("fileName", fileName);
|
||||
fileKeyList.put("userAddress", curUserHostAddress);
|
||||
} else {
|
||||
fileKeyList = null;
|
||||
}
|
||||
fileKey = fileKeyList;
|
||||
}
|
||||
}
|
||||
@ -20,6 +20,7 @@ package com.onlyoffice.integration.documentserver.storage;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
@ -37,5 +38,5 @@ public interface FileStorageMutator {
|
||||
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
|
||||
boolean createOrUpdateFile(Path path, ByteArrayInputStream stream); // create or update a file
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
@ -332,7 +333,7 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
}
|
||||
|
||||
// create or update a file
|
||||
public boolean createOrUpdateFile(final Path path, final InputStream stream) {
|
||||
public boolean createOrUpdateFile(final Path path, final ByteArrayInputStream stream) {
|
||||
if (!Files.exists(path)) { // if the specified file does not exist
|
||||
return createFile(path, stream); // create it in the specified directory
|
||||
} else {
|
||||
@ -372,7 +373,7 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run through all the files in the history directory
|
||||
|
||||
@ -23,6 +23,7 @@ import com.onlyoffice.integration.documentserver.managers.jwt.JwtManager;
|
||||
import com.onlyoffice.integration.documentserver.models.enums.ConvertErrorType;
|
||||
import com.onlyoffice.integration.documentserver.util.file.FileUtility;
|
||||
import com.onlyoffice.integration.dto.Convert;
|
||||
import com.onlyoffice.integration.dto.ConvertedData;
|
||||
import lombok.SneakyThrows;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
@ -105,17 +106,17 @@ public class DefaultServiceConverter implements ServiceConverter {
|
||||
|
||||
connection.connect();
|
||||
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
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
|
||||
}
|
||||
|
||||
int statusCode = connection.getResponseCode();
|
||||
if (statusCode != HttpStatus.OK.value()) { // checking status code
|
||||
connection.disconnect();
|
||||
throw new RuntimeException("Convertation service returned status: " + statusCode);
|
||||
}
|
||||
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
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(); // get the input stream
|
||||
jsonString = convertStreamToString(response); // convert the response stream into a string
|
||||
} finally {
|
||||
@ -125,9 +126,9 @@ public class DefaultServiceConverter implements ServiceConverter {
|
||||
}
|
||||
|
||||
// get the URL to the converted file
|
||||
public String getConvertedUri(final String documentUri, final String fromExtension,
|
||||
final String toExtension, final String documentRevisionId,
|
||||
final String filePass, final Boolean isAsync, final String lang) {
|
||||
public ConvertedData getConvertedData(final String documentUri, final String fromExtension,
|
||||
final String toExtension, final String documentRevisionId,
|
||||
final String filePass, final Boolean isAsync, final String lang) {
|
||||
// check if the fromExtension parameter is defined; if not, get it from the document url
|
||||
String fromExt = fromExtension == null || fromExtension.isEmpty()
|
||||
? fileUtility.getFileExtension(documentUri) : fromExtension;
|
||||
@ -155,7 +156,7 @@ public class DefaultServiceConverter implements ServiceConverter {
|
||||
}
|
||||
|
||||
String headerToken = "";
|
||||
if (jwtManager.tokenEnabled()) {
|
||||
if (jwtManager.tokenEnabled() && jwtManager.tokenUseForRequest()) {
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("region", lang);
|
||||
map.put("url", body.getUrl());
|
||||
@ -179,7 +180,7 @@ public class DefaultServiceConverter implements ServiceConverter {
|
||||
|
||||
String jsonString = postToServer(body, headerToken);
|
||||
|
||||
return getResponseUri(jsonString);
|
||||
return getResponseData(jsonString);
|
||||
}
|
||||
|
||||
// generate document key
|
||||
@ -203,7 +204,7 @@ public class DefaultServiceConverter implements ServiceConverter {
|
||||
|
||||
// get the response URL
|
||||
@SneakyThrows
|
||||
private String getResponseUri(final String jsonString) {
|
||||
private ConvertedData getResponseData(final String jsonString) {
|
||||
JSONObject jsonObj = convertStringToJSON(jsonString);
|
||||
|
||||
Object error = jsonObj.get("error");
|
||||
@ -216,10 +217,15 @@ public class DefaultServiceConverter implements ServiceConverter {
|
||||
|
||||
Long resultPercent = 0L;
|
||||
String responseUri = null;
|
||||
String responseFileType = null;
|
||||
ConvertedData convertedData = new ConvertedData("", "");
|
||||
|
||||
if (isEndConvert) { // if the conversion is completed
|
||||
resultPercent = FULL_LOADING_IN_PERCENT;
|
||||
responseUri = (String) jsonObj.get("fileUrl"); // get the file URL
|
||||
responseFileType = (String) jsonObj.get("fileType"); // get the file type
|
||||
convertedData.setUri(responseUri);
|
||||
convertedData.setFileType(responseFileType);
|
||||
} else { // if the conversion isn't completed
|
||||
resultPercent = (Long) jsonObj.get("percent");
|
||||
|
||||
@ -227,7 +233,7 @@ public class DefaultServiceConverter implements ServiceConverter {
|
||||
resultPercent = resultPercent >= FULL_LOADING_IN_PERCENT ? FULL_LOADING_IN_PERCENT - 1 : resultPercent;
|
||||
}
|
||||
|
||||
return resultPercent >= FULL_LOADING_IN_PERCENT ? responseUri : "";
|
||||
return convertedData;
|
||||
}
|
||||
|
||||
// convert stream to string
|
||||
|
||||
@ -18,15 +18,16 @@
|
||||
|
||||
package com.onlyoffice.integration.documentserver.util.service;
|
||||
|
||||
import com.onlyoffice.integration.dto.ConvertedData;
|
||||
import org.json.simple.JSONObject;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
// specify the converter service functions
|
||||
public interface ServiceConverter {
|
||||
String getConvertedUri(String documentUri, String fromExtension, // get the URL to the converted file
|
||||
String toExtension, String documentRevisionId,
|
||||
String filePass, Boolean isAsync, String lang);
|
||||
ConvertedData getConvertedData(String documentUri, String fromExtension, // get the URL to the converted file
|
||||
String toExtension, String documentRevisionId,
|
||||
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
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2023
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.onlyoffice.integration.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ConvertedData {
|
||||
private String uri;
|
||||
private String fileType;
|
||||
}
|
||||
@ -52,4 +52,5 @@ public class Permission extends AbstractEntity {
|
||||
private List<Group> commentsRemoveGroups;
|
||||
@ManyToMany
|
||||
private List<Group> userInfoGroups;
|
||||
private Boolean protect = true;
|
||||
}
|
||||
|
||||
@ -38,7 +38,8 @@ public class PermissionServices {
|
||||
final List<Group> commentEditGroups,
|
||||
final List<Group> commentRemoveGroups,
|
||||
final List<Group> userInfoGroups,
|
||||
final Boolean chat) {
|
||||
final Boolean chat,
|
||||
final Boolean protect) {
|
||||
|
||||
Permission permission = new Permission();
|
||||
permission.setReviewGroups(reviewGroups); // define the groups whose changes the user can accept/reject
|
||||
@ -48,6 +49,7 @@ public class PermissionServices {
|
||||
whose comments the user can remove */
|
||||
permission.setUserInfoGroups(userInfoGroups);
|
||||
permission.setChat(chat);
|
||||
permission.setProtect(protect);
|
||||
|
||||
permissionRepository.save(permission); // save new permissions
|
||||
|
||||
|
||||
@ -57,7 +57,8 @@ public class UserServices {
|
||||
final List<String> editGroups,
|
||||
final List<String> removeGroups,
|
||||
final List<String> userInfoGroups, final Boolean favoriteDoc,
|
||||
final Boolean chat) {
|
||||
final Boolean chat,
|
||||
final Boolean protect) {
|
||||
User newUser = new User();
|
||||
newUser.setName(name); // set the user name
|
||||
newUser.setEmail(email); // set the user email
|
||||
@ -81,7 +82,8 @@ public class UserServices {
|
||||
commentGroupsEdit,
|
||||
commentGroupsRemove,
|
||||
usInfoGroups,
|
||||
chat); // specify permissions for the current user
|
||||
chat,
|
||||
protect); // specify permissions for the current user
|
||||
newUser.setPermissions(permission);
|
||||
|
||||
userRepository.save(newUser); // save a new user
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
package com.onlyoffice.integration.services.configurers.implementations;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.onlyoffice.integration.documentserver.models.filemodel.Document;
|
||||
import com.onlyoffice.integration.documentserver.models.filemodel.Permission;
|
||||
import com.onlyoffice.integration.documentserver.storage.FileStoragePathBuilder;
|
||||
@ -31,6 +32,8 @@ import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
@Primary
|
||||
@ -71,7 +74,20 @@ public class DefaultDocumentConfigurer implements DocumentConfigurer<DefaultDocu
|
||||
+ "/" + fileName + "/"
|
||||
+ new File(storagePathBuilder.getFileLocation(fileName)).lastModified());
|
||||
|
||||
Gson gson = new Gson();
|
||||
HashMap<String, String> fileKey = new HashMap<>();
|
||||
fileKey.put("fileName", fileName);
|
||||
try {
|
||||
fileKey.put("userAddress", InetAddress.getLocalHost().getHostAddress());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HashMap<String, Object> referenceData = new HashMap<>();
|
||||
referenceData.put("instanceId", storagePathBuilder.getServerUrl(true));
|
||||
referenceData.put("fileKey", gson.toJson(fileKey));
|
||||
|
||||
document.setKey(key); // set the key to the document config
|
||||
document.setPermissions(permission); // set the permission parameters to the document config
|
||||
document.setReferenceData(referenceData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
package com.onlyoffice.integration.services.configurers.wrappers;
|
||||
|
||||
import com.onlyoffice.integration.documentserver.models.filemodel.Permission;
|
||||
import com.onlyoffice.integration.documentserver.models.filemodel.ReferenceData;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@ -29,4 +30,5 @@ public class DefaultDocumentWrapper {
|
||||
private String fileName;
|
||||
private Boolean favorite;
|
||||
private Boolean isEnableDirectUrl;
|
||||
private ReferenceData referenceData;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
server.version=1.5.1
|
||||
server.version=1.6.0
|
||||
|
||||
server.address=
|
||||
server.port=4000
|
||||
@ -8,10 +8,10 @@ filesize-max=5242880
|
||||
files.storage=
|
||||
files.storage.folder=documents
|
||||
|
||||
files.docservice.fillforms-docs=.oform|.docx
|
||||
files.docservice.viewed-docs=.pdf|.djvu|.xps|.oxps
|
||||
files.docservice.edited-docs=.docx|.xlsx|.csv|.pptx|.txt|.docxf
|
||||
files.docservice.convert-docs=.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
|
||||
files.docservice.fillforms-docs=.docx|.oform
|
||||
files.docservice.viewed-docs=.djvu|.oxps|.pdf|.xps
|
||||
files.docservice.edited-docs=.csv|.docm|.docx|.docxf|.dotm|.dotx|.epub|.fb2|.html|.odp|.ods|.odt|.otp|.ots|.ott|.potm|.potx|.ppsm|.ppsx|.pptm|.pptx|.rtf|.txt|.xlsm|.xlsx|.xltm|.xltx
|
||||
files.docservice.convert-docs=.doc|.dot|.dps|.dpt|.epub|.et|.ett|.fb2|.fodp|.fods|.fodt|.htm|.html|.mht|.mhtml|.odp|.ods|.odt|.otp|.ots|.ott|.pot|.pps|.ppt|.rtf|.stw|.sxc|.sxi|.sxw|.wps|.wpt|.xls|.xlsb|.xlt|.xml
|
||||
files.docservice.timeout=120000
|
||||
files.docservice.history.postfix=-hist
|
||||
|
||||
@ -24,10 +24,11 @@ files.docservice.url.example=
|
||||
|
||||
files.docservice.secret=
|
||||
files.docservice.header=Authorization
|
||||
files.docservice.token-use-for-request=true
|
||||
|
||||
files.docservice.verify-peer-off=true
|
||||
|
||||
files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (People's Republic of China)|zh-TW:Chinese (Traditional, Taiwan)|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|ms:Malay (Malaysia)|nb:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA:Test Language
|
||||
files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (Simplified)|zh-TW:Chinese (Traditional)|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|lo:Lao|lv:Latvian|ms:Malay (Malaysia)|no:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|si:Sinhala (Sri Lanka)|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA:Test Language
|
||||
|
||||
spring.datasource.url=jdbc:h2:mem:usersdb
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
@ -37,6 +38,8 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
hibernate.ddl-auto
|
||||
spring.h2.console.enabled=true
|
||||
spring.h2.console.path=/h2
|
||||
spring.servlet.multipart.max-file-size=5MB
|
||||
spring.servlet.multipart.max-request-size=5MB
|
||||
|
||||
url.index=/
|
||||
url.converter=/converter
|
||||
|
||||
@ -668,4 +668,9 @@
|
||||
.main-panel > span{
|
||||
max-width:15%;
|
||||
}
|
||||
}
|
||||
}
|
||||
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
|
||||
.tableRow td:first-child{
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
|
||||
// the user is trying to switch the document from the viewing into the editing mode
|
||||
var onRequestEditRights = function () {
|
||||
location.href = location.href.replace(RegExp("\&?action=view\&?", "i"), "");
|
||||
location.href = location.href.replace(RegExp("\&?action=view", "i"), "");
|
||||
};
|
||||
|
||||
// an error or some other specific event occurs
|
||||
@ -160,12 +160,45 @@
|
||||
}
|
||||
};
|
||||
|
||||
var onRequestReferenceData = function(event) { // user refresh external data source
|
||||
event.data.directUrl = !!config.document.directUrl;
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "reference");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(JSON.stringify(event.data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
docEditor.setReferenceData(JSON.parse(xhr.responseText));
|
||||
}
|
||||
};
|
||||
|
||||
function onRequestRestore(event) {
|
||||
const query = new URLSearchParams(window.location.search)
|
||||
const config = [[${model}]]
|
||||
const payload = {
|
||||
fileName: query.get('fileName'),
|
||||
version: event.data.version,
|
||||
userId: config.editorConfig.user.id
|
||||
}
|
||||
const request = new XMLHttpRequest()
|
||||
request.open('PUT', 'restore')
|
||||
request.setRequestHeader('Content-Type', 'application/json')
|
||||
request.send(JSON.stringify(payload))
|
||||
request.onload = function () {
|
||||
if (request.status != 200) {
|
||||
response = JSON.parse(request.response)
|
||||
innerAlert(response.error)
|
||||
return
|
||||
}
|
||||
document.location.reload()
|
||||
}
|
||||
}
|
||||
|
||||
config.width = "100%";
|
||||
config.height = "100%";
|
||||
config.events = {
|
||||
"onAppReady": onAppReady,
|
||||
"onDocumentStateChange": onDocumentStateChange,
|
||||
'onRequestEditRights': onRequestEditRights,
|
||||
"onError": onError,
|
||||
"onOutdatedVersion": onOutdatedVersion,
|
||||
"onMakeActionLink": onMakeActionLink,
|
||||
@ -173,6 +206,7 @@
|
||||
"onRequestInsertImage": onRequestInsertImage,
|
||||
"onRequestCompareFile": onRequestCompareFile,
|
||||
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
|
||||
"onRequestRestore": onRequestRestore
|
||||
};
|
||||
|
||||
var histArray = [[${fileHistory}]];
|
||||
@ -211,6 +245,9 @@
|
||||
};
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
config.events['onRequestReferenceData'] = onRequestReferenceData;
|
||||
// prevent switch the document from the viewing into the editing mode for anonymous users
|
||||
config.events['onRequestEditRights'] = onRequestEditRights;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
ONLYOFFICE Applications example uses code from the following 3rd party projects:
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
ONLYOFFICE Applications example uses code from the following 3rd party projects:
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
package controllers;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import entities.FileType;
|
||||
import entities.User;
|
||||
import helpers.ConfigManager;
|
||||
@ -47,6 +48,7 @@ import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
@ -56,14 +58,15 @@ import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static utils.Constants.KILOBYTE_SIZE;
|
||||
|
||||
|
||||
@WebServlet(name = "IndexServlet", urlPatterns = {"/IndexServlet"})
|
||||
@MultipartConfig
|
||||
public class IndexServlet extends HttpServlet {
|
||||
@ -78,6 +81,11 @@ public class IndexServlet extends HttpServlet {
|
||||
return;
|
||||
}
|
||||
|
||||
// charset for response headers if upload or convert
|
||||
if (action.matches("upload|convert")) {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
}
|
||||
|
||||
DocumentManager.init(request, response);
|
||||
|
||||
// create a variable to display information about the application and error messages
|
||||
@ -118,6 +126,12 @@ public class IndexServlet extends HttpServlet {
|
||||
case "rename":
|
||||
rename(request, response, writer);
|
||||
break;
|
||||
case "reference":
|
||||
reference(request, response, writer);
|
||||
break;
|
||||
case "restore":
|
||||
restore(request, response, writer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -262,16 +276,18 @@ public class IndexServlet extends HttpServlet {
|
||||
String fileUri = DocumentManager.getDownloadUrl(fileName, true);
|
||||
String fileExt = FileUtility.getFileExtension(fileName);
|
||||
FileType fileType = FileUtility.getFileType(fileName);
|
||||
String internalFileExt = DocumentManager.getInternalExtension(fileType);
|
||||
String internalFileExt = "ooxml";
|
||||
|
||||
// check if the file with such an extension can be converted
|
||||
if (DocumentManager.getConvertExts().contains(fileExt)) {
|
||||
// generate document key
|
||||
String key = ServiceConverter.generateRevisionId(fileUri);
|
||||
|
||||
// get the url to the converted file
|
||||
String newFileUri = ServiceConverter
|
||||
.getConvertedUri(fileUri, fileExt, internalFileExt, key, filePass, true, lang);
|
||||
// get the url and file type to the converted file
|
||||
Map<String, String> newFileData = ServiceConverter
|
||||
.getConvertedData(fileUri, fileExt, internalFileExt, key, filePass, true, lang);
|
||||
String newFileUri = newFileData.get("fileUrl");
|
||||
String newFileType = "." + newFileData.get("fileType");
|
||||
|
||||
if (newFileUri.isEmpty()) {
|
||||
writer.write("{ \"step\" : \"0\", \"filename\" : \"" + fileName + "\"}");
|
||||
@ -281,7 +297,7 @@ public class IndexServlet extends HttpServlet {
|
||||
/* get a file name of an internal file extension with an index if the file
|
||||
with such a name already exists */
|
||||
String correctName = DocumentManager.getCorrectName(FileUtility
|
||||
.getFileNameWithoutExtension(fileName) + internalFileExt, null);
|
||||
.getFileNameWithoutExtension(fileName) + newFileType, null);
|
||||
|
||||
URL url = new URL(newFileUri);
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
@ -305,9 +321,9 @@ public class IndexServlet extends HttpServlet {
|
||||
|
||||
connection.disconnect();
|
||||
|
||||
// remove source file ?
|
||||
// File sourceFile = new File(DocumentManager.StoragePath(fileName, null));
|
||||
// sourceFile.delete();
|
||||
// remove source file
|
||||
File sourceFile = new File(DocumentManager.storagePath(fileName, null));
|
||||
sourceFile.delete();
|
||||
|
||||
fileName = correctName;
|
||||
|
||||
@ -441,7 +457,7 @@ public class IndexServlet extends HttpServlet {
|
||||
private static void csv(final HttpServletRequest request,
|
||||
final HttpServletResponse response,
|
||||
final PrintWriter writer) {
|
||||
String fileName = "assets/sample/csv.csv";
|
||||
String fileName = "assets/document-templates/sample/csv.csv";
|
||||
URL fileUrl = Thread.currentThread().getContextClassLoader().getResource(fileName);
|
||||
Path filePath = null;
|
||||
try {
|
||||
@ -456,7 +472,7 @@ public class IndexServlet extends HttpServlet {
|
||||
private static void assets(final HttpServletRequest request,
|
||||
final HttpServletResponse response,
|
||||
final PrintWriter writer) {
|
||||
String fileName = "assets/sample/" + FileUtility.getFileName(request.getParameter("name"));
|
||||
String fileName = "assets/document-templates/sample/" + FileUtility.getFileName(request.getParameter("name"));
|
||||
URL fileUrl = Thread.currentThread().getContextClassLoader().getResource(fileName);
|
||||
Path filePath = null;
|
||||
try {
|
||||
@ -472,7 +488,7 @@ public class IndexServlet extends HttpServlet {
|
||||
final HttpServletResponse response,
|
||||
final PrintWriter writer) {
|
||||
try {
|
||||
if (DocumentManager.tokenEnabled()) {
|
||||
if (DocumentManager.tokenEnabled() && DocumentManager.tokenUseForRequest()) {
|
||||
|
||||
String documentJwtHeader = ConfigManager.getProperty("files.docservice.header");
|
||||
|
||||
@ -517,22 +533,24 @@ public class IndexServlet extends HttpServlet {
|
||||
String userAddress = request.getParameter("userAddress");
|
||||
String isEmbedded = request.getParameter("dmode");
|
||||
|
||||
if (DocumentManager.tokenEnabled() && isEmbedded == null) {
|
||||
if (DocumentManager.tokenEnabled() && isEmbedded == null && userAddress != null
|
||||
&& DocumentManager.tokenUseForRequest()) {
|
||||
|
||||
String documentJwtHeader = ConfigManager.getProperty("files.docservice.header");
|
||||
|
||||
String header = (String) request.getHeader(documentJwtHeader == null || documentJwtHeader.isEmpty()
|
||||
? "Authorization" : documentJwtHeader);
|
||||
String token = "";
|
||||
if (header != null && !header.isEmpty()) {
|
||||
String bearerPrefix = "Bearer ";
|
||||
String token = header.startsWith(bearerPrefix) ? header.substring(bearerPrefix.length()) : header;
|
||||
try {
|
||||
Verifier verifier = HMACVerifier.newVerifier(DocumentManager.getTokenSecret());
|
||||
JWT jwt = JWT.getDecoder().decode(token, verifier);
|
||||
} catch (Exception e) {
|
||||
response.sendError(HttpServletResponse.SC_FORBIDDEN, "JWT validation failed");
|
||||
return;
|
||||
}
|
||||
token = header.startsWith(bearerPrefix) ? header.substring(bearerPrefix.length()) : header;
|
||||
}
|
||||
try {
|
||||
Verifier verifier = HMACVerifier.newVerifier(DocumentManager.getTokenSecret());
|
||||
JWT jwt = JWT.getDecoder().decode(token, verifier);
|
||||
} catch (Exception e) {
|
||||
response.sendError(HttpServletResponse.SC_FORBIDDEN, "JWT validation failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -632,6 +650,180 @@ public class IndexServlet extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
// reference data
|
||||
private static void reference(final HttpServletRequest request,
|
||||
final HttpServletResponse response,
|
||||
final PrintWriter writer) {
|
||||
try {
|
||||
Scanner scanner = new Scanner(request.getInputStream());
|
||||
scanner.useDelimiter("\\A");
|
||||
String bodyString = scanner.hasNext() ? scanner.next() : "";
|
||||
scanner.close();
|
||||
|
||||
String fileKeyValue = "";
|
||||
String userAddress = "";
|
||||
String fileName = "";
|
||||
boolean incorrectFileKey = false;
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
JSONObject body = (JSONObject) parser.parse(bodyString);
|
||||
|
||||
if (body.containsKey("referenceData")) {
|
||||
JSONObject referenceDataObj = (JSONObject) body.get("referenceData");
|
||||
String instanceId = (String) referenceDataObj.get("instanceId");
|
||||
|
||||
if (instanceId.equals(DocumentManager.getServerUrl(false))) {
|
||||
try {
|
||||
JSONObject fileKey = (JSONObject) parser.parse((String) referenceDataObj.get("fileKey"));
|
||||
userAddress = (String) fileKey.get("userAddress");
|
||||
|
||||
if (userAddress.equals(DocumentManager.curUserHostAddress(null))) {
|
||||
fileName = (String) fileKey.get("fileName");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
incorrectFileKey = true; //data from DocEditor can give incorrect fileKey param in java Example
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName.equals("")) {
|
||||
try {
|
||||
String path = (String) body.get("path");
|
||||
path = FileUtility.getFileName(path);
|
||||
File f = new File(DocumentManager.storagePath(path, null));
|
||||
if (f.exists()) {
|
||||
fileName = path;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
writer.write("{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}");
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName.equals("")) {
|
||||
writer.write("{ \"error\": \"File not found\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean directUrl = (boolean) body.get("directUrl");
|
||||
|
||||
HashMap<String, Object> fileKey = new HashMap<>();
|
||||
fileKey.put("fileName", fileName);
|
||||
fileKey.put("userAddress", DocumentManager.curUserHostAddress(null));
|
||||
|
||||
HashMap<String, Object> referenceData = new HashMap<>();
|
||||
referenceData.put("instanceId", DocumentManager.getServerUrl(false));
|
||||
referenceData.put("fileKey", gson.toJson(fileKey));
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("fileType", FileUtility.getFileExtension(fileName).replace(".", ""));
|
||||
data.put("url", DocumentManager.getDownloadUrl(fileName, true));
|
||||
data.put("directUrl", directUrl ? DocumentManager.getDownloadUrl(fileName, false) : null);
|
||||
data.put("referenceData", referenceData);
|
||||
data.put("path", fileName);
|
||||
|
||||
if (DocumentManager.tokenEnabled()) {
|
||||
String token = DocumentManager.createToken(data);
|
||||
data.put("token", token);
|
||||
}
|
||||
writer.write(gson.toJson(data));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
writer.write("{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void restore(final HttpServletRequest request,
|
||||
final HttpServletResponse response,
|
||||
final PrintWriter writer) {
|
||||
try {
|
||||
Scanner scanner = new Scanner(request.getInputStream());
|
||||
scanner.useDelimiter("\\A");
|
||||
String bodyString = scanner.hasNext() ? scanner.next() : "";
|
||||
scanner.close();
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject body = (JSONObject) parser.parse(bodyString);
|
||||
|
||||
String sourceBasename = (String) body.get("fileName");
|
||||
Integer version = ((Long) body.get("version")).intValue();
|
||||
String userID = (String) body.get("userId");
|
||||
|
||||
String sourceStringFile = DocumentManager.storagePath(sourceBasename, null);
|
||||
File sourceFile = new File(sourceStringFile);
|
||||
Path sourcePathFile = sourceFile.toPath();
|
||||
String historyDirectory = DocumentManager.historyDir(sourceStringFile);
|
||||
|
||||
Integer bumpedVersion = DocumentManager.getFileVersion(historyDirectory);
|
||||
String bumpedVersionStringDirectory = DocumentManager.versionDir(historyDirectory, bumpedVersion);
|
||||
File bumpedVersionDirectory = new File(bumpedVersionStringDirectory);
|
||||
if (!bumpedVersionDirectory.exists()) {
|
||||
bumpedVersionDirectory.mkdir();
|
||||
}
|
||||
|
||||
Path bumpedKeyPathFile = Paths.get(bumpedVersionStringDirectory, "key.txt");
|
||||
String bumpedKeyStringFile = bumpedKeyPathFile.toString();
|
||||
File bumpedKeyFile = new File(bumpedKeyStringFile);
|
||||
String bumpedKey = ServiceConverter.generateRevisionId(
|
||||
DocumentManager.curUserHostAddress(null)
|
||||
+ "/"
|
||||
+ sourceBasename
|
||||
+ "/"
|
||||
+ Long.toString(sourceFile.lastModified())
|
||||
);
|
||||
FileWriter bumpedKeyFileWriter = new FileWriter(bumpedKeyFile);
|
||||
bumpedKeyFileWriter.write(bumpedKey);
|
||||
bumpedKeyFileWriter.close();
|
||||
|
||||
User user = Users.getUser(userID);
|
||||
|
||||
Path bumpedChangesPathFile = Paths.get(bumpedVersionStringDirectory, "changes.json");
|
||||
String bumpedChangesStringFile = bumpedChangesPathFile.toString();
|
||||
File bumpedChangesFile = new File(bumpedChangesStringFile);
|
||||
JSONObject bumpedChangesUser = new JSONObject();
|
||||
bumpedChangesUser.put("id", user.getId());
|
||||
bumpedChangesUser.put("name", user.getName());
|
||||
JSONObject bumpedChangesChangesItem = new JSONObject();
|
||||
bumpedChangesChangesItem.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
bumpedChangesChangesItem.put("user", bumpedChangesUser);
|
||||
JSONArray bumpedChangesChanges = new JSONArray();
|
||||
bumpedChangesChanges.add(bumpedChangesChangesItem);
|
||||
JSONObject bumpedChanges = new JSONObject();
|
||||
bumpedChanges.put("serverVersion", null);
|
||||
bumpedChanges.put("changes", bumpedChangesChanges);
|
||||
String bumpedChangesContent = bumpedChanges.toJSONString();
|
||||
FileWriter bumpedChangesFileWriter = new FileWriter(bumpedChangesFile);
|
||||
bumpedChangesFileWriter.write(bumpedChangesContent);
|
||||
bumpedChangesFileWriter.close();
|
||||
|
||||
String sourceExtension = FileUtility.getFileExtension(sourceBasename);
|
||||
String previousBasename = "prev" + sourceExtension;
|
||||
|
||||
Path bumpedFile = Paths.get(bumpedVersionStringDirectory, previousBasename);
|
||||
Files.move(sourcePathFile, bumpedFile);
|
||||
|
||||
String recoveryVersionStringDirectory = DocumentManager.versionDir(historyDirectory, version);
|
||||
Path recoveryPathFile = Paths.get(recoveryVersionStringDirectory, previousBasename);
|
||||
String recoveryStringFile = recoveryPathFile.toString();
|
||||
FileInputStream recoveryStream = new FileInputStream(recoveryStringFile);
|
||||
DocumentManager.createFile(sourcePathFile, recoveryStream);
|
||||
recoveryStream.close();
|
||||
|
||||
JSONObject responseBody = new JSONObject();
|
||||
responseBody.put("error", null);
|
||||
responseBody.put("success", true);
|
||||
String responseContent = responseBody.toJSONString();
|
||||
writer.write(responseContent);
|
||||
} catch (Exception error) {
|
||||
error.printStackTrace();
|
||||
JSONObject responseBody = new JSONObject();
|
||||
responseBody.put("error", error.getMessage());
|
||||
responseBody.put("success", false);
|
||||
String responseContent = responseBody.toJSONString();
|
||||
writer.write(responseContent);
|
||||
}
|
||||
}
|
||||
|
||||
// process get request
|
||||
@Override
|
||||
@ -647,6 +839,12 @@ public class IndexServlet extends HttpServlet {
|
||||
processRequest(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPut(final HttpServletRequest request,
|
||||
final HttpServletResponse response) throws ServletException, IOException {
|
||||
processRequest(request, response);
|
||||
}
|
||||
|
||||
// get servlet information
|
||||
@Override
|
||||
public String getServletInfo() {
|
||||
|
||||
@ -21,6 +21,18 @@ package entities;
|
||||
import java.util.List;
|
||||
|
||||
public class CommentGroups {
|
||||
public List<String> getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
public List<String> getEdit() {
|
||||
return edit;
|
||||
}
|
||||
|
||||
public List<String> getRemove() {
|
||||
return remove;
|
||||
}
|
||||
|
||||
private List<String> view;
|
||||
private List<String> edit;
|
||||
private List<String> remove;
|
||||
|
||||
@ -77,6 +77,7 @@ public class FileModel {
|
||||
.lastModified())));
|
||||
document.setInfo(new Info());
|
||||
document.getInfo().setFavorite(user.getFavorite());
|
||||
document.setReferenceData(new ReferenceData(fileName, DocumentManager.curUserHostAddress(null), user));
|
||||
|
||||
String templatesImageUrl = DocumentManager.getTemplateImageUrl(FileUtility.getFileType(fileName));
|
||||
List<Map<String, String>> templates = new ArrayList<>();
|
||||
@ -123,6 +124,26 @@ public class FileModel {
|
||||
changeType(mode, type, user, fileName);
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public Document getDocument() {
|
||||
return document;
|
||||
}
|
||||
|
||||
public EditorConfig getEditorConfig() {
|
||||
return editorConfig;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
// change the document type
|
||||
public void changeType(final String modeParam, final String typeParam, final User user, final String fileName) {
|
||||
if (modeParam != null) {
|
||||
@ -302,6 +323,7 @@ public class FileModel {
|
||||
private String key;
|
||||
private Info info;
|
||||
private Permissions permissions;
|
||||
private ReferenceData referenceData;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
@ -327,6 +349,10 @@ public class FileModel {
|
||||
this.directUrl = directUrlParam;
|
||||
}
|
||||
|
||||
public String getFileType() {
|
||||
return fileType;
|
||||
}
|
||||
|
||||
public void setFileType(final String fileTypeParam) {
|
||||
this.fileType = fileTypeParam;
|
||||
}
|
||||
@ -354,6 +380,13 @@ public class FileModel {
|
||||
public void setPermissions(final Permissions permissionsParam) {
|
||||
this.permissions = permissionsParam;
|
||||
}
|
||||
|
||||
public ReferenceData getReferenceData() {
|
||||
return referenceData;
|
||||
}
|
||||
public void setReferenceData(final ReferenceData referenceDataParam) {
|
||||
this.referenceData = referenceDataParam;
|
||||
}
|
||||
}
|
||||
|
||||
// the permissions parameters
|
||||
@ -371,6 +404,7 @@ public class FileModel {
|
||||
private final List<String> reviewGroups;
|
||||
private final CommentGroups commentGroups;
|
||||
private final List<String> userInfoGroups;
|
||||
private final Boolean protect;
|
||||
//public Gson gson = new Gson();
|
||||
|
||||
// defines what can be done with a document
|
||||
@ -391,23 +425,115 @@ public class FileModel {
|
||||
reviewGroups = user.getReviewGroups();
|
||||
commentGroups = user.getCommentGroups();
|
||||
userInfoGroups = user.getUserInfoGroups();
|
||||
protect = !user.getDeniedPermissions().contains("protect");
|
||||
}
|
||||
|
||||
public Boolean getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public Boolean getCopy() {
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Boolean getDownload() {
|
||||
return download;
|
||||
}
|
||||
|
||||
public Boolean getEdit() {
|
||||
return edit;
|
||||
}
|
||||
|
||||
public Boolean getPrint() {
|
||||
return print;
|
||||
}
|
||||
|
||||
public Boolean getFillForms() {
|
||||
return fillForms;
|
||||
}
|
||||
|
||||
public Boolean getModifyFilter() {
|
||||
return modifyFilter;
|
||||
}
|
||||
|
||||
public Boolean getModifyContentControl() {
|
||||
return modifyContentControl;
|
||||
}
|
||||
|
||||
public Boolean getReview() {
|
||||
return review;
|
||||
}
|
||||
|
||||
public Boolean getChat() {
|
||||
return chat;
|
||||
}
|
||||
|
||||
public List<String> getReviewGroups() {
|
||||
return reviewGroups;
|
||||
}
|
||||
|
||||
public CommentGroups getCommentGroups() {
|
||||
return commentGroups;
|
||||
}
|
||||
|
||||
public List<String> getUserInfoGroups() {
|
||||
return userInfoGroups;
|
||||
}
|
||||
|
||||
public Boolean getProtect() {
|
||||
return protect;
|
||||
}
|
||||
}
|
||||
|
||||
public class ReferenceData {
|
||||
private final String instanceId;
|
||||
private final Map<String, String> fileKey;
|
||||
public ReferenceData(final String fileName, final String curUserHostAddress, final User user) {
|
||||
instanceId = DocumentManager.getServerUrl(true);
|
||||
Map<String, String> fileKeyList = new HashMap<>();
|
||||
if (!user.getId().equals("uid-0")) {
|
||||
fileKeyList.put("fileName", fileName);
|
||||
fileKeyList.put("userAddress", curUserHostAddress);
|
||||
} else {
|
||||
fileKeyList = null;
|
||||
}
|
||||
fileKey = fileKeyList;
|
||||
}
|
||||
|
||||
public String getInstanceId() {
|
||||
return instanceId;
|
||||
}
|
||||
|
||||
public Map<String, String> getFileKey() {
|
||||
return fileKey;
|
||||
}
|
||||
}
|
||||
// the Favorite icon state
|
||||
public class Info {
|
||||
private String owner = "Me";
|
||||
private Boolean favorite;
|
||||
private String uploaded = getDate();
|
||||
|
||||
private String getDate() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd yyyy", Locale.US);
|
||||
return simpleDateFormat.format(new Date());
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public Boolean getFavorite() {
|
||||
return favorite;
|
||||
}
|
||||
|
||||
public void setFavorite(final Boolean favoriteParam) {
|
||||
this.favorite = favoriteParam;
|
||||
}
|
||||
|
||||
public String getUploaded() {
|
||||
return uploaded;
|
||||
}
|
||||
|
||||
private String getDate() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd yyyy", Locale.US);
|
||||
return simpleDateFormat.format(new Date());
|
||||
}
|
||||
}
|
||||
// the editor config parameters
|
||||
public class EditorConfig {
|
||||
@ -432,6 +558,34 @@ public class FileModel {
|
||||
customization = new Customization();
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getActionLink() {
|
||||
return actionLink;
|
||||
}
|
||||
|
||||
public String getCallbackUrl() {
|
||||
return callbackUrl;
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getCoEditing() {
|
||||
return coEditing;
|
||||
}
|
||||
|
||||
public String getLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
public String getCreateUrl() {
|
||||
return createUrl;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
|
||||
public Embedded getEmbedded() {
|
||||
return embedded;
|
||||
}
|
||||
|
||||
// set parameters for the embedded document
|
||||
public void initDesktop(final String url) {
|
||||
embedded = new Embedded();
|
||||
@ -529,10 +683,6 @@ public class FileModel {
|
||||
private Boolean comments;
|
||||
private Boolean feedback;
|
||||
|
||||
public Goback getGoback() {
|
||||
return goback;
|
||||
}
|
||||
|
||||
public void setSubmitForm(final Boolean submitFormParam) {
|
||||
this.submitForm = submitFormParam;
|
||||
}
|
||||
@ -545,6 +695,30 @@ public class FileModel {
|
||||
goback = new Goback();
|
||||
}
|
||||
|
||||
public Goback getGoback() {
|
||||
return goback;
|
||||
}
|
||||
|
||||
public Boolean getForcesave() {
|
||||
return forcesave;
|
||||
}
|
||||
|
||||
public Boolean getSubmitForm() {
|
||||
return submitForm;
|
||||
}
|
||||
|
||||
public Boolean getAbout() {
|
||||
return about;
|
||||
}
|
||||
|
||||
public Boolean getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public Boolean getFeedback() {
|
||||
return feedback;
|
||||
}
|
||||
|
||||
public class Goback {
|
||||
private String url;
|
||||
|
||||
@ -565,18 +739,34 @@ public class FileModel {
|
||||
private String shareUrl;
|
||||
private String toolbarDocked;
|
||||
|
||||
public String getSaveUrl() {
|
||||
return saveUrl;
|
||||
}
|
||||
|
||||
public void setSaveUrl(final String saveUrlParam) {
|
||||
this.saveUrl = saveUrlParam;
|
||||
}
|
||||
|
||||
public String getEmbedUrl() {
|
||||
return embedUrl;
|
||||
}
|
||||
|
||||
public void setEmbedUrl(final String embedUrlParam) {
|
||||
this.embedUrl = embedUrlParam;
|
||||
}
|
||||
|
||||
public String getShareUrl() {
|
||||
return shareUrl;
|
||||
}
|
||||
|
||||
public void setShareUrl(final String shareUrlParam) {
|
||||
this.shareUrl = shareUrlParam;
|
||||
}
|
||||
|
||||
public String getToolbarDocked() {
|
||||
return toolbarDocked;
|
||||
}
|
||||
|
||||
public void setToolbarDocked(final String toolbarDockedParam) {
|
||||
this.toolbarDocked = toolbarDockedParam;
|
||||
}
|
||||
|
||||
@ -306,7 +306,12 @@ public final class DocumentManager {
|
||||
String demoName = (sample ? "sample." : "new.") + fileExt;
|
||||
|
||||
// get the path to the sample document
|
||||
String demoPath = "assets" + File.separator + (sample ? "sample" : "new") + File.separator;
|
||||
String demoPath = "assets"
|
||||
+ File.separator
|
||||
+ "document-templates"
|
||||
+ File.separator
|
||||
+ (sample ? "sample" : "new")
|
||||
+ File.separator;
|
||||
|
||||
// get a file name with an index if the file with such a name already exists
|
||||
String fileName = getCorrectName(demoName, null);
|
||||
@ -565,11 +570,22 @@ public final class DocumentManager {
|
||||
return secret != null && !secret.isEmpty();
|
||||
}
|
||||
|
||||
// check if the token is enabled for request
|
||||
public static Boolean tokenUseForRequest() {
|
||||
String tokenUseForRequest = getTokenUseForRequest();
|
||||
return Boolean.parseBoolean(tokenUseForRequest) && !tokenUseForRequest.isEmpty();
|
||||
}
|
||||
|
||||
// get token secret from the config parameters
|
||||
public static String getTokenSecret() {
|
||||
return ConfigManager.getProperty("files.docservice.secret");
|
||||
}
|
||||
|
||||
// get config request jwt
|
||||
public static String getTokenUseForRequest() {
|
||||
return ConfigManager.getProperty("files.docservice.token-use-for-request");
|
||||
}
|
||||
|
||||
// get languages
|
||||
public static Map<String, String> getLanguages() {
|
||||
String langs = ConfigManager.getProperty("files.docservice.languages");
|
||||
|
||||
@ -137,10 +137,10 @@ public final class ServiceConverter {
|
||||
}
|
||||
|
||||
// get the url of the converted file
|
||||
public static String getConvertedUri(final String documentUri, final String fromExtension,
|
||||
final String toExtension, final String documentRevisionId,
|
||||
final String filePass, final Boolean isAsync,
|
||||
final String lang) throws Exception {
|
||||
public static Map<String, String> getConvertedData(final String documentUri, final String fromExtension,
|
||||
final String toExtension, final String documentRevisionId,
|
||||
final String filePass, final Boolean isAsync,
|
||||
final String lang) throws Exception {
|
||||
// check if the fromExtension parameter is defined; if not, get it from the document url
|
||||
String fromExt = fromExtension == null || fromExtension.isEmpty()
|
||||
? FileUtility.getFileExtension(documentUri) : fromExtension;
|
||||
@ -168,7 +168,7 @@ public final class ServiceConverter {
|
||||
}
|
||||
|
||||
String headerToken = "";
|
||||
if (DocumentManager.tokenEnabled()) {
|
||||
if (DocumentManager.tokenEnabled() && DocumentManager.tokenUseForRequest()) {
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("region", lang);
|
||||
map.put("url", body.getUrl());
|
||||
@ -213,14 +213,15 @@ public final class ServiceConverter {
|
||||
|
||||
connection.connect();
|
||||
|
||||
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
os.write(bodyByte);
|
||||
}
|
||||
int statusCode = connection.getResponseCode();
|
||||
if (statusCode != HttpServletResponse.SC_OK) { // checking status code
|
||||
connection.disconnect();
|
||||
throw new Exception("Conversion service returned status: " + statusCode);
|
||||
}
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
os.write(bodyByte);
|
||||
}
|
||||
|
||||
InputStream stream = connection.getInputStream();
|
||||
|
||||
@ -233,7 +234,7 @@ public final class ServiceConverter {
|
||||
|
||||
connection.disconnect();
|
||||
|
||||
return getResponseUri(jsonString);
|
||||
return getResponseData(jsonString);
|
||||
}
|
||||
|
||||
// generate document key
|
||||
@ -254,8 +255,8 @@ public final class ServiceConverter {
|
||||
throw new Exception(errorMessage);
|
||||
}
|
||||
|
||||
// get the response url
|
||||
private static String getResponseUri(final String jsonString) throws Exception {
|
||||
// get the response data
|
||||
private static Map<String, String> getResponseData(final String jsonString) throws Exception {
|
||||
JSONObject jsonObj = convertStringToJSON(jsonString);
|
||||
|
||||
Object error = jsonObj.get("error");
|
||||
@ -268,17 +269,23 @@ public final class ServiceConverter {
|
||||
|
||||
Long resultPercent = 0L;
|
||||
String responseUri = null;
|
||||
String responseFileType = null;
|
||||
Map<String, String> responseData = new HashMap<>();
|
||||
|
||||
if (isEndConvert) { // if the conversion is completed
|
||||
resultPercent = FULL_LOADING_IN_PERCENT;
|
||||
responseUri = (String) jsonObj.get("fileUrl"); // get the file url
|
||||
responseFileType = (String) jsonObj.get("fileType"); // get the file type
|
||||
responseData.put("fileUrl", responseUri);
|
||||
responseData.put("fileType", responseFileType);
|
||||
} else { // if the conversion isn't completed
|
||||
resultPercent = (Long) jsonObj.get("percent");
|
||||
responseData.put("fileUrl", "");
|
||||
resultPercent = resultPercent >= FULL_LOADING_IN_PERCENT
|
||||
? FULL_LOADING_IN_PERCENT - 1 : resultPercent; // get the percentage value
|
||||
}
|
||||
|
||||
return resultPercent >= FULL_LOADING_IN_PERCENT ? responseUri : "";
|
||||
return responseData;
|
||||
}
|
||||
|
||||
// convert stream to string
|
||||
|
||||
@ -26,19 +26,26 @@ import org.primeframework.jwt.domain.JWT;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
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.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static utils.Constants.BUFFER_SIZE;
|
||||
import static utils.Constants.FILE_SAVE_TIMEOUT;
|
||||
import static utils.Constants.KILOBYTE_SIZE;
|
||||
|
||||
@ -80,7 +87,7 @@ public final class TrackManager {
|
||||
}
|
||||
|
||||
// if the secret key to generate token exists
|
||||
if (DocumentManager.tokenEnabled()) {
|
||||
if (DocumentManager.tokenEnabled() && DocumentManager.tokenUseForRequest()) {
|
||||
String token = (String) body.get("token"); // get the document token
|
||||
|
||||
if (token == null) { // if JSON web token is not received
|
||||
@ -149,9 +156,9 @@ public final class TrackManager {
|
||||
if (!curExt.equals(downloadExt)) {
|
||||
try {
|
||||
String newFileUri = ServiceConverter
|
||||
.getConvertedUri(downloadUri, downloadExt, curExt,
|
||||
.getConvertedData(downloadUri, downloadExt, curExt,
|
||||
ServiceConverter.generateRevisionId(downloadUri),
|
||||
null, false, null); // convert file and get url to a new file
|
||||
null, false, null).get("fileUrl"); // convert file and get url to a new file
|
||||
if (newFileUri.isEmpty()) {
|
||||
|
||||
// get the correct file name if it already exists
|
||||
@ -167,6 +174,8 @@ public final class TrackManager {
|
||||
}
|
||||
}
|
||||
|
||||
byte[] byteArrayFile = getDownloadFile(downloadUri); // download document file
|
||||
|
||||
String storagePath = DocumentManager.storagePath(newFileName, userAddress); // get the file path
|
||||
File histDir = new File(DocumentManager.historyDir(storagePath)); // get the path to the history direction
|
||||
if (!histDir.exists()) {
|
||||
@ -177,7 +186,7 @@ public final class TrackManager {
|
||||
.getFileVersion(histDir.getAbsolutePath())); // get the path to the file version
|
||||
File ver = new File(versionDir);
|
||||
File lastVersion = new File(DocumentManager.storagePath(fileName, userAddress));
|
||||
File toSave = new File(storagePath);
|
||||
Path toSave = Paths.get(storagePath);
|
||||
|
||||
if (!ver.exists()) {
|
||||
ver.mkdirs();
|
||||
@ -186,10 +195,10 @@ public final class TrackManager {
|
||||
// get the path to the previous file version and rename the last file version with it
|
||||
lastVersion.renameTo(new File(versionDir + File.separator + "prev" + curExt));
|
||||
|
||||
downloadToFile(downloadUri, toSave); // save file to the storage path
|
||||
saveFile(byteArrayFile, toSave); // save document file
|
||||
|
||||
// save file changes to the diff.zip archive
|
||||
downloadToFile(changesUri, new File(versionDir + File.separator + "diff.zip"));
|
||||
byte[] byteArrayChanges = getDownloadFile(changesUri);
|
||||
saveFile(byteArrayChanges, Paths.get(versionDir + File.separator + "diff.zip"));
|
||||
|
||||
String history = (String) body.get("changeshistory");
|
||||
if (history == null && body.containsKey("history")) {
|
||||
@ -235,9 +244,9 @@ public final class TrackManager {
|
||||
if (!curExt.equals(downloadExt)) {
|
||||
try {
|
||||
String newFileUri = ServiceConverter
|
||||
.getConvertedUri(downloadUri, downloadExt, curExt,
|
||||
.getConvertedData(downloadUri, downloadExt, curExt,
|
||||
ServiceConverter.generateRevisionId(downloadUri), null,
|
||||
false, null); // convert file and get url to a new file
|
||||
false, null).get("fileUrl"); // convert file and get url to a new file
|
||||
if (newFileUri.isEmpty()) {
|
||||
newFileName = true;
|
||||
} else {
|
||||
@ -248,6 +257,7 @@ public final class TrackManager {
|
||||
}
|
||||
}
|
||||
|
||||
byte[] byteArrayFile = getDownloadFile(downloadUri); // download document file
|
||||
String forcesavePath = "";
|
||||
boolean isSubmitForm = body.get("forcesavetype").toString().equals("3"); // SubmitForm
|
||||
|
||||
@ -274,8 +284,7 @@ public final class TrackManager {
|
||||
}
|
||||
}
|
||||
|
||||
File toSave = new File(forcesavePath);
|
||||
downloadToFile(downloadUri, toSave);
|
||||
saveFile(byteArrayFile, Paths.get(forcesavePath));
|
||||
|
||||
if (isSubmitForm) {
|
||||
JSONArray actions = (JSONArray) body.get("actions");
|
||||
@ -287,43 +296,79 @@ public final class TrackManager {
|
||||
}
|
||||
}
|
||||
|
||||
// save file information from the url to the file specified
|
||||
private static void downloadToFile(final String url, final File file) throws Exception {
|
||||
if (url == null || url.isEmpty()) {
|
||||
throw new Exception("argument url"); // url isn't specified
|
||||
// create a new file if it does not exist
|
||||
private static boolean createFile(final byte[] byteArray, final Path path) {
|
||||
if (Files.exists(path)) {
|
||||
return true;
|
||||
}
|
||||
if (file == null) {
|
||||
throw new Exception("argument path"); // file isn't specified
|
||||
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray)) {
|
||||
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[KILOBYTE_SIZE];
|
||||
while ((read = byteArrayInputStream.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, read); // write bytes to the output stream
|
||||
}
|
||||
out.flush(); // force write data to the output stream that can be cached in the current thread
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// get byte array from stream
|
||||
private static byte[] getAllBytes(final InputStream is) throws IOException {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
for (int len = is.read(buffer); len != -1; len = is.read(buffer)) {
|
||||
os.write(buffer, 0, len);
|
||||
}
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
// save file
|
||||
private static boolean saveFile(final byte[] byteArray, final Path path) {
|
||||
if (path == null) {
|
||||
throw new RuntimeException("Path argument is not specified"); // file isn't specified
|
||||
}
|
||||
if (!Files.exists(path)) { // if the specified file does not exist
|
||||
return createFile(byteArray, path); // create it in the specified directory
|
||||
} else {
|
||||
try {
|
||||
Files.write(path, byteArray); // otherwise, write new information in the bytes format to the file
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// download file from url
|
||||
private static byte[] getDownloadFile(final String url) throws Exception {
|
||||
if (url == null || url.isEmpty()) {
|
||||
throw new RuntimeException("Url argument is not specified"); // URL isn't specified
|
||||
}
|
||||
|
||||
URL uri = new URL(url);
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) uri.openConnection();
|
||||
connection.setConnectTimeout(FILE_SAVE_TIMEOUT);
|
||||
InputStream stream = connection.getInputStream(); // get input stream of the file information from the URL
|
||||
|
||||
int statusCode = connection.getResponseCode();
|
||||
|
||||
if (statusCode != HttpServletResponse.SC_OK) { // checking status code
|
||||
connection.disconnect();
|
||||
throw new RuntimeException("Document editing service returned status: " + statusCode);
|
||||
}
|
||||
|
||||
InputStream stream = connection.getInputStream(); // get input stream of the file information from the url
|
||||
|
||||
if (stream == null) {
|
||||
throw new Exception("Stream is null");
|
||||
connection.disconnect();
|
||||
throw new RuntimeException("Input stream is null");
|
||||
}
|
||||
|
||||
try (FileOutputStream out = new FileOutputStream(file)) {
|
||||
int read;
|
||||
final byte[] bytes = new byte[KILOBYTE_SIZE];
|
||||
while ((read = stream.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, read); // write bytes to the output stream
|
||||
}
|
||||
|
||||
// force write data to the output stream that can be cached in the current thread
|
||||
out.flush();
|
||||
}
|
||||
|
||||
connection.disconnect();
|
||||
return getAllBytes(stream);
|
||||
}
|
||||
|
||||
// create a command request
|
||||
@ -343,7 +388,8 @@ public final class TrackManager {
|
||||
}
|
||||
|
||||
String headerToken = "";
|
||||
if (DocumentManager.tokenEnabled()) { // check if a secret key to generate token exists or not
|
||||
// check if a secret key to generate token exists or not
|
||||
if (DocumentManager.tokenEnabled() && DocumentManager.tokenUseForRequest()) {
|
||||
Map<String, Object> payloadMap = new HashMap<String, Object>();
|
||||
payloadMap.put("payload", params);
|
||||
headerToken = DocumentManager.createToken(payloadMap); // encode a payload object into a header token
|
||||
|
||||
@ -72,6 +72,7 @@ public final class Users {
|
||||
add("Can’t see anyone’s information");
|
||||
add("Can't rename files from the editor");
|
||||
add("Can't view chat");
|
||||
add("Can't protect file");
|
||||
add("View file without collaboration");
|
||||
}};
|
||||
|
||||
@ -85,12 +86,12 @@ public final class Users {
|
||||
true, new ArrayList<String>(), descriptionUserSecond, false));
|
||||
add(new User("uid-3", "Hamish Mitchell", "mitchell@example.com",
|
||||
"group-3", Arrays.asList("group-2"), new CommentGroups(Arrays.asList("group-3", "group-2"),
|
||||
Arrays.asList("group-2"), new ArrayList<String>()), Arrays.asList("group-2"),
|
||||
Arrays.asList("group-2"), null), Arrays.asList("group-2"),
|
||||
false, Arrays.asList("copy", "download", "print"),
|
||||
descriptionUserThird, false));
|
||||
add(new User("uid-0", null, null,
|
||||
"", null, new CommentGroups(), new ArrayList<String>(),
|
||||
null, new ArrayList<String>(), descriptionUserZero, false));
|
||||
"", null, null, null,
|
||||
null, Arrays.asList("protect"), descriptionUserZero, false));
|
||||
}};
|
||||
|
||||
private Users() { }
|
||||
|
||||
@ -26,6 +26,7 @@ public final class Constants {
|
||||
public static final Integer FILE_SAVE_TIMEOUT = 5000;
|
||||
public static final Integer MAX_KEY_LENGTH = 20;
|
||||
public static final Integer KILOBYTE_SIZE = 1024;
|
||||
public static final Integer BUFFER_SIZE = 0xFFFF;
|
||||
|
||||
private Constants() { }
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
version=1.5.1
|
||||
version=1.6.0
|
||||
|
||||
filesize-max=5242880
|
||||
storage-folder=app_data
|
||||
|
||||
files.docservice.fill-docs=.oform|.docx
|
||||
files.docservice.viewed-docs=.pdf|.djvu|.xps|.oxps
|
||||
files.docservice.edited-docs=.docx|.xlsx|.csv|.pptx|.txt|.docxf
|
||||
files.docservice.convert-docs=.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
|
||||
files.docservice.fill-docs=.docx|.oform
|
||||
files.docservice.viewed-docs=.djvu|.oxps|.pdf|.xps
|
||||
files.docservice.edited-docs=.csv|.docm|.docx|.docxf|.dotm|.dotx|.epub|.fb2|.html|.odp|.ods|.odt|.otp|.ots|.ott|.potm|.potx|.ppsm|.ppsx|.pptm|.pptx|.rtf|.txt|.xlsm|.xlsx|.xltm|.xltx
|
||||
files.docservice.convert-docs=.doc|.dot|.dps|.dpt|.epub|.et|.ett|.fb2|.fodp|.fods|.fodt|.htm|.html|.mht|.mhtml|.odp|.ods|.odt|.otp|.ots|.ott|.pot|.pps|.ppt|.rtf|.stw|.sxc|.sxi|.sxw|.wps|.wpt|.xls|.xlsb|.xlt|.xml
|
||||
files.docservice.timeout=120000
|
||||
|
||||
files.docservice.url.site=http://documentserver/
|
||||
@ -16,9 +16,10 @@ files.docservice.url.api=web-apps/apps/api/documents/api.js
|
||||
files.docservice.url.preloader=web-apps/apps/api/documents/cache-scripts.html
|
||||
files.docservice.url.example=
|
||||
|
||||
files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (People's Republic of China)|zh-TW:Chinese (Traditional, Taiwan)|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|ms:Malay (Malaysia)|nb:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA:Test Language
|
||||
files.docservice.languages=en:English|hy:Armenian|az:Azerbaijani|eu:Basque|be:Belarusian|bg:Bulgarian|ca:Catalan|zh:Chinese (Simplified)|zh-TW:Chinese (Traditional)|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|lo:Lao|lv:Latvian|ms:Malay (Malaysia)|no:Norwegian|pl:Polish|pt:Portuguese (Brazil)|pt-PT:Portuguese (Portugal)|ro:Romanian|ru:Russian|si:Sinhala (Sri Lanka)|sk:Slovak|sl:Slovenian|es:Spanish|sv:Swedish|tr:Turkish|uk:Ukrainian|vi:Vietnamese|aa-AA:Test Language
|
||||
|
||||
files.docservice.secret=
|
||||
files.docservice.header=Authorization
|
||||
files.docservice.token-use-for-request=TRUE
|
||||
|
||||
files.docservice.verify-peer-off=TRUE
|
||||
|
||||
@ -668,3 +668,8 @@
|
||||
max-width:15%;
|
||||
}
|
||||
}
|
||||
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
|
||||
.tableRow td:first-child{
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,13 +161,44 @@
|
||||
}
|
||||
};
|
||||
|
||||
var onRequestReferenceData = function(event) { // user refresh external data source
|
||||
event.data.directUrl = !!config.document.directUrl;
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "IndexServlet?type=reference");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.send(JSON.stringify(event.data));
|
||||
xhr.onload = function () {
|
||||
innerAlert(xhr.responseText);
|
||||
docEditor.setReferenceData(JSON.parse(xhr.responseText));
|
||||
}
|
||||
};
|
||||
|
||||
function onRequestRestore(event) {
|
||||
const query = new URLSearchParams(window.location.search)
|
||||
const payload = {
|
||||
fileName: query.get('fileName'),
|
||||
version: event.data.version,
|
||||
userId: config.editorConfig.user.id
|
||||
}
|
||||
const request = new XMLHttpRequest()
|
||||
request.open('PUT', 'IndexServlet?type=restore')
|
||||
request.send(JSON.stringify(payload))
|
||||
request.onload = function () {
|
||||
if (request.status != 200) {
|
||||
response = JSON.parse(request.response)
|
||||
innerAlert(response.error)
|
||||
return
|
||||
}
|
||||
document.location.reload()
|
||||
}
|
||||
}
|
||||
|
||||
config = JSON.parse('<%= FileModel.serialize(Model) %>');
|
||||
config.width = "100%";
|
||||
config.height = "100%";
|
||||
config.events = {
|
||||
"onAppReady": onAppReady,
|
||||
"onDocumentStateChange": onDocumentStateChange,
|
||||
'onRequestEditRights': onRequestEditRights,
|
||||
"onError": onError,
|
||||
"onOutdatedVersion": onOutdatedVersion,
|
||||
"onMakeActionLink": onMakeActionLink,
|
||||
@ -175,6 +206,7 @@
|
||||
"onRequestInsertImage": onRequestInsertImage,
|
||||
"onRequestCompareFile": onRequestCompareFile,
|
||||
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
|
||||
"onRequestRestore": onRequestRestore
|
||||
};
|
||||
|
||||
<%
|
||||
@ -215,6 +247,9 @@
|
||||
};
|
||||
// prevent file renaming for anonymous users
|
||||
config.events['onRequestRename'] = onRequestRename;
|
||||
config.events['onRequestReferenceData'] = onRequestReferenceData;
|
||||
// prevent switch the document from the viewing into the editing mode for anonymous users
|
||||
config.events['onRequestEditRights'] = onRequestEditRights;
|
||||
}
|
||||
|
||||
if (config.editorConfig.createUrl) {
|
||||
|
||||
@ -11,5 +11,11 @@ module.exports = {
|
||||
ecmaVersion: 'latest',
|
||||
},
|
||||
rules: {
|
||||
'max-len': ['error', { code: 120 }],
|
||||
'no-console': 'off',
|
||||
'no-continue': 'off',
|
||||
'no-extend-native': ['error', { exceptions: ['String'] }],
|
||||
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
|
||||
'no-prototype-builtins': 'off',
|
||||
},
|
||||
};
|
||||
|
||||
@ -32,10 +32,6 @@ he - a robust HTML entity encoder/decoder written in JavaScript. (htt
|
||||
License: MIT
|
||||
License File: he.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
License File: jQuery.BlockUI.license
|
||||
@ -48,9 +44,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.5.1",
|
||||
"version": "1.6.0",
|
||||
"log": {
|
||||
"appenders": [
|
||||
{
|
||||
@ -22,10 +22,6 @@
|
||||
"apiUrl": "web-apps/apps/api/documents/api.js",
|
||||
"preloaderUrl": "web-apps/apps/api/documents/cache-scripts.html",
|
||||
"exampleUrl": null,
|
||||
"viewedDocs": [".pdf", ".djvu", ".xps", ".oxps"],
|
||||
"editedDocs": [".docx", ".xlsx", ".csv", ".pptx", ".txt", ".docxf"],
|
||||
"fillDocs": [".docx", ".oform"],
|
||||
"convertedDocs": [".docm", ".doc", ".dotx", ".dotm", ".dot", ".odt", ".fodt", ".ott", ".xlsm", ".xlsb", ".xls", ".xltx", ".xltm", ".xlt", ".ods", ".fods", ".ots", ".pptm", ".ppt", ".ppsx", ".ppsm", ".pps", ".potx", ".potm", ".pot", ".odp", ".fodp", ".otp", ".rtf", ".mht", ".html", ".htm", ".xml", ".epub", ".fb2"],
|
||||
"storageFolder": "./files",
|
||||
"storagePath": "/files",
|
||||
"maxFileSize": 1073741824,
|
||||
@ -54,8 +50,8 @@
|
||||
"be": "Belarusian",
|
||||
"bg": "Bulgarian",
|
||||
"ca": "Catalan",
|
||||
"zh" : "Chinese (People's Republic of China)",
|
||||
"zh-TW" : "Chinese (Traditional, Taiwan)",
|
||||
"zh": "Chinese (Simplified)",
|
||||
"zh-TW": "Chinese (Traditional)",
|
||||
"cs": "Czech",
|
||||
"da": "Danish",
|
||||
"nl": "Dutch",
|
||||
@ -69,15 +65,16 @@
|
||||
"it": "Italian",
|
||||
"ja": "Japanese",
|
||||
"ko": "Korean",
|
||||
"lv": "Latvian",
|
||||
"lo": "Lao",
|
||||
"lv": "Latvian",
|
||||
"ms": "Malay (Malaysia)",
|
||||
"nb": "Norwegian",
|
||||
"no": "Norwegian",
|
||||
"pl": "Polish",
|
||||
"pt" : "Portuguese (Brazil)",
|
||||
"pt-PT" : "Portuguese (Portugal)",
|
||||
"pt": "Portuguese (Brazil)",
|
||||
"pt-PT": "Portuguese (Portugal)",
|
||||
"ro": "Romanian",
|
||||
"ru": "Russian",
|
||||
"si": "Sinhala (Sri Lanka)",
|
||||
"sk": "Slovak",
|
||||
"sl": "Slovenian",
|
||||
"es": "Spanish",
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2023
|
||||
*
|
||||
@ -16,42 +16,43 @@
|
||||
*
|
||||
*/
|
||||
|
||||
var cache = {};
|
||||
let cache = {};
|
||||
|
||||
// write the key value and its creation time to the cache
|
||||
exports.put = function (key, value) {
|
||||
cache[key] = { value:value, time: new Date().getTime()};
|
||||
}
|
||||
exports.put = function put(key, value) {
|
||||
cache[key] = { value, time: new Date().getTime() };
|
||||
};
|
||||
|
||||
// check if the given key is in the cache
|
||||
exports.containsKey = function (key) {
|
||||
if (typeof cache[key] == "undefined"){
|
||||
return false;
|
||||
}
|
||||
exports.containsKey = function containsKey(key) {
|
||||
if (typeof cache[key] === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var secondsCache = 30;
|
||||
const secondsCache = 30;
|
||||
|
||||
var t1 = new Date(cache[key].time + (1000 * secondsCache)); // get the creation time of the given key and add 30 seconds to it
|
||||
var t2 = new Date(); // get the current time
|
||||
if (t1 < t2 ){ // if the current time is greater
|
||||
delete cache[key]; // delete the given key from the cache
|
||||
return false;
|
||||
}
|
||||
// get the creation time of the given key and add 30 seconds to it
|
||||
const t1 = new Date(cache[key].time + (1000 * secondsCache));
|
||||
const t2 = new Date(); // get the current time
|
||||
if (t1 < t2) { // if the current time is greater
|
||||
delete cache[key]; // delete the given key from the cache
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// get the given key from the cache
|
||||
exports.get = function (key) {
|
||||
return cache[key];
|
||||
}
|
||||
exports.get = function get(key) {
|
||||
return cache[key];
|
||||
};
|
||||
|
||||
// delete the given key from the cache
|
||||
exports.delete = function (key) {
|
||||
delete cache[key];
|
||||
}
|
||||
exports.delete = function deleteKey(key) {
|
||||
delete cache[key];
|
||||
};
|
||||
|
||||
// clear the cache
|
||||
exports.clear = function () {
|
||||
cache = {};
|
||||
}
|
||||
exports.clear = function clear() {
|
||||
cache = {};
|
||||
};
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
"use strict";
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2023
|
||||
@ -17,488 +16,596 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const path = require("path");
|
||||
const fileSystem = require("fs");
|
||||
const fileUtility = require("./fileUtility");
|
||||
const documentService = require("./documentService");
|
||||
const path = require('path');
|
||||
const fileSystem = require('fs');
|
||||
const configServer = require('config').get('server');
|
||||
const storageConfigFolder = configServer.get("storageFolder");
|
||||
const fileUtility = require('./fileUtility');
|
||||
const documentService = require('./documentService');
|
||||
|
||||
function docManager(req, res) {
|
||||
this.req = req;
|
||||
this.res = res;
|
||||
}
|
||||
const storageConfigFolder = configServer.get('storageFolder');
|
||||
|
||||
const DocManager = function DocManager(req, res) {
|
||||
this.req = req;
|
||||
this.res = res;
|
||||
};
|
||||
|
||||
// check if the path exists or not
|
||||
docManager.prototype.existsSync = function(path) {
|
||||
let res = true;
|
||||
try {
|
||||
fileSystem.accessSync(path, fileSystem.F_OK); // synchronously test the user's permissions for the directory specified by path; the directory is visible to the calling process
|
||||
} catch (e) { // the response is set to false, if an error occurs
|
||||
res = false;
|
||||
}
|
||||
return res;
|
||||
DocManager.prototype.existsSync = function existsSync(directory) {
|
||||
let res = true;
|
||||
try {
|
||||
// synchronously test the user's permissions for the directory specified by path;
|
||||
// the directory is visible to the calling process
|
||||
fileSystem.accessSync(directory, fileSystem.F_OK);
|
||||
} catch (e) { // the response is set to false, if an error occurs
|
||||
res = false;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
// create a new directory if it doesn't exist
|
||||
docManager.prototype.createDirectory = function(path) {
|
||||
if (!this.existsSync(path)) {
|
||||
fileSystem.mkdirSync(path);
|
||||
}
|
||||
DocManager.prototype.createDirectory = function createDirectory(directory) {
|
||||
if (!this.existsSync(directory)) {
|
||||
fileSystem.mkdirSync(directory);
|
||||
}
|
||||
};
|
||||
|
||||
// get the language from the request
|
||||
docManager.prototype.getLang = function () {
|
||||
if (new RegExp("^[a-z]{2}(-[A-Z]{2})?$", "i").test(this.req.query.lang)) {
|
||||
return this.req.query.lang;
|
||||
} else { // the default language value is English
|
||||
return "en"
|
||||
}
|
||||
DocManager.prototype.getLang = function getLang() {
|
||||
if (/^[a-z]{2}(-[A-Z]{2})?$/i.test(this.req.query.lang)) {
|
||||
return this.req.query.lang;
|
||||
} // the default language value is English
|
||||
return 'en';
|
||||
};
|
||||
|
||||
// get customization parameters
|
||||
docManager.prototype.getCustomParams = function () {
|
||||
let params = "";
|
||||
DocManager.prototype.getCustomParams = function getCustomParams() {
|
||||
let params = '';
|
||||
|
||||
const userid = this.req.query.userid; // user id
|
||||
params += (userid ? "&userid=" + userid : "");
|
||||
const { userid } = this.req.query; // user id
|
||||
params += (userid ? `&userid=${userid}` : '');
|
||||
|
||||
const lang = this.req.query.lang; // language
|
||||
params += (lang ? "&lang=" + this.getLang() : "");
|
||||
const { lang } = this.req.query; // language
|
||||
params += (lang ? `&lang=${this.getLang()}` : '');
|
||||
|
||||
const directUrl = this.req.query.directUrl; // directUrl
|
||||
params += (directUrl ? "&directUrl=" + (directUrl == "true") : "");
|
||||
const { directUrl } = this.req.query; // directUrl
|
||||
params += (directUrl ? `&directUrl=${directUrl === 'true'}` : '');
|
||||
|
||||
const fileName = this.req.query.fileName; // file name
|
||||
params += (fileName ? "&fileName=" + fileName : "");
|
||||
const { fileName } = this.req.query; // file name
|
||||
params += (fileName ? `&fileName=${fileName}` : '');
|
||||
|
||||
const mode = this.req.query.mode; // mode: view/edit/review/comment/fillForms/embedded
|
||||
params += (mode ? "&mode=" + mode : "");
|
||||
const { mode } = this.req.query; // mode: view/edit/review/comment/fillForms/embedded
|
||||
params += (mode ? `&mode=${mode}` : '');
|
||||
|
||||
const type = this.req.query.type; // type: embedded/mobile/desktop
|
||||
params += (type ? "&type=" + type : "");
|
||||
const { type } = this.req.query; // type: embedded/mobile/desktop
|
||||
params += (type ? `&type=${type}` : '');
|
||||
|
||||
return params;
|
||||
return params;
|
||||
};
|
||||
|
||||
// get the correct file name if such a name already exists
|
||||
docManager.prototype.getCorrectName = function (fileName, userAddress) {
|
||||
const baseName = fileUtility.getFileName(fileName, true); // get file name from the url without extension
|
||||
const ext = fileUtility.getFileExtension(fileName); // get file extension from the url
|
||||
let name = baseName + ext; // get full file name
|
||||
let index = 1;
|
||||
DocManager.prototype.getCorrectName = function getCorrectName(fileName, userAddress) {
|
||||
const baseName = fileUtility.getFileName(fileName, true); // get file name from the url without extension
|
||||
const ext = fileUtility.getFileExtension(fileName); // get file extension from the url
|
||||
let name = baseName + ext; // get full file name
|
||||
let index = 1;
|
||||
|
||||
while (this.existsSync(this.storagePath(name, userAddress))) { // if the file with such a name already exists in this directory
|
||||
name = baseName + " (" + index + ")" + ext; // add an index after its base name
|
||||
index++;
|
||||
}
|
||||
// if the file with such a name already exists in this directory
|
||||
while (this.existsSync(this.storagePath(name, userAddress))) {
|
||||
name = `${baseName} (${index})${ext}`; // add an index after its base name
|
||||
index += 1;
|
||||
}
|
||||
|
||||
return name;
|
||||
return name;
|
||||
};
|
||||
|
||||
// processes a request editnew
|
||||
docManager.prototype.RequestEditnew = function (req, fileName, user) {
|
||||
if (req.params['id'] != fileName){ // processes a repeated request editnew
|
||||
this.fileRemove(req.params['id']);
|
||||
fileName = this.getCorrectName(req.params['id']);
|
||||
}
|
||||
this.fileSizeZero(fileName);
|
||||
this.saveFileData(fileName, user.id, user.name);
|
||||
DocManager.prototype.requestEditnew = function requestEditnew(req, fileName, user) {
|
||||
let correctName = fileName;
|
||||
if (req.params.id !== fileName) { // processes a repeated request editnew
|
||||
this.fileRemove(req.params.id);
|
||||
correctName = this.getCorrectName(req.params.id);
|
||||
}
|
||||
this.fileSizeZero(correctName);
|
||||
this.saveFileData(correctName, user.id, user.name);
|
||||
|
||||
return fileName;
|
||||
}
|
||||
return correctName;
|
||||
};
|
||||
|
||||
// delete a file with its history
|
||||
docManager.prototype.fileRemove = function (fileName) {
|
||||
const filePath = this.storagePath(fileName); // get the path to this file
|
||||
fileSystem.unlinkSync(filePath); // and delete it
|
||||
DocManager.prototype.fileRemove = function fileRemove(fileName) {
|
||||
const filePath = this.storagePath(fileName); // get the path to this file
|
||||
fileSystem.unlinkSync(filePath); // and delete it
|
||||
|
||||
const userAddress = this.curUserHostAddress();
|
||||
const historyPath = this.historyPath(fileName, userAddress, true);
|
||||
this.cleanFolderRecursive(historyPath, true); // clean all the files from the history folder
|
||||
}
|
||||
const userAddress = this.curUserHostAddress();
|
||||
const historyPath = this.historyPath(fileName, userAddress, true);
|
||||
this.cleanFolderRecursive(historyPath, true); // clean all the files from the history folder
|
||||
};
|
||||
|
||||
// create a zero-size file
|
||||
docManager.prototype.fileSizeZero = function (fileName) {
|
||||
var path = this.storagePath(fileName);
|
||||
var fh = fileSystem.openSync(path, 'w');
|
||||
fileSystem.closeSync(fh);
|
||||
}
|
||||
DocManager.prototype.fileSizeZero = function fileSizeZero(fileName) {
|
||||
const storagePath = this.storagePath(fileName);
|
||||
const fh = fileSystem.openSync(storagePath, 'w');
|
||||
fileSystem.closeSync(fh);
|
||||
};
|
||||
|
||||
// create demo document
|
||||
docManager.prototype.createDemo = function (isSample, fileExt, userid, username, wopi) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
DocManager.prototype.createDemo = function createDemo(isSample, fileExt, userid, username, wopi) {
|
||||
const demoName = `${isSample ? 'sample' : 'new'}.${fileExt}`;
|
||||
const fileName = this.getCorrectName(demoName); // get the correct file name if such a name already exists
|
||||
|
||||
const demoName = (isSample ? "sample" : "new") + "." + fileExt;
|
||||
const fileName = this.getCorrectName(demoName); // get the correct file name if such a name already exists
|
||||
// copy sample document of a necessary extension to the storage path
|
||||
this.copyFile(path.join(__dirname, '..', 'public', 'assets', 'document-templates', isSample
|
||||
? 'sample' : 'new', demoName), this.storagePath(fileName));
|
||||
|
||||
this.copyFile(path.join(__dirname, "..","public", "assets", isSample ? "sample" : "new", demoName), this.storagePath(fileName)); // copy sample document of a necessary extension to the storage path
|
||||
this.saveFileData(fileName, userid, username); // save file data to the file
|
||||
|
||||
this.saveFileData(fileName, userid, username); // save file data to the file
|
||||
|
||||
return fileName;
|
||||
return fileName;
|
||||
};
|
||||
|
||||
// save file data to the file
|
||||
docManager.prototype.saveFileData = function (fileName, userid, username, userAddress) {
|
||||
if (!userAddress) {
|
||||
userAddress = this.curUserHostAddress(); // get current user host address
|
||||
}
|
||||
// get full creation date of the document
|
||||
const date_create = fileSystem.statSync(this.storagePath(fileName, userAddress)).mtime;
|
||||
const minutes = (date_create.getMinutes() < 10 ? '0' : '') + date_create.getMinutes().toString();
|
||||
const month = (date_create.getMonth() < 10 ? '0' : '') + (parseInt(date_create.getMonth().toString()) + 1);
|
||||
const sec = (date_create.getSeconds() < 10 ? '0' : '') + date_create.getSeconds().toString();
|
||||
const date_format = date_create.getFullYear() + "-" + month + "-" + date_create.getDate() + " " + date_create.getHours() + ":" + minutes + ":" + sec;
|
||||
DocManager.prototype.saveFileData = function saveFileData(fileName, userid, username, userAddress) {
|
||||
let address = userAddress;
|
||||
if (!address) {
|
||||
address = this.curUserHostAddress(); // get current user host address
|
||||
}
|
||||
// get full creation date of the document
|
||||
const dateCreate = fileSystem.statSync(this.storagePath(fileName, address)).mtime;
|
||||
const minutes = (dateCreate.getMinutes() < 10 ? '0' : '') + dateCreate.getMinutes().toString();
|
||||
const month = (dateCreate.getMonth() < 10 ? '0' : '') + (parseInt(dateCreate.getMonth().toString(), 10) + 1);
|
||||
const sec = (dateCreate.getSeconds() < 10 ? '0' : '') + dateCreate.getSeconds().toString();
|
||||
const dateFormat = `${dateCreate.getFullYear()}-${month}-${dateCreate.getDate()} `
|
||||
+ `${dateCreate.getHours()}:${minutes}:${sec}`;
|
||||
|
||||
const file_info = this.historyPath(fileName, userAddress, true); // get file history information
|
||||
this.createDirectory(file_info); // create a new history directory if it doesn't exist
|
||||
const fileInfo = this.historyPath(fileName, address, true); // get file history information
|
||||
this.createDirectory(fileInfo); // create a new history directory if it doesn't exist
|
||||
|
||||
fileSystem.writeFileSync(path.join(file_info, fileName + ".txt"), date_format + "," + userid + "," + username); // write all the file information to a new txt file
|
||||
// write all the file information to a new txt file
|
||||
fileSystem.writeFileSync(path.join(fileInfo, `${fileName}.txt`), `${dateFormat},${userid},${username}`);
|
||||
};
|
||||
|
||||
// get file data
|
||||
docManager.prototype.getFileData = function (fileName, userAddress) {
|
||||
const history = path.join(this.historyPath(fileName, userAddress, true), fileName + ".txt"); // get the path to the file with file information
|
||||
if (!this.existsSync(history)) { // if such a file doesn't exist
|
||||
return ["2017-01-01", "uid-1", "John Smith"]; // return default information
|
||||
}
|
||||
DocManager.prototype.getFileData = function getFileData(fileName, userAddress) {
|
||||
// get the path to the file with file information
|
||||
const history = path.join(this.historyPath(fileName, userAddress, true), `${fileName}.txt`);
|
||||
if (!this.existsSync(history)) { // if such a file doesn't exist
|
||||
return ['2017-01-01', 'uid-1', 'John Smith']; // return default information
|
||||
}
|
||||
|
||||
return ((fileSystem.readFileSync(history)).toString()).split(",");
|
||||
return ((fileSystem.readFileSync(history)).toString())
|
||||
.split(',');
|
||||
};
|
||||
|
||||
// get server url
|
||||
docManager.prototype.getServerUrl = function (forDocumentServer) {
|
||||
return (forDocumentServer && !!configServer.get("exampleUrl")) ? configServer.get("exampleUrl") : this.getServerPath();
|
||||
DocManager.prototype.getServerUrl = function getServerUrl(forDocumentServer) {
|
||||
return (forDocumentServer && !!configServer.get('exampleUrl'))
|
||||
? configServer.get('exampleUrl') : this.getServerPath();
|
||||
};
|
||||
|
||||
// get server address from the request
|
||||
docManager.prototype.getServerPath = function () {
|
||||
return this.getServerHost() + (this.req.headers["x-forwarded-path"] || this.req.baseUrl);
|
||||
DocManager.prototype.getServerPath = function getServerPath() {
|
||||
return this.getServerHost() + (this.req.headers['x-forwarded-path'] || this.req.baseUrl);
|
||||
};
|
||||
|
||||
// get host address from the request
|
||||
docManager.prototype.getServerHost = function () {
|
||||
return this.getProtocol() + "://" + (this.req.headers["x-forwarded-host"] || this.req.headers["host"]);
|
||||
DocManager.prototype.getServerHost = function getServerHost() {
|
||||
return `${this.getProtocol()}://${this.req.headers['x-forwarded-host'] || this.req.headers.host}`
|
||||
+ `${this.req.headers['x-forwarded-prefix'] || ''}`;
|
||||
};
|
||||
|
||||
// get protocol from the request
|
||||
docManager.prototype.getProtocol = function () {
|
||||
return this.req.headers["x-forwarded-proto"] || this.req.protocol;
|
||||
DocManager.prototype.getProtocol = function getProtocol() {
|
||||
return this.req.headers['x-forwarded-proto'] || this.req.protocol;
|
||||
};
|
||||
|
||||
// get callback url
|
||||
docManager.prototype.getCallback = function (fileName) {
|
||||
const server = this.getServerUrl(true);
|
||||
const hostAddress = this.curUserHostAddress();
|
||||
const handler = "/track?filename=" + encodeURIComponent(fileName) + "&useraddress=" + encodeURIComponent(hostAddress); // get callback handler
|
||||
DocManager.prototype.getCallback = function getCallback(fileName) {
|
||||
const server = this.getServerUrl(true);
|
||||
const hostAddress = this.curUserHostAddress();
|
||||
// get callback handler
|
||||
const handler = `/track?filename=${encodeURIComponent(fileName)}&useraddress=${encodeURIComponent(hostAddress)}`;
|
||||
|
||||
return server + handler;
|
||||
return server + handler;
|
||||
};
|
||||
|
||||
// get url to the created file
|
||||
docManager.prototype.getCreateUrl = function (docType, userid, type, lang) {
|
||||
const server = this.getServerUrl();
|
||||
var ext = this.getInternalExtension(docType).replace(".", "");
|
||||
const handler = "/editor?fileExt=" + ext + "&userid=" + userid + "&type=" + type + "&lang=" + lang;
|
||||
DocManager.prototype.getCreateUrl = function getCreateUrl(docType, userid, type, lang) {
|
||||
const server = this.getServerUrl();
|
||||
const ext = this.getInternalExtension(docType).replace('.', '');
|
||||
const handler = `/editor?fileExt=${ext}&userid=${userid}&type=${type}&lang=${lang}`;
|
||||
|
||||
return server + handler;
|
||||
}
|
||||
|
||||
// get url to download a file
|
||||
docManager.prototype.getDownloadUrl = function (fileName, forDocumentServer) {
|
||||
const server = this.getServerUrl(forDocumentServer);
|
||||
var handler = "/download?fileName=" + encodeURIComponent(fileName);
|
||||
if (forDocumentServer) {
|
||||
const hostAddress = this.curUserHostAddress();
|
||||
handler += "&useraddress=" + encodeURIComponent(hostAddress);
|
||||
}
|
||||
|
||||
return server + handler;
|
||||
return server + handler;
|
||||
};
|
||||
|
||||
docManager.prototype.storageRootPath = function (userAddress) {
|
||||
return path.join(storageConfigFolder, this.curUserHostAddress(userAddress)); // get the path to the directory for the host address
|
||||
}
|
||||
// get url to download a file
|
||||
DocManager.prototype.getDownloadUrl = function getDownloadUrl(fileName, forDocumentServer) {
|
||||
const server = this.getServerUrl(forDocumentServer);
|
||||
let handler = `/download?fileName=${encodeURIComponent(fileName)}`;
|
||||
if (forDocumentServer) {
|
||||
const hostAddress = this.curUserHostAddress();
|
||||
handler += `&useraddress=${encodeURIComponent(hostAddress)}`;
|
||||
}
|
||||
|
||||
return server + handler;
|
||||
};
|
||||
|
||||
DocManager.prototype.storageRootPath = function storageRootPath(userAddress) {
|
||||
// get the path to the directory for the host address
|
||||
return path.join(storageConfigFolder, this.curUserHostAddress(userAddress));
|
||||
};
|
||||
|
||||
// get the storage path of the given file
|
||||
docManager.prototype.storagePath = function (fileName, userAddress) {
|
||||
fileName = fileUtility.getFileName(fileName); // get the file name with extension
|
||||
const directory = this.storageRootPath(userAddress);
|
||||
this.createDirectory(directory); // create a new directory if it doesn't exist
|
||||
return path.join(directory, fileName); // put the given file to this directory
|
||||
DocManager.prototype.storagePath = function storagePath(fileName, userAddress) {
|
||||
const fileNameExt = fileUtility.getFileName(fileName); // get the file name with extension
|
||||
const directory = this.storageRootPath(userAddress);
|
||||
this.createDirectory(directory); // create a new directory if it doesn't exist
|
||||
return path.join(directory, fileNameExt); // put the given file to this directory
|
||||
};
|
||||
|
||||
// get the path to the forcesaved file version
|
||||
docManager.prototype.forcesavePath = function (fileName, userAddress, create) {
|
||||
let directory = this.storageRootPath(userAddress);
|
||||
if (!this.existsSync(directory)) { // the directory with host address doesn't exist
|
||||
return "";
|
||||
}
|
||||
directory = path.join(directory, fileName + "-history"); // get the path to the history of the given file
|
||||
if (!create && !this.existsSync(directory)) { // the history directory doesn't exist and we are not supposed to create it
|
||||
return "";
|
||||
}
|
||||
this.createDirectory(directory); // create history directory if it doesn't exist
|
||||
directory = path.join(directory, fileName); // and get the path to the given file
|
||||
if (!create && !this.existsSync(directory)) {
|
||||
return "";
|
||||
}
|
||||
return directory;
|
||||
DocManager.prototype.forcesavePath = function forcesavePath(fileName, userAddress, create) {
|
||||
let directory = this.storageRootPath(userAddress);
|
||||
if (!this.existsSync(directory)) { // the directory with host address doesn't exist
|
||||
return '';
|
||||
}
|
||||
directory = path.join(directory, `${fileName}-history`); // get the path to the history of the given file
|
||||
// the history directory doesn't exist and we are not supposed to create it
|
||||
if (!create && !this.existsSync(directory)) {
|
||||
return '';
|
||||
}
|
||||
this.createDirectory(directory); // create history directory if it doesn't exist
|
||||
directory = path.join(directory, fileName); // and get the path to the given file
|
||||
if (!create && !this.existsSync(directory)) {
|
||||
return '';
|
||||
}
|
||||
return directory;
|
||||
};
|
||||
|
||||
// create the path to the file history
|
||||
docManager.prototype.historyPath = function (fileName, userAddress, create) {
|
||||
let directory = this.storageRootPath(userAddress);
|
||||
if (!this.existsSync(directory)) {
|
||||
return "";
|
||||
}
|
||||
directory = path.join(directory, fileName + "-history");
|
||||
if (!create && !this.existsSync(path.join(directory, "1"))) {
|
||||
return "";
|
||||
}
|
||||
return directory;
|
||||
DocManager.prototype.historyPath = function historyPath(fileName, userAddress, create) {
|
||||
let directory = this.storageRootPath(userAddress);
|
||||
if (!this.existsSync(directory)) {
|
||||
return '';
|
||||
}
|
||||
directory = path.join(directory, `${fileName}-history`);
|
||||
if (!create && !this.existsSync(path.join(directory, '1'))) {
|
||||
return '';
|
||||
}
|
||||
return directory;
|
||||
};
|
||||
|
||||
// get the path to the specified file version
|
||||
docManager.prototype.versionPath = function (fileName, userAddress, version) {
|
||||
const historyPath = this.historyPath(fileName, userAddress, true); // get the path to the history of a given file or create it if it doesn't exist
|
||||
return path.join(historyPath, "" + version);
|
||||
DocManager.prototype.versionPath = function versionPath(fileName, userAddress, version) {
|
||||
// get the path to the history of a given file or create it if it doesn't exist
|
||||
const historyPath = this.historyPath(fileName, userAddress, true);
|
||||
return path.join(historyPath, `${version}`);
|
||||
};
|
||||
|
||||
// get the path to the previous file version
|
||||
docManager.prototype.prevFilePath = function (fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), "prev" + fileUtility.getFileExtension(fileName));
|
||||
DocManager.prototype.prevFilePath = function prevFilePath(fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), `prev${fileUtility.getFileExtension(fileName)}`);
|
||||
};
|
||||
|
||||
// get the path to the file with document versions differences
|
||||
docManager.prototype.diffPath = function (fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), "diff.zip");
|
||||
DocManager.prototype.diffPath = function diffPath(fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), 'diff.zip');
|
||||
};
|
||||
|
||||
// get the path to the file with document changes
|
||||
docManager.prototype.changesPath = function (fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), "changes.txt");
|
||||
DocManager.prototype.changesPath = function changesPath(fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), 'changes.txt');
|
||||
};
|
||||
|
||||
// get the path to the file with key value in it
|
||||
docManager.prototype.keyPath = function (fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), "key.txt");
|
||||
DocManager.prototype.keyPath = function keyPath(fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), 'key.txt');
|
||||
};
|
||||
|
||||
// get the path to the file with the user information
|
||||
docManager.prototype.changesUser = function (fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), "user.txt");
|
||||
DocManager.prototype.changesUser = function changesUser(fileName, userAddress, version) {
|
||||
return path.join(this.versionPath(fileName, userAddress, version), 'user.txt');
|
||||
};
|
||||
|
||||
// get all the stored files
|
||||
docManager.prototype.getStoredFiles = function () {
|
||||
const userAddress = this.curUserHostAddress();
|
||||
const directory = this.storageRootPath(userAddress);
|
||||
this.createDirectory(directory);
|
||||
const result = [];
|
||||
const storedFiles = fileSystem.readdirSync(directory); // read the user host directory contents
|
||||
for (let i = 0; i < storedFiles.length; i++) { // run through all the elements from the folder
|
||||
const stats = fileSystem.lstatSync(path.join(directory, storedFiles[i])); // save element parameters
|
||||
DocManager.prototype.getStoredFiles = function getStoredFiles() {
|
||||
const userAddress = this.curUserHostAddress();
|
||||
const directory = this.storageRootPath(userAddress);
|
||||
this.createDirectory(directory);
|
||||
const result = [];
|
||||
const storedFiles = fileSystem.readdirSync(directory); // read the user host directory contents
|
||||
for (let i = 0; i < storedFiles.length; i++) { // run through all the elements from the folder
|
||||
const stats = fileSystem.lstatSync(path.join(directory, storedFiles[i])); // save element parameters
|
||||
|
||||
if (!stats.isDirectory()) { // if the element isn't a directory
|
||||
let historyPath = this.historyPath(storedFiles[i], userAddress); // get the path to the file history
|
||||
let version = 0;
|
||||
if (historyPath != "") { // if the history path exists
|
||||
version = this.countVersion(historyPath); // get the last file version
|
||||
}
|
||||
if (!stats.isDirectory()) { // if the element isn't a directory
|
||||
const historyPath = this.historyPath(storedFiles[i], userAddress); // get the path to the file history
|
||||
let version = 0;
|
||||
if (historyPath !== '') { // if the history path exists
|
||||
version = this.countVersion(historyPath); // get the last file version
|
||||
}
|
||||
|
||||
const time = stats.mtime.getTime(); // get the time of element modification
|
||||
const item = { // create an object with element data
|
||||
time: time,
|
||||
name: storedFiles[i],
|
||||
documentType: fileUtility.getFileType(storedFiles[i]),
|
||||
canEdit: configServer.get("editedDocs").indexOf(fileUtility.getFileExtension(storedFiles[i])) != -1,
|
||||
version: version+1
|
||||
};
|
||||
const time = stats.mtime.getTime(); // get the time of element modification
|
||||
const item = { // create an object with element data
|
||||
time,
|
||||
name: storedFiles[i],
|
||||
documentType: fileUtility.getFileType(storedFiles[i]),
|
||||
canEdit: fileUtility.getEditExtensions().indexOf(fileUtility.getFileExtension(storedFiles[i], true)) !== -1,
|
||||
version: version + 1,
|
||||
};
|
||||
|
||||
if (!result.length) { // if the result array is empty
|
||||
result.push(item); // push the item object to it
|
||||
} else {
|
||||
let j = 0;
|
||||
for (; j < result.length; j++) {
|
||||
if (time > result[j].time) { // otherwise, run through all the objects from the result array
|
||||
break;
|
||||
}
|
||||
}
|
||||
result.splice(j, 0, item); // and add new object in ascending order of time
|
||||
}
|
||||
if (!result.length) { // if the result array is empty
|
||||
result.push(item); // push the item object to it
|
||||
} else {
|
||||
let j = 0;
|
||||
for (; j < result.length; j++) {
|
||||
if (time > result[j].time) { // otherwise, run through all the objects from the result array
|
||||
break;
|
||||
}
|
||||
}
|
||||
result.splice(j, 0, item); // and add new object in ascending order of time
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
// get current user host address
|
||||
docManager.prototype.curUserHostAddress = function (userAddress) {
|
||||
if (!userAddress) // if user address isn't passed to the function
|
||||
userAddress = this.req.headers["x-forwarded-for"] || this.req.connection.remoteAddress; // take it from the header or use the remote address
|
||||
DocManager.prototype.curUserHostAddress = function curUserHostAddress(userAddress) {
|
||||
let address = userAddress;
|
||||
if (!address) { // if user address isn't passed to the function
|
||||
// take it from the header or use the remote address
|
||||
address = this.req.headers['x-forwarded-for'] || this.req.connection.remoteAddress;
|
||||
}
|
||||
|
||||
return userAddress.replace(new RegExp("[^0-9a-zA-Z.=]", "g"), "_");
|
||||
return address.replace(/[^0-9a-zA-Z.=]/g, '_');
|
||||
};
|
||||
|
||||
// copy file
|
||||
docManager.prototype.copyFile = function (exist, target) {
|
||||
fileSystem.writeFileSync(target, fileSystem.readFileSync(exist));
|
||||
DocManager.prototype.copyFile = function copyFile(exist, target) {
|
||||
fileSystem.writeFileSync(target, fileSystem.readFileSync(exist));
|
||||
};
|
||||
|
||||
// get an internal extension
|
||||
docManager.prototype.getInternalExtension = function (fileType) {
|
||||
if (fileType == fileUtility.fileType.word) // .docx for word type
|
||||
return ".docx";
|
||||
DocManager.prototype.getInternalExtension = function getInternalExtension(fileType) {
|
||||
if (fileType === fileUtility.fileType.word) { // .docx for word type
|
||||
return '.docx';
|
||||
}
|
||||
|
||||
if (fileType == fileUtility.fileType.cell) // .xlsx for cell type
|
||||
return ".xlsx";
|
||||
if (fileType === fileUtility.fileType.cell) { // .xlsx for cell type
|
||||
return '.xlsx';
|
||||
}
|
||||
|
||||
if (fileType == fileUtility.fileType.slide) // .pptx for slide type
|
||||
return ".pptx";
|
||||
if (fileType === fileUtility.fileType.slide) { // .pptx for slide type
|
||||
return '.pptx';
|
||||
}
|
||||
|
||||
return ".docx"; // the default value is .docx
|
||||
return '.docx'; // the default value is .docx
|
||||
};
|
||||
|
||||
// get the template image url
|
||||
docManager.prototype.getTemplateImageUrl = function (fileType) {
|
||||
let path = this.getServerUrl(true);
|
||||
if (fileType == fileUtility.fileType.word) // for word type
|
||||
return path + "/images/file_docx.svg";
|
||||
DocManager.prototype.getTemplateImageUrl = function getTemplateImageUrl(fileType) {
|
||||
const serverUrl = this.getServerUrl(true);
|
||||
if (fileType === fileUtility.fileType.word) { // for word type
|
||||
return `${serverUrl}/images/file_docx.svg`;
|
||||
}
|
||||
|
||||
if (fileType == fileUtility.fileType.cell) // for cell type
|
||||
return path + "/images/file_xlsx.svg";
|
||||
if (fileType === fileUtility.fileType.cell) { // for cell type
|
||||
return `${serverUrl}/images/file_xlsx.svg`;
|
||||
}
|
||||
|
||||
if (fileType == fileUtility.fileType.slide) // for slide type
|
||||
return path + "/images/file_pptx.svg";
|
||||
if (fileType === fileUtility.fileType.slide) { // for slide type
|
||||
return `${serverUrl}/images/file_pptx.svg`;
|
||||
}
|
||||
|
||||
return path + "/images/file_docx.svg"; // the default value
|
||||
}
|
||||
return `${serverUrl}/images/file_docx.svg`; // the default value
|
||||
};
|
||||
|
||||
// get document key
|
||||
docManager.prototype.getKey = function (fileName, userAddress) {
|
||||
userAddress = userAddress || this.curUserHostAddress();
|
||||
let key = userAddress + fileName; // get document key by adding local file url to the current user host address
|
||||
DocManager.prototype.getKey = function getKey(fileName, userAddress) {
|
||||
const address = userAddress || this.curUserHostAddress();
|
||||
let key = address + fileName; // get document key by adding local file url to the current user host address
|
||||
|
||||
let historyPath = this.historyPath(fileName, userAddress); // get the path to the file history
|
||||
if (historyPath != ""){ // if the path to the file history exists
|
||||
key += this.countVersion(historyPath); // add file version number to the document key
|
||||
}
|
||||
const historyPath = this.historyPath(fileName, address); // get the path to the file history
|
||||
if (historyPath !== '') { // if the path to the file history exists
|
||||
key += this.countVersion(historyPath); // add file version number to the document key
|
||||
}
|
||||
|
||||
let storagePath = this.storagePath(fileName, userAddress); // get the storage path to the given file
|
||||
const stat = fileSystem.statSync(storagePath); // get file information
|
||||
key += stat.mtime.getTime(); // and add creation time to the document key
|
||||
const storagePath = this.storagePath(fileName, address); // get the storage path to the given file
|
||||
const stat = fileSystem.statSync(storagePath); // get file information
|
||||
key += stat.mtime.getTime(); // and add creation time to the document key
|
||||
|
||||
return documentService.generateRevisionId(key); // generate the document key value
|
||||
return documentService.generateRevisionId(key); // generate the document key value
|
||||
};
|
||||
|
||||
// get current date
|
||||
docManager.prototype.getDate = function (date) {
|
||||
const minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes().toString();
|
||||
return date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear() + " " + date.getHours() + ":" + minutes;
|
||||
DocManager.prototype.getDate = function getDate(date) {
|
||||
const minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes().toString();
|
||||
return `${date.getMonth()}/${date.getDate()}/${date.getFullYear()} ${date.getHours()}:${minutes}`;
|
||||
};
|
||||
|
||||
// get changes made in the file
|
||||
docManager.prototype.getChanges = function (fileName) {
|
||||
if (this.existsSync(fileName)) { // if the directory with such a file exists
|
||||
return JSON.parse(fileSystem.readFileSync(fileName)); // read this file and parse it
|
||||
}
|
||||
return null;
|
||||
DocManager.prototype.getChanges = function getChanges(fileName) {
|
||||
if (this.existsSync(fileName)) { // if the directory with such a file exists
|
||||
return JSON.parse(fileSystem.readFileSync(fileName)); // read this file and parse it
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// get the last file version
|
||||
docManager.prototype.countVersion = function(directory) {
|
||||
let i = 0;
|
||||
while (this.existsSync(path.join(directory, '' + (i + 1)))) { // run through all the file versions
|
||||
i++; // and count them
|
||||
}
|
||||
return i;
|
||||
DocManager.prototype.countVersion = function countVersion(directory) {
|
||||
let i = 0;
|
||||
while (this.existsSync(path.join(directory, `${i + 1}`))) { // run through all the file versions
|
||||
i += 1; // and count them
|
||||
}
|
||||
return i;
|
||||
};
|
||||
|
||||
// get file history information
|
||||
docManager.prototype.getHistory = function (fileName, content, keyVersion, version) {
|
||||
let oldVersion = false;
|
||||
let contentJson = null;
|
||||
if (content) { // if content is defined
|
||||
if (content.changes && content.changes.length) { // and there are some modifications in the content
|
||||
contentJson = content.changes[0]; // write these modifications to the json content
|
||||
} else if (content.length){
|
||||
contentJson = content[0]; // otherwise, write original content to the json content
|
||||
oldVersion = true; // and note that this is an old version
|
||||
} else {
|
||||
content = false;
|
||||
}
|
||||
DocManager.prototype.getHistoryObject = function getHistoryObject(fileName, userAddr = null, userDirectUrl = null) {
|
||||
const userAddress = userAddr || this.curUserHostAddress();
|
||||
const historyPath = this.historyPath(fileName, userAddress);
|
||||
const key = this.getKey(fileName);
|
||||
const directUrl = this.getDownloadUrl(fileName);
|
||||
const fileExt = fileUtility.getFileExtension(fileName);
|
||||
const url = this.getDownloadUrl(fileName, true);
|
||||
const history = [];
|
||||
const historyData = [];
|
||||
let countVersion = 1;
|
||||
let changes = null;
|
||||
let keyVersion = key;
|
||||
|
||||
if (historyPath !== '') {
|
||||
countVersion = this.countVersion(historyPath) + 1; // get the number of file versions
|
||||
for (let i = 1; i <= countVersion; i++) { // get keys to all the file versions
|
||||
if (i < countVersion) {
|
||||
const keyPath = this.keyPath(fileName, userAddress, i);
|
||||
if (!fileSystem.existsSync(keyPath)) continue;
|
||||
keyVersion = `${fileSystem.readFileSync(keyPath)}`;
|
||||
} else {
|
||||
keyVersion = key;
|
||||
}
|
||||
// write all the file history information
|
||||
history.push(this.getHistory(fileName, changes, keyVersion, i));
|
||||
|
||||
const userUrl = i === countVersion ? directUrl : (`${this.getServerUrl(false)}/history?fileName=`
|
||||
+ `${encodeURIComponent(fileName)}&file=prev${fileExt}&ver=${i}`);
|
||||
const historyD = {
|
||||
fileType: fileExt.slice(1),
|
||||
version: i,
|
||||
key: keyVersion,
|
||||
url: i === countVersion ? url : (`${this.getServerUrl(true)}/history?fileName=`
|
||||
+ `${encodeURIComponent(fileName)}&file=prev${fileExt}&ver=${i}&useraddress=${userAddress}`),
|
||||
directUrl: !userDirectUrl ? null : userUrl,
|
||||
};
|
||||
|
||||
// check if the path to the file with document versions differences exists
|
||||
if (i > 1 && this.existsSync(this.diffPath(fileName, userAddress, i - 1))) {
|
||||
historyD.previous = { // write information about previous file version
|
||||
fileType: historyData[i - 2].fileType,
|
||||
key: historyData[i - 2].key,
|
||||
url: historyData[i - 2].url,
|
||||
directUrl: !userDirectUrl ? null : historyData[i - 2].directUrl,
|
||||
};
|
||||
const changesUrl = `${this.getServerUrl(true)}/history?fileName=`
|
||||
+ `${encodeURIComponent(fileName)}&file=diff.zip&ver=${i - 1}&useraddress=${userAddress}`;
|
||||
historyD.changesUrl = changesUrl; // get the path to the diff.zip file and write it to the history object
|
||||
}
|
||||
|
||||
historyData.push(historyD);
|
||||
|
||||
if (i < countVersion) {
|
||||
// get the path to the file with document changes
|
||||
const changesFile = this.changesPath(fileName, userAddress, i);
|
||||
changes = this.getChanges(changesFile); // get changes made in the file
|
||||
}
|
||||
}
|
||||
} else { // if history path is empty
|
||||
// write the history information about the last file version
|
||||
history.push(this.getHistory(fileName, changes, keyVersion, countVersion));
|
||||
historyData.push({
|
||||
fileType: fileExt.slice(1),
|
||||
version: countVersion,
|
||||
key,
|
||||
url,
|
||||
directUrl: !userDirectUrl ? null : directUrl,
|
||||
});
|
||||
}
|
||||
|
||||
const userAddress = this.curUserHostAddress();
|
||||
const username = content ? (oldVersion ? contentJson.username : contentJson.user.name) : (this.getFileData(fileName, userAddress))[2];
|
||||
const userid = content ? (oldVersion ? contentJson.userid : contentJson.user.id) : (this.getFileData(fileName, userAddress))[1];
|
||||
const created = content ? (oldVersion ? contentJson.date : contentJson.created) : (this.getFileData(fileName, userAddress))[0];
|
||||
const res = (content && !oldVersion) ? content : {changes: content};
|
||||
res.key = keyVersion; // write the information about the user, creation time, key and version to the result object
|
||||
res.version = version;
|
||||
res.created = created;
|
||||
res.user = {
|
||||
id: userid,
|
||||
name: username != "null" ? username : null
|
||||
};
|
||||
return { history, historyData, countVersion };
|
||||
};
|
||||
// get file history information
|
||||
DocManager.prototype.getHistory = function getHistory(fileName, content, keyVersion, version) {
|
||||
let oldVersion = false;
|
||||
let contentJson = null;
|
||||
let fileContent = content;
|
||||
let userNameFromJson = null;
|
||||
let userIdFromJson = null;
|
||||
let createdFromJson = null;
|
||||
if (fileContent) { // if content is defined
|
||||
if (fileContent.changes && fileContent.changes.length) { // and there are some modifications in the content
|
||||
[contentJson] = fileContent.changes; // write these modifications to the json content
|
||||
} else if (fileContent.length) {
|
||||
[contentJson] = fileContent; // otherwise, write original content to the json content
|
||||
oldVersion = true; // and note that this is an old version
|
||||
} else {
|
||||
fileContent = false;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
const userAddress = this.curUserHostAddress();
|
||||
|
||||
if (content && contentJson) {
|
||||
userNameFromJson = oldVersion ? contentJson.username : contentJson.user.name;
|
||||
userIdFromJson = oldVersion ? contentJson.userid : contentJson.user.userid;
|
||||
createdFromJson = oldVersion ? contentJson.date : contentJson.created;
|
||||
}
|
||||
|
||||
const username = userNameFromJson || (this.getFileData(fileName, userAddress))[2];
|
||||
const userid = userIdFromJson || (this.getFileData(fileName, userAddress))[1];
|
||||
const created = createdFromJson || (this.getFileData(fileName, userAddress))[0];
|
||||
const res = (fileContent && !oldVersion) ? fileContent : { changes: fileContent };
|
||||
res.key = keyVersion; // write the information about the user, creation time, key and version to the result object
|
||||
res.version = version;
|
||||
res.created = created;
|
||||
res.user = {
|
||||
id: userid,
|
||||
name: username !== 'null' ? username : null,
|
||||
};
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
// clean folder
|
||||
docManager.prototype.cleanFolderRecursive = function (folder, me) {
|
||||
if (fileSystem.existsSync(folder)) { // if the given folder exists
|
||||
const files = fileSystem.readdirSync(folder);
|
||||
files.forEach((file) => { // for each file from the folder
|
||||
const curPath = path.join(folder, file); // get its current path
|
||||
if (fileSystem.lstatSync(curPath).isDirectory()) {
|
||||
this.cleanFolderRecursive(curPath, true); // for each folder included in this one repeat the same procedure
|
||||
} else {
|
||||
fileSystem.unlinkSync(curPath); // remove the file
|
||||
}
|
||||
});
|
||||
if (me) {
|
||||
fileSystem.rmdirSync(folder);
|
||||
}
|
||||
DocManager.prototype.cleanFolderRecursive = function cleanFolderRecursive(folder, me) {
|
||||
if (fileSystem.existsSync(folder)) { // if the given folder exists
|
||||
const files = fileSystem.readdirSync(folder);
|
||||
files.forEach((file) => { // for each file from the folder
|
||||
const curPath = path.join(folder, file); // get its current path
|
||||
if (fileSystem.lstatSync(curPath).isDirectory()) {
|
||||
this.cleanFolderRecursive(curPath, true); // for each folder included in this one repeat the same procedure
|
||||
} else {
|
||||
fileSystem.unlinkSync(curPath); // remove the file
|
||||
}
|
||||
});
|
||||
if (me) {
|
||||
fileSystem.rmdirSync(folder);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// get files information
|
||||
docManager.prototype.getFilesInfo = function (fileId) {
|
||||
const userAddress = this.curUserHostAddress();
|
||||
const directory = this.storageRootPath(userAddress);
|
||||
const filesInDirectory = this.getStoredFiles(); // get all the stored files from the folder
|
||||
let responseArray = [];
|
||||
let responseObject;
|
||||
for (let currentFile = 0; currentFile < filesInDirectory.length; currentFile++) { // run through all the files from the directory
|
||||
const file = filesInDirectory[currentFile];
|
||||
const stats = fileSystem.lstatSync(path.join(directory, file.name)); // get file information
|
||||
const fileObject = { // write file parameters to the file object
|
||||
version: file.version,
|
||||
id: this.getKey(file.name),
|
||||
contentLength: `${(stats.size/1024).toFixed(2)} KB`,
|
||||
pureContentLength: stats.size,
|
||||
title: file.name,
|
||||
updated: stats.mtime
|
||||
};
|
||||
if (fileId !== undefined) { // if file id is defined
|
||||
if (this.getKey(file.name) == fileId) { // and it is equal to the document key value
|
||||
responseObject = fileObject; // response object will be equal to the file object
|
||||
break;
|
||||
}
|
||||
}
|
||||
else responseArray.push(fileObject); // otherwise, push file object to the response array
|
||||
DocManager.prototype.getFilesInfo = function getFilesInfo(fileId) {
|
||||
const userAddress = this.curUserHostAddress();
|
||||
const directory = this.storageRootPath(userAddress);
|
||||
const filesInDirectory = this.getStoredFiles(); // get all the stored files from the folder
|
||||
const responseArray = [];
|
||||
let responseObject;
|
||||
// run through all the files from the directory
|
||||
for (let currentFile = 0; currentFile < filesInDirectory.length; currentFile++) {
|
||||
const file = filesInDirectory[currentFile];
|
||||
const stats = fileSystem.lstatSync(path.join(directory, file.name)); // get file information
|
||||
const fileObject = { // write file parameters to the file object
|
||||
version: file.version,
|
||||
id: this.getKey(file.name),
|
||||
contentLength: `${(stats.size / 1024).toFixed(2)} KB`,
|
||||
pureContentLength: stats.size,
|
||||
title: file.name,
|
||||
updated: stats.mtime,
|
||||
};
|
||||
if (fileId !== undefined) {
|
||||
if (responseObject !== undefined) return responseObject;
|
||||
else return "File not found";
|
||||
}
|
||||
else return responseArray;
|
||||
if (fileId !== undefined) { // if file id is defined
|
||||
if (this.getKey(file.name) === fileId) { // and it is equal to the document key value
|
||||
responseObject = fileObject; // response object will be equal to the file object
|
||||
break;
|
||||
}
|
||||
} else responseArray.push(fileObject); // otherwise, push file object to the response array
|
||||
}
|
||||
if (fileId !== undefined) {
|
||||
if (responseObject !== undefined) return responseObject;
|
||||
return 'File not found';
|
||||
} return responseArray;
|
||||
};
|
||||
|
||||
docManager.prototype.getInstanceId = function () {
|
||||
return this.getServerUrl();
|
||||
DocManager.prototype.getInstanceId = function getInstanceId() {
|
||||
return this.getServerUrl();
|
||||
};
|
||||
|
||||
// save all the functions to the docManager module to export it later in other files
|
||||
module.exports = docManager;
|
||||
// save all the functions to the DocManager module to export it later in other files
|
||||
module.exports = DocManager;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2023
|
||||
*
|
||||
@ -17,226 +17,261 @@
|
||||
*/
|
||||
|
||||
// get all the necessary values and modules
|
||||
var urlModule = require("url");
|
||||
var urllib = require("urllib");
|
||||
var jwt = require("jsonwebtoken");
|
||||
var fileUtility = require("./fileUtility");
|
||||
var guidManager = require("./guidManager");
|
||||
var configServer = require('config').get('server');
|
||||
var siteUrl = configServer.get('siteUrl'); // the path to the editors installation
|
||||
var cfgSignatureEnable = configServer.get('token.enable');
|
||||
var cfgSignatureUseForRequest = configServer.get('token.useforrequest');
|
||||
var cfgSignatureAuthorizationHeader = configServer.get('token.authorizationHeader');
|
||||
var cfgSignatureAuthorizationHeaderPrefix = configServer.get('token.authorizationHeaderPrefix');
|
||||
var cfgSignatureSecretExpiresIn = configServer.get('token.expiresIn');
|
||||
var cfgSignatureSecret = configServer.get('token.secret');
|
||||
var cfgSignatureSecretAlgorithmRequest = configServer.get('token.algorithmRequest');
|
||||
const urlModule = require('url');
|
||||
const urllib = require('urllib');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const configServer = require('config').get('server');
|
||||
const fileUtility = require('./fileUtility');
|
||||
const guidManager = require('./guidManager');
|
||||
|
||||
var documentService = {};
|
||||
const siteUrl = configServer.get('siteUrl'); // the path to the editors installation
|
||||
const cfgSignatureEnable = configServer.get('token.enable');
|
||||
const cfgSignatureUseForRequest = configServer.get('token.useforrequest');
|
||||
const cfgSignatureAuthorizationHeader = configServer.get('token.authorizationHeader');
|
||||
const cfgSignatureAuthorizationHeaderPrefix = configServer.get('token.authorizationHeaderPrefix');
|
||||
const cfgSignatureSecretExpiresIn = configServer.get('token.expiresIn');
|
||||
const cfgSignatureSecret = configServer.get('token.secret');
|
||||
const cfgSignatureSecretAlgorithmRequest = configServer.get('token.algorithmRequest');
|
||||
|
||||
const documentService = {};
|
||||
|
||||
documentService.userIp = null;
|
||||
|
||||
// get the url of the converted file (synchronous)
|
||||
documentService.getConvertedUriSync = function (documentUri, fromExtension, toExtension, documentRevisionId, callback) {
|
||||
documentService.getConvertedUri(documentUri, fromExtension, toExtension, documentRevisionId, false, function (err, data) {
|
||||
callback(err, data);
|
||||
});
|
||||
documentService.getConvertedUriSync = function getConvertedUriSync(
|
||||
documentUri,
|
||||
fromExtension,
|
||||
toExtension,
|
||||
documentRevisionId,
|
||||
callback,
|
||||
) {
|
||||
documentService.getConvertedUri(documentUri, fromExtension, toExtension, documentRevisionId, false, (err, data) => {
|
||||
callback(err, data);
|
||||
});
|
||||
};
|
||||
|
||||
// get the url of the converted file
|
||||
documentService.getConvertedUri = function (documentUri, fromExtension, toExtension, documentRevisionId, async, callback, filePass = null, lang = null) {
|
||||
fromExtension = fromExtension || fileUtility.getFileExtension(documentUri); // get the current document extension
|
||||
documentService.getConvertedUri = function getConvertedUri(
|
||||
documentUri,
|
||||
fromExtension,
|
||||
toExtension,
|
||||
documentRevisionId,
|
||||
async,
|
||||
callback,
|
||||
filePass = null,
|
||||
lang = null,
|
||||
) {
|
||||
const fromExt = fromExtension || fileUtility.getFileExtension(documentUri); // get the current document extension
|
||||
|
||||
var title = fileUtility.getFileName(documentUri) || guidManager.newGuid(); // get the current document name or uuid
|
||||
const title = fileUtility.getFileName(documentUri) || guidManager.newGuid(); // get the current document name or uuid
|
||||
|
||||
documentRevisionId = documentService.generateRevisionId(documentRevisionId || documentUri); // generate the document key value
|
||||
// generate the document key value
|
||||
const revisionId = documentService.generateRevisionId(documentRevisionId || documentUri);
|
||||
|
||||
var params = { // write all the conversion parameters to the params dictionary
|
||||
async: async,
|
||||
url: documentUri,
|
||||
outputtype: toExtension.replace(".", ""),
|
||||
filetype: fromExtension.replace(".", ""),
|
||||
title: title,
|
||||
key: documentRevisionId,
|
||||
password: filePass,
|
||||
region: lang,
|
||||
};
|
||||
const params = { // write all the conversion parameters to the params dictionary
|
||||
async,
|
||||
url: documentUri,
|
||||
outputtype: toExtension.replace('.', ''),
|
||||
filetype: fromExt.replace('.', ''),
|
||||
title,
|
||||
key: revisionId,
|
||||
password: filePass,
|
||||
region: lang,
|
||||
};
|
||||
|
||||
var uri = siteUrl + configServer.get('converterUrl'); // get the absolute converter url
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
"Accept": "application/json"
|
||||
};
|
||||
const uri = siteUrl + configServer.get('converterUrl'); // get the absolute converter url
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
};
|
||||
|
||||
if (cfgSignatureEnable && cfgSignatureUseForRequest) { // if the signature is enabled and it can be used for request
|
||||
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params); // write signature authorization header
|
||||
params.token = documentService.getToken(params); // get token and save it to the parameters
|
||||
}
|
||||
if (cfgSignatureEnable && cfgSignatureUseForRequest) { // if the signature is enabled and it can be used for request
|
||||
// write signature authorization header
|
||||
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params);
|
||||
params.token = documentService.getToken(params); // get token and save it to the parameters
|
||||
}
|
||||
|
||||
//parse url to allow request by relative url after https://github.com/node-modules/urllib/pull/321/commits/514de1924bf17a38a6c2db2a22a6bc3494c0a959
|
||||
urllib.request(urlModule.parse(uri),
|
||||
{
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
data: params
|
||||
},
|
||||
callback);
|
||||
// parse url to allow request by relative url after
|
||||
// https://github.com/node-modules/urllib/pull/321/commits/514de1924bf17a38a6c2db2a22a6bc3494c0a959
|
||||
urllib.request(
|
||||
urlModule.parse(uri),
|
||||
{
|
||||
method: 'POST',
|
||||
headers,
|
||||
data: params,
|
||||
},
|
||||
callback,
|
||||
);
|
||||
};
|
||||
|
||||
// generate the document key value
|
||||
documentService.generateRevisionId = function (expectedKey) {
|
||||
let maxKeyLength = 128; // the max key length is 128
|
||||
if (expectedKey.length > maxKeyLength) { // if the expected key length is greater than the max key length
|
||||
expectedKey = expectedKey.hashCode().toString(); // the expected key is hashed and a fixed length value is stored in the string format
|
||||
}
|
||||
documentService.generateRevisionId = function generateRevisionId(expectedKey) {
|
||||
const maxKeyLength = 128; // the max key length is 128
|
||||
let expKey = expectedKey;
|
||||
if (expKey.length > maxKeyLength) { // if the expected key length is greater than the max key length
|
||||
// the expected key is hashed and a fixed length value is stored in the string format
|
||||
expKey = expKey.hashCode().toString();
|
||||
}
|
||||
|
||||
var key = expectedKey.replace(new RegExp("[^0-9-.a-zA-Z_=]", "g"), "_");
|
||||
const key = expKey.replace(/[^0-9-.a-zA-Z_=]/g, '_');
|
||||
|
||||
return key.substring(0, Math.min(key.length, maxKeyLength)); // the resulting key is of the max key length or less
|
||||
return key.substring(0, Math.min(key.length, maxKeyLength)); // the resulting key is of the max key length or less
|
||||
};
|
||||
|
||||
// create an error message for the error code
|
||||
documentService.processConvertServiceResponceError = function (errorCode) {
|
||||
var errorMessage = "";
|
||||
var errorMessageTemplate = "Error occurred in the ConvertService: ";
|
||||
documentService.processConvertServiceResponceError = function processConvertServiceResponceError(errorCode) {
|
||||
let errorMessage = '';
|
||||
const errorMessageTemplate = 'Error occurred in the ConvertService: ';
|
||||
|
||||
// add the error message to the error message template depending on the error code
|
||||
switch (errorCode) {
|
||||
case -20:
|
||||
errorMessage = errorMessageTemplate + "Error encrypt signature";
|
||||
break;
|
||||
case -8:
|
||||
errorMessage = errorMessageTemplate + "Error document signature";
|
||||
break;
|
||||
case -7:
|
||||
errorMessage = errorMessageTemplate + "Error document request";
|
||||
break;
|
||||
case -6:
|
||||
errorMessage = errorMessageTemplate + "Error database";
|
||||
break;
|
||||
case -5:
|
||||
errorMessage = errorMessageTemplate + "Incorrect password";
|
||||
break;
|
||||
case -4:
|
||||
errorMessage = errorMessageTemplate + "Error download error";
|
||||
break;
|
||||
case -3:
|
||||
errorMessage = errorMessageTemplate + "Error convertation error";
|
||||
break;
|
||||
case -2:
|
||||
errorMessage = errorMessageTemplate + "Error convertation timeout";
|
||||
break;
|
||||
case -1:
|
||||
errorMessage = errorMessageTemplate + "Error convertation unknown";
|
||||
break;
|
||||
case 0: // if the error code is equal to 0, the error message is empty
|
||||
break;
|
||||
default:
|
||||
errorMessage = "ErrorCode = " + errorCode; // default value for the error message
|
||||
break;
|
||||
}
|
||||
// add the error message to the error message template depending on the error code
|
||||
switch (errorCode) {
|
||||
case -20:
|
||||
errorMessage = `${errorMessageTemplate}Error encrypt signature`;
|
||||
break;
|
||||
case -8:
|
||||
errorMessage = `${errorMessageTemplate}Error document signature`;
|
||||
break;
|
||||
case -7:
|
||||
errorMessage = `${errorMessageTemplate}Error document request`;
|
||||
break;
|
||||
case -6:
|
||||
errorMessage = `${errorMessageTemplate}Error database`;
|
||||
break;
|
||||
case -5:
|
||||
errorMessage = `${errorMessageTemplate}Incorrect password`;
|
||||
break;
|
||||
case -4:
|
||||
errorMessage = `${errorMessageTemplate}Error download error`;
|
||||
break;
|
||||
case -3:
|
||||
errorMessage = `${errorMessageTemplate}Error convertation error`;
|
||||
break;
|
||||
case -2:
|
||||
errorMessage = `${errorMessageTemplate}Error convertation timeout`;
|
||||
break;
|
||||
case -1:
|
||||
errorMessage = `${errorMessageTemplate}Error convertation unknown`;
|
||||
break;
|
||||
case 0: // if the error code is equal to 0, the error message is empty
|
||||
break;
|
||||
default:
|
||||
errorMessage = `ErrorCode = ${errorCode}`; // default value for the error message
|
||||
break;
|
||||
}
|
||||
|
||||
throw { message: errorMessage };
|
||||
throw new Error(errorMessage);
|
||||
};
|
||||
|
||||
// get the response url
|
||||
documentService.getResponseUri = function (json) {
|
||||
var fileResult = JSON.parse(json);
|
||||
documentService.getResponseUri = function getResponseUri(json) {
|
||||
const fileResult = JSON.parse(json);
|
||||
|
||||
if (fileResult.error) // if an error occurs
|
||||
documentService.processConvertServiceResponceError(parseInt(fileResult.error)); // get an error message
|
||||
if (fileResult.error) { // if an error occurs
|
||||
documentService.processConvertServiceResponceError(parseInt(fileResult.error, 10)); // get an error message
|
||||
}
|
||||
|
||||
var isEndConvert = fileResult.endConvert // check if the conversion is completed
|
||||
const isEndConvert = fileResult.endConvert; // check if the conversion is completed
|
||||
|
||||
var percent = parseInt(fileResult.percent); // get the conversion percentage
|
||||
var uri = null;
|
||||
let percent = parseInt(fileResult.percent, 10); // get the conversion percentage
|
||||
let uri = null;
|
||||
let fileType = null;
|
||||
|
||||
if (isEndConvert) { // if the conversion is completed
|
||||
if (!fileResult.fileUrl) // and the file url doesn't exist
|
||||
throw { message: "FileUrl is null" }; // the file url is null
|
||||
|
||||
uri = fileResult.fileUrl; // otherwise, get the file url
|
||||
percent = 100;
|
||||
} else { // if the conversion isn't completed
|
||||
percent = percent >= 100 ? 99 : percent; // get the percentage value
|
||||
if (isEndConvert) { // if the conversion is completed
|
||||
if (!fileResult.fileUrl) { // and the file url doesn't exist
|
||||
throw new Error('FileUrl is null'); // the file url is null
|
||||
}
|
||||
|
||||
return {
|
||||
key: percent,
|
||||
value: uri
|
||||
};
|
||||
uri = fileResult.fileUrl; // otherwise, get the file url
|
||||
({ fileType } = fileResult); // get the file type
|
||||
percent = 100;
|
||||
} else { // if the conversion isn't completed
|
||||
percent = percent >= 100 ? 99 : percent; // get the percentage value
|
||||
}
|
||||
|
||||
return {
|
||||
percent,
|
||||
uri,
|
||||
fileType,
|
||||
};
|
||||
};
|
||||
|
||||
// create a command request
|
||||
documentService.commandRequest = function (method, documentRevisionId, meta = null, callback) {
|
||||
documentService.commandRequest = function commandRequest(method, documentRevisionId, callback, meta = null) {
|
||||
const revisionId = documentService.generateRevisionId(documentRevisionId); // generate the document key value
|
||||
const params = { // create a parameter object with command method and the document key value in it
|
||||
c: method,
|
||||
key: revisionId,
|
||||
};
|
||||
|
||||
documentRevisionId = documentService.generateRevisionId(documentRevisionId); // generate the document key value
|
||||
params = { // create a parameter object with command method and the document key value in it
|
||||
c: method,
|
||||
key: documentRevisionId
|
||||
};
|
||||
if (meta) {
|
||||
params.meta = meta;
|
||||
}
|
||||
|
||||
if (meta) {
|
||||
params.meta = meta;
|
||||
}
|
||||
const uri = siteUrl + configServer.get('commandUrl'); // get the absolute command url
|
||||
const headers = { // create a headers object
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
if (cfgSignatureEnable && cfgSignatureUseForRequest) {
|
||||
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params);
|
||||
params.token = documentService.getToken(params);
|
||||
}
|
||||
|
||||
var uri = siteUrl + configServer.get('commandUrl'); // get the absolute command url
|
||||
var headers = { // create a headers object
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
if (cfgSignatureEnable && cfgSignatureUseForRequest) {
|
||||
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params);
|
||||
params.token = documentService.getToken(params);
|
||||
}
|
||||
|
||||
//parse url to allow request by relative url after https://github.com/node-modules/urllib/pull/321/commits/514de1924bf17a38a6c2db2a22a6bc3494c0a959
|
||||
urllib.request(urlModule.parse(uri),
|
||||
{
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
data: params
|
||||
},
|
||||
callback);
|
||||
// parse url to allow request by relative url after
|
||||
// https://github.com/node-modules/urllib/pull/321/commits/514de1924bf17a38a6c2db2a22a6bc3494c0a959
|
||||
urllib.request(
|
||||
urlModule.parse(uri),
|
||||
{
|
||||
method: 'POST',
|
||||
headers,
|
||||
data: params,
|
||||
},
|
||||
callback,
|
||||
);
|
||||
};
|
||||
|
||||
// check jwt token headers
|
||||
documentService.checkJwtHeader = function (req) {
|
||||
var decoded = null;
|
||||
var authorization = req.get(cfgSignatureAuthorizationHeader); // get signature authorization header from the request
|
||||
if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) { // if authorization header exists and it starts with the authorization header prefix
|
||||
var token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length); // the resulting token starts after the authorization header prefix
|
||||
documentService.checkJwtHeader = function checkJwtHeader(req) {
|
||||
let decoded = null;
|
||||
const authorization = req.get(cfgSignatureAuthorizationHeader); // get signature authorization header from the request
|
||||
// if authorization header exists and it starts with the authorization header prefix
|
||||
if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) {
|
||||
// the resulting token starts after the authorization header prefix
|
||||
const token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length);
|
||||
try {
|
||||
decoded = jwt.verify(token, cfgSignatureSecret); // verify signature on jwt token using signature secret
|
||||
decoded = jwt.verify(token, cfgSignatureSecret); // verify signature on jwt token using signature secret
|
||||
} catch (err) {
|
||||
console.log('checkJwtHeader error: name = ' + err.name + ' message = ' + err.message + ' token = ' + token) // print debug information to the console
|
||||
// print debug information to the console
|
||||
console.log(`checkJwtHeader error: name = ${err.name} message = ${err.message} token = ${token}`);
|
||||
}
|
||||
}
|
||||
return decoded;
|
||||
}
|
||||
};
|
||||
|
||||
// get jwt token using url information
|
||||
documentService.fillJwtByUrl = function (uri, opt_dataObject) {
|
||||
var parseObject = urlModule.parse(uri, true); // get parse object from the url
|
||||
var payload = {query: parseObject.query, payload: opt_dataObject}; // create payload object
|
||||
documentService.fillJwtByUrl = function fillJwtByUrl(uri, optDataObject) {
|
||||
const parseObject = urlModule.parse(uri, true); // get parse object from the url
|
||||
const payload = { query: parseObject.query, payload: optDataObject }; // create payload object
|
||||
|
||||
var options = {algorithm: cfgSignatureSecretAlgorithmRequest, expiresIn: cfgSignatureSecretExpiresIn};
|
||||
return jwt.sign(payload, cfgSignatureSecret, options); // sign token with given data using signature secret and options parameters
|
||||
}
|
||||
const options = { algorithm: cfgSignatureSecretAlgorithmRequest, expiresIn: cfgSignatureSecretExpiresIn };
|
||||
// sign token with given data using signature secret and options parameters
|
||||
return jwt.sign(payload, cfgSignatureSecret, options);
|
||||
};
|
||||
|
||||
// get token
|
||||
documentService.getToken = function (data) {
|
||||
var options = {algorithm: cfgSignatureSecretAlgorithmRequest, expiresIn: cfgSignatureSecretExpiresIn};
|
||||
return jwt.sign(data, cfgSignatureSecret, options); // sign token with given data using signature secret and options parameters
|
||||
documentService.getToken = function getToken(data) {
|
||||
const options = { algorithm: cfgSignatureSecretAlgorithmRequest, expiresIn: cfgSignatureSecretExpiresIn };
|
||||
// sign token with given data using signature secret and options parameters
|
||||
return jwt.sign(data, cfgSignatureSecret, options);
|
||||
};
|
||||
|
||||
// read and verify token
|
||||
documentService.readToken = function (token) {
|
||||
try {
|
||||
return jwt.verify(token, cfgSignatureSecret); // verify signature on jwt token using signature secret
|
||||
} catch (err) {
|
||||
console.log('checkJwtHeader error: name = ' + err.name + ' message = ' + err.message + ' token = ' + token)
|
||||
}
|
||||
return null;
|
||||
documentService.readToken = function readToken(token) {
|
||||
try {
|
||||
return jwt.verify(token, cfgSignatureSecret); // verify signature on jwt token using signature secret
|
||||
} catch (err) {
|
||||
console.log(`checkJwtHeader error: name = ${err.name} message = ${err.message} token = ${token}`);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// save all the functions to the documentService module to export it later in other files
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2023
|
||||
*
|
||||
@ -16,79 +16,101 @@
|
||||
*
|
||||
*/
|
||||
|
||||
var fileUtility = {};
|
||||
const supportedFormats = require('../public/assets/document-formats/onlyoffice-docs-formats.json'); // eslint-disable-line
|
||||
|
||||
const fileUtility = {};
|
||||
|
||||
// get file name from the given url
|
||||
fileUtility.getFileName = function (url, withoutExtension) {
|
||||
if (!url) return "";
|
||||
fileUtility.getFileName = function getFileName(url, withoutExtension) {
|
||||
if (!url) return '';
|
||||
|
||||
var parts = url.split("\\");
|
||||
parts = parts.pop();
|
||||
parts = parts.split("/");
|
||||
var fileName = parts.pop(); // get the file name from the last part of the url
|
||||
fileName = fileName.split("?")[0];
|
||||
let parts = url.split('\\');
|
||||
parts = parts.pop();
|
||||
parts = parts.split('/');
|
||||
let fileName = parts.pop(); // get the file name from the last part of the url
|
||||
[fileName] = fileName.split('?');
|
||||
|
||||
// get file name without extension
|
||||
if (withoutExtension) {
|
||||
return fileName.substring(0, fileName.lastIndexOf("."));
|
||||
}
|
||||
// get file name without extension
|
||||
if (withoutExtension) {
|
||||
return fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
return fileName;
|
||||
return fileName;
|
||||
};
|
||||
|
||||
// get file extension from the given url
|
||||
fileUtility.getFileExtension = function (url, withoutDot) {
|
||||
if (!url) return null;
|
||||
fileUtility.getFileExtension = function getFileExtension(url, withoutDot) {
|
||||
if (!url) return null;
|
||||
|
||||
var fileName = fileUtility.getFileName(url); // get file name from the given url
|
||||
const fileName = fileUtility.getFileName(url); // get file name from the given url
|
||||
|
||||
var parts = fileName.toLowerCase().split(".");
|
||||
const parts = fileName.toLowerCase().split('.');
|
||||
|
||||
return withoutDot ? parts.pop() : "." + parts.pop(); // get the extension from the file name with or without dot
|
||||
return withoutDot ? parts.pop() : `.${parts.pop()}`; // get the extension from the file name with or without dot
|
||||
};
|
||||
|
||||
// get file type from the given url
|
||||
fileUtility.getFileType = function (url) {
|
||||
var ext = fileUtility.getFileExtension(url); // get the file extension from the given url
|
||||
fileUtility.getFileType = function getFileType(url) {
|
||||
const ext = fileUtility.getFileExtension(url, true); // get the file extension from the given url
|
||||
|
||||
if (fileUtility.documentExts.indexOf(ext) != -1) return fileUtility.fileType.word; // word type for document extensions
|
||||
if (fileUtility.spreadsheetExts.indexOf(ext) != -1) return fileUtility.fileType.cell; // cell type for spreadsheet extensions
|
||||
if (fileUtility.presentationExts.indexOf(ext) != -1) return fileUtility.fileType.slide; // slide type for presentation extensions
|
||||
for (let i = 0; i < supportedFormats.length; i++) {
|
||||
if (supportedFormats[i].name === ext) return supportedFormats[i].type;
|
||||
}
|
||||
|
||||
return fileUtility.fileType.word; // the default file type is word
|
||||
}
|
||||
return fileUtility.fileType.word; // the default file type is word
|
||||
};
|
||||
|
||||
fileUtility.fileType = {
|
||||
word: "word",
|
||||
cell: "cell",
|
||||
slide: "slide"
|
||||
}
|
||||
word: 'word',
|
||||
cell: 'cell',
|
||||
slide: 'slide',
|
||||
};
|
||||
|
||||
// the document extension list
|
||||
fileUtility.documentExts = [".doc", ".docx", ".oform", ".docm", ".dot", ".dotx", ".dotm", ".odt", ".fodt", ".ott", ".rtf", ".txt", ".html", ".htm", ".mht", ".xml", ".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps"];
|
||||
fileUtility.getSuppotredExtensions = function getSuppotredExtensions() {
|
||||
return supportedFormats.reduce((extensions, format) => [...extensions, format.name], []);
|
||||
};
|
||||
|
||||
// the spreadsheet extension list
|
||||
fileUtility.spreadsheetExts = [".xls", ".xlsx", ".xlsm", ".xlsb", ".xlt", ".xltx", ".xltm", ".ods", ".fods", ".ots", ".csv"];
|
||||
fileUtility.getViewExtensions = function getViewExtensions() {
|
||||
return supportedFormats.filter(
|
||||
(format) => format.actions.includes('view'),
|
||||
).reduce((extensions, format) => [...extensions, format.name], []);
|
||||
};
|
||||
|
||||
// the presentation extension list
|
||||
fileUtility.presentationExts = [".pps", ".ppsx", ".ppsm", ".ppt", ".pptx", ".pptm", ".pot", ".potx", ".potm", ".odp", ".fodp", ".otp"];
|
||||
fileUtility.getEditExtensions = function getEditExtensions() {
|
||||
return supportedFormats.filter(
|
||||
(format) => format.actions.includes('edit') || format.actions.includes('lossy-edit'),
|
||||
).reduce((extensions, format) => [...extensions, format.name], []);
|
||||
};
|
||||
|
||||
fileUtility.getFillExtensions = function getFillExtensions() {
|
||||
return supportedFormats.filter(
|
||||
(format) => format.actions.includes('fill'),
|
||||
).reduce((extensions, format) => [...extensions, format.name], []);
|
||||
};
|
||||
|
||||
fileUtility.getConvertExtensions = function getConvertExtensions() {
|
||||
return supportedFormats.filter(
|
||||
(format) => format.actions.includes('auto-convert'),
|
||||
).reduce((extensions, format) => [...extensions, format.name], []);
|
||||
};
|
||||
|
||||
// get url parameters
|
||||
function getUrlParams(url) {
|
||||
try {
|
||||
var query = url.split("?").pop(); // take all the parameters which are placed after ? sign in the file url
|
||||
var params = query.split("&"); // parameters are separated by & sign
|
||||
var map = {}; // write parameters and their values to the map dictionary
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
var parts = param.split("=");
|
||||
map[parts[0]] = parts[1];
|
||||
}
|
||||
return map;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const getUrlParams = function getUrlParams(url) {
|
||||
try {
|
||||
const query = url.split('?').pop(); // take all the parameters which are placed after ? sign in the file url
|
||||
const params = query.split('&'); // parameters are separated by & sign
|
||||
const map = {}; // write parameters and their values to the map dictionary
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
// eslint-disable-next-line no-undef
|
||||
const parts = param.split('=');
|
||||
[, map[parts[0]]] = parts;
|
||||
}
|
||||
catch (ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return map;
|
||||
} catch (ex) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// save all the functions to the fileUtility module to export it later in other files
|
||||
module.exports = fileUtility;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* (c) Copyright Ascensio System SIA 2023
|
||||
*
|
||||
@ -17,11 +17,12 @@
|
||||
*/
|
||||
|
||||
// generate 16 octet
|
||||
var s4 = function () {
|
||||
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
|
||||
const s4 = function s4() {
|
||||
return Math.trunc((1 + Math.random()) * 0x10000).toString(16)
|
||||
.substring(1);
|
||||
};
|
||||
|
||||
// create uuid v4
|
||||
exports.newGuid = function () {
|
||||
return (s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4());
|
||||
};
|
||||
exports.newGuid = function newGuid() {
|
||||
return (`${s4() + s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`);
|
||||
};
|
||||
|
||||
@ -16,79 +16,20 @@
|
||||
*
|
||||
*/
|
||||
|
||||
var descr_user_1 = [
|
||||
"File author by default",
|
||||
"Doesn’t belong to any group",
|
||||
"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 see the information about all users",
|
||||
//"Can submit forms"
|
||||
];
|
||||
|
||||
var descr_user_2 = [
|
||||
"Belongs to Group2",
|
||||
"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 see the information about users from Group2 and users who don’t belong to any group",
|
||||
//"Can’t submit forms"
|
||||
];
|
||||
|
||||
var descr_user_3 = [
|
||||
"Belongs to Group3",
|
||||
"Can review changes made 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 see the information about Group2 users",
|
||||
//"Can’t submit forms"
|
||||
];
|
||||
|
||||
var descr_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 see anyone’s information",
|
||||
"Can't rename files from the editor",
|
||||
"Can't view chat",
|
||||
"View file without collaboration",
|
||||
//"Can’t submit forms"
|
||||
];
|
||||
|
||||
var users = [
|
||||
new User("uid-1", "John Smith", "smith@example.com",
|
||||
null, null, {}, null,
|
||||
null, [], descr_user_1, true),
|
||||
new User("uid-2", "Mark Pottato", "pottato@example.com",
|
||||
"group-2", ["group-2", ""], {
|
||||
view: "",
|
||||
edit: ["group-2", ""],
|
||||
remove: ["group-2"]
|
||||
}, ["group-2", ""],
|
||||
true, [], descr_user_2, false), // own and without group
|
||||
new User("uid-3", "Hamish Mitchell", "mitchell@example.com",
|
||||
"group-3", ["group-2"], {
|
||||
view: ["group-3", "group-2"],
|
||||
edit: ["group-2"],
|
||||
remove: []
|
||||
}, ["group-2"],
|
||||
false, ["copy", "download", "print"], descr_user_3, false), // other group only
|
||||
new User("uid-0", null, null,
|
||||
null, null, {}, [],
|
||||
null, [], descr_user_0, false),
|
||||
];
|
||||
|
||||
function User(id, name, email, group, reviewGroups, commentGroups, userInfoGroups, favorite, deniedPermissions, descriptions, templates) {
|
||||
class User {
|
||||
constructor(
|
||||
id,
|
||||
name,
|
||||
email,
|
||||
group,
|
||||
reviewGroups,
|
||||
commentGroups,
|
||||
userInfoGroups,
|
||||
favorite,
|
||||
deniedPermissions,
|
||||
descriptions,
|
||||
templates,
|
||||
) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
@ -100,33 +41,117 @@ function User(id, name, email, group, reviewGroups, commentGroups, userInfoGroup
|
||||
this.deniedPermissions = deniedPermissions;
|
||||
this.descriptions = descriptions;
|
||||
this.templates = templates;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const descrUser1 = [
|
||||
'File author by default',
|
||||
'Doesn’t belong to any group',
|
||||
'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 see the information about all users',
|
||||
'Can submit forms',
|
||||
];
|
||||
|
||||
const descrUser2 = [
|
||||
'Belongs to Group2',
|
||||
'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 see the information about users from Group2 and users who don’t belong to any group',
|
||||
'Can’t submit forms',
|
||||
];
|
||||
|
||||
const descrUser3 = [
|
||||
'Belongs to Group3',
|
||||
'Can review changes made 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 see the information about Group2 users',
|
||||
'Can’t submit forms',
|
||||
];
|
||||
|
||||
const descrUser0 = [
|
||||
'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 see anyone’s information',
|
||||
'Can\'t rename files from the editor',
|
||||
'Can\'t view chat',
|
||||
'Can\'t protect file',
|
||||
'View file without collaboration',
|
||||
'Can’t submit forms',
|
||||
];
|
||||
|
||||
const users = [
|
||||
new User('uid-1', 'John Smith', 'smith@example.com', null, null, {}, null, null, [], descrUser1, true),
|
||||
new User('uid-2', 'Mark Pottato', 'pottato@example.com', 'group-2', ['group-2', ''], {
|
||||
view: '',
|
||||
edit: ['group-2', ''],
|
||||
remove: ['group-2'],
|
||||
}, ['group-2', ''], true, [], descrUser2, false), // own and without group
|
||||
new User('uid-3', 'Hamish Mitchell', 'mitchell@example.com', 'group-3', ['group-2'], {
|
||||
view: ['group-3', 'group-2'],
|
||||
edit: ['group-2'],
|
||||
remove: [],
|
||||
}, ['group-2'], false, ['copy', 'download', 'print'], descrUser3, false), // other group only
|
||||
new User('uid-0', null, null, null, null, {}, [], null, ['protect'], descrUser0, false),
|
||||
];
|
||||
|
||||
// get a list of all the users
|
||||
users.getAllUsers = function () {
|
||||
return users;
|
||||
users.getAllUsers = function getAllUsers() {
|
||||
return users;
|
||||
};
|
||||
|
||||
// get a user by id specified
|
||||
users.getUser = function (id) {
|
||||
var result = null;
|
||||
this.forEach(user => {
|
||||
if (user.id == id) {
|
||||
result = user;
|
||||
}
|
||||
});
|
||||
return result ? result : this[0];
|
||||
users.getUser = function getUser(id) {
|
||||
let result = null;
|
||||
this.forEach((user) => {
|
||||
if (user.id === id) {
|
||||
result = user;
|
||||
}
|
||||
});
|
||||
return result || this[0];
|
||||
};
|
||||
|
||||
// get a list of users with their names and emails for mentions
|
||||
users.getUsersForMentions = function (id) {
|
||||
var result = [];
|
||||
this.forEach(user => {
|
||||
if (user.id != id && user.name != null && user.email != null) {
|
||||
result.push({ name: user.name, email: user.email });
|
||||
}
|
||||
});
|
||||
return result;
|
||||
// get a list of users with their name and email for mentions
|
||||
users.getUsersForMentions = function getUsersForMentions(id) {
|
||||
const result = [];
|
||||
this.forEach((user) => {
|
||||
if (user.id !== id && user.name && user.email) {
|
||||
result.push({
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
});
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
// get a list of users with their name, id and email for protect
|
||||
users.getUsersForProtect = function getUsersForProtect(id) {
|
||||
const result = [];
|
||||
this.forEach((user) => {
|
||||
if (user.id !== id && user.name != null) {
|
||||
result.push({
|
||||
email: user.email,
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
});
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = users;
|
||||
|
||||
@ -16,14 +16,343 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const fileSystem = require('fs');
|
||||
const mime = require('mime');
|
||||
const path = require('path');
|
||||
const reqConsts = require('./request');
|
||||
const fileUtility = require("../fileUtility");
|
||||
const lockManager = require("./lockManager");
|
||||
const fileSystem = require("fs");
|
||||
const mime = require("mime");
|
||||
const path = require("path");
|
||||
const users = require("../users");
|
||||
const docManager = require("../docManager");
|
||||
const fileUtility = require('../fileUtility');
|
||||
const lockManager = require('./lockManager');
|
||||
const users = require('../users');
|
||||
const DocManager = require('../docManager');
|
||||
|
||||
// return lock mismatch
|
||||
const returnLockMismatch = function returnLockMismatch(res, lock, reason) {
|
||||
res.setHeader(reqConsts.requestHeaders.Lock, lock || ''); // set the X-WOPI-Lock header
|
||||
if (reason) { // if there is a reason for lock mismatch
|
||||
res.setHeader(reqConsts.requestHeaders.LockFailureReason, reason); // set it as the X-WOPI-LockFailureReason header
|
||||
}
|
||||
res.sendStatus(409); // conflict
|
||||
};
|
||||
|
||||
// lock file editing
|
||||
const lock = function lock(wopi, req, res, userHost) {
|
||||
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
|
||||
const userAddress = req.DocManager.curUserHostAddress(userHost); // get current user host address
|
||||
const filePath = req.DocManager.storagePath(wopi.id, userAddress); // get the storage path of the given file
|
||||
|
||||
if (!lockManager.hasLock(filePath)) {
|
||||
// file isn't locked => lock
|
||||
lockManager.lock(filePath, requestLock);
|
||||
res.sendStatus(200);
|
||||
} else if (lockManager.getLock(filePath) === requestLock) {
|
||||
// lock matches current lock => extend duration
|
||||
lockManager.lock(filePath, requestLock);
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
// file locked by someone else => return lock mismatch
|
||||
const locked = lockManager.getLock(filePath);
|
||||
returnLockMismatch(res, lock, `File already locked by ${locked}`);
|
||||
}
|
||||
};
|
||||
|
||||
const saveFileFromBody = function saveFileFromBody(req, filename, userAddress, isNewVersion, callback) {
|
||||
if (req.body) {
|
||||
const storagePath = req.DocManager.storagePath(filename, userAddress);
|
||||
let historyPath = req.DocManager.historyPath(filename, userAddress); // get the path to the file history
|
||||
if (historyPath === '') { // if it is empty
|
||||
historyPath = req.DocManager.historyPath(filename, userAddress, true); // create it
|
||||
req.DocManager.createDirectory(historyPath); // and create a new directory for the history
|
||||
}
|
||||
|
||||
let version = 0;
|
||||
if (isNewVersion) {
|
||||
const countVersion = req.DocManager.countVersion(historyPath); // get the last file version
|
||||
version = countVersion + 1; // get a number of a new file version
|
||||
// get the path to the specified file version
|
||||
const versionPath = req.DocManager.versionPath(filename, userAddress, version);
|
||||
req.DocManager.createDirectory(versionPath); // and create a new directory for the specified version
|
||||
|
||||
// get the path to the previous file version
|
||||
const pathPrev = path.join(versionPath, `prev${fileUtility.getFileExtension(filename)}`);
|
||||
fileSystem.renameSync(storagePath, pathPrev); // synchronously rename the given file as the previous file version
|
||||
}
|
||||
|
||||
const filestream = fileSystem.createWriteStream(storagePath);
|
||||
req.pipe(filestream);
|
||||
req.on('end', () => {
|
||||
filestream.close();
|
||||
callback(null, version);
|
||||
});
|
||||
} else {
|
||||
callback('empty body');
|
||||
}
|
||||
};
|
||||
|
||||
// return name that wopi-client can use as the value of X-WOPI-RelativeTarget in a future PutRelativeFile operation
|
||||
const returnValidRelativeTarget = function returnValidRelativeTarget(res, filename) {
|
||||
res.setHeader(reqConsts.requestHeaders.ValidRelativeTarget, filename); // set the X-WOPI-ValidRelativeTarget header
|
||||
res.sendStatus(409); // file with that name already exists
|
||||
};
|
||||
|
||||
// retrieve a lock on a file
|
||||
const getLock = function getLock(wopi, req, res, userHost) {
|
||||
const userAddress = req.DocManager.curUserHostAddress(userHost);
|
||||
const filePath = req.DocManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
// get the lock of the specified file and set it as the X-WOPI-Lock header
|
||||
res.setHeader(reqConsts.requestHeaders.lock, lockManager.getLock(filePath));
|
||||
res.sendStatus(200);
|
||||
};
|
||||
|
||||
// refresh the lock on a file by resetting its automatic expiration timer to 30 minutes
|
||||
const refreshLock = function refreshLock(wopi, req, res, userHost) {
|
||||
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
|
||||
const userAddress = req.DocManager.curUserHostAddress(userHost);
|
||||
const filePath = req.DocManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
if (!lockManager.hasLock(filePath)) {
|
||||
// file isn't locked => mismatch
|
||||
returnLockMismatch(res, '', 'File isn\'t locked');
|
||||
} else if (lockManager.getLock(filePath) === requestLock) {
|
||||
// lock matches current lock => extend duration
|
||||
lockManager.lock(filePath, requestLock);
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
// lock mismatch
|
||||
returnLockMismatch(res, lockManager.getLock(filePath), 'Lock mismatch');
|
||||
}
|
||||
};
|
||||
|
||||
// allow for file editing
|
||||
const unlock = function unlock(wopi, req, res, userHost) {
|
||||
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
|
||||
const userAddress = req.DocManager.curUserHostAddress(userHost);
|
||||
const filePath = req.DocManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
if (!lockManager.hasLock(filePath)) {
|
||||
// file isn't locked => mismatch
|
||||
returnLockMismatch(res, '', 'File isn\'t locked');
|
||||
} else if (lockManager.getLock(filePath) === requestLock) {
|
||||
// lock matches current lock => unlock
|
||||
lockManager.unlock(filePath);
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
// lock mismatch
|
||||
returnLockMismatch(res, lockManager.getLock(filePath), 'Lock mismatch');
|
||||
}
|
||||
};
|
||||
|
||||
// allow for file editing, and then immediately take a new lock on the file
|
||||
const unlockAndRelock = function unlockAndRelock(wopi, req, res, userHost) {
|
||||
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
const oldLock = req.headers[reqConsts.requestHeaders.oldLock.toLowerCase()]; // get the X-WOPI-OldLock header
|
||||
|
||||
const userAddress = req.DocManager.curUserHostAddress(userHost);
|
||||
const filePath = req.DocManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
if (!lockManager.hasLock(filePath)) {
|
||||
// file isn't locked => mismatch
|
||||
returnLockMismatch(res, '', 'File isn\'t locked');
|
||||
} else if (lockManager.getLock(filePath) === oldLock) {
|
||||
// lock matches current lock => lock with new key
|
||||
lockManager.lock(filePath, requestLock);
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
// lock mismatch
|
||||
returnLockMismatch(res, lockManager.getLock(filePath), 'Lock mismatch');
|
||||
}
|
||||
};
|
||||
|
||||
// request a message to retrieve a file
|
||||
const getFile = function getFile(wopi, req, res, userHost) {
|
||||
const userAddress = req.DocManager.curUserHostAddress(userHost);
|
||||
|
||||
const storagePath = req.DocManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
res.setHeader('Content-Length', fileSystem.statSync(storagePath).size);
|
||||
res.setHeader('Content-Type', mime.getType(storagePath));
|
||||
|
||||
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(wopi.id)}`);
|
||||
|
||||
const filestream = fileSystem.createReadStream(storagePath); // open a file as a readable stream
|
||||
filestream.pipe(res); // retrieve data from file stream and output it to the response object
|
||||
};
|
||||
|
||||
// request a message to update a file
|
||||
const putFile = function putFile(wopi, req, res, userHost) {
|
||||
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
|
||||
const userAddress = req.DocManager.curUserHostAddress(userHost);
|
||||
const storagePath = req.DocManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
if (!lockManager.hasLock(storagePath)) {
|
||||
// ToDo: if body length is 0 bytes => handle document creation
|
||||
|
||||
// file isn't locked => mismatch
|
||||
returnLockMismatch(res, '', 'File isn\'t locked');
|
||||
} else if (lockManager.getLock(storagePath) === requestLock) {
|
||||
// lock matches current lock => put file
|
||||
saveFileFromBody(req, wopi.id, userAddress, true, (err, version) => {
|
||||
if (!err) {
|
||||
res.setHeader(reqConsts.requestHeaders.ItemVersion, version); // set the X-WOPI-ItemVersion header
|
||||
}
|
||||
res.sendStatus(err ? 404 : 200);
|
||||
});
|
||||
} else {
|
||||
// lock mismatch
|
||||
returnLockMismatch(res, lockManager.getLock(storagePath), 'Lock mismatch');
|
||||
}
|
||||
};
|
||||
|
||||
const putRelativeFile = function putRelativeFile(wopi, req, res, userHost) {
|
||||
const userAddress = req.DocManager.curUserHostAddress(userHost);
|
||||
const storagePath = req.DocManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
let filename = req.headers[reqConsts.requestHeaders.RelativeTarget.toLowerCase()]; // we cannot modify this filename
|
||||
if (filename) {
|
||||
if (req.DocManager.existsSync(storagePath)) { // check if already exists
|
||||
const overwrite = req.headers[reqConsts.requestHeaders.OverwriteRelativeTarget.toLowerCase()]; // overwrite header
|
||||
if (overwrite && overwrite === 'true') { // check if we can overwrite
|
||||
if (lockManager.hasLock(storagePath)) { // check if file locked
|
||||
// file is locked, cannot overwrite
|
||||
returnValidRelativeTarget(res, req.DocManager.getCorrectName(wopi.id, userAddress));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// file exists and overwrite header is false
|
||||
returnValidRelativeTarget(res, req.DocManager.getCorrectName(wopi.id, userAddress));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filename = req.headers[reqConsts.requestHeaders.SuggestedTarget.toLowerCase()]; // we can modify this filename
|
||||
|
||||
if (filename.startsWith('.')) { // check if extension
|
||||
filename = fileUtility.getFileName(wopi.id, true) + filename; // get original filename with new extension
|
||||
}
|
||||
|
||||
filename = req.DocManager.getCorrectName(filename, userAddress); // get correct filename if already exists
|
||||
}
|
||||
|
||||
const isConverted = req.headers[reqConsts.requestHeaders.FileConversion.toLowerCase()];
|
||||
console.log(`putRelativeFile after conversation: ${isConverted}`);
|
||||
|
||||
// if we got here, then we can save a file
|
||||
saveFileFromBody(req, filename, userAddress, false, (err) => {
|
||||
if (err) {
|
||||
res.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
|
||||
const serverUrl = req.DocManager.getServerUrl(true);
|
||||
const fileActionUrl = `${serverUrl}/wopi-action/${filename}?action=`;
|
||||
|
||||
const fileInfo = {
|
||||
Name: filename,
|
||||
Url: `${serverUrl}/wopi/files/${filename}`,
|
||||
HostViewUrl: `${fileActionUrl}view`,
|
||||
HostEditNewUrl: `${fileActionUrl}editnew`,
|
||||
HostEditUrl: `${fileActionUrl}edit`,
|
||||
};
|
||||
res.status(200).send(fileInfo);
|
||||
});
|
||||
};
|
||||
|
||||
// return information about the file properties, access rights and editor settings
|
||||
const checkFileInfo = function checkFileInfo(wopi, req, res, userHost) {
|
||||
const userAddress = req.DocManager.curUserHostAddress(userHost);
|
||||
const version = req.DocManager.getKey(wopi.id, userAddress);
|
||||
|
||||
const storagePath = req.DocManager.storagePath(wopi.id, userAddress);
|
||||
// add wopi query
|
||||
const query = new URLSearchParams(wopi.accessToken);
|
||||
const user = users.getUser(query.get('userid'));
|
||||
|
||||
// create the file information object
|
||||
const fileInfo = {
|
||||
BaseFileName: wopi.id,
|
||||
OwnerId: req.DocManager.getFileData(wopi.id, userAddress)[1],
|
||||
Size: fileSystem.statSync(storagePath).size,
|
||||
UserId: user.id,
|
||||
UserFriendlyName: user.name,
|
||||
Version: version,
|
||||
UserCanWrite: true,
|
||||
SupportsGetLock: true,
|
||||
SupportsLocks: true,
|
||||
SupportsUpdate: true,
|
||||
};
|
||||
res.status(200).send(fileInfo);
|
||||
};
|
||||
|
||||
// parse wopi request
|
||||
const parseWopiRequest = function parseWopiRequest(req) {
|
||||
const wopiData = {
|
||||
requestType: reqConsts.requestType.None,
|
||||
accessToken: req.query.access_token,
|
||||
id: req.params.id,
|
||||
};
|
||||
|
||||
// get the request path
|
||||
const reqPath = req.path.substring('/wopi/'.length);
|
||||
|
||||
if (reqPath.startsWith('files')) { // if it starts with "files"
|
||||
if (reqPath.endsWith('/contents')) { // ends with "/contents"
|
||||
if (req.method === 'GET') { // and the request method is GET
|
||||
wopiData.requestType = reqConsts.requestType.GetFile; // then the request type is GetFile
|
||||
} else if (req.method === 'POST') { // if the request method is POST
|
||||
wopiData.requestType = reqConsts.requestType.PutFile; // then the request type is PutFile
|
||||
}
|
||||
} else if (req.method === 'GET') { // otherwise, if the request method is GET
|
||||
wopiData.requestType = reqConsts.requestType.CheckFileInfo; // the request type is CheckFileInfo
|
||||
} else if (req.method === 'POST') { // if the request method is POST
|
||||
// get the X-WOPI-Override header which determines the request type
|
||||
const wopiOverride = req.headers[reqConsts.requestHeaders.RequestType.toLowerCase()];
|
||||
switch (wopiOverride) {
|
||||
case 'LOCK': // if it is equal to LOCK
|
||||
// check if the request sends the X-WOPI-OldLock header
|
||||
if (req.headers[reqConsts.requestHeaders.OldLock.toLowerCase()]) {
|
||||
// if yes, then the request type is UnlockAndRelock
|
||||
wopiData.requestType = reqConsts.requestType.UnlockAndRelock;
|
||||
} else {
|
||||
wopiData.requestType = reqConsts.requestType.Lock; // otherwise, it is Lock
|
||||
}
|
||||
break;
|
||||
|
||||
case 'GET_LOCK': // if it is equal to GET_LOCK
|
||||
wopiData.requestType = reqConsts.requestType.GetLock; // the request type is GetLock
|
||||
break;
|
||||
|
||||
case 'REFRESH_LOCK': // if it is equal to REFRESH_LOCK
|
||||
wopiData.requestType = reqConsts.requestType.RefreshLock; // the request type is RefreshLock
|
||||
break;
|
||||
|
||||
case 'UNLOCK': // if it is equal to UNLOCK
|
||||
wopiData.requestType = reqConsts.requestType.Unlock; // the request type is Unlock
|
||||
break;
|
||||
|
||||
case 'PUT_RELATIVE': // if it is equal to PUT_RELATIVE
|
||||
// the request type is PutRelativeFile (creates a new file on the host based on the current file)
|
||||
wopiData.requestType = reqConsts.requestType.PutRelativeFile;
|
||||
break;
|
||||
|
||||
case 'RENAME_FILE': // if it is equal to RENAME_FILE
|
||||
wopiData.requestType = reqConsts.requestType.RenameFile; // the request type is RenameFile (renames a file)
|
||||
break;
|
||||
|
||||
case 'PUT_USER_INFO': // if it is equal to PUT_USER_INFO
|
||||
// the request type is PutUserInfo (stores some basic user information on the host)
|
||||
wopiData.requestType = reqConsts.requestType.PutUserInfo;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wopiData;
|
||||
};
|
||||
|
||||
const actionMapping = {};
|
||||
actionMapping[reqConsts.requestType.GetFile] = getFile;
|
||||
@ -36,352 +365,33 @@ actionMapping[reqConsts.requestType.GetLock] = getLock;
|
||||
actionMapping[reqConsts.requestType.RefreshLock] = refreshLock;
|
||||
actionMapping[reqConsts.requestType.Unlock] = unlock;
|
||||
|
||||
// parse wopi request
|
||||
function parseWopiRequest(req) {
|
||||
let wopiData = {
|
||||
requestType: reqConsts.requestType.None,
|
||||
accessToken: req.query["access_token"],
|
||||
id: req.params['id']
|
||||
}
|
||||
|
||||
// get the request path
|
||||
let reqPath = req.path.substring("/wopi/".length)
|
||||
|
||||
if (reqPath.startsWith("files")) { // if it starts with "files"
|
||||
if (reqPath.endsWith("/contents")) { // ends with "/contents"
|
||||
if (req.method == "GET") { // and the request method is GET
|
||||
wopiData.requestType = reqConsts.requestType.GetFile; // then the request type is GetFile
|
||||
} else if (req.method == "POST") { // if the request method is POST
|
||||
wopiData.requestType = reqConsts.requestType.PutFile; // then the request type is PutFile
|
||||
}
|
||||
} else {
|
||||
if (req.method == "GET") { // otherwise, if the request method is GET
|
||||
wopiData.requestType = reqConsts.requestType.CheckFileInfo; // the request type is CheckFileInfo
|
||||
} else if (req.method == "POST") { // if the request method is POST
|
||||
let wopiOverride = req.headers[reqConsts.requestHeaders.RequestType.toLowerCase()]; // get the X-WOPI-Override header which determines the request type
|
||||
switch (wopiOverride) {
|
||||
case "LOCK": // if it is equal to LOCK
|
||||
if (req.headers[reqConsts.requestHeaders.OldLock.toLowerCase()]) { // check if the request sends the X-WOPI-OldLock header
|
||||
wopiData.requestType = reqConsts.requestType.UnlockAndRelock; // if yes, then the request type is UnlockAndRelock
|
||||
} else {
|
||||
wopiData.requestType = reqConsts.requestType.Lock; // otherwise, it is Lock
|
||||
}
|
||||
break;
|
||||
|
||||
case "GET_LOCK": // if it is equal to GET_LOCK
|
||||
wopiData.requestType = reqConsts.requestType.GetLock; // the request type is GetLock
|
||||
break;
|
||||
|
||||
case "REFRESH_LOCK": // if it is equal to REFRESH_LOCK
|
||||
wopiData.requestType = reqConsts.requestType.RefreshLock; // the request type is RefreshLock
|
||||
break;
|
||||
|
||||
case "UNLOCK": // if it is equal to UNLOCK
|
||||
wopiData.requestType = reqConsts.requestType.Unlock; // the request type is Unlock
|
||||
break;
|
||||
|
||||
case "PUT_RELATIVE": // if it is equal to PUT_RELATIVE
|
||||
wopiData.requestType = reqConsts.requestType.PutRelativeFile; // the request type is PutRelativeFile (creates a new file on the host based on the current file)
|
||||
break;
|
||||
|
||||
case "RENAME_FILE": // if it is equal to RENAME_FILE
|
||||
wopiData.requestType = reqConsts.requestType.RenameFile; // the request type is RenameFile (renames a file)
|
||||
break;
|
||||
|
||||
case "PUT_USER_INFO": // if it is equal to PUT_USER_INFO
|
||||
wopiData.requestType = reqConsts.requestType.PutUserInfo; // the request type is PutUserInfo (stores some basic user information on the host)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (reqPath.startsWith("folders")) {
|
||||
|
||||
}
|
||||
|
||||
return wopiData;
|
||||
}
|
||||
|
||||
// lock file editing
|
||||
function lock(wopi, req, res, userHost) {
|
||||
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost); // get current user host address
|
||||
let filePath = req.docManager.storagePath(wopi.id, userAddress); // get the storage path of the given file
|
||||
|
||||
if (!lockManager.hasLock(filePath)) {
|
||||
// file isn't locked => lock
|
||||
lockManager.lock(filePath, requestLock);
|
||||
res.sendStatus(200);
|
||||
} else if (lockManager.getLock(filePath) == requestLock) {
|
||||
// lock matches current lock => extend duration
|
||||
lockManager.lock(filePath, requestLock);
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
// file locked by someone else => return lock mismatch
|
||||
let lock = lockManager.getLock(filePath);
|
||||
returnLockMismatch(res, lock, "File already locked by " + lock)
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve a lock on a file
|
||||
function getLock(wopi, req, res, userHost) {
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost);
|
||||
let filePath = req.docManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
// get the lock of the specified file and set it as the X-WOPI-Lock header
|
||||
res.setHeader(reqConsts.requestHeaders.lock, lockManager.getLock(filePath));
|
||||
res.sendStatus(200);
|
||||
}
|
||||
|
||||
// refresh the lock on a file by resetting its automatic expiration timer to 30 minutes
|
||||
function refreshLock(wopi, req, res, userHost) {
|
||||
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost);
|
||||
let filePath = req.docManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
if (!lockManager.hasLock(filePath)) {
|
||||
// file isn't locked => mismatch
|
||||
returnLockMismatch(res, "", "File isn't locked");
|
||||
} else if (lockManager.getLock(filePath) == requestLock) {
|
||||
// lock matches current lock => extend duration
|
||||
lockManager.lock(filePath, requestLock);
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
// lock mismatch
|
||||
returnLockMismatch(res, lockManager.getLock(filePath), "Lock mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
// allow for file editing
|
||||
function unlock(wopi, req, res, userHost) {
|
||||
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost);
|
||||
let filePath = req.docManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
if (!lockManager.hasLock(filePath)) {
|
||||
// file isn't locked => mismatch
|
||||
returnLockMismatch(res, "", "File isn't locked");
|
||||
} else if (lockManager.getLock(filePath) == requestLock) {
|
||||
// lock matches current lock => unlock
|
||||
lockManager.unlock(filePath);
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
// lock mismatch
|
||||
returnLockMismatch(res, lockManager.getLock(filePath), "Lock mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
// allow for file editing, and then immediately take a new lock on the file
|
||||
function unlockAndRelock(wopi, req, res, userHost) {
|
||||
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
let oldLock = req.headers[reqConsts.requestHeaders.oldLock.toLowerCase()]; // get the X-WOPI-OldLock header
|
||||
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost);
|
||||
let filePath = req.docManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
if (!lockManager.hasLock(filePath)) {
|
||||
// file isn't locked => mismatch
|
||||
returnLockMismatch(res, "", "File isn't locked");
|
||||
} else if (lockManager.getLock(filePath) == oldLock) {
|
||||
// lock matches current lock => lock with new key
|
||||
lockManager.lock(filePath, requestLock);
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
// lock mismatch
|
||||
returnLockMismatch(res, lockManager.getLock(filePath), "Lock mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
// request a message to retrieve a file
|
||||
function getFile(wopi, req, res, userHost) {
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost);
|
||||
|
||||
let path = req.docManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
res.setHeader("Content-Length", fileSystem.statSync(path).size);
|
||||
res.setHeader("Content-Type", mime.getType(path));
|
||||
|
||||
res.setHeader("Content-Disposition", "attachment; filename*=UTF-8\'\'" + encodeURIComponent(wopi.id));
|
||||
|
||||
let filestream = fileSystem.createReadStream(path); // open a file as a readable stream
|
||||
filestream.pipe(res); // retrieve data from file stream and output it to the response object
|
||||
}
|
||||
|
||||
// request a message to update a file
|
||||
function putFile(wopi, req, res, userHost) {
|
||||
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
|
||||
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost);
|
||||
let storagePath = req.docManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
if (!lockManager.hasLock(storagePath)) {
|
||||
// ToDo: if body length is 0 bytes => handle document creation
|
||||
|
||||
// file isn't locked => mismatch
|
||||
returnLockMismatch(res, "", "File isn't locked");
|
||||
} else if (lockManager.getLock(storagePath) == requestLock) {
|
||||
// lock matches current lock => put file
|
||||
saveFileFromBody(req, wopi.id, userAddress, true, (err, version) => {
|
||||
if (!err) {
|
||||
res.setHeader(reqConsts.requestHeaders.ItemVersion, version); // set the X-WOPI-ItemVersion header
|
||||
}
|
||||
res.sendStatus(err ? 404 : 200);
|
||||
});
|
||||
} else {
|
||||
// lock mismatch
|
||||
returnLockMismatch(res, lockManager.getLock(storagePath), "Lock mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
function putRelativeFile(wopi, req, res, userHost) {
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost);
|
||||
let storagePath = req.docManager.storagePath(wopi.id, userAddress);
|
||||
|
||||
let filename = req.headers[reqConsts.requestHeaders.RelativeTarget.toLowerCase()]; // we cannot modify this filename
|
||||
if (filename) {
|
||||
if (req.docManager.existsSync(storagePath)) { // check if already exists
|
||||
let overwrite = req.headers[reqConsts.requestHeaders.OverwriteRelativeTarget.toLowerCase()]; // overwrite header
|
||||
if (overwrite && overwrite === "true") { // check if we can overwrite
|
||||
if (lockManager.hasLock(storagePath)) { // check if file locked
|
||||
returnValidRelativeTarget(res, req.docManager.getCorrectName(wopi.id, userAddress)); // file is locked, cannot overwrite
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
returnValidRelativeTarget(res, req.docManager.getCorrectName(wopi.id, userAddress)); // file exists and overwrite header is false
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filename = req.headers[reqConsts.requestHeaders.SuggestedTarget.toLowerCase()]; // we can modify this filename
|
||||
|
||||
if (filename.startsWith(".")) { // check if extension
|
||||
filename = fileUtility.getFileName(wopi.id, true) + filename; // get original filename with new extension
|
||||
}
|
||||
|
||||
filename = req.docManager.getCorrectName(filename, userAddress); // get correct filename if already exists
|
||||
}
|
||||
|
||||
let isConverted = req.headers[reqConsts.requestHeaders.FileConversion.toLowerCase()];
|
||||
console.log("putRelativeFile after conversation: " + isConverted);
|
||||
|
||||
// if we got here, then we can save a file
|
||||
saveFileFromBody(req, filename, userAddress, false, (err) => {
|
||||
if (err) {
|
||||
res.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
|
||||
let serverUrl = req.docManager.getServerUrl(true);
|
||||
let fileActionUrl = serverUrl + "/wopi-action/" + filename + "?action=";
|
||||
|
||||
let fileInfo = {
|
||||
"Name": filename,
|
||||
"Url": serverUrl + "/wopi/files/" + filename,
|
||||
"HostViewUrl": fileActionUrl + "view",
|
||||
"HostEditNewUrl": fileActionUrl + "editnew",
|
||||
"HostEditUrl": fileActionUrl + "edit",
|
||||
};
|
||||
res.status(200).send(fileInfo);
|
||||
});
|
||||
}
|
||||
|
||||
// return information about the file properties, access rights and editor settings
|
||||
function checkFileInfo(wopi, req, res, userHost) {
|
||||
let userAddress = req.docManager.curUserHostAddress(userHost);
|
||||
let version = req.docManager.getKey(wopi.id, userAddress);
|
||||
|
||||
let path = req.docManager.storagePath(wopi.id, userAddress);
|
||||
// add wopi query
|
||||
var query = new URLSearchParams(wopi.accessToken);
|
||||
let user = users.getUser(query.get("userid"));
|
||||
|
||||
// create the file information object
|
||||
let fileInfo = {
|
||||
"BaseFileName": wopi.id,
|
||||
"OwnerId": req.docManager.getFileData(wopi.id, userAddress)[1],
|
||||
"Size": fileSystem.statSync(path).size,
|
||||
"UserId": user.id,
|
||||
"UserFriendlyName": user.name,
|
||||
"Version": version,
|
||||
"UserCanWrite": true,
|
||||
"SupportsGetLock": true,
|
||||
"SupportsLocks": true,
|
||||
"SupportsUpdate": true,
|
||||
};
|
||||
res.status(200).send(fileInfo);
|
||||
}
|
||||
|
||||
function saveFileFromBody(req, filename, userAddress, isNewVersion, callback) {
|
||||
if (req.body) {
|
||||
var storagePath = req.docManager.storagePath(filename, userAddress);
|
||||
var historyPath = req.docManager.historyPath(filename, userAddress); // get the path to the file history
|
||||
if (historyPath == "") { // if it is empty
|
||||
historyPath = req.docManager.historyPath(filename, userAddress, true); // create it
|
||||
req.docManager.createDirectory(historyPath); // and create a new directory for the history
|
||||
}
|
||||
|
||||
var version = 0;
|
||||
if (isNewVersion) {
|
||||
var count_version = req.docManager.countVersion(historyPath); // get the last file version
|
||||
version = count_version + 1; // get a number of a new file version
|
||||
var versionPath = req.docManager.versionPath(filename, userAddress, version); // get the path to the specified file version
|
||||
req.docManager.createDirectory(versionPath); // and create a new directory for the specified version
|
||||
|
||||
var path_prev = path.join(versionPath, "prev" + fileUtility.getFileExtension(filename)); // get the path to the previous file version
|
||||
fileSystem.renameSync(storagePath, path_prev); // synchronously rename the given file as the previous file version
|
||||
}
|
||||
|
||||
let filestream = fileSystem.createWriteStream(storagePath);
|
||||
req.pipe(filestream);
|
||||
req.on('end', () => {
|
||||
filestream.close();
|
||||
callback(null, version);
|
||||
})
|
||||
} else {
|
||||
callback("empty body");
|
||||
}
|
||||
}
|
||||
|
||||
// return name that wopi-client can use as the value of X-WOPI-RelativeTarget in a future PutRelativeFile operation
|
||||
function returnValidRelativeTarget(res, filename) {
|
||||
res.setHeader(reqConsts.requestHeaders.ValidRelativeTarget, filename); // set the X-WOPI-ValidRelativeTarget header
|
||||
res.sendStatus(409); // file with that name already exists
|
||||
}
|
||||
|
||||
// return lock mismatch
|
||||
function returnLockMismatch(res, lock, reason) {
|
||||
res.setHeader(reqConsts.requestHeaders.Lock, lock || ""); // set the X-WOPI-Lock header
|
||||
if (reason) { // if there is a reason for lock mismatch
|
||||
res.setHeader(reqConsts.requestHeaders.LockFailureReason, reason); // set it as the X-WOPI-LockFailureReason header
|
||||
}
|
||||
res.sendStatus(409); // conflict
|
||||
}
|
||||
|
||||
exports.fileRequestHandler = (req, res) => {
|
||||
let userAddress = null;
|
||||
req.docManager = new docManager(req, res);
|
||||
if (req.params['id'].includes("@")) { // if there is the "@" sign in the id parameter
|
||||
let split = req.params['id'].split("@"); // split this parameter by "@"
|
||||
req.params['id'] = split[0]; // rewrite id with the first part of the split parameter
|
||||
userAddress = split[1]; // save the second part as the user address
|
||||
}
|
||||
let userAddress = null;
|
||||
req.DocManager = new DocManager(req, res);
|
||||
if (req.params.id.includes('@')) { // if there is the "@" sign in the id parameter
|
||||
const split = req.params.id.split('@'); // split this parameter by "@"
|
||||
[req.params.id] = split; // rewrite id with the first part of the split parameter
|
||||
[, userAddress] = split; // save the second part as the user address
|
||||
}
|
||||
|
||||
let wopiData = parseWopiRequest(req); // get the wopi data
|
||||
const wopiData = parseWopiRequest(req); // get the wopi data
|
||||
|
||||
// an error of the unknown request type
|
||||
if (wopiData.requestType == reqConsts.requestType.None) {
|
||||
res.status(500).send({ 'title': 'fileHandler', 'method': req.method, 'id': req.params['id'], 'error': "unknown" });
|
||||
return;
|
||||
}
|
||||
// an error of the unknown request type
|
||||
if (wopiData.requestType === reqConsts.requestType.None) {
|
||||
res.status(500).send({
|
||||
title: 'fileHandler', method: req.method, id: req.params.id, error: 'unknown',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// an error of the unsupported request type
|
||||
let action = actionMapping[wopiData.requestType];
|
||||
if (!action) {
|
||||
res.status(501).send({ 'title': 'fileHandler', 'method': req.method, 'id': req.params['id'], 'error': "unsupported" });
|
||||
return;
|
||||
}
|
||||
// an error of the unsupported request type
|
||||
const action = actionMapping[wopiData.requestType];
|
||||
if (!action) {
|
||||
res.status(501).send({
|
||||
title: 'fileHandler', method: req.method, id: req.params.id, error: 'unsupported',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
action(wopiData, req, res, userAddress);
|
||||
}
|
||||
action(wopiData, req, res, userAddress);
|
||||
};
|
||||
|
||||
@ -16,54 +16,54 @@
|
||||
*
|
||||
*/
|
||||
|
||||
var lockDict = {};
|
||||
const lockDict = {};
|
||||
|
||||
// get the lock object of the specified file
|
||||
function getLockObject(filePath) {
|
||||
return lockDict[filePath];
|
||||
}
|
||||
const getLockObject = function getLockObject(filePath) {
|
||||
return lockDict[filePath];
|
||||
};
|
||||
|
||||
// clear the lock timeout
|
||||
function clearLockTimeout(lockObject) {
|
||||
if (lockObject && lockObject.timeout) {
|
||||
clearTimeout(lockObject.timeout);
|
||||
}
|
||||
}
|
||||
const clearLockTimeout = function clearLockTimeout(lockObject) {
|
||||
if (lockObject && lockObject.timeout) {
|
||||
clearTimeout(lockObject.timeout);
|
||||
}
|
||||
};
|
||||
|
||||
// get the lock value of the specified file
|
||||
function getLockValue(filePath) {
|
||||
let lock = getLockObject(filePath); // get the lock object of the specified file
|
||||
if (lock) return lock.value; // if it exists, get the lock value from it
|
||||
return "";
|
||||
}
|
||||
const getLockValue = function getLockValue(filePath) {
|
||||
const lock = getLockObject(filePath); // get the lock object of the specified file
|
||||
if (lock) return lock.value; // if it exists, get the lock value from it
|
||||
return '';
|
||||
};
|
||||
|
||||
// check if the specified file path has lock or not
|
||||
function hasLock(filePath) {
|
||||
return !!getLockObject(filePath);
|
||||
}
|
||||
|
||||
// lock file editing
|
||||
function lock(filePath, lockValue) {
|
||||
let oldLock = getLockObject(filePath); // get the old lock of the specified file
|
||||
clearLockTimeout(oldLock); // clear its timeout
|
||||
|
||||
// create a new lock object
|
||||
lockDict[filePath] = {
|
||||
value: lockValue,
|
||||
timeout: setTimeout(unlock, 1000 * 60 * 30, filePath) // set lock for 30 minutes
|
||||
}
|
||||
}
|
||||
const hasLock = function hasLock(filePath) {
|
||||
return !!getLockObject(filePath);
|
||||
};
|
||||
|
||||
// allow for file editing
|
||||
function unlock(filePath) {
|
||||
let lock = getLockObject(filePath); // get the lock of the specified file
|
||||
clearLockTimeout(lock); // clear its timeout
|
||||
delete lockDict[filePath]; // delete the lock
|
||||
}
|
||||
const unlock = function unlock(filePath) {
|
||||
const lock = getLockObject(filePath); // get the lock of the specified file
|
||||
clearLockTimeout(lock); // clear its timeout
|
||||
delete lockDict[filePath]; // delete the lock
|
||||
};
|
||||
|
||||
// lock file editing
|
||||
const lock = function lock(filePath, lockValue) {
|
||||
const oldLock = getLockObject(filePath); // get the old lock of the specified file
|
||||
clearLockTimeout(oldLock); // clear its timeout
|
||||
|
||||
// create a new lock object
|
||||
lockDict[filePath] = {
|
||||
value: lockValue,
|
||||
timeout: setTimeout(unlock, 1000 * 60 * 30, filePath), // set lock for 30 minutes
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
hasLock: hasLock,
|
||||
getLock: getLockValue,
|
||||
lock: lock,
|
||||
unlock: unlock
|
||||
}
|
||||
hasLock,
|
||||
getLock: getLockValue,
|
||||
lock,
|
||||
unlock,
|
||||
};
|
||||
|
||||
@ -18,55 +18,55 @@
|
||||
|
||||
// request types
|
||||
const requestType = Object.freeze({
|
||||
"None": 0,
|
||||
None: 0,
|
||||
|
||||
"CheckFileInfo": 1,
|
||||
"PutRelativeFile": 2,
|
||||
CheckFileInfo: 1,
|
||||
PutRelativeFile: 2,
|
||||
|
||||
"Lock": 3,
|
||||
"GetLock": 4,
|
||||
"Unlock": 5,
|
||||
"RefreshLock": 6,
|
||||
"UnlockAndRelock": 7,
|
||||
Lock: 3,
|
||||
GetLock: 4,
|
||||
Unlock: 5,
|
||||
RefreshLock: 6,
|
||||
UnlockAndRelock: 7,
|
||||
|
||||
"ExecuteCobaltRequest": 8,
|
||||
ExecuteCobaltRequest: 8,
|
||||
|
||||
"DeleteFile": 9,
|
||||
"ReadSecureStore": 10,
|
||||
"GetRestrictedLink": 11,
|
||||
"RevokeRestrictedLink": 12,
|
||||
DeleteFile: 9,
|
||||
ReadSecureStore: 10,
|
||||
GetRestrictedLink: 11,
|
||||
RevokeRestrictedLink: 12,
|
||||
|
||||
"CheckFolderInfo": 13,
|
||||
CheckFolderInfo: 13,
|
||||
|
||||
"GetFile": 14,
|
||||
"PutFile": 16,
|
||||
GetFile: 14,
|
||||
PutFile: 16,
|
||||
|
||||
"EnumerateChildren": 16,
|
||||
EnumerateChildren: 16,
|
||||
|
||||
"RenameFile": 17,
|
||||
"PutUserInfo": 18,
|
||||
RenameFile: 17,
|
||||
PutUserInfo: 18,
|
||||
});
|
||||
|
||||
// request headers
|
||||
const requestHeaders = Object.freeze({
|
||||
"RequestType": "X-WOPI-Override",
|
||||
"ItemVersion": "X-WOPI-ItemVersion",
|
||||
RequestType: 'X-WOPI-Override',
|
||||
ItemVersion: 'X-WOPI-ItemVersion',
|
||||
|
||||
"Lock": "X-WOPI-Lock",
|
||||
"OldLock": "X-WOPI-OldLock",
|
||||
"LockFailureReason": "X-WOPI-LockFailureReason",
|
||||
"LockedByOtherInterface": "X-WOPI-LockedByOtherInterface",
|
||||
Lock: 'X-WOPI-Lock',
|
||||
OldLock: 'X-WOPI-OldLock',
|
||||
LockFailureReason: 'X-WOPI-LockFailureReason',
|
||||
LockedByOtherInterface: 'X-WOPI-LockedByOtherInterface',
|
||||
|
||||
"FileConversion": "X-WOPI-FileConversion",
|
||||
FileConversion: 'X-WOPI-FileConversion',
|
||||
|
||||
"SuggestedTarget": "X-WOPI-SuggestedTarget",
|
||||
"RelativeTarget": "X-WOPI-RelativeTarget",
|
||||
"OverwriteRelativeTarget": "X-WOPI-OverwriteRelativeTarget",
|
||||
SuggestedTarget: 'X-WOPI-SuggestedTarget',
|
||||
RelativeTarget: 'X-WOPI-RelativeTarget',
|
||||
OverwriteRelativeTarget: 'X-WOPI-OverwriteRelativeTarget',
|
||||
|
||||
"ValidRelativeTarget": "X-WOPI-ValidRelativeTarget",
|
||||
ValidRelativeTarget: 'X-WOPI-ValidRelativeTarget',
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
requestType: requestType,
|
||||
requestHeaders: requestHeaders,
|
||||
}
|
||||
requestType,
|
||||
requestHeaders,
|
||||
};
|
||||
|
||||
@ -16,8 +16,4 @@
|
||||
*
|
||||
*/
|
||||
|
||||
exports.isValidToken = (req, res, next) => {
|
||||
if (true) {
|
||||
return next();
|
||||
}
|
||||
}
|
||||
exports.isValidToken = (req, res, next) => next();
|
||||
|
||||
@ -16,129 +16,141 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const config = require("config");
|
||||
const configServer = config.get("server");
|
||||
var urlModule = require("url");
|
||||
var urllib = require("urllib");
|
||||
const xmlParser = require("fast-xml-parser");
|
||||
const he = require("he");
|
||||
const siteUrl = configServer.get("siteUrl"); // the path to the editors installation
|
||||
const config = require('config');
|
||||
const urlModule = require('url');
|
||||
const urllib = require('urllib');
|
||||
const xmlParser = require('fast-xml-parser');
|
||||
const he = require('he');
|
||||
|
||||
var cache = null;
|
||||
const configServer = config.get('server');
|
||||
const siteUrl = configServer.get('siteUrl'); // the path to the editors installation
|
||||
|
||||
async function initWopi(docManager) {
|
||||
let absSiteUrl = siteUrl;
|
||||
if (absSiteUrl.indexOf("/") === 0) {
|
||||
absSiteUrl = docManager.getServerHost() + siteUrl;
|
||||
}
|
||||
let cache = null;
|
||||
|
||||
// get the wopi discovery information
|
||||
await getDiscoveryInfo(absSiteUrl);
|
||||
}
|
||||
const requestDiscovery = async function requestDiscovery(url) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
return new Promise((resolve, reject) => {
|
||||
const actions = [];
|
||||
urllib.request(urlModule.parse(url + configServer.get('wopi.discovery')), { method: 'GET' }, (err, data) => {
|
||||
if (data) {
|
||||
// create the discovery XML file with the parameters from the response
|
||||
const xmlParseOptions = {
|
||||
attributeNamePrefix: '',
|
||||
ignoreAttributes: false,
|
||||
parseAttributeValue: true,
|
||||
attrValueProcessor: (val) => he.decode(val, { isAttributeValue: true }),
|
||||
};
|
||||
const parser = new xmlParser.XMLParser(xmlParseOptions);
|
||||
// create the discovery XML file with the parameters from the response
|
||||
const discovery = parser.parse(data.toString());
|
||||
if (discovery['wopi-discovery']) {
|
||||
discovery['wopi-discovery']['net-zone'].app.forEach((app) => {
|
||||
let appAction = app.action;
|
||||
if (!Array.isArray(appAction)) {
|
||||
appAction = [appAction];
|
||||
}
|
||||
appAction.forEach((action) => {
|
||||
actions.push({ // write all the parameters to the actions element
|
||||
app: app.name,
|
||||
favIconUrl: app.favIconUrl,
|
||||
checkLicense: app.checkLicense === 'true',
|
||||
name: action.name,
|
||||
ext: action.ext || '',
|
||||
progid: action.progid || '',
|
||||
isDefault: !!action.default,
|
||||
urlsrc: action.urlsrc,
|
||||
requires: action.requires || '',
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
resolve(actions);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// get the wopi discovery information
|
||||
async function getDiscoveryInfo(siteUrl) {
|
||||
let actions = [];
|
||||
const getDiscoveryInfo = async function getDiscoveryInfo(url) {
|
||||
let actions = [];
|
||||
|
||||
if (cache) return cache;
|
||||
|
||||
try {
|
||||
actions = await requestDiscovery(siteUrl);
|
||||
} catch (e) {
|
||||
return actions;
|
||||
}
|
||||
|
||||
cache = actions;
|
||||
setTimeout(() => cache = null, 1000 * 60 * 60); // 1 hour
|
||||
if (cache) return cache;
|
||||
|
||||
try {
|
||||
actions = await requestDiscovery(url);
|
||||
} catch (e) {
|
||||
return actions;
|
||||
}
|
||||
}
|
||||
|
||||
async function requestDiscovery(siteUrl) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var actions = [];
|
||||
urllib.request(urlModule.parse(siteUrl + configServer.get("wopi.discovery")), {method: "GET"}, (err, data) => {
|
||||
if (data) {
|
||||
let discovery = xmlParser.parse(data.toString(), { // create the discovery XML file with the parameters from the response
|
||||
attributeNamePrefix: "",
|
||||
ignoreAttributes: false,
|
||||
parseAttributeValue: true,
|
||||
attrValueProcessor: (val, attrName) => he.decode(val, {isAttributeValue: true})
|
||||
});
|
||||
if (discovery["wopi-discovery"]) {
|
||||
for (let app of discovery["wopi-discovery"]["net-zone"].app) {
|
||||
if (!Array.isArray(app.action)) {
|
||||
app.action = [app.action];
|
||||
}
|
||||
for (let action of app.action) {
|
||||
actions.push({ // write all the parameters to the actions element
|
||||
app: app.name,
|
||||
favIconUrl: app.favIconUrl,
|
||||
checkLicense: app.checkLicense == 'true',
|
||||
name: action.name,
|
||||
ext: action.ext || "",
|
||||
progid: action.progid || "",
|
||||
isDefault: action.default ? true : false,
|
||||
urlsrc: action.urlsrc,
|
||||
requires: action.requires || ""
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
resolve(actions);
|
||||
});
|
||||
})
|
||||
}
|
||||
cache = actions;
|
||||
setTimeout(() => {
|
||||
cache = null;
|
||||
return cache;
|
||||
}, 1000 * 60 * 60); // 1 hour
|
||||
|
||||
return actions;
|
||||
};
|
||||
|
||||
const initWopi = async function initWopi(DocManager) {
|
||||
let absSiteUrl = siteUrl;
|
||||
if (absSiteUrl.indexOf('/') === 0) {
|
||||
absSiteUrl = DocManager.getServerHost() + siteUrl;
|
||||
}
|
||||
|
||||
// get the wopi discovery information
|
||||
await getDiscoveryInfo(absSiteUrl);
|
||||
};
|
||||
|
||||
// get actions of the specified extension
|
||||
async function getActions(ext) {
|
||||
let actions = await getDiscoveryInfo(); // get the wopi discovery information
|
||||
let filtered = [];
|
||||
const getActions = async function getActions(ext) {
|
||||
const actions = await getDiscoveryInfo(); // get the wopi discovery information
|
||||
const filtered = [];
|
||||
|
||||
for (let action of actions) { // and filter it by the specified extention
|
||||
if (action.ext == ext) {
|
||||
filtered.push(action);
|
||||
}
|
||||
actions.forEach((action) => { // and filter it by the specified extention
|
||||
if (action.ext === ext) {
|
||||
filtered.push(action);
|
||||
}
|
||||
});
|
||||
|
||||
return filtered;
|
||||
}
|
||||
return filtered;
|
||||
};
|
||||
|
||||
// get an action for the specified extension and name
|
||||
async function getAction(ext, name) {
|
||||
let actions = await getDiscoveryInfo();
|
||||
const getAction = async function getAction(ext, name) {
|
||||
const actions = await getDiscoveryInfo();
|
||||
let act = null;
|
||||
|
||||
for (let action of actions) {
|
||||
if (action.ext == ext && action.name == name) {
|
||||
return action;
|
||||
}
|
||||
actions.forEach((action) => {
|
||||
if (action.ext === ext && action.name === name) {
|
||||
act = action;
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
return act;
|
||||
};
|
||||
|
||||
// get the default action for the specified extension
|
||||
async function getDefaultAction(ext) {
|
||||
let actions = await getDiscoveryInfo();
|
||||
const getDefaultAction = async function getDefaultAction(ext) {
|
||||
const actions = await getDiscoveryInfo();
|
||||
let act = null;
|
||||
|
||||
for (let action of actions) {
|
||||
if (action.ext == ext && action.isDefault) {
|
||||
return action;
|
||||
}
|
||||
actions.forEach((action) => {
|
||||
if (action.ext === ext && action.isDefault) {
|
||||
act = action;
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
return act;
|
||||
};
|
||||
|
||||
// get the action url
|
||||
function getActionUrl(host, userAddress, action, filename) {
|
||||
return action.urlsrc.replace(/<.*&>/g, "") + "WOPISrc=" + host + "/wopi/files/" + filename + "@" + userAddress;
|
||||
}
|
||||
const getActionUrl = function getActionUrl(host, userAddress, action, filename) {
|
||||
return `${action.urlsrc.replace(/<.*&>/g, '')}WOPISrc=${host}/wopi/files/${filename}@${userAddress}`;
|
||||
};
|
||||
|
||||
exports.initWopi = initWopi;
|
||||
exports.getDiscoveryInfo = getDiscoveryInfo;
|
||||
exports.getAction = getAction;
|
||||
exports.getActions = getActions;
|
||||
exports.getActionUrl = getActionUrl;
|
||||
exports.getDefaultAction = getDefaultAction;
|
||||
exports.getDefaultAction = getDefaultAction;
|
||||
|
||||
@ -16,144 +16,160 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const tokenValidator = require("./tokenValidator");
|
||||
const filesController = require("./filesController");
|
||||
const utils = require("./utils");
|
||||
const docManager = require("../docManager");
|
||||
const fileUtility = require("../fileUtility");
|
||||
const config = require('config');
|
||||
const tokenValidator = require('./tokenValidator');
|
||||
const filesController = require('./filesController');
|
||||
const utils = require('./utils');
|
||||
const DocManager = require('../docManager');
|
||||
const fileUtility = require('../fileUtility');
|
||||
const users = require('../users');
|
||||
|
||||
const configServer = config.get('server');
|
||||
const siteUrl = configServer.get("siteUrl"); // the path to the editors installation
|
||||
const users = require("../users");
|
||||
const siteUrl = configServer.get('siteUrl'); // the path to the editors installation
|
||||
|
||||
exports.registerRoutes = function(app) {
|
||||
const getCustomWopiParams = function getCustomWopiParams(query) {
|
||||
let tokenParams = '';
|
||||
let actionParams = '';
|
||||
|
||||
// define a handler for the default wopi page
|
||||
app.get("/wopi", async function(req, res) {
|
||||
const { userid } = query; // user id
|
||||
tokenParams += (userid ? `&userid=${userid}` : '');
|
||||
|
||||
req.docManager = new docManager(req, res);
|
||||
|
||||
await utils.initWopi(req.docManager);
|
||||
|
||||
// get the wopi discovery information
|
||||
let actions = await utils.getDiscoveryInfo();
|
||||
let wopiEnable = actions.length != 0 ? true : false;
|
||||
let docsExtEdit = []; // Supported extensions for WOPI
|
||||
|
||||
actions.forEach(el => {
|
||||
if (el.name == "edit") docsExtEdit.push("."+el.ext);
|
||||
});
|
||||
|
||||
let editedExts = configServer.get('editedDocs').filter(i => docsExtEdit.includes(i)); // Checking supported extensions
|
||||
let fillExts = configServer.get("fillDocs").filter(i => docsExtEdit.includes(i));
|
||||
|
||||
try {
|
||||
// get all the stored files
|
||||
let files = req.docManager.getStoredFiles();
|
||||
|
||||
// run through all the files and write the corresponding information to each file
|
||||
for (var file of files) {
|
||||
let ext = fileUtility.getFileExtension(file.name, true); // get an extension of each file
|
||||
file.actions = await utils.getActions(ext); // get actions of the specified extension
|
||||
file.defaultAction = await utils.getDefaultAction(ext); // get the default action of the specified extension
|
||||
}
|
||||
|
||||
// render wopiIndex template with the parameters specified
|
||||
res.render("wopiIndex", {
|
||||
wopiEnable : wopiEnable,
|
||||
storedFiles: wopiEnable ? files : [],
|
||||
params: req.docManager.getCustomParams(),
|
||||
users: users,
|
||||
serverUrl: req.docManager.getServerUrl(),
|
||||
preloaderUrl: siteUrl + configServer.get('preloaderUrl'),
|
||||
convertExts: configServer.get('convertedDocs'),
|
||||
editedExts: editedExts,
|
||||
fillExts: fillExts,
|
||||
languages: configServer.get('languages'),
|
||||
});
|
||||
|
||||
} catch (ex) {
|
||||
console.log(ex); // display error message in the console
|
||||
res.status(500); // write status parameter to the response
|
||||
res.render("error", { message: "Server error" }); // render error template with the message parameter specified
|
||||
return;
|
||||
}
|
||||
});
|
||||
// define a handler for creating a new wopi editing session
|
||||
app.get("/wopi-new", function(req, res) {
|
||||
var fileExt = req.query.fileExt; // get the file extension from the request
|
||||
|
||||
req.docManager = new docManager(req, res);
|
||||
|
||||
if (fileExt != null) { // if the file extension exists
|
||||
var fileName = req.docManager.getCorrectName("new." + fileExt)
|
||||
var redirectPath = req.docManager.getServerUrl(true) + "/wopi-action/" + encodeURIComponent(fileName) + "?action=editnew" + req.docManager.getCustomParams(); // get the redirect path
|
||||
res.redirect(redirectPath);
|
||||
return;
|
||||
}
|
||||
});
|
||||
// define a handler for getting wopi action information by its id
|
||||
app.get("/wopi-action/:id", async function(req, res) {
|
||||
try {
|
||||
req.docManager = new docManager(req, res);
|
||||
|
||||
await utils.initWopi(req.docManager);
|
||||
|
||||
var fileName = req.docManager.getCorrectName(req.params['id'])
|
||||
var fileExt = fileUtility.getFileExtension(fileName, true); // get the file extension from the request
|
||||
var user = users.getUser(req.query.userid); // get a user by the id
|
||||
|
||||
// get an action for the specified extension and name
|
||||
let action = await utils.getAction(fileExt, req.query["action"]);
|
||||
|
||||
if (action != null && req.query["action"] == "editnew") {
|
||||
fileName = req.docManager.RequestEditnew(req, fileName, user);
|
||||
}
|
||||
|
||||
// render wopiAction template with the parameters specified
|
||||
res.render("wopiAction", {
|
||||
actionUrl: utils.getActionUrl(req.docManager.getServerUrl(true), req.docManager.curUserHostAddress(), action, req.params['id']),
|
||||
token: "test",
|
||||
tokenTtl: Date.now() + 1000 * 60 * 60 * 10,
|
||||
params: req.docManager.getCustomParams(),
|
||||
});
|
||||
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
res.status(500);
|
||||
res.render("error", { message: "Server error" });
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// define a handler for getting file information by its id
|
||||
app.route('/wopi/files/:id')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
|
||||
// define a handler for reading/writing the file contents
|
||||
app.route('/wopi/files/:id/contents')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
|
||||
// define a handler for getting folder information by its id
|
||||
app.route('/wopi/folders/:id')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
|
||||
// define a handler for reading/writing the folder contents
|
||||
app.route('/wopi/folders/:id/contents')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
|
||||
// define a handler for upload files
|
||||
app.route('/wopi/upload')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
const { lang } = query; // language
|
||||
actionParams += (lang ? `&ui=${lang}` : '');
|
||||
|
||||
return { tokenParams, actionParams };
|
||||
};
|
||||
|
||||
exports.registerRoutes = function registerRoutes(app) {
|
||||
// define a handler for the default wopi page
|
||||
app.get('/wopi', async (req, res) => {
|
||||
req.DocManager = new DocManager(req, res);
|
||||
|
||||
await utils.initWopi(req.DocManager);
|
||||
|
||||
// get the wopi discovery information
|
||||
const actions = await utils.getDiscoveryInfo();
|
||||
const wopiEnable = actions.length !== 0;
|
||||
const docsExtEdit = []; // Supported extensions for WOPI
|
||||
|
||||
actions.forEach((el) => {
|
||||
if (el.name === 'edit') docsExtEdit.push(`.${el.ext}`);
|
||||
});
|
||||
|
||||
// Checking supported extensions
|
||||
const editedExts = fileUtility.getEditExtensions().filter((i) => docsExtEdit.includes(i));
|
||||
const fillExts = fileUtility.getFillExtensions().filter((i) => docsExtEdit.includes(i));
|
||||
|
||||
try {
|
||||
// get all the stored files
|
||||
const files = req.DocManager.getStoredFiles();
|
||||
|
||||
// run through all the files and write the corresponding information to each file
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const file of files) {
|
||||
const ext = fileUtility.getFileExtension(file.name, true); // get an extension of each file
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
file.actions = await utils.getActions(ext); // get actions of the specified extension
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
file.defaultAction = await utils.getDefaultAction(ext);// get the default action of the specified extension
|
||||
}
|
||||
|
||||
// render wopiIndex template with the parameters specified
|
||||
res.render('wopiIndex', {
|
||||
wopiEnable,
|
||||
storedFiles: wopiEnable ? files : [],
|
||||
params: req.DocManager.getCustomParams(),
|
||||
users,
|
||||
preloaderUrl: siteUrl + configServer.get('preloaderUrl'),
|
||||
convertExts: fileUtility.getConvertExtensions(),
|
||||
editedExts,
|
||||
fillExts,
|
||||
languages: configServer.get('languages'),
|
||||
});
|
||||
} catch (ex) {
|
||||
console.log(ex); // display error message in the console
|
||||
res.status(500); // write status parameter to the response
|
||||
// render error template with the message parameter specified
|
||||
res.render('error', { message: 'Server error' });
|
||||
}
|
||||
});
|
||||
// define a handler for creating a new wopi editing session
|
||||
app.get('/wopi-new', (req, res) => {
|
||||
const { fileExt } = req.query; // get the file extension from the request
|
||||
|
||||
req.DocManager = new DocManager(req, res);
|
||||
|
||||
if (fileExt) { // if the file extension exists
|
||||
const fileName = req.DocManager.getCorrectName(`new.${fileExt}`);
|
||||
const redirectPath = `${req.DocManager.getServerUrl(true)}/wopi-action/`
|
||||
+ `${encodeURIComponent(fileName)}?action=editnew${req.DocManager.getCustomParams()}`; // get the redirect path
|
||||
res.redirect(redirectPath);
|
||||
}
|
||||
});
|
||||
// define a handler for getting wopi action information by its id
|
||||
app.get('/wopi-action/:id', async (req, res) => {
|
||||
try {
|
||||
req.DocManager = new DocManager(req, res);
|
||||
|
||||
await utils.initWopi(req.DocManager);
|
||||
|
||||
let fileName = req.DocManager.getCorrectName(req.params.id);
|
||||
const fileExt = fileUtility.getFileExtension(fileName, true); // get the file extension from the request
|
||||
const user = users.getUser(req.query.userid); // get a user by the id
|
||||
|
||||
// get an action for the specified extension and name
|
||||
const action = await utils.getAction(fileExt, req.query.action);
|
||||
|
||||
if (action && req.query.action === 'editnew') {
|
||||
fileName = req.DocManager.requestEditnew(req, fileName, user);
|
||||
}
|
||||
|
||||
// render wopiAction template with the parameters specified
|
||||
res.render('wopiAction', {
|
||||
actionUrl: utils.getActionUrl(
|
||||
req.DocManager.getServerUrl(true),
|
||||
req.DocManager.curUserHostAddress(),
|
||||
action,
|
||||
req.params.id,
|
||||
),
|
||||
token: 'test',
|
||||
tokenTtl: Date.now() + 1000 * 60 * 60 * 10,
|
||||
params: getCustomWopiParams(req.query),
|
||||
});
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
res.status(500);
|
||||
res.render('error', { message: 'Server error' });
|
||||
}
|
||||
});
|
||||
|
||||
// define a handler for getting file information by its id
|
||||
app.route('/wopi/files/:id')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
|
||||
// define a handler for reading/writing the file contents
|
||||
app.route('/wopi/files/:id/contents')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
|
||||
// define a handler for getting folder information by its id
|
||||
app.route('/wopi/folders/:id')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
|
||||
// define a handler for reading/writing the folder contents
|
||||
app.route('/wopi/folders/:id/contents')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
|
||||
// define a handler for upload files
|
||||
app.route('/wopi/upload')
|
||||
.all(tokenValidator.isValidToken)
|
||||
.get(filesController.fileRequestHandler)
|
||||
.post(filesController.fileRequestHandler);
|
||||
};
|
||||
|
||||
@ -20,13 +20,17 @@ express - Fast, unopinionated, minimalist web framework for node. (https:/
|
||||
License: MIT
|
||||
License File: express.license
|
||||
|
||||
fast-xml-parser - Validate XML, Parse XML to JS/JSON and vice versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback. (https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/LICENSE)
|
||||
License: MIT
|
||||
License File: fast-xml-parser.license
|
||||
|
||||
formidable - A Node.js module for parsing form data, especially file uploads. (https://github.com/node-formidable/formidable/blob/master/LICENSE)
|
||||
License: MIT
|
||||
License File: formidable.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
he - a robust HTML entity encoder/decoder written in JavaScript. (https://github.com/mathiasbynens/he/blob/master/LICENSE-MIT.txt)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
License File: he.license
|
||||
|
||||
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
|
||||
License: MIT, GPL
|
||||
@ -40,9 +44,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
|
||||
License: MIT
|
||||
License File: jQuery.iframe-transport.license
|
||||
|
||||
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
|
||||
License: MIT
|
||||
License File: jQuery.license
|
||||
|
||||
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
License: OpenJS
|
||||
License File: jQuery.Migrate.license
|
||||
|
||||
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
|
||||
License: MIT
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "OnlineEditorsExampleNodeJS",
|
||||
"version": "4.1.0",
|
||||
"version": "1.6.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "OnlineEditorsExampleNodeJS",
|
||||
"version": "4.1.0",
|
||||
"version": "1.6.0",
|
||||
"license": "Apache",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
@ -14,7 +14,7 @@
|
||||
"debug": "^4.2.0",
|
||||
"ejs": "^3.1.5",
|
||||
"express": "^4.17.1",
|
||||
"fast-xml-parser": "^3.19.0",
|
||||
"fast-xml-parser": "^4.3.1",
|
||||
"formidable": "^1.2.2",
|
||||
"he": "^1.2.0",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
@ -1509,15 +1509,24 @@
|
||||
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc="
|
||||
},
|
||||
"node_modules/fast-xml-parser": {
|
||||
"version": "3.19.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.19.0.tgz",
|
||||
"integrity": "sha512-4pXwmBplsCPv8FOY1WRakF970TjNGnGnfbOnLqjlYvMiF1SR3yOHyxMR/YCXpPTOspNF5gwudqktIP4VsWkvBg==",
|
||||
"bin": {
|
||||
"xml2js": "cli.js"
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.3.1.tgz",
|
||||
"integrity": "sha512-viVv3xb8D+SiS1W4cv4tva3bni08kAkx0gQnWrykMM8nXPc1FxqZPU00dCEVjkiCg4HoXd2jC4x29Nzg/l2DAA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "paypal",
|
||||
"url": "https://paypal.me/naturalintelligence"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/NaturalIntelligence"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"strnum": "^1.0.5"
|
||||
},
|
||||
"funding": {
|
||||
"type": "paypal",
|
||||
"url": "https://paypal.me/naturalintelligence"
|
||||
"bin": {
|
||||
"fxparser": "src/cli/cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/fastq": {
|
||||
@ -3515,6 +3524,11 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/strnum": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz",
|
||||
"integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA=="
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
||||
@ -4993,9 +5007,12 @@
|
||||
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc="
|
||||
},
|
||||
"fast-xml-parser": {
|
||||
"version": "3.19.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.19.0.tgz",
|
||||
"integrity": "sha512-4pXwmBplsCPv8FOY1WRakF970TjNGnGnfbOnLqjlYvMiF1SR3yOHyxMR/YCXpPTOspNF5gwudqktIP4VsWkvBg=="
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.3.1.tgz",
|
||||
"integrity": "sha512-viVv3xb8D+SiS1W4cv4tva3bni08kAkx0gQnWrykMM8nXPc1FxqZPU00dCEVjkiCg4HoXd2jC4x29Nzg/l2DAA==",
|
||||
"requires": {
|
||||
"strnum": "^1.0.5"
|
||||
}
|
||||
},
|
||||
"fastq": {
|
||||
"version": "1.13.0",
|
||||
@ -6511,6 +6528,11 @@
|
||||
"integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==",
|
||||
"dev": true
|
||||
},
|
||||
"strnum": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz",
|
||||
"integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA=="
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "OnlineEditorsExampleNodeJS",
|
||||
"version": "4.1.0",
|
||||
"version": "1.6.0",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"start": "node ./bin/www",
|
||||
@ -22,7 +22,7 @@
|
||||
"debug": "^4.2.0",
|
||||
"ejs": "^3.1.5",
|
||||
"express": "^4.17.1",
|
||||
"fast-xml-parser": "^3.19.0",
|
||||
"fast-xml-parser": "^4.3.1",
|
||||
"formidable": "^1.2.2",
|
||||
"he": "^1.2.0",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
|
||||
@ -1,8 +1 @@
|
||||
<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 0H21.674C22.4697 0 23.2327 0.316071 23.7953 0.87868L29.1213 6.20465C29.6839 6.76726 30 7.53032 30 8.32597V37C30 38.6569 28.6569 40 27 40H3C1.34315 40 0 38.6569 0 37V3Z" fill="#3779A6"/>
|
||||
<path d="M22.9167 0L30.0001 7.08333H25.9167C24.2599 7.08333 22.9167 5.74019 22.9167 4.08333V0Z" fill="#1D5880"/>
|
||||
<path d="M6.17627 14.7059H23.8233V15.8823H6.17627V14.7059Z" fill="white"/>
|
||||
<path d="M6.17627 18.5294H23.8233V19.7059H6.17627V18.5294Z" fill="white"/>
|
||||
<path d="M6.17627 22.3529H23.8233V23.5294H6.17627V22.3529Z" fill="white"/>
|
||||
<path d="M6.17627 26.1765H23.8233V27.3529H6.17627V26.1765Z" fill="white"/>
|
||||
</svg>
|
||||
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#1E7AAA"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#000" fill-opacity=".25"/><path d="M6 15h18v1H6v-1zM6 19h18v1H6v-1zM6 23h18v1H6v-1zM6 27h18v1H6v-1z" fill="#fff"/></svg>
|
||||
|
Before Width: | Height: | Size: 738 B After Width: | Height: | Size: 387 B |
@ -1,6 +1 @@
|
||||
<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>
|
||||
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#27ABA3"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#008078"/><path fill-rule="evenodd" clip-rule="evenodd" d="M24 14H6v7h18v-7zm-.8182 5.9978H6.81818V15H23.1818v4.9978zM24 23H6v7h18v-7zm-.8182 5.9978H6.81818V24H23.1818v4.9978z" fill="#fff"/></svg>
|
||||
|
Before Width: | Height: | Size: 477 B After Width: | Height: | Size: 463 B |
@ -1,8 +1 @@
|
||||
<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="#F36700"/>
|
||||
<path d="M22.9167 0L30.0001 7.08333H25.9168C24.2599 7.08333 22.9167 5.74019 22.9167 4.08333V0Z" fill="#AB531F"/>
|
||||
<path d="M6.17627 16.1275H23.8233V17.3039H6.17627V16.1275Z" fill="white"/>
|
||||
<path d="M6.17627 28.7745L6.17627 16.1275L7.35274 16.1275L7.35274 28.7745H6.17627Z" fill="white"/>
|
||||
<path d="M23.8233 16.1275V28.7745H22.6469V16.1275L23.8233 16.1275Z" fill="white"/>
|
||||
<path d="M6.17627 27.598H23.8233V28.7745H6.17627L6.17627 27.598Z" fill="white"/>
|
||||
</svg>
|
||||
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#F36700"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#000" fill-opacity=".25"/><path stroke="#fff" stroke-opacity=".95" d="M6.5 15.5h17v12h-17z"/></svg>
|
||||
|
Before Width: | Height: | Size: 691 B After Width: | Height: | Size: 366 B |
@ -1,6 +1 @@
|
||||
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M30 7.44186L22 0H3C1.22739 0 0 0.822551 0 2.32558V37.2093C0 38.7123 1.22739 40 3 40H27C28.7726 40 30 38.7123 30 37.2093V7.44186Z" fill="#D0D5DA"/>
|
||||
<path d="M24.1042 7.27273H29.9631L22 0V5.32334C22 6.4105 22.949 7.27273 24.1042 7.27273Z" fill="#646464"/>
|
||||
<path d="M16.9562 22.3485H12.9746V17.803H10.9839L14.9654 14.1667L18.947 17.803H16.9562V22.3485Z" fill="#646464"/>
|
||||
<path d="M20.9378 23.7121C20.9378 24.1666 20.4401 24.6212 19.9424 24.6212H9.98848C9.49078 24.6212 8.99309 24.1666 8.99309 23.7121V22.3485C8.99309 21.8939 9.49078 21.4394 9.98848 21.4394H10.9839V20.0757H9.49078C8.49539 20.0757 7.5 20.9848 7.5 21.8939V24.1666C7.5 25.0757 8.61982 25.9848 9.49078 25.9848H20.4401C21.3111 25.9848 22.4309 25.0757 22.4309 24.1666V21.8939C22.4309 20.9848 21.4355 20.0757 20.4401 20.0757H18.947V21.4394H19.9424C20.4401 21.4394 20.9378 21.8939 20.9378 22.3485V23.7121Z" fill="#646464"/>
|
||||
</svg>
|
||||
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#D0D5DA"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M7.5 23c-.27614 0-.5.2239-.5.5v4c0 .2761.22386.5.5.5h15c.2761 0 .5-.2239.5-.5v-4c0-.2761-.2239-.5-.5-.5h-2c-.2761 0-.5-.2239-.5-.5s.2239-.5.5-.5h2c.8284 0 1.5.6716 1.5 1.5v4c0 .8284-.6716 1.5-1.5 1.5h-15c-.82843 0-1.5-.6716-1.5-1.5v-4c0-.8284.67157-1.5 1.5-1.5h2c.27614 0 .5.2239.5.5s-.22386.5-.5.5h-2z" fill="#646464"/><path fill-rule="evenodd" clip-rule="evenodd" d="M20 20.0001L15 14l-5 6.0001h3v4c0 .5523.4477 1 1 1h2c.5523 0 1-.4477 1-1v-4h3z" fill="#646464"/></svg>
|
||||
|
Before Width: | Height: | Size: 992 B After Width: | Height: | Size: 797 B |
@ -1,12 +1 @@
|
||||
<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="#78A73B"/>
|
||||
<path d="M22.9167 0L30.0001 7.08333H25.9168C24.2599 7.08333 22.9167 5.74019 22.9167 4.08333V0Z" fill="#5A7D2B"/>
|
||||
<path d="M6.17644 15.2941H23.8235V16.4706H6.17644V15.2941Z" fill="white"/>
|
||||
<path d="M6.17644 19.1177H23.8235V20.2941H6.17644V19.1177Z" fill="white"/>
|
||||
<path d="M6.17644 22.9412H23.8235V24.1177H6.17644V22.9412Z" fill="white"/>
|
||||
<path d="M6.17644 26.7647H23.8235V27.9412H6.17644V26.7647Z" fill="white"/>
|
||||
<path d="M5.88232 27.9412L5.88232 15.2941L7.0588 15.2941L7.0588 27.9412H5.88232Z" fill="white"/>
|
||||
<path d="M11.4706 27.9412L11.4706 15.2941L12.647 15.2941V27.9412H11.4706Z" fill="white"/>
|
||||
<path d="M17.0588 27.9412L17.0588 15.2941L18.2353 15.2941V27.9412H17.0588Z" fill="white"/>
|
||||
<path d="M22.647 27.9412V15.2941H23.8235V27.9412H22.647Z" fill="white"/>
|
||||
</svg>
|
||||
<svg width="30" height="40" viewBox="0 0 30 40" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 3c0-1.65685 1.34315-3 3-3h20l7 7v30c0 1.6569-1.3431 3-3 3H3c-1.65685 0-3-1.3431-3-3V3z" fill="#6AAA1E"/><path d="M23 0l7 7h-4c-1.6569 0-3-1.34315-3-3V0z" fill="#000" fill-opacity=".25"/><path fill-rule="evenodd" clip-rule="evenodd" d="M6 15h18v13H7.00001v-1H12v-3H7v4H6V15zm7 12h4v-3h-4v3zm5 0h5v-3h-5v3zm5-7v3h-5v-3h5zm-6 0v3h-4v-3h4zm-5 0v3H7v-3h5zm11-1v-3h-5v3h5zm-10-3h4v3h-4v-3zm-1 3v-3H7v3h5z" fill="#fff" fill-opacity=".95"/></svg>
|
||||
|
Before Width: | Height: | Size: 1004 B After Width: | Height: | Size: 545 B |
@ -0,0 +1,4 @@
|
||||
<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="M4 5C4 3.89543 4.89543 3 6 3H15C16.1046 3 17 3.89543 17 5V7H16V6H5V18H16V17H17V19C17 20.1046 16.1046 21 15 21H6C4.89543 21 4 20.1046 4 19V5ZM12 4H9V5H12V4ZM11 19.5C11 19.7761 10.7761 20 10.5 20C10.2239 20 10 19.7761 10 19.5C10 19.2239 10.2239 19 10.5 19C10.7761 19 11 19.2239 11 19.5Z" fill="#444444"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 16H14L14.6464 15.3536L12.6464 13.3536L12 14V16ZM15.3536 14.6464L21 9V8H20V7H19L13.3536 12.6464L15.3536 14.6464Z" fill="#444444"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 638 B |
@ -0,0 +1,4 @@
|
||||
<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="M4 5C4 3.89543 4.89543 3 6 3H15C16.1046 3 17 3.89543 17 5V7H16V6H5V18H16V17H17V19C17 20.1046 16.1046 21 15 21H6C4.89543 21 4 20.1046 4 19V5ZM12 4H9V5H12V4ZM11 19.5C11 19.7761 10.7761 20 10.5 20C10.2239 20 10 19.7761 10 19.5C10 19.2239 10.2239 19 10.5 19C10.7761 19 11 19.2239 11 19.5Z" fill="#444444"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M14 8C11.3252 8 8.89946 9.40288 7.10954 11.6815C6.96349 11.8682 6.96349 12.129 7.10954 12.3157C8.89946 14.5971 11.3252 16 14 16C16.6748 16 19.1005 14.5971 20.8905 12.3185C21.0365 12.1318 21.0365 11.871 20.8905 11.6843C19.1005 9.40288 16.6748 8 14 8ZM14.1955 14.9939C12.3863 15.1077 10.8923 13.6166 11.0061 11.8045C11.0995 10.3105 12.3105 9.09949 13.8045 9.00611C15.6137 8.89231 17.1077 10.3834 16.9939 12.1955C16.8976 13.6866 15.6866 14.8976 14.1955 14.9939ZM14.0641 12.998C13.4609 13.0359 12.9625 12.5392 13.0022 11.9359C13.0329 11.4373 13.4375 11.0346 13.9359 11.002C14.5391 10.9641 15.0375 11.4608 14.9978 12.0641C14.9653 12.5645 14.5607 12.9673 14.0641 12.998Z" fill="#444444"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |