Compare commits
868 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e1777e9071 | |||
| 613ccbcd94 | |||
| b9a09a2511 | |||
| 213628e400 | |||
| d6bb2bfb72 | |||
| 33bd290679 | |||
| 85ab5393fd | |||
| 98c73bb6df | |||
| 3e9d9a459f | |||
| a394c3f210 | |||
| a1a19e091a | |||
| ec030d500d | |||
| cfa74f84e7 | |||
| 97cbe7f446 | |||
| 7e4d081027 | |||
| 1e5ae92135 | |||
| 036ee6fac4 | |||
| 6028295748 | |||
| aa4cfd374d | |||
| 3303a4af84 | |||
| 37a136787b | |||
| 300ff37694 | |||
| c1d9d39dc1 | |||
| 93d6ee04d4 | |||
| ae7bf2e132 | |||
| 0020242571 | |||
| 4f796e788c | |||
| 3d192c1179 | |||
| 2f8d188d59 | |||
| 19766662f1 | |||
| 301aad3f73 | |||
| 92a8f8aa4c | |||
| 0c856a5252 | |||
| 2df6138ff1 | |||
| b2942f3f47 | |||
| 94f20c8fc2 | |||
| 5d48b93c8b | |||
| bbf2e00920 | |||
| c97361f5f4 | |||
| 7c799e8abf | |||
| d196e1dbd0 | |||
| 1679315322 | |||
| dd3a5f4a5b | |||
| 3580fb04fa | |||
| 699fdc30d9 | |||
| 704e9aa47f | |||
| d741238ccb | |||
| 9776374d17 | |||
| 2d10ddb9fa | |||
| e746a0b03f | |||
| 85cacf4239 | |||
| f138ae6ed9 | |||
| 399af4004a | |||
| d36f13e984 | |||
| 9a3699160d | |||
| 4103e7513d | |||
| ed9970b102 | |||
| afa875366e | |||
| 9696f04c64 | |||
| 40e1a1fc2c | |||
| ee1e553460 | |||
| d20ce6dd0b | |||
| 72f7909a42 | |||
| 4e1fb64868 | |||
| 85c1bfa300 | |||
| 172c78c41d | |||
| 3b08d5b485 | |||
| 832479a706 | |||
| 3b3148fa6b | |||
| b38d55f486 | |||
| 2804a490ed | |||
| 8c098def61 | |||
| e10ddb50c0 | |||
| 4df2c3e6f6 | |||
| 2f53fc78b6 | |||
| fded87654d | |||
| 08cd777f81 | |||
| 96b88353c5 | |||
| 302026feb9 | |||
| ba6d322da7 | |||
| 488563e9c1 | |||
| 130bb4c102 | |||
| 9368aebe70 | |||
| ca2843822e | |||
| bd91b4a346 | |||
| 35b951967d | |||
| 63d2cf91e9 | |||
| 263cf9e04f | |||
| 22ebecba67 | |||
| 903b48ed12 | |||
| a550291c85 | |||
| 47394fc620 | |||
| b180089b1b | |||
| a275aa5965 | |||
| 87edb2486c | |||
| 10617f3144 | |||
| 6654ad28b7 | |||
| 771d4325c2 | |||
| 1536a6d3f3 | |||
| 620726cc25 | |||
| 0eef7c0b89 | |||
| 321e40ea3f | |||
| a218b4ea4f | |||
| 9613ccd0c3 | |||
| 9493c1ad06 | |||
| e92ac1a13f | |||
| 1517b4d91e | |||
| 38cc4c043d | |||
| 05c1d727dc | |||
| 84645c7ed9 | |||
| 7c505bde7f | |||
| 9f543f1b6b | |||
| 0f7b882749 | |||
| f9f4375a40 | |||
| 12c2848cc7 | |||
| 4cfb3e2494 | |||
| 090b0a6f0d | |||
| 4502b77094 | |||
| 8f5a86206a | |||
| 340157f80d | |||
| 16b10695df | |||
| b8eb631aa3 | |||
| 5c9094fede | |||
| 4e2ca515ce | |||
| eccfbd3fbc | |||
| 8408342b5d | |||
| c47921bb25 | |||
| 03f470f04c | |||
| 5770c3b85b | |||
| c92f46b2c9 | |||
| 69eba69528 | |||
| c302d842e0 | |||
| f660220495 | |||
| 155df7bdf0 | |||
| 29055d1957 | |||
| d6ee49b880 | |||
| 248ed265c4 | |||
| a1f958ee7a | |||
| abf352b957 | |||
| 393f8e5e0c | |||
| 4dfe300ee3 | |||
| 65829094c9 | |||
| d5c3e6d6f0 | |||
| d702dd2fae | |||
| 0d855823c9 | |||
| 2dd33769d4 | |||
| 4ea9f6ecf1 | |||
| 3b0b6c4b0b | |||
| 4328fad5a3 | |||
| b26822c045 | |||
| f372282b04 | |||
| 145253ccbf | |||
| 485223a3dd | |||
| 7f75fa74e7 | |||
| 821fce1903 | |||
| ce484de61e | |||
| 35fb57718d | |||
| 35d12d7cae | |||
| 846154efe1 | |||
| 1ec7acbdfe | |||
| e384fdfcff | |||
| ed58e44d2e | |||
| f151dee339 | |||
| 61f25941e8 | |||
| 0628a14be6 | |||
| b46ae83377 | |||
| 70bc7f8edf | |||
| aff481b947 | |||
| 29ef73d307 | |||
| db205d0d9d | |||
| 57ab7edf23 | |||
| e4bd9d65cf | |||
| 17e4ddb32d | |||
| 4fd85b30f1 | |||
| 6148f29c66 | |||
| 1a3fad2d6a | |||
| 0945d3bc53 | |||
| 9a824f06c3 | |||
| eec09d79fe | |||
| 7f63d2a129 | |||
| 79b639c3e6 | |||
| efef208f53 | |||
| 27e0f755f6 | |||
| a9d7aae5d6 | |||
| 42e584a363 | |||
| 8c37ea3ec3 | |||
| 3c14fa0058 | |||
| ab94cca210 | |||
| ea62388985 | |||
| a9219efee4 | |||
| 776ed058c7 | |||
| aa3e196b8f | |||
| 52cb7270a9 | |||
| 66376afb36 | |||
| 96860be1be | |||
| 3bf61efc34 | |||
| d95549f58b | |||
| bf24e4878a | |||
| 9ae231fcef | |||
| c32acb2fcf | |||
| 770c77ee81 | |||
| aa3e4d7cf8 | |||
| 156a875f02 | |||
| cfed02bbcf | |||
| 4d3db9af73 | |||
| c1c606bc86 | |||
| f401949037 | |||
| e8dc0942e5 | |||
| 9fbafd8e79 | |||
| b9ea83a602 | |||
| 2ada5a83af | |||
| ec25599d1f | |||
| 57551610e2 | |||
| 8948b7acc1 | |||
| ccf7ff2bc9 | |||
| 39de967141 | |||
| 118cfd7166 | |||
| c2fd4ab3a5 | |||
| 70b5bee00f | |||
| de605deb1e | |||
| 116974f811 | |||
| c57f36ccca | |||
| 9def0355aa | |||
| 4e833c2061 | |||
| 5871ed7301 | |||
| 97632fdbfe | |||
| 1f8da7e63d | |||
| 76ca7c1462 | |||
| f06f444a13 | |||
| 10dfecf45c | |||
| a7b899817a | |||
| e0258003b9 | |||
| 2326eb77cd | |||
| 504d41d887 | |||
| 5a7d5e8099 | |||
| 74a1daac8c | |||
| 1f855601ea | |||
| f22c4d5c78 | |||
| ce4b216722 | |||
| 9016995d92 | |||
| 853a1db028 | |||
| 712ee30a1f | |||
| 9e5f9255d1 | |||
| 2e35441483 | |||
| 5c74f598d8 | |||
| 5d711dc47c | |||
| 9ae3057106 | |||
| b7ea154e51 | |||
| 692e6b1c82 | |||
| 528f1bac48 | |||
| 35aa2374c4 | |||
| 3eb7662aef | |||
| de4fcaee93 | |||
| 812fd3d956 | |||
| 5d3b480790 | |||
| 2f1801acae | |||
| 0404528908 | |||
| 4529b929d8 | |||
| 889decc720 | |||
| db0f1a3c46 | |||
| ef57ef91f0 | |||
| 073b72c9ed | |||
| 45a6744d4d | |||
| 4d19861a25 | |||
| f5906cacf3 | |||
| 03ba77a577 | |||
| 0fc7372781 | |||
| 6c2846980a | |||
| 0685c59bf3 | |||
| 5f629195f8 | |||
| 13eeedb620 | |||
| a076c132ca | |||
| a76e0dfe5b | |||
| 8faac20977 | |||
| b04edfa05e | |||
| 1f62bf27f8 | |||
| 1e0d1fb97a | |||
| 19d30c12d1 | |||
| 384474930c | |||
| 4cb64e0a8c | |||
| cd2a2df48d | |||
| cbf960500b | |||
| 3d434f1923 | |||
| 52022fb597 | |||
| d96940c848 | |||
| b17884681d | |||
| 78a001ac89 | |||
| 9b04fb96e6 | |||
| d23002b817 | |||
| 6282b98b03 | |||
| d75600ba14 | |||
| e6ea302319 | |||
| df005a28f8 | |||
| 15134eed60 | |||
| 7dd56a71e3 | |||
| 06d2f68ecd | |||
| 9a640b3438 | |||
| 9791607793 | |||
| ccd3c8a3f2 | |||
| 6bbadc78b0 | |||
| e1673787b4 | |||
| 1dd176dd80 | |||
| 5c59687cb8 | |||
| a24e3c46e6 | |||
| 267fecba66 | |||
| fc99d2b7a0 | |||
| 1b32fa1e34 | |||
| ce42524273 | |||
| 595fa05660 | |||
| f8a0dff526 | |||
| 06d216c7ed | |||
| f44bca30f4 | |||
| e4180b3b38 | |||
| 992a482b96 | |||
| 0ad845e0f7 | |||
| ee97213c90 | |||
| 6d919da049 | |||
| 6c615d01ad | |||
| f8870af9fe | |||
| 2fe2505a01 | |||
| e41fa353e4 | |||
| effdc44943 | |||
| fd341bdb22 | |||
| 68c794c54b | |||
| 7b3b00be23 | |||
| 41ccacc5d3 | |||
| 4ef9350ce7 | |||
| 5d08ff6c3b | |||
| 01dca62ce5 | |||
| 6ab1ecd57b | |||
| b13444895f | |||
| 771c157fe5 | |||
| b5e1076b0e | |||
| 6cc43c2420 | |||
| f365041a45 | |||
| ae9c9262f7 | |||
| 40ce515e6c | |||
| bc96af7f5f | |||
| 811c20c8fb | |||
| 4b4c22cf8a | |||
| 0524b0b153 | |||
| cd6c57b9c5 | |||
| f608f7a4d6 | |||
| 803680186b | |||
| 68a01d5f9b | |||
| 5b3a472b66 | |||
| 2a85f775e9 | |||
| a958300a58 | |||
| a8be31b177 | |||
| 6cd68ab8b0 | |||
| a589435f4f | |||
| 39b49c707e | |||
| c4bb1f771b | |||
| 28440271bb | |||
| 0ab7774e29 | |||
| 33afe9111e | |||
| d8a2e1925f | |||
| 2804f44a06 | |||
| 2165c286ae | |||
| 8cbf410faf | |||
| c521a81373 | |||
| 7ade0550c9 | |||
| 41bc2d6949 | |||
| de6e9c0e2e | |||
| 38ebc9ea41 | |||
| 8f976be998 | |||
| e5a2850105 | |||
| 85727c6d4c | |||
| 87247a23b3 | |||
| 61785364e3 | |||
| 76f688c967 | |||
| 05df3b89a1 | |||
| 4e42a34337 | |||
| 62372201e0 | |||
| 036913a828 | |||
| b2a889b9e4 | |||
| fae8338772 | |||
| 79b5d9a690 | |||
| 3e54d10981 | |||
| a1c3bfb646 | |||
| b2528c21ff | |||
| fcc9e1d81b | |||
| 3093f713ef | |||
| 4ea29d29a0 | |||
| 6b8d90d8b6 | |||
| bd3e6a5a91 | |||
| 46f4676efb | |||
| c814ac5681 | |||
| 0887399048 | |||
| f2a2bf2b23 | |||
| e2702a187b | |||
| d78a57ce47 | |||
| 10acbdd41f | |||
| 73009818f2 | |||
| fb5027becd | |||
| 86609b51fa | |||
| 44799e94fd | |||
| f14c307786 | |||
| 174624f5c1 | |||
| 5f91345d69 | |||
| 9ca975113c | |||
| 38a55857c6 | |||
| 9343d3a120 | |||
| c5656971c9 | |||
| ed55b66253 | |||
| 713ffb9506 | |||
| 9969e844ca | |||
| 0c61dca9ca | |||
| 957725fbf8 | |||
| 1f6361a9a2 | |||
| cf870971d1 | |||
| 08ac7227b5 | |||
| 88eb61c320 | |||
| 1c1dbd481a | |||
| 86b4f622ea | |||
| f854bc5838 | |||
| 489156f4a3 | |||
| 01e8b0bce8 | |||
| 9183d04e66 | |||
| 5e463e2cc9 | |||
| 6e2bff10f7 | |||
| 3e9d9a81b7 | |||
| 98e0754976 | |||
| da7870eeba | |||
| c1562f3868 | |||
| e0390cb105 | |||
| 32cd91cfb9 | |||
| 991dfccf3b | |||
| 16e012ba00 | |||
| 871618f45d | |||
| 680d321a2e | |||
| c37ff54857 | |||
| d4018d61d4 | |||
| 21a0059755 | |||
| 05f4c186f4 | |||
| 53512a6167 | |||
| 7cf7700ef7 | |||
| 216855d3a7 | |||
| 23f273e5e8 | |||
| 70949fad02 | |||
| 1f5ce8e504 | |||
| 2316d36e03 | |||
| 2b1ddc71ac | |||
| b9dac1a21a | |||
| 95fb5a3c71 | |||
| 75b43a738f | |||
| 5bd467c4c1 | |||
| 74d6dc5089 | |||
| 994a4dbb2d | |||
| 67996cc938 | |||
| f5e776c4d7 | |||
| e27fc47287 | |||
| 0ed91b89ff | |||
| 00862790a1 | |||
| ab6f39c192 | |||
| 4edc201c14 | |||
| a1a7acfe94 | |||
| 6b5a1d2130 | |||
| 85e35fdb5d | |||
| da9e13622c | |||
| 8f4dd8a57b | |||
| 78b0535063 | |||
| 6323c7aef8 | |||
| 7f0ad56d07 | |||
| e7eea3901f | |||
| 0979471e54 | |||
| 8d69051a61 | |||
| 55ca1345e1 | |||
| ad951ca842 | |||
| cb8e2e9294 | |||
| 038d65acaa | |||
| e392a89526 | |||
| d62f51665b | |||
| e42aa6fe8e | |||
| ab126563f3 | |||
| c1b9ebdae6 | |||
| d3e11c78d7 | |||
| 4ccfec8019 | |||
| bb5157637d | |||
| 456df3e535 | |||
| f0112850fa | |||
| a6a21d5dfa | |||
| 249fbbe891 | |||
| e925865767 | |||
| 28643fc2c2 | |||
| 3db10a09bb | |||
| a80a95d471 | |||
| e407d58ee9 | |||
| a6d839a766 | |||
| f3b67ab6c9 | |||
| 66f5628a27 | |||
| 4b3b5c1f40 | |||
| 3e687f3af0 | |||
| 119d3e4f6a | |||
| a21d66178e | |||
| 52967f3e47 | |||
| 29439f9d02 | |||
| bc72a4c2d1 | |||
| 3ded0e2166 | |||
| 27c10e5e5c | |||
| 816aefe72a | |||
| bff50f8e4c | |||
| be1c22815b | |||
| 08ab7ffd08 | |||
| 8709f6cf9f | |||
| 04cae95635 | |||
| 5d37b2534a | |||
| eafafdaadf | |||
| 6897b8fa58 | |||
| 16d3279d72 | |||
| 36c76c534d | |||
| 26f460be89 | |||
| b9fb13104a | |||
| 5cc411158f | |||
| ca69c93531 | |||
| 95cb7cc904 | |||
| 0a62fa46aa | |||
| 2e60410969 | |||
| a12d3a591b | |||
| 3cf7c67b6d | |||
| 2cf79f31b7 | |||
| 24cf941303 | |||
| 38cf9b5496 | |||
| b9607b32ac | |||
| 3393da2560 | |||
| 7566f94690 | |||
| ee8312fb57 | |||
| 76219704f3 | |||
| 2a43d4e88a | |||
| f0ce073a37 | |||
| 8047196394 | |||
| 3cf52b3985 | |||
| ac378e448b | |||
| daae2038f8 | |||
| a2356c6e59 | |||
| 44b91c6f07 | |||
| 144565d13e | |||
| 07fd66863d | |||
| 385a5f7c33 | |||
| 8c8c2edc66 | |||
| f7e393bded | |||
| 1df25e34b0 | |||
| ed491bad21 | |||
| 306f2d5738 | |||
| 2196cb95c0 | |||
| b4d494a5c7 | |||
| e8432f575e | |||
| eb48723c08 | |||
| 65168202b4 | |||
| dced3cf881 | |||
| 170fd6026c | |||
| 1ccaa817b3 | |||
| 65ba083720 | |||
| dba902d262 | |||
| d52c7a3afa | |||
| c63f88fb7f | |||
| 4412e0598f | |||
| eb22c1168e | |||
| 917eda356d | |||
| bc6580bbdc | |||
| 920cf622c5 | |||
| 13dcb193dc | |||
| 3afb724fed | |||
| 9662936b44 | |||
| 4780472d48 | |||
| 6f68c4504b | |||
| 28e0cdfe63 | |||
| a5003526c8 | |||
| ec3d78b509 | |||
| 4205e38605 | |||
| 8438d48c71 | |||
| 52faf5996b | |||
| 69eccc50a3 | |||
| 54cbdb236f | |||
| 34c374de1a | |||
| 113722e4ba | |||
| 3b429909f1 | |||
| f1cdf4552f | |||
| 7d320e57da | |||
| e1a598a459 | |||
| 6107842303 | |||
| 65372d2018 | |||
| 4842385ca6 | |||
| 05f55fc1ca | |||
| e8153d4b42 | |||
| 2087a659f9 | |||
| 1770336c11 | |||
| 9c177f6286 | |||
| 93a2c6d99f | |||
| 5ef76873b7 | |||
| b97c3fdb87 | |||
| 64838ad864 | |||
| 4df2ce5744 | |||
| c1f42836d9 | |||
| 0cbc9438d4 | |||
| ca6cd534d8 | |||
| f529e803ef | |||
| e5bc84badf | |||
| e2077bed59 | |||
| 9ab9d29efb | |||
| 5373a674e1 | |||
| bfaa2fafaf | |||
| d4a13a13d4 | |||
| 92c0368dd8 | |||
| 80c0426768 | |||
| 71b21289ab | |||
| fa861ff314 | |||
| 400d2dee32 | |||
| 3993dda17d | |||
| b1255efdcd | |||
| 22036c6a94 | |||
| f2df4b7d7d | |||
| 7c57bf78a1 | |||
| 8d898ff477 | |||
| a1045dbce9 | |||
| 23a07f3f7b | |||
| 458d87fef1 | |||
| 82df86d09e | |||
| 858cad2995 | |||
| c0483cf12e | |||
| 57a54cf016 | |||
| 325d8cde08 | |||
| 9e2c76c3bc | |||
| 996b161c1e | |||
| 831ef88431 | |||
| 89517e5988 | |||
| 48dbcf75a9 | |||
| a56a9bc9c5 | |||
| 918103fa29 | |||
| c9b8f5a739 | |||
| d58ff36d80 | |||
| 00d647c0ad | |||
| a27f196578 | |||
| abe82b79ce | |||
| 95230c3a23 | |||
| eade69a12c | |||
| 4f89e214ef | |||
| 2936679326 | |||
| 18a67fe1b5 | |||
| ba29c8ef6f | |||
| d253f1a020 | |||
| 03060d6ee2 | |||
| ac8ad3aae2 | |||
| 14e294efed | |||
| ec3205b372 | |||
| 45119d9a8c | |||
| 1065078f75 | |||
| 0ce904a985 | |||
| 254eec8e6a | |||
| 0e4cb4f6e1 | |||
| 9b05ac90df | |||
| f28a7fa508 | |||
| 65e95d8998 | |||
| 808b8f8e98 | |||
| 43b46a8be4 | |||
| 9bbfc71fc8 | |||
| 5d58b31f1c | |||
| e31a2238fb | |||
| 7de37bc9b7 | |||
| 13f7734751 | |||
| b4395bce99 | |||
| 7c82b08615 | |||
| 6498dbfbb7 | |||
| 74254aed4a | |||
| 8c48abf48e | |||
| 8958226604 | |||
| 005a6db230 | |||
| 4397abd8ab | |||
| e53882f555 | |||
| 5d5e61dfa1 | |||
| c5c6b70a89 | |||
| 6778a0e943 | |||
| 677e238c6d | |||
| b0bc2372fa | |||
| 6a808c7cc5 | |||
| d53543ccb1 | |||
| 88d7d54601 | |||
| 0f0c896887 | |||
| 65233c0a9a | |||
| 32e1e4788f | |||
| 181a78876b | |||
| 61d5446113 | |||
| c786569171 | |||
| d83a75e3f4 | |||
| a6f06559ea | |||
| 2084145dd3 | |||
| dd54058516 | |||
| 4056a54d44 | |||
| 191cd11741 | |||
| 800e74da67 | |||
| 237da47950 | |||
| ec12539fd0 | |||
| a537db559b | |||
| 2ba158df67 | |||
| c0c066547f | |||
| c3f59b14b9 | |||
| 1d06a8f1ad | |||
| efaf1295e9 | |||
| 4bc9cf3ad1 | |||
| 1e3851ea69 | |||
| b6d38536e3 | |||
| 9b4c678aa9 | |||
| a65775d85b | |||
| 192c7677c3 | |||
| 2a31a7b601 | |||
| 355fd7cb1d | |||
| 40efd73dfc | |||
| 31b144c76d | |||
| 31a46514cb | |||
| c8d906eb99 | |||
| 2895a1c819 | |||
| a4a5d08662 | |||
| b97c9d2165 | |||
| 5b7e8a69a5 | |||
| 9601e99e33 | |||
| d9a59f1b07 | |||
| b6a6af906a | |||
| 2c4799ce27 | |||
| b33b19849c | |||
| e398f36c57 | |||
| ee6064eee8 | |||
| 9d012c8f3c | |||
| 8888dbba0a | |||
| 6f8d5c1eb4 | |||
| 62da4a3d5c | |||
| 5cfc8e71a5 | |||
| a599760891 | |||
| 00324f668f | |||
| d4549704b9 | |||
| 0836e3d693 | |||
| 0058c3053d | |||
| 2a1a0a23a5 | |||
| 5614e3bd59 | |||
| acbda3cde1 | |||
| 0755436458 | |||
| 3daf405ae2 | |||
| 53dc3b0c03 | |||
| 371dcc5091 | |||
| 905fe54fa3 | |||
| 62c0827ff5 | |||
| d6c65ce81a | |||
| 5532b4a4d7 | |||
| 637bd3347b | |||
| bac373a818 | |||
| f0e7ea5640 | |||
| 4b981e0fad | |||
| 8fb9d861de | |||
| 199269ba3c | |||
| 0b9ec4c52c | |||
| 0e51565cc8 | |||
| 0418d35b67 | |||
| bf9d25363b | |||
| 84f00c57d1 | |||
| 7c1a5421fa | |||
| 3815bfe980 | |||
| de448c3192 | |||
| 967e2dfde6 | |||
| dd3c1eac5f | |||
| abc0a794c1 | |||
| ef628aa498 | |||
| 011bd9602d | |||
| b0745cfd82 | |||
| d1b1d9f507 | |||
| 742d545f1c | |||
| 67dec4df22 | |||
| 33f3bbb774 | |||
| 7c1df80695 | |||
| 2adbb6f74c | |||
| 79c05e8381 | |||
| 31a1591043 | |||
| 0ede2ab3ab | |||
| 43656d8e46 | |||
| b7cc2369a7 | |||
| 05a98175bf | |||
| 346a67fe1c | |||
| a22f5f2336 | |||
| 55439990c6 | |||
| 3b0f28d061 | |||
| ac3acfb4ac | |||
| d5256e9ffc | |||
| 13be46445c | |||
| c67b702425 | |||
| e01539ef16 | |||
| de4380fd34 | |||
| 5651e11ba1 | |||
| 5815602309 | |||
| a0a69dfb22 | |||
| d98132db80 | |||
| 25fe2ad802 | |||
| 48fab8ad2c | |||
| a7d8d49faf | |||
| 388acd6738 | |||
| d3c035aa39 | |||
| 12a8d00f8e | |||
| b9ea06a01a | |||
| 1e67b3c13c | |||
| 5a5c8bdac8 | |||
| 44f9d36df1 | |||
| 7d349c2de6 | |||
| 79715ec7c7 | |||
| f4d7dfb261 | |||
| c525410062 | |||
| af5b0b961b | |||
| 2f7a5cbf56 | |||
| 1506802c20 | |||
| 897ea8e11e | |||
| 858806149a | |||
| 0da9572627 | |||
| 94cc260803 | |||
| 7198b06a33 | |||
| 81006e1db8 | |||
| 0f7094a70e | |||
| a0b661fffe | |||
| 4bef91f08b | |||
| 20c17be124 | |||
| ae3344f318 | |||
| 9187e4dde9 | |||
| 89c185f819 | |||
| 09b9a37720 | |||
| 12a8bfcf2d | |||
| b2be00b125 | |||
| 914d394bd0 | |||
| 811db1be0e | |||
| cd81f042b9 | |||
| c6111fcd28 | |||
| 82ebdc023c | |||
| 7b110179a9 | |||
| afd66ce7cb | |||
| 9dac97045b | |||
| 188d4ac063 | |||
| 0fbefe2cdc | |||
| eedd5fe4e9 | |||
| 27a1a56223 | |||
| 8e3322776a | |||
| 3d4336c548 | |||
| 0c8c607aa4 | |||
| 60d6734fe2 | |||
| 8c372aa6fc | |||
| d1a74ca8e6 | |||
| c374e0af4c | |||
| 58e8569048 | |||
| 83dbf2a945 | |||
| d7d6d5f644 | |||
| 9aa9885a89 | |||
| 7fe1e083e0 | |||
| a946823554 | |||
| 3a1872c03e | |||
| 5424f9110f | |||
| a597816617 | |||
| fa7a44f6bb | |||
| dfcdcc1833 | |||
| 6345a57498 | |||
| 87457c0ed1 | |||
| 859a1fd528 | |||
| 5069aab584 | |||
| 033fde38fe | |||
| 7b2bab0f9d | |||
| a419ef5319 | |||
| f77dce9f12 | |||
| 4c2cd92f0d | |||
| dd932e1f15 | |||
| 4376810d96 | |||
| c961f4751b | |||
| 9e5ec0c9df | |||
| 112c034e27 | |||
| 664a3ddeea | |||
| 2ffd357d95 | |||
| 2bc4a13964 |
@@ -10,8 +10,8 @@ executors:
|
|||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
docker:
|
docker:
|
||||||
- image: plumeorg/plume-buildenv:v0.4.0
|
- image: plumeorg/plume-buildenv:v0.8.0
|
||||||
- image: <<#parameters.postgres>>circleci/postgres:9.6-alpine<</parameters.postgres>><<^parameters.postgres>>alpine:latest<</parameters.postgres>>
|
- image: <<#parameters.postgres>>cimg/postgres:14.2<</parameters.postgres>><<^parameters.postgres>>alpine:latest<</parameters.postgres>>
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_DB: plume
|
POSTGRES_DB: plume
|
||||||
@@ -38,7 +38,7 @@ commands:
|
|||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- v0-<< parameters.cache >>-{{ checksum "Cargo.lock" }}-{{ .Branch }}
|
- v0-<< parameters.cache >>-{{ checksum "Cargo.lock" }}-{{ .Branch }}
|
||||||
- v0-<< parameters.cache >>-{{ checksum "Cargo.lock" }}-master
|
- v0-<< parameters.cache >>-{{ checksum "Cargo.lock" }}-main
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
description: push cache
|
description: push cache
|
||||||
@@ -63,6 +63,7 @@ commands:
|
|||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
steps:
|
steps:
|
||||||
|
- run: rustup component add clippy --toolchain nightly-2022-07-19-x86_64-unknown-linux-gnu
|
||||||
- run: cargo clippy <<^parameters.no_feature>>--no-default-features --features="${FEATURES}"<</parameters.no_feature>> --release -p <<parameters.package>> -- -D warnings
|
- run: cargo clippy <<^parameters.no_feature>>--no-default-features --features="${FEATURES}"<</parameters.no_feature>> --release -p <<parameters.package>> -- -D warnings
|
||||||
|
|
||||||
run_with_coverage:
|
run_with_coverage:
|
||||||
@@ -111,6 +112,7 @@ jobs:
|
|||||||
name: default
|
name: default
|
||||||
steps:
|
steps:
|
||||||
- restore_env
|
- restore_env
|
||||||
|
- run: rustup component add rustfmt --toolchain nightly-2022-07-19-x86_64-unknown-linux-gnu
|
||||||
- run: cargo fmt --all -- --check
|
- run: cargo fmt --all -- --check
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
@@ -258,4 +260,4 @@ workflows:
|
|||||||
filters:
|
filters:
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- /^master/
|
- /^main/
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM debian:buster-20210208
|
FROM rust:1
|
||||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||||
|
|
||||||
#install native/circleci/build dependancies
|
#install native/circleci/build dependancies
|
||||||
@@ -6,19 +6,19 @@ RUN apt update &&\
|
|||||||
apt install -y --no-install-recommends git ssh tar gzip ca-certificates default-jre&&\
|
apt install -y --no-install-recommends git ssh tar gzip ca-certificates default-jre&&\
|
||||||
echo "deb [trusted=yes] https://apt.fury.io/caddy/ /" \
|
echo "deb [trusted=yes] https://apt.fury.io/caddy/ /" \
|
||||||
| tee -a /etc/apt/sources.list.d/caddy-fury.list &&\
|
| tee -a /etc/apt/sources.list.d/caddy-fury.list &&\
|
||||||
|
wget -qO - https://artifacts.crowdin.com/repo/GPG-KEY-crowdin | apt-key add - &&\
|
||||||
|
echo "deb https://artifacts.crowdin.com/repo/deb/ /" > /etc/apt/sources.list.d/crowdin.list &&\
|
||||||
apt update &&\
|
apt update &&\
|
||||||
apt install -y --no-install-recommends binutils-dev build-essential cmake curl gcc gettext git libcurl4-openssl-dev libdw-dev libelf-dev libiberty-dev libpq-dev libsqlite3-dev libssl-dev make openssl pkg-config postgresql postgresql-contrib python zlib1g-dev python3-pip zip unzip libclang-dev clang caddy&&\
|
apt install -y --no-install-recommends binutils-dev build-essential cmake curl gcc gettext git libcurl4-openssl-dev libdw-dev libelf-dev libiberty-dev libpq-dev libsqlite3-dev libssl-dev make openssl pkg-config postgresql postgresql-contrib python zlib1g-dev python3-dev python3-pip python3-setuptools zip unzip libclang-dev clang caddy crowdin3 &&\
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
#install and configure rust
|
#stick rust environment
|
||||||
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2021-01-15 -y &&\
|
COPY rust-toolchain ./
|
||||||
rustup component add rustfmt clippy &&\
|
RUN rustup component add rustfmt clippy
|
||||||
rustup component add rust-std --target wasm32-unknown-unknown
|
|
||||||
|
|
||||||
#compile some deps
|
#compile some deps
|
||||||
RUN cargo install wasm-pack &&\
|
RUN cargo install wasm-pack &&\
|
||||||
cargo install grcov &&\
|
cargo install grcov &&\
|
||||||
strip /root/.cargo/bin/* &&\
|
|
||||||
rm -fr ~/.cargo/registry
|
rm -fr ~/.cargo/registry
|
||||||
|
|
||||||
#set some compilation parametters
|
#set some compilation parametters
|
||||||
@@ -29,11 +29,3 @@ RUN pip3 install selenium
|
|||||||
|
|
||||||
#configure caddy
|
#configure caddy
|
||||||
COPY Caddyfile /Caddyfile
|
COPY Caddyfile /Caddyfile
|
||||||
|
|
||||||
#install crowdin
|
|
||||||
RUN mkdir /crowdin && cd /crowdin &&\
|
|
||||||
curl -O https://downloads.crowdin.com/cli/v2/crowdin-cli.zip &&\
|
|
||||||
unzip crowdin-cli.zip && rm crowdin-cli.zip &&\
|
|
||||||
cd * && mv crowdin-cli.jar /usr/local/bin && cd && rm -rf /crowdin &&\
|
|
||||||
/bin/echo -e '#!/bin/sh\njava -jar /usr/local/bin/crowdin-cli.jar $@' > /usr/local/bin/crowdin &&\
|
|
||||||
chmod +x /usr/local/bin/crowdin
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
nightly-2022-07-19
|
||||||
@@ -3,3 +3,5 @@ data
|
|||||||
Dockerfile
|
Dockerfile
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
.env
|
.env
|
||||||
|
target
|
||||||
|
data
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ DATABASE_URL=postgres://plume:plume@localhost/plume
|
|||||||
BASE_URL=plu.me
|
BASE_URL=plu.me
|
||||||
|
|
||||||
# Log level for each crate
|
# Log level for each crate
|
||||||
RUST_LOG=warn,html5ever=warn,hyper=warn,tantivy=warn
|
RUST_LOG=info
|
||||||
|
|
||||||
# The secret key for private cookies and CSRF protection
|
# The secret key for private cookies and CSRF protection
|
||||||
# You can generate one with `openssl rand -base64 32`
|
# You can generate one with `openssl rand -base64 32`
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: cargo
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
name: cd
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
-
|
||||||
|
name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
id: docker_build
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: plumeorg/plume:latest
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
name: cd
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*.*.*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v3
|
||||||
|
with:
|
||||||
|
images: plumeorg/plume
|
||||||
|
-
|
||||||
|
name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
id: docker_build
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
+80
-2
@@ -6,19 +6,88 @@
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Add 'My feed' to i18n timeline name (#1084)
|
||||||
|
- Bidirectional support for user page header (#1092)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Use blog title as slug (#1094, #1126, #1127)
|
||||||
|
- Bump Rust to nightly 2022-07-19 (#1119)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Malfunction while creating a blog post in Persian (#1116)
|
||||||
|
- Email block list is ignored when email sign-up (#1122)
|
||||||
|
- Bug that some Activity Sytreams properties are not parsed properly (#1129)
|
||||||
|
- Allow empty avatar for remote users (#1129)
|
||||||
|
- Percent encode blog FQN for federation interoperability (#1129)
|
||||||
|
- The same to `preferredUsername` (#1129)
|
||||||
|
|
||||||
|
## [[0.7.2]] - 2022-05-11
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Basque language (#1013)
|
||||||
|
- Unit tests for ActivityPub (#1021)
|
||||||
|
- Move to action area after liking/boosting/commenting (#1074)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Bump Rust to nightly 2022-01-26 (#1015)
|
||||||
|
- Remove "Latest articles" timeline (#1069)
|
||||||
|
- Change order of timeline tabs (#1069, #1070, #1072)
|
||||||
|
- Migrate ActivityPub-related crates from activitypub 0.1 to activitystreams 0.7 (#1022)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Add explanation of sign-up step at sign-up page when email sign-up mode (#1012)
|
||||||
|
- Add NOT NULL constraint to email_blocklist table fields (#1016)
|
||||||
|
- Don't fill empty content when switching rich editor (#1017)
|
||||||
|
- Fix accept header (#1058)
|
||||||
|
- Render 404 page instead of 500 when data is not found (#1062)
|
||||||
|
- Reuse reqwest client on broadcasting (#1059)
|
||||||
|
- Reduce broadcasting HTTP request at once to prevent them being timed out (#1068, #1071)
|
||||||
|
- Some ActivityPub data (#1021)
|
||||||
|
|
||||||
|
## [[0.7.1]] - 2022-01-12
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Introduce environment variable `MAIL_PORT` (#980)
|
||||||
|
- Introduce email sign-up feature (#636, #1002)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Some styling improvements (#976, #977, #978)
|
||||||
|
- Respond with error status code when error (#1002)
|
||||||
|
|
||||||
|
### Fiexed
|
||||||
|
|
||||||
|
- Fix comment link (#974)
|
||||||
|
- Fix a bug that prevents posting articles (#975)
|
||||||
|
- Fix a bug that notification page doesn't show (#981)
|
||||||
|
|
||||||
|
## [[0.7.0]] - 2022-01-02
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
- Allow `dir` attributes for LtoR text in RtoL document (#860)
|
- Allow `dir` attributes for LtoR text in RtoL document (#860)
|
||||||
- More translation languages (#862)
|
- More translation languages (#862)
|
||||||
- Proxy support (#829)
|
- Proxy support (#829)
|
||||||
- Riker a actor system library (#870)
|
- Riker a actor system library (#870)
|
||||||
- (request-target) and Host header in HTTP Signature (#872)
|
- (request-target) and Host header in HTTP Signature (#872)
|
||||||
|
- Default log levels for RUST_LOG (#885, #886, #919)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Upgrade some dependent crates (#858)
|
- Upgrade some dependent crates (#858)
|
||||||
- Use tracing crate (#868)
|
- Use tracing crate (#868)
|
||||||
- Update Rust version to nightly-2021-01-15 (#878)
|
- Update Rust version to nightly-2021-11-27 (#961)
|
||||||
- Upgrade Tantivy to 0.13.3 and lindera-tantivy to 0.7.1 (#878)
|
- Upgrade Tantivy to 0.13.3 and lindera-tantivy to 0.7.1 (#878)
|
||||||
- Run searcher on actor system (#870)
|
- Run searcher on actor system (#870)
|
||||||
|
- Extract a function to calculate posts' ap_url and share it with some places (#918)
|
||||||
|
- Use article title as its slug instead of capitalizing and inserting hyphens (#920)
|
||||||
|
- Sign GET requests to other instances (#957)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
@@ -26,6 +95,12 @@
|
|||||||
- Menu animation not opening on iOS (#876, #897)
|
- Menu animation not opening on iOS (#876, #897)
|
||||||
- Make actors subscribe to channel once (#913)
|
- Make actors subscribe to channel once (#913)
|
||||||
- Upsert posts and media instead of trying to insert and fail (#912)
|
- Upsert posts and media instead of trying to insert and fail (#912)
|
||||||
|
- Update post's ActivityPub id when published by update (#915)
|
||||||
|
- Calculate media URI properly even when MEDIA_UPLOAD_DIRECTORY configured (#916)
|
||||||
|
- Prevent duplicated posts in 'all' timeline (#917)
|
||||||
|
- Draw side line for blockquote on start (#933)
|
||||||
|
- Fix URIs of posts on Mastodon (#947)
|
||||||
|
- Place edit link proper position (#956, #963, #964)
|
||||||
|
|
||||||
## [[0.6.0]] - 2020-12-29
|
## [[0.6.0]] - 2020-12-29
|
||||||
|
|
||||||
@@ -206,7 +281,10 @@
|
|||||||
- Ability to create multiple blogs
|
- Ability to create multiple blogs
|
||||||
|
|
||||||
<!-- next-url -->
|
<!-- next-url -->
|
||||||
[Unreleased]: https://github.com/Plume-org/Plume/compare/0.6.0...HEAD
|
[Unreleased]: https://github.com/Plume-org/Plume/compare/0.7.2...HEAD
|
||||||
|
[[0.7.2]]: https://github.com/Plume-org/Plume/compare/0.7.1...0.7.2
|
||||||
|
[[0.7.1]]: https://github.com/Plume-org/Plume/compare/0.7.0...0.7.1
|
||||||
|
[[0.7.0]]: https://github.com/Plume-org/Plume/compare/0.6.0...0.7.0
|
||||||
[[0.6.0]]: https://github.com/Plume-org/Plume/compare/0.5.0...0.6.0
|
[[0.6.0]]: https://github.com/Plume-org/Plume/compare/0.5.0...0.6.0
|
||||||
[0.5.0]: https://github.com/Plume-org/Plume/compare/0.4.0-alpha-4...0.5.0
|
[0.5.0]: https://github.com/Plume-org/Plume/compare/0.4.0-alpha-4...0.5.0
|
||||||
[0.4.0]: https://github.com/Plume-org/Plume/compare/0.3.0-alpha-2...0.4.0-alpha-4
|
[0.4.0]: https://github.com/Plume-org/Plume/compare/0.3.0-alpha-2...0.4.0-alpha-4
|
||||||
|
|||||||
Generated
+1923
-1358
File diff suppressed because it is too large
Load Diff
+23
-28
@@ -1,38 +1,33 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["Plume contributors"]
|
authors = ["Plume contributors"]
|
||||||
name = "plume"
|
name = "plume"
|
||||||
version = "0.6.1-dev"
|
version = "0.7.3-dev"
|
||||||
repository = "https://github.com/Plume-org/Plume"
|
repository = "https://github.com/Plume-org/Plume"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
activitypub = "0.1.3"
|
atom_syndication = "0.12.0"
|
||||||
askama_escape = "0.1"
|
|
||||||
atom_syndication = "0.6"
|
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
gettext = { git = "https://github.com/Plume-org/gettext/", rev = "294c54d74c699fbc66502b480a37cc66c1daa7f3" }
|
gettext = "0.4.0"
|
||||||
gettext-macros = { git = "https://github.com/Plume-org/gettext-macros/", rev = "a7c605f7edd6bfbfbfe7778026bfefd88d82db10" }
|
gettext-macros = "0.6.1"
|
||||||
gettext-utils = { git = "https://github.com/Plume-org/gettext-macros/", rev = "a7c605f7edd6bfbfbfe7778026bfefd88d82db10" }
|
gettext-utils = "0.1.0"
|
||||||
guid-create = "0.1"
|
guid-create = "0.2"
|
||||||
heck = "0.3.0"
|
|
||||||
lettre = "0.9.2"
|
|
||||||
lettre_email = "0.9.2"
|
lettre_email = "0.9.2"
|
||||||
num_cpus = "1.10"
|
num_cpus = "1.10"
|
||||||
rocket = "0.4.6"
|
rocket = "0.4.11"
|
||||||
rocket_contrib = { version = "0.4.5", features = ["json"] }
|
rocket_contrib = { version = "0.4.11", features = ["json"] }
|
||||||
rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" }
|
rocket_i18n = "0.4.1"
|
||||||
rpassword = "4.0"
|
scheduled-thread-pool = "0.2.6"
|
||||||
scheduled-thread-pool = "0.2.2"
|
serde = "1.0.137"
|
||||||
serde = "1.0"
|
serde_json = "1.0.81"
|
||||||
serde_json = "1.0"
|
shrinkwraprs = "0.3.0"
|
||||||
shrinkwraprs = "0.2.1"
|
validator = { version = "0.15", features = ["derive"] }
|
||||||
validator = "0.8"
|
|
||||||
validator_derive = "0.8"
|
|
||||||
webfinger = "0.4.1"
|
webfinger = "0.4.1"
|
||||||
tracing = "0.1.22"
|
tracing = "0.1.35"
|
||||||
tracing-subscriber = "0.2.15"
|
tracing-subscriber = "0.3.10"
|
||||||
riker = "0.4.2"
|
riker = "0.4.2"
|
||||||
|
activitystreams = "=0.7.0-alpha.20"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "plume"
|
name = "plume"
|
||||||
@@ -44,7 +39,7 @@ version = "0.4"
|
|||||||
|
|
||||||
[dependencies.ctrlc]
|
[dependencies.ctrlc]
|
||||||
features = ["termination"]
|
features = ["termination"]
|
||||||
version = "3.1.2"
|
version = "3.2.2"
|
||||||
|
|
||||||
[dependencies.diesel]
|
[dependencies.diesel]
|
||||||
features = ["r2d2", "chrono"]
|
features = ["r2d2", "chrono"]
|
||||||
@@ -53,7 +48,7 @@ version = "1.4.5"
|
|||||||
[dependencies.multipart]
|
[dependencies.multipart]
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["server"]
|
features = ["server"]
|
||||||
version = "0.16"
|
version = "0.18"
|
||||||
|
|
||||||
[dependencies.plume-api]
|
[dependencies.plume-api]
|
||||||
path = "plume-api"
|
path = "plume-api"
|
||||||
@@ -65,12 +60,12 @@ path = "plume-common"
|
|||||||
path = "plume-models"
|
path = "plume-models"
|
||||||
|
|
||||||
[dependencies.rocket_csrf]
|
[dependencies.rocket_csrf]
|
||||||
git = "https://github.com/fdb-hiroshima/rocket_csrf"
|
git = "https://git.joinplu.me/plume/rocket_csrf"
|
||||||
rev = "29910f2829e7e590a540da3804336577b48c7b31"
|
rev = "0.1.2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
ructe = "0.13.0"
|
ructe = "0.15.0"
|
||||||
rsass = "0.9"
|
rsass = "0.26"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["postgres"]
|
default = ["postgres"]
|
||||||
|
|||||||
+3
-5
@@ -1,4 +1,4 @@
|
|||||||
FROM rust:1-buster as builder
|
FROM rust:1 as builder
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
@@ -18,17 +18,15 @@ COPY script/wasm-deps.sh .
|
|||||||
RUN chmod a+x ./wasm-deps.sh && sleep 1 && ./wasm-deps.sh
|
RUN chmod a+x ./wasm-deps.sh && sleep 1 && ./wasm-deps.sh
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY Cargo.toml Cargo.lock rust-toolchain ./
|
|
||||||
RUN cargo install wasm-pack
|
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN cargo install wasm-pack
|
||||||
RUN chmod a+x ./script/plume-front.sh && sleep 1 && ./script/plume-front.sh
|
RUN chmod a+x ./script/plume-front.sh && sleep 1 && ./script/plume-front.sh
|
||||||
RUN cargo install --path ./ --force --no-default-features --features postgres
|
RUN cargo install --path ./ --force --no-default-features --features postgres
|
||||||
RUN cargo install --path plume-cli --force --no-default-features --features postgres
|
RUN cargo install --path plume-cli --force --no-default-features --features postgres
|
||||||
RUN cargo clean
|
RUN cargo clean
|
||||||
|
|
||||||
FROM debian:buster-slim
|
FROM debian:stable-slim
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<h1 align="center">
|
<h1 align="center">
|
||||||
<img src="https://raw.githubusercontent.com/Plume-org/Plume/master/assets/icons/trwnh/feather/plumeFeather64.png" alt="Plume's logo">
|
<img src="https://raw.githubusercontent.com/Plume-org/Plume/main/assets/icons/trwnh/feather/plumeFeather64.png" alt="Plume's logo">
|
||||||
Plume
|
Plume
|
||||||
</h1>
|
</h1>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/Plume-org/Plume/"><img alt="CircleCI" src="https://img.shields.io/circleci/build/gh/Plume-org/Plume.svg"></a>
|
<a href="https://github.com/Plume-org/Plume/"><img alt="CircleCI" src="https://img.shields.io/circleci/build/gh/Plume-org/Plume.svg"></a>
|
||||||
<a href="https://codecov.io/gh/Plume-org/Plume"><img src="https://codecov.io/gh/Plume-org/Plume/branch/master/graph/badge.svg" alt="Code coverage"></a>
|
<a href="https://codecov.io/gh/Plume-org/Plume"><img src="https://codecov.io/gh/Plume-org/Plume/branch/main/graph/badge.svg" alt="Code coverage"></a>
|
||||||
<a title="Crowdin" target="_blank" href="https://crowdin.com/project/plume"><img src="https://d322cqt584bo4o.cloudfront.net/plume/localized.svg"></a>
|
<a title="Crowdin" target="_blank" href="https://crowdin.com/project/plume"><img src="https://d322cqt584bo4o.cloudfront.net/plume/localized.svg"></a>
|
||||||
<a href="https://hub.docker.com/r/plumeorg/plume"><img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/plumeorg/plume.svg"></a>
|
<a href="https://hub.docker.com/r/plumeorg/plume"><img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/plumeorg/plume.svg"></a>
|
||||||
<a href="https://liberapay.com/Plume"><img alt="Liberapay patrons" src="https://img.shields.io/liberapay/patrons/Plume.svg"></a>
|
<a href="https://liberapay.com/Plume"><img alt="Liberapay patrons" src="https://img.shields.io/liberapay/patrons/Plume.svg"></a>
|
||||||
@@ -30,7 +30,7 @@ A lot of features are still missing, but what is already here should be quite st
|
|||||||
- **Media management**: you can upload pictures to illustrate your articles, but also audio files if you host a podcast, and manage them all from Plume.
|
- **Media management**: you can upload pictures to illustrate your articles, but also audio files if you host a podcast, and manage them all from Plume.
|
||||||
- **Federation**: Plume is part of a network of interconnected websites called the Fediverse. Each of these websites (often called *instances*) have their own
|
- **Federation**: Plume is part of a network of interconnected websites called the Fediverse. Each of these websites (often called *instances*) have their own
|
||||||
rules and thematics, but they can all communicate with each other.
|
rules and thematics, but they can all communicate with each other.
|
||||||
- **Collaborative writing**: invite other people to your blogs, and write articles together.
|
- **Collaborative writing**: invite other people to your blogs, and write articles together. (Not implemented yet, but will be in 1.0)
|
||||||
|
|
||||||
## Get involved
|
## Get involved
|
||||||
|
|
||||||
@@ -53,3 +53,4 @@ As we want the various spaces related to the project (GitHub, Matrix, Loomio, et
|
|||||||
|
|
||||||
We provide various way to install Plume: from source, with pre-built binaries, with Docker or with YunoHost.
|
We provide various way to install Plume: from source, with pre-built binaries, with Docker or with YunoHost.
|
||||||
For detailed explanations, please refer to [the documentation](https://docs.joinplu.me/installation/).
|
For detailed explanations, please refer to [the documentation](https://docs.joinplu.me/installation/).
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ main article {
|
|||||||
}
|
}
|
||||||
|
|
||||||
blockquote {
|
blockquote {
|
||||||
border-left: 5px solid $gray;
|
border-inline-start: 5px solid $gray;
|
||||||
margin: 1em auto;
|
margin: 1em auto;
|
||||||
padding: 0em 2em;
|
padding: 0em 2em;
|
||||||
}
|
}
|
||||||
@@ -516,4 +516,11 @@ input:checked ~ .cw-container > .cw-text {
|
|||||||
main .article-meta > *, main .article-meta .comments, main .article-meta > .banner > * {
|
main .article-meta > *, main .article-meta .comments, main .article-meta > .banner > * {
|
||||||
margin: 0 5%;
|
margin: 0 5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bottom-bar {
|
||||||
|
align-items: center;
|
||||||
|
& > div:nth-child(2) {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ form.new-post {
|
|||||||
|
|
||||||
.button + .button {
|
.button + .button {
|
||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
|
margin-inline-start: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.split {
|
.split {
|
||||||
|
|||||||
@@ -219,15 +219,23 @@ p.error {
|
|||||||
margin: 20px;
|
margin: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cover-link {
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.cover {
|
.cover {
|
||||||
min-height: 10em;
|
min-height: 10em;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
&:hover {
|
header {
|
||||||
opacity: 0.9;
|
display: flex;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h3 {
|
h3 {
|
||||||
@@ -236,9 +244,14 @@ p.error {
|
|||||||
font-family: $playfair;
|
font-family: $playfair;
|
||||||
font-size: 1.75em;
|
font-size: 1.75em;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
line-height: 1.75;
|
line-height: 1.10;
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
a {
|
a {
|
||||||
display: block;
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
padding-block-start: 0.5em;
|
||||||
transition: color 0.1s ease-in;
|
transition: color 0.1s ease-in;
|
||||||
color: $text-color;
|
color: $text-color;
|
||||||
|
|
||||||
@@ -247,7 +260,8 @@ p.error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.controls {
|
.controls {
|
||||||
float: right;
|
flex-shrink: 0;
|
||||||
|
text-align: end;
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
@@ -261,7 +275,7 @@ p.error {
|
|||||||
font-family: $lora;
|
font-family: $lora;
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
line-height: 1.25;
|
line-height: 1.25;
|
||||||
text-align: left;
|
text-align: initial;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -465,9 +479,10 @@ figure {
|
|||||||
|
|
||||||
/// Avatars
|
/// Avatars
|
||||||
.avatar {
|
.avatar {
|
||||||
background-position: center;
|
background-position: center !important;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
border-radius: 100%;
|
border-radius: 100%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
|
||||||
&.small {
|
&.small {
|
||||||
width: 50px;
|
width: 50px;
|
||||||
@@ -492,6 +507,7 @@ figure {
|
|||||||
margin: auto $horizontal-margin 2em;
|
margin: auto $horizontal-margin 2em;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
a {
|
a {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@@ -561,14 +577,6 @@ figure {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.bottom-bar {
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
& > div {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main .article-meta .comments .comment {
|
main .article-meta .comments .comment {
|
||||||
header {
|
header {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ fn main() {
|
|||||||
.expect("compile templates");
|
.expect("compile templates");
|
||||||
|
|
||||||
compile_themes().expect("Theme compilation error");
|
compile_themes().expect("Theme compilation error");
|
||||||
recursive_copy(&Path::new("assets").join("icons"), &Path::new("static"))
|
recursive_copy(&Path::new("assets").join("icons"), Path::new("static"))
|
||||||
.expect("Couldn't copy icons");
|
.expect("Couldn't copy icons");
|
||||||
recursive_copy(&Path::new("assets").join("images"), &Path::new("static"))
|
recursive_copy(&Path::new("assets").join("images"), Path::new("static"))
|
||||||
.expect("Couldn't copy images");
|
.expect("Couldn't copy images");
|
||||||
create_dir_all(&Path::new("static").join("media")).expect("Couldn't init media directory");
|
create_dir_all(&Path::new("static").join("media")).expect("Couldn't init media directory");
|
||||||
|
|
||||||
@@ -97,12 +97,12 @@ fn compile_theme(path: &Path, out_dir: &Path) -> std::io::Result<()> {
|
|||||||
.components()
|
.components()
|
||||||
.skip_while(|c| *c != Component::Normal(OsStr::new("themes")))
|
.skip_while(|c| *c != Component::Normal(OsStr::new("themes")))
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.filter_map(|c| {
|
.map(|c| {
|
||||||
c.as_os_str()
|
c.as_os_str()
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.splitn(2, '.')
|
.split_once('.')
|
||||||
.next()
|
.map_or(c.as_os_str().to_str().unwrap_or_default(), |x| x.0)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("-");
|
.join("-");
|
||||||
@@ -120,8 +120,14 @@ fn compile_theme(path: &Path, out_dir: &Path) -> std::io::Result<()> {
|
|||||||
// compile the .scss/.sass file
|
// compile the .scss/.sass file
|
||||||
let mut out = File::create(out.join("theme.css"))?;
|
let mut out = File::create(out.join("theme.css"))?;
|
||||||
out.write_all(
|
out.write_all(
|
||||||
&rsass::compile_scss_file(path, rsass::OutputStyle::Compressed)
|
&rsass::compile_scss_path(
|
||||||
.expect("SCSS compilation error"),
|
path,
|
||||||
|
rsass::output::Format {
|
||||||
|
style: rsass::output::Style::Compressed,
|
||||||
|
..rsass::output::Format::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.expect("SCSS compilation error"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE email_signups;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE email_signups (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
email VARCHAR NOT NULL,
|
||||||
|
token VARCHAR NOT NULL,
|
||||||
|
expiration_date TIMESTAMP NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX email_signups_token ON email_signups (token);
|
||||||
|
CREATE UNIQUE INDEX email_signups_token_requests_email ON email_signups (email);
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE email_blocklist ALTER COLUMN notification_text DROP NOT NULL;
|
||||||
|
ALTER TABLE email_blocklist ALTER COLUMN notify_user DROP NOT NULL;
|
||||||
|
ALTER TABLE email_blocklist ALTER COLUMN note DROP NOT NULL;
|
||||||
|
ALTER TABLE email_blocklist ALTER COLUMN email_address DROP NOT NULL;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE email_blocklist ALTER COLUMN email_address SET NOT NULL;
|
||||||
|
ALTER TABLE email_blocklist ALTER COLUMN note SET NOT NULL;
|
||||||
|
ALTER TABLE email_blocklist ALTER COLUMN notify_user SET NOT NULL;
|
||||||
|
ALTER TABLE email_blocklist ALTER COLUMN notification_text SET NOT NULL;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE email_signups;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE email_signups (
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
email VARCHAR NOT NULL,
|
||||||
|
token VARCHAR NOT NULL,
|
||||||
|
expiration_date TIMESTAMP NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX email_signups_token ON email_signups (token);
|
||||||
|
CREATE UNIQUE INDEX email_signups_token_requests_email ON email_signups (email);
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE email_blocklist2(id INTEGER PRIMARY KEY,
|
||||||
|
email_address TEXT UNIQUE,
|
||||||
|
note TEXT,
|
||||||
|
notify_user BOOLEAN DEFAULT FALSE,
|
||||||
|
notification_text TEXT);
|
||||||
|
|
||||||
|
INSERT INTO email_blocklist2 SELECT * FROM email_blocklist;
|
||||||
|
DROP TABLE email_blocklist;
|
||||||
|
ALTER TABLE email_blocklist2 RENAME TO email_blocklist;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE email_blocklist2(id INTEGER PRIMARY KEY,
|
||||||
|
email_address TEXT UNIQUE NOT NULL,
|
||||||
|
note TEXT NOT NULL,
|
||||||
|
notify_user BOOLEAN DEFAULT FALSE NOT NULL,
|
||||||
|
notification_text TEXT NOT NULL);
|
||||||
|
|
||||||
|
INSERT INTO email_blocklist2 SELECT * FROM email_blocklist;
|
||||||
|
DROP TABLE email_blocklist;
|
||||||
|
ALTER TABLE email_blocklist2 RENAME TO email_blocklist;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "plume-api"
|
name = "plume-api"
|
||||||
version = "0.6.1-dev"
|
version = "0.7.2"
|
||||||
authors = ["Plume contributors"]
|
authors = ["Plume contributors"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = "1.0"
|
serde = "1.0.137"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pre-release-hook = ["cargo", "fmt"]
|
pre-release-hook = ["cargo", "fmt"]
|
||||||
pre-release-replacements = []
|
pre-release-replacements = []
|
||||||
|
release = false
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "plume-cli"
|
name = "plume-cli"
|
||||||
version = "0.6.1-dev"
|
version = "0.7.2"
|
||||||
authors = ["Plume contributors"]
|
authors = ["Plume contributors"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
@@ -10,8 +10,8 @@ path = "src/main.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
dotenv = "0.14"
|
dotenv = "0.15"
|
||||||
rpassword = "5.0.0"
|
rpassword = "6.0.1"
|
||||||
|
|
||||||
[dependencies.diesel]
|
[dependencies.diesel]
|
||||||
features = ["r2d2", "chrono"]
|
features = ["r2d2", "chrono"]
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pre-release-hook = ["cargo", "fmt"]
|
pre-release-hook = ["cargo", "fmt"]
|
||||||
pre-release-replacements = []
|
pre-release-replacements = []
|
||||||
|
release = false
|
||||||
|
|||||||
@@ -68,4 +68,6 @@ fn new<'a>(args: &ArgMatches<'a>, conn: &Connection) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.expect("Couldn't save instance");
|
.expect("Couldn't save instance");
|
||||||
|
Instance::cache_local(conn);
|
||||||
|
Instance::create_local_instance_user(conn).expect("Couldn't save local instance user");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,262 @@
|
|||||||
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
|
|
||||||
|
use plume_models::{blogs::Blog, instance::Instance, lists::*, users::User, Connection};
|
||||||
|
|
||||||
|
pub fn command<'a, 'b>() -> App<'a, 'b> {
|
||||||
|
SubCommand::with_name("lists")
|
||||||
|
.about("Manage lists")
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("new")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("name")
|
||||||
|
.short("n")
|
||||||
|
.long("name")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The name of this list"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("type")
|
||||||
|
.short("t")
|
||||||
|
.long("type")
|
||||||
|
.takes_value(true)
|
||||||
|
.help(
|
||||||
|
r#"The type of this list (one of "user", "blog", "word" or "prefix")"#,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("user")
|
||||||
|
.short("u")
|
||||||
|
.long("user")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Username of whom this list is for. Empty for an instance list"),
|
||||||
|
)
|
||||||
|
.about("Create a new list"),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("delete")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("name")
|
||||||
|
.short("n")
|
||||||
|
.long("name")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The name of the list to delete"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("user")
|
||||||
|
.short("u")
|
||||||
|
.long("user")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Username of whom this list was for. Empty for instance list"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("yes")
|
||||||
|
.short("y")
|
||||||
|
.long("yes")
|
||||||
|
.help("Confirm the deletion"),
|
||||||
|
)
|
||||||
|
.about("Delete a list"),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("add")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("name")
|
||||||
|
.short("n")
|
||||||
|
.long("name")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The name of the list to add an element to"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("user")
|
||||||
|
.short("u")
|
||||||
|
.long("user")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Username of whom this list is for. Empty for instance list"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("value")
|
||||||
|
.short("v")
|
||||||
|
.long("value")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The value to add"),
|
||||||
|
)
|
||||||
|
.about("Add element to a list"),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("rm")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("name")
|
||||||
|
.short("n")
|
||||||
|
.long("name")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The name of the list to remove an element from"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("user")
|
||||||
|
.short("u")
|
||||||
|
.long("user")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Username of whom this list is for. Empty for instance list"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("value")
|
||||||
|
.short("v")
|
||||||
|
.long("value")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The value to remove"),
|
||||||
|
)
|
||||||
|
.about("Remove element from list"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run<'a>(args: &ArgMatches<'a>, conn: &Connection) {
|
||||||
|
let conn = conn;
|
||||||
|
match args.subcommand() {
|
||||||
|
("new", Some(x)) => new(x, conn),
|
||||||
|
("delete", Some(x)) => delete(x, conn),
|
||||||
|
("add", Some(x)) => add(x, conn),
|
||||||
|
("rm", Some(x)) => rm(x, conn),
|
||||||
|
("", None) => command().print_help().unwrap(),
|
||||||
|
_ => println!("Unknown subcommand"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_list_identifier(args: &ArgMatches<'_>) -> (String, Option<String>) {
|
||||||
|
let name = args
|
||||||
|
.value_of("name")
|
||||||
|
.map(String::from)
|
||||||
|
.expect("No name provided for the list");
|
||||||
|
let user = args.value_of("user").map(String::from);
|
||||||
|
(name, user)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_list_type(args: &ArgMatches<'_>) -> ListType {
|
||||||
|
let typ = args
|
||||||
|
.value_of("type")
|
||||||
|
.map(String::from)
|
||||||
|
.expect("No name type for the list");
|
||||||
|
match typ.as_str() {
|
||||||
|
"user" => ListType::User,
|
||||||
|
"blog" => ListType::Blog,
|
||||||
|
"word" => ListType::Word,
|
||||||
|
"prefix" => ListType::Prefix,
|
||||||
|
_ => panic!("Invalid list type: {}", typ),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_value(args: &ArgMatches<'_>) -> String {
|
||||||
|
args.value_of("value")
|
||||||
|
.map(String::from)
|
||||||
|
.expect("No query provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolve_user(username: &str, conn: &Connection) -> User {
|
||||||
|
let instance = Instance::get_local_uncached(conn).expect("Failed to load local instance");
|
||||||
|
|
||||||
|
User::find_by_name(conn, username, instance.id).expect("User not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new(args: &ArgMatches<'_>, conn: &Connection) {
|
||||||
|
let (name, user) = get_list_identifier(args);
|
||||||
|
let typ = get_list_type(args);
|
||||||
|
|
||||||
|
let user = user.map(|user| resolve_user(&user, conn));
|
||||||
|
|
||||||
|
List::new(conn, &name, user.as_ref(), typ).expect("failed to create list");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete(args: &ArgMatches<'_>, conn: &Connection) {
|
||||||
|
let (name, user) = get_list_identifier(args);
|
||||||
|
|
||||||
|
if !args.is_present("yes") {
|
||||||
|
panic!("Warning, this operation is destructive. Add --yes to confirm you want to do it.")
|
||||||
|
}
|
||||||
|
|
||||||
|
let user = user.map(|user| resolve_user(&user, conn));
|
||||||
|
|
||||||
|
let list =
|
||||||
|
List::find_for_user_by_name(conn, user.map(|u| u.id), &name).expect("list not found");
|
||||||
|
|
||||||
|
list.delete(conn).expect("Failed to update list");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add(args: &ArgMatches<'_>, conn: &Connection) {
|
||||||
|
let (name, user) = get_list_identifier(args);
|
||||||
|
let value = get_value(args);
|
||||||
|
|
||||||
|
let user = user.map(|user| resolve_user(&user, conn));
|
||||||
|
|
||||||
|
let list =
|
||||||
|
List::find_for_user_by_name(conn, user.map(|u| u.id), &name).expect("list not found");
|
||||||
|
|
||||||
|
match list.kind() {
|
||||||
|
ListType::Blog => {
|
||||||
|
let blog_id = Blog::find_by_fqn(conn, &value).expect("unknown blog").id;
|
||||||
|
if !list.contains_blog(conn, blog_id).unwrap() {
|
||||||
|
list.add_blogs(conn, &[blog_id]).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ListType::User => {
|
||||||
|
let user_id = User::find_by_fqn(conn, &value).expect("unknown user").id;
|
||||||
|
if !list.contains_user(conn, user_id).unwrap() {
|
||||||
|
list.add_users(conn, &[user_id]).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ListType::Word => {
|
||||||
|
if !list.contains_word(conn, &value).unwrap() {
|
||||||
|
list.add_words(conn, &[&value]).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ListType::Prefix => {
|
||||||
|
if !list.contains_prefix(conn, &value).unwrap() {
|
||||||
|
list.add_prefixes(conn, &[&value]).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rm(args: &ArgMatches<'_>, conn: &Connection) {
|
||||||
|
let (name, user) = get_list_identifier(args);
|
||||||
|
let value = get_value(args);
|
||||||
|
|
||||||
|
let user = user.map(|user| resolve_user(&user, conn));
|
||||||
|
|
||||||
|
let list =
|
||||||
|
List::find_for_user_by_name(conn, user.map(|u| u.id), &name).expect("list not found");
|
||||||
|
|
||||||
|
match list.kind() {
|
||||||
|
ListType::Blog => {
|
||||||
|
let blog_id = Blog::find_by_fqn(conn, &value).expect("unknown blog").id;
|
||||||
|
let mut blogs = list.list_blogs(conn).unwrap();
|
||||||
|
if let Some(index) = blogs.iter().position(|b| b.id == blog_id) {
|
||||||
|
blogs.swap_remove(index);
|
||||||
|
let blogs = blogs.iter().map(|b| b.id).collect::<Vec<_>>();
|
||||||
|
list.set_blogs(conn, &blogs).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ListType::User => {
|
||||||
|
let user_id = User::find_by_fqn(conn, &value).expect("unknown user").id;
|
||||||
|
let mut users = list.list_users(conn).unwrap();
|
||||||
|
if let Some(index) = users.iter().position(|u| u.id == user_id) {
|
||||||
|
users.swap_remove(index);
|
||||||
|
let users = users.iter().map(|u| u.id).collect::<Vec<_>>();
|
||||||
|
list.set_users(conn, &users).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ListType::Word => {
|
||||||
|
let mut words = list.list_words(conn).unwrap();
|
||||||
|
if let Some(index) = words.iter().position(|w| *w == value) {
|
||||||
|
words.swap_remove(index);
|
||||||
|
let words = words.iter().map(String::as_str).collect::<Vec<_>>();
|
||||||
|
list.set_words(conn, &words).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ListType::Prefix => {
|
||||||
|
let mut prefixes = list.list_prefixes(conn).unwrap();
|
||||||
|
if let Some(index) = prefixes.iter().position(|p| *p == value) {
|
||||||
|
prefixes.swap_remove(index);
|
||||||
|
let prefixes = prefixes.iter().map(String::as_str).collect::<Vec<_>>();
|
||||||
|
list.set_prefixes(conn, &prefixes).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,10 @@ use plume_models::{instance::Instance, Connection as Conn, CONFIG};
|
|||||||
use std::io::{self, prelude::*};
|
use std::io::{self, prelude::*};
|
||||||
|
|
||||||
mod instance;
|
mod instance;
|
||||||
|
mod list;
|
||||||
mod migration;
|
mod migration;
|
||||||
mod search;
|
mod search;
|
||||||
|
mod timeline;
|
||||||
mod users;
|
mod users;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -16,6 +18,8 @@ fn main() {
|
|||||||
.subcommand(instance::command())
|
.subcommand(instance::command())
|
||||||
.subcommand(migration::command())
|
.subcommand(migration::command())
|
||||||
.subcommand(search::command())
|
.subcommand(search::command())
|
||||||
|
.subcommand(timeline::command())
|
||||||
|
.subcommand(list::command())
|
||||||
.subcommand(users::command());
|
.subcommand(users::command());
|
||||||
let matches = app.clone().get_matches();
|
let matches = app.clone().get_matches();
|
||||||
|
|
||||||
@@ -25,7 +29,7 @@ fn main() {
|
|||||||
e => e.map(|_| ()).unwrap(),
|
e => e.map(|_| ()).unwrap(),
|
||||||
}
|
}
|
||||||
let conn = Conn::establish(CONFIG.database_url.as_str());
|
let conn = Conn::establish(CONFIG.database_url.as_str());
|
||||||
let _ = conn.as_ref().map(|conn| Instance::cache_local(conn));
|
let _ = conn.as_ref().map(Instance::cache_local);
|
||||||
|
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
("instance", Some(args)) => {
|
("instance", Some(args)) => {
|
||||||
@@ -37,6 +41,10 @@ fn main() {
|
|||||||
("search", Some(args)) => {
|
("search", Some(args)) => {
|
||||||
search::run(args, &conn.expect("Couldn't connect to the database."))
|
search::run(args, &conn.expect("Couldn't connect to the database."))
|
||||||
}
|
}
|
||||||
|
("timeline", Some(args)) => {
|
||||||
|
timeline::run(args, &conn.expect("Couldn't connect to the database."))
|
||||||
|
}
|
||||||
|
("lists", Some(args)) => list::run(args, &conn.expect("Couldn't connect to the database.")),
|
||||||
("users", Some(args)) => {
|
("users", Some(args)) => {
|
||||||
users::run(args, &conn.expect("Couldn't connect to the database."))
|
users::run(args, &conn.expect("Couldn't connect to the database."))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,257 @@
|
|||||||
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
|
|
||||||
|
use plume_models::{instance::Instance, posts::Post, timeline::*, users::*, Connection};
|
||||||
|
|
||||||
|
pub fn command<'a, 'b>() -> App<'a, 'b> {
|
||||||
|
SubCommand::with_name("timeline")
|
||||||
|
.about("Manage public timeline")
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("new")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("name")
|
||||||
|
.short("n")
|
||||||
|
.long("name")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The name of this timeline"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("query")
|
||||||
|
.short("q")
|
||||||
|
.long("query")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The query posts in this timelines have to match"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("user")
|
||||||
|
.short("u")
|
||||||
|
.long("user")
|
||||||
|
.takes_value(true)
|
||||||
|
.help(
|
||||||
|
"Username of whom this timeline is for. Empty for an instance timeline",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("preload-count")
|
||||||
|
.short("p")
|
||||||
|
.long("preload-count")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Number of posts to try to preload in this timeline at its creation"),
|
||||||
|
)
|
||||||
|
.about("Create a new timeline"),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("delete")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("name")
|
||||||
|
.short("n")
|
||||||
|
.long("name")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The name of the timeline to delete"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("user")
|
||||||
|
.short("u")
|
||||||
|
.long("user")
|
||||||
|
.takes_value(true)
|
||||||
|
.help(
|
||||||
|
"Username of whom this timeline was for. Empty for instance timeline",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("yes")
|
||||||
|
.short("y")
|
||||||
|
.long("yes")
|
||||||
|
.help("Confirm the deletion"),
|
||||||
|
)
|
||||||
|
.about("Delete a timeline"),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("edit")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("name")
|
||||||
|
.short("n")
|
||||||
|
.long("name")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The name of the timeline to edit"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("user")
|
||||||
|
.short("u")
|
||||||
|
.long("user")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Username of whom this timeline is for. Empty for instance timeline"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("query")
|
||||||
|
.short("q")
|
||||||
|
.long("query")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The query posts in this timelines have to match"),
|
||||||
|
)
|
||||||
|
.about("Edit the query of a timeline"),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("repopulate")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("name")
|
||||||
|
.short("n")
|
||||||
|
.long("name")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("The name of the timeline to repopulate"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("user")
|
||||||
|
.short("u")
|
||||||
|
.long("user")
|
||||||
|
.takes_value(true)
|
||||||
|
.help(
|
||||||
|
"Username of whom this timeline was for. Empty for instance timeline",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("preload-count")
|
||||||
|
.short("p")
|
||||||
|
.long("preload-count")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Number of posts to try to preload in this timeline at its creation"),
|
||||||
|
)
|
||||||
|
.about("Repopulate a timeline. Run this after modifying a list the timeline depends on."),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run<'a>(args: &ArgMatches<'a>, conn: &Connection) {
|
||||||
|
let conn = conn;
|
||||||
|
match args.subcommand() {
|
||||||
|
("new", Some(x)) => new(x, conn),
|
||||||
|
("edit", Some(x)) => edit(x, conn),
|
||||||
|
("delete", Some(x)) => delete(x, conn),
|
||||||
|
("repopulate", Some(x)) => repopulate(x, conn),
|
||||||
|
("", None) => command().print_help().unwrap(),
|
||||||
|
_ => println!("Unknown subcommand"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_timeline_identifier(args: &ArgMatches<'_>) -> (String, Option<String>) {
|
||||||
|
let name = args
|
||||||
|
.value_of("name")
|
||||||
|
.map(String::from)
|
||||||
|
.expect("No name provided for the timeline");
|
||||||
|
let user = args.value_of("user").map(String::from);
|
||||||
|
(name, user)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_query(args: &ArgMatches<'_>) -> String {
|
||||||
|
let query = args
|
||||||
|
.value_of("query")
|
||||||
|
.map(String::from)
|
||||||
|
.expect("No query provided");
|
||||||
|
|
||||||
|
match TimelineQuery::parse(&query) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(QueryError::SyntaxError(start, end, message)) => panic!(
|
||||||
|
"Query parsing error between {} and {}: {}",
|
||||||
|
start, end, message
|
||||||
|
),
|
||||||
|
Err(QueryError::UnexpectedEndOfQuery) => {
|
||||||
|
panic!("Query parsing error: unexpected end of query")
|
||||||
|
}
|
||||||
|
Err(QueryError::RuntimeError(message)) => panic!("Query parsing error: {}", message),
|
||||||
|
}
|
||||||
|
|
||||||
|
query
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_preload_count(args: &ArgMatches<'_>) -> usize {
|
||||||
|
args.value_of("preload-count")
|
||||||
|
.map(|arg| arg.parse().expect("invalid preload-count"))
|
||||||
|
.unwrap_or(plume_models::ITEMS_PER_PAGE as usize)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolve_user(username: &str, conn: &Connection) -> User {
|
||||||
|
let instance = Instance::get_local_uncached(conn).expect("Failed to load local instance");
|
||||||
|
|
||||||
|
User::find_by_name(conn, username, instance.id).expect("User not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn preload(timeline: Timeline, count: usize, conn: &Connection) {
|
||||||
|
timeline.remove_all_posts(conn).unwrap();
|
||||||
|
|
||||||
|
if count == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut posts = Vec::with_capacity(count as usize);
|
||||||
|
for post in Post::list_filtered(conn, None, None, None)
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.rev()
|
||||||
|
{
|
||||||
|
if timeline.matches(conn, &post, Kind::Original).unwrap() {
|
||||||
|
posts.push(post);
|
||||||
|
if posts.len() >= count {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for post in posts.iter().rev() {
|
||||||
|
timeline.add_post(conn, post).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new(args: &ArgMatches<'_>, conn: &Connection) {
|
||||||
|
let (name, user) = get_timeline_identifier(args);
|
||||||
|
let query = get_query(args);
|
||||||
|
let preload_count = get_preload_count(args);
|
||||||
|
|
||||||
|
let user = user.map(|user| resolve_user(&user, conn));
|
||||||
|
|
||||||
|
let timeline = if let Some(user) = user {
|
||||||
|
Timeline::new_for_user(conn, user.id, name, query)
|
||||||
|
} else {
|
||||||
|
Timeline::new_for_instance(conn, name, query)
|
||||||
|
}
|
||||||
|
.expect("Failed to create new timeline");
|
||||||
|
|
||||||
|
preload(timeline, preload_count, conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn edit(args: &ArgMatches<'_>, conn: &Connection) {
|
||||||
|
let (name, user) = get_timeline_identifier(args);
|
||||||
|
let query = get_query(args);
|
||||||
|
|
||||||
|
let user = user.map(|user| resolve_user(&user, conn));
|
||||||
|
|
||||||
|
let mut timeline = Timeline::find_for_user_by_name(conn, user.map(|u| u.id), &name)
|
||||||
|
.expect("timeline not found");
|
||||||
|
|
||||||
|
timeline.query = query;
|
||||||
|
|
||||||
|
timeline.update(conn).expect("Failed to update timeline");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete(args: &ArgMatches<'_>, conn: &Connection) {
|
||||||
|
let (name, user) = get_timeline_identifier(args);
|
||||||
|
|
||||||
|
if !args.is_present("yes") {
|
||||||
|
panic!("Warning, this operation is destructive. Add --yes to confirm you want to do it.")
|
||||||
|
}
|
||||||
|
|
||||||
|
let user = user.map(|user| resolve_user(&user, conn));
|
||||||
|
|
||||||
|
let timeline = Timeline::find_for_user_by_name(conn, user.map(|u| u.id), &name)
|
||||||
|
.expect("timeline not found");
|
||||||
|
|
||||||
|
timeline.delete(conn).expect("Failed to update timeline");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn repopulate(args: &ArgMatches<'_>, conn: &Connection) {
|
||||||
|
let (name, user) = get_timeline_identifier(args);
|
||||||
|
let preload_count = get_preload_count(args);
|
||||||
|
|
||||||
|
let user = user.map(|user| resolve_user(&user, conn));
|
||||||
|
|
||||||
|
let timeline = Timeline::find_for_user_by_name(conn, user.map(|u| u.id), &name)
|
||||||
|
.expect("timeline not found");
|
||||||
|
preload(timeline, preload_count, conn);
|
||||||
|
}
|
||||||
+23
-16
@@ -1,29 +1,30 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "plume-common"
|
name = "plume-common"
|
||||||
version = "0.6.1-dev"
|
version = "0.7.2"
|
||||||
authors = ["Plume contributors"]
|
authors = ["Plume contributors"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
activitypub = "0.1.1"
|
|
||||||
activitystreams-derive = "0.1.1"
|
|
||||||
activitystreams-traits = "0.1.0"
|
|
||||||
array_tool = "1.0"
|
array_tool = "1.0"
|
||||||
base64 = "0.10"
|
base64 = "0.13"
|
||||||
heck = "0.3.0"
|
hex = "0.4"
|
||||||
hex = "0.3"
|
openssl = "0.10.40"
|
||||||
hyper = "0.12.33"
|
rocket = "0.4.11"
|
||||||
openssl = "0.10.22"
|
reqwest = { version = "0.11.11", features = ["blocking", "json", "socks"] }
|
||||||
rocket = "0.4.6"
|
serde = "1.0.137"
|
||||||
reqwest = { version = "0.9", features = ["socks"] }
|
|
||||||
serde = "1.0"
|
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0.81"
|
||||||
shrinkwraprs = "0.3.0"
|
shrinkwraprs = "0.3.0"
|
||||||
syntect = "4.5.0"
|
syntect = "4.5.0"
|
||||||
tokio = "0.1.22"
|
regex-syntax = { version = "0.6.26", default-features = false, features = ["unicode-perl"] }
|
||||||
regex-syntax = { version = "0.6.17", default-features = false, features = ["unicode-perl"] }
|
tracing = "0.1.35"
|
||||||
tracing = "0.1.22"
|
askama_escape = "0.10.3"
|
||||||
|
activitystreams = "=0.7.0-alpha.20"
|
||||||
|
activitystreams-ext = "0.1.0-alpha.2"
|
||||||
|
url = "2.2.2"
|
||||||
|
flume = "0.10.13"
|
||||||
|
tokio = { version = "1.19.2", features = ["full"] }
|
||||||
|
futures = "0.3.25"
|
||||||
|
|
||||||
[dependencies.chrono]
|
[dependencies.chrono]
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
@@ -33,3 +34,9 @@ version = "0.4"
|
|||||||
default-features = false
|
default-features = false
|
||||||
git = "https://git.joinplu.me/Plume/pulldown-cmark"
|
git = "https://git.joinplu.me/Plume/pulldown-cmark"
|
||||||
branch = "bidi-plume"
|
branch = "bidi-plume"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
assert-json-diff = "2.0.1"
|
||||||
|
once_cell = "1.12.0"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pre-release-hook = ["cargo", "fmt"]
|
pre-release-hook = ["cargo", "fmt"]
|
||||||
pre-release-replacements = []
|
pre-release-replacements = []
|
||||||
|
release = false
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use reqwest::header::{HeaderValue, ACCEPT};
|
use reqwest;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
use super::{request, sign::Signer};
|
||||||
|
|
||||||
/// Represents an ActivityPub inbox.
|
/// Represents an ActivityPub inbox.
|
||||||
///
|
///
|
||||||
/// It routes an incoming Activity through the registered handlers.
|
/// It routes an incoming Activity through the registered handlers.
|
||||||
@@ -8,9 +10,51 @@ use std::fmt::Debug;
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate activitypub;
|
/// # use activitystreams::{prelude::*, base::Base, actor::Person, activity::{Announce, Create}, object::Note, iri_string::types::IriString};
|
||||||
/// # use activitypub::{actor::Person, activity::{Announce, Create}, object::Note};
|
/// # use openssl::{hash::MessageDigest, pkey::PKey, rsa::Rsa};
|
||||||
|
/// # use once_cell::sync::Lazy;
|
||||||
/// # use plume_common::activity_pub::inbox::*;
|
/// # use plume_common::activity_pub::inbox::*;
|
||||||
|
/// # use plume_common::activity_pub::sign::{gen_keypair, Error as SignError, Result as SignResult, Signer};
|
||||||
|
/// #
|
||||||
|
/// # static MY_SIGNER: Lazy<MySigner> = Lazy::new(|| MySigner::new());
|
||||||
|
/// #
|
||||||
|
/// # struct MySigner {
|
||||||
|
/// # public_key: String,
|
||||||
|
/// # private_key: String,
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # impl MySigner {
|
||||||
|
/// # fn new() -> Self {
|
||||||
|
/// # let (pub_key, priv_key) = gen_keypair();
|
||||||
|
/// # Self {
|
||||||
|
/// # public_key: String::from_utf8(pub_key).unwrap(),
|
||||||
|
/// # private_key: String::from_utf8(priv_key).unwrap(),
|
||||||
|
/// # }
|
||||||
|
/// # }
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # impl Signer for MySigner {
|
||||||
|
/// # fn get_key_id(&self) -> String {
|
||||||
|
/// # "mysigner".into()
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # fn sign(&self, to_sign: &str) -> SignResult<Vec<u8>> {
|
||||||
|
/// # let key = PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.as_ref()).unwrap())
|
||||||
|
/// # .unwrap();
|
||||||
|
/// # let mut signer = openssl::sign::Signer::new(MessageDigest::sha256(), &key).unwrap();
|
||||||
|
/// # signer.update(to_sign.as_bytes()).unwrap();
|
||||||
|
/// # signer.sign_to_vec().map_err(|_| SignError())
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # fn verify(&self, data: &str, signature: &[u8]) -> SignResult<bool> {
|
||||||
|
/// # let key = PKey::from_rsa(Rsa::public_key_from_pem(self.public_key.as_ref()).unwrap())
|
||||||
|
/// # .unwrap();
|
||||||
|
/// # let mut verifier = openssl::sign::Verifier::new(MessageDigest::sha256(), &key).unwrap();
|
||||||
|
/// # verifier.update(data.as_bytes()).unwrap();
|
||||||
|
/// # verifier.verify(&signature).map_err(|_| SignError())
|
||||||
|
/// # }
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
/// # struct User;
|
/// # struct User;
|
||||||
/// # impl FromId<()> for User {
|
/// # impl FromId<()> for User {
|
||||||
/// # type Error = ();
|
/// # type Error = ();
|
||||||
@@ -23,6 +67,10 @@ use std::fmt::Debug;
|
|||||||
/// # fn from_activity(_: &(), obj: Person) -> Result<Self, Self::Error> {
|
/// # fn from_activity(_: &(), obj: Person) -> Result<Self, Self::Error> {
|
||||||
/// # Ok(User)
|
/// # Ok(User)
|
||||||
/// # }
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # fn get_sender() -> &'static dyn Signer {
|
||||||
|
/// # &*MY_SIGNER
|
||||||
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// # impl AsActor<&()> for User {
|
/// # impl AsActor<&()> for User {
|
||||||
/// # fn get_inbox_url(&self) -> String {
|
/// # fn get_inbox_url(&self) -> String {
|
||||||
@@ -42,6 +90,10 @@ use std::fmt::Debug;
|
|||||||
/// # fn from_activity(_: &(), obj: Note) -> Result<Self, Self::Error> {
|
/// # fn from_activity(_: &(), obj: Note) -> Result<Self, Self::Error> {
|
||||||
/// # Ok(Message)
|
/// # Ok(Message)
|
||||||
/// # }
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # fn get_sender() -> &'static dyn Signer {
|
||||||
|
/// # &*MY_SIGNER
|
||||||
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// # impl AsObject<User, Create, &()> for Message {
|
/// # impl AsObject<User, Create, &()> for Message {
|
||||||
/// # type Error = ();
|
/// # type Error = ();
|
||||||
@@ -60,12 +112,13 @@ use std::fmt::Debug;
|
|||||||
/// # }
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// # let mut act = Create::default();
|
/// # let mut person = Person::new();
|
||||||
/// # act.object_props.set_id_string(String::from("https://test.ap/activity")).unwrap();
|
/// # person.set_id("https://test.ap/actor".parse::<IriString>().unwrap());
|
||||||
/// # let mut person = Person::default();
|
/// # let mut act = Create::new(
|
||||||
/// # person.object_props.set_id_string(String::from("https://test.ap/actor")).unwrap();
|
/// # Base::retract(person).unwrap().into_generic().unwrap(),
|
||||||
/// # act.create_props.set_actor_object(person).unwrap();
|
/// # Base::retract(Note::new()).unwrap().into_generic().unwrap()
|
||||||
/// # act.create_props.set_object_object(Note::default()).unwrap();
|
/// # );
|
||||||
|
/// # act.set_id("https://test.ap/activity".parse::<IriString>().unwrap());
|
||||||
/// # let activity_json = serde_json::to_value(act).unwrap();
|
/// # let activity_json = serde_json::to_value(act).unwrap();
|
||||||
/// #
|
/// #
|
||||||
/// # let conn = ();
|
/// # let conn = ();
|
||||||
@@ -144,29 +197,29 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Registers an handler on this Inbox.
|
/// Registers an handler on this Inbox.
|
||||||
pub fn with<A, V, M>(self, proxy: Option<&reqwest::Proxy>) -> Inbox<'a, C, E, R>
|
pub fn with<A, V, M>(self, proxy: Option<&reqwest::Proxy>) -> Self
|
||||||
where
|
where
|
||||||
A: AsActor<&'a C> + FromId<C, Error = E>,
|
A: AsActor<&'a C> + FromId<C, Error = E>,
|
||||||
V: activitypub::Activity,
|
V: activitystreams::markers::Activity + serde::de::DeserializeOwned,
|
||||||
M: AsObject<A, V, &'a C, Error = E> + FromId<C, Error = E>,
|
M: AsObject<A, V, &'a C, Error = E> + FromId<C, Error = E>,
|
||||||
M::Output: Into<R>,
|
M::Output: Into<R>,
|
||||||
{
|
{
|
||||||
if let Inbox::NotHandled(ctx, mut act, e) = self {
|
if let Self::NotHandled(ctx, mut act, e) = self {
|
||||||
if serde_json::from_value::<V>(act.clone()).is_ok() {
|
if serde_json::from_value::<V>(act.clone()).is_ok() {
|
||||||
let act_clone = act.clone();
|
let act_clone = act.clone();
|
||||||
let act_id = match act_clone["id"].as_str() {
|
let act_id = match act_clone["id"].as_str() {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => return Inbox::NotHandled(ctx, act, InboxError::InvalidID),
|
None => return Self::NotHandled(ctx, act, InboxError::InvalidID),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get the actor ID
|
// Get the actor ID
|
||||||
let actor_id = match get_id(act["actor"].clone()) {
|
let actor_id = match get_id(act["actor"].clone()) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => return Inbox::NotHandled(ctx, act, InboxError::InvalidActor(None)),
|
None => return Self::NotHandled(ctx, act, InboxError::InvalidActor(None)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if Self::is_spoofed_activity(&actor_id, &act) {
|
if Self::is_spoofed_activity(&actor_id, &act) {
|
||||||
return Inbox::NotHandled(ctx, act, InboxError::InvalidObject(None));
|
return Self::NotHandled(ctx, act, InboxError::InvalidObject(None));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform this actor to a model (see FromId for details about the from_id function)
|
// Transform this actor to a model (see FromId for details about the from_id function)
|
||||||
@@ -182,14 +235,14 @@ where
|
|||||||
if let Some(json) = json {
|
if let Some(json) = json {
|
||||||
act["actor"] = json;
|
act["actor"] = json;
|
||||||
}
|
}
|
||||||
return Inbox::NotHandled(ctx, act, InboxError::InvalidActor(Some(e)));
|
return Self::NotHandled(ctx, act, InboxError::InvalidActor(Some(e)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Same logic for "object"
|
// Same logic for "object"
|
||||||
let obj_id = match get_id(act["object"].clone()) {
|
let obj_id = match get_id(act["object"].clone()) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => return Inbox::NotHandled(ctx, act, InboxError::InvalidObject(None)),
|
None => return Self::NotHandled(ctx, act, InboxError::InvalidObject(None)),
|
||||||
};
|
};
|
||||||
let obj = match M::from_id(
|
let obj = match M::from_id(
|
||||||
ctx,
|
ctx,
|
||||||
@@ -202,19 +255,19 @@ where
|
|||||||
if let Some(json) = json {
|
if let Some(json) = json {
|
||||||
act["object"] = json;
|
act["object"] = json;
|
||||||
}
|
}
|
||||||
return Inbox::NotHandled(ctx, act, InboxError::InvalidObject(Some(e)));
|
return Self::NotHandled(ctx, act, InboxError::InvalidObject(Some(e)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle the activity
|
// Handle the activity
|
||||||
match obj.activity(ctx, actor, &act_id) {
|
match obj.activity(ctx, actor, act_id) {
|
||||||
Ok(res) => Inbox::Handled(res.into()),
|
Ok(res) => Self::Handled(res.into()),
|
||||||
Err(e) => Inbox::Failed(e),
|
Err(e) => Self::Failed(e),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If the Activity type is not matching the expected one for
|
// If the Activity type is not matching the expected one for
|
||||||
// this handler, try with the next one.
|
// this handler, try with the next one.
|
||||||
Inbox::NotHandled(ctx, act, e)
|
Self::NotHandled(ctx, act, e)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self
|
self
|
||||||
@@ -280,7 +333,7 @@ pub trait FromId<C>: Sized {
|
|||||||
type Error: From<InboxError<Self::Error>> + Debug;
|
type Error: From<InboxError<Self::Error>> + Debug;
|
||||||
|
|
||||||
/// The ActivityPub object type representing Self
|
/// The ActivityPub object type representing Self
|
||||||
type Object: activitypub::Object;
|
type Object: activitystreams::markers::Object + serde::de::DeserializeOwned;
|
||||||
|
|
||||||
/// Tries to get an instance of `Self` from an ActivityPub ID.
|
/// Tries to get an instance of `Self` from an ActivityPub ID.
|
||||||
///
|
///
|
||||||
@@ -311,35 +364,16 @@ pub trait FromId<C>: Sized {
|
|||||||
id: &str,
|
id: &str,
|
||||||
proxy: Option<reqwest::Proxy>,
|
proxy: Option<reqwest::Proxy>,
|
||||||
) -> Result<Self::Object, (Option<serde_json::Value>, Self::Error)> {
|
) -> Result<Self::Object, (Option<serde_json::Value>, Self::Error)> {
|
||||||
if let Some(proxy) = proxy {
|
request::get(id, Self::get_sender(), proxy)
|
||||||
reqwest::ClientBuilder::new().proxy(proxy)
|
.map_err(|_| (None, InboxError::DerefError))
|
||||||
} else {
|
.and_then(|r| {
|
||||||
reqwest::ClientBuilder::new()
|
let json: serde_json::Value = r
|
||||||
}
|
.json()
|
||||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
.map_err(|_| (None, InboxError::InvalidObject(None)))?;
|
||||||
.build()
|
serde_json::from_value(json.clone())
|
||||||
.map_err(|_| (None, InboxError::DerefError.into()))?
|
.map_err(|_| (Some(json), InboxError::InvalidObject(None)))
|
||||||
.get(id)
|
})
|
||||||
.header(
|
.map_err(|(json, e)| (json, e.into()))
|
||||||
ACCEPT,
|
|
||||||
HeaderValue::from_str(
|
|
||||||
&super::ap_accept_header()
|
|
||||||
.into_iter()
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", "),
|
|
||||||
)
|
|
||||||
.map_err(|_| (None, InboxError::DerefError.into()))?,
|
|
||||||
)
|
|
||||||
.send()
|
|
||||||
.map_err(|_| (None, InboxError::DerefError))
|
|
||||||
.and_then(|mut r| {
|
|
||||||
let json: serde_json::Value = r
|
|
||||||
.json()
|
|
||||||
.map_err(|_| (None, InboxError::InvalidObject(None)))?;
|
|
||||||
serde_json::from_value(json.clone())
|
|
||||||
.map_err(|_| (Some(json), InboxError::InvalidObject(None)))
|
|
||||||
})
|
|
||||||
.map_err(|(json, e)| (json, e.into()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a `Self` from its ActivityPub representation
|
/// Builds a `Self` from its ActivityPub representation
|
||||||
@@ -347,6 +381,8 @@ pub trait FromId<C>: Sized {
|
|||||||
|
|
||||||
/// Tries to find a `Self` with a given ID (`id`), using `ctx` (a database)
|
/// Tries to find a `Self` with a given ID (`id`), using `ctx` (a database)
|
||||||
fn from_db(ctx: &C, id: &str) -> Result<Self, Self::Error>;
|
fn from_db(ctx: &C, id: &str) -> Result<Self, Self::Error>;
|
||||||
|
|
||||||
|
fn get_sender() -> &'static dyn Signer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Should be implemented by anything representing an ActivityPub actor.
|
/// Should be implemented by anything representing an ActivityPub actor.
|
||||||
@@ -382,9 +418,51 @@ pub trait AsActor<C> {
|
|||||||
/// representing the Note by a Message type, without any specific context.
|
/// representing the Note by a Message type, without any specific context.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate activitypub;
|
/// # use activitystreams::{prelude::*, activity::Create, actor::Person, object::Note};
|
||||||
/// # use activitypub::{activity::Create, actor::Person, object::Note};
|
|
||||||
/// # use plume_common::activity_pub::inbox::{AsActor, AsObject, FromId};
|
/// # use plume_common::activity_pub::inbox::{AsActor, AsObject, FromId};
|
||||||
|
/// # use plume_common::activity_pub::sign::{gen_keypair, Error as SignError, Result as SignResult, Signer};
|
||||||
|
/// # use openssl::{hash::MessageDigest, pkey::PKey, rsa::Rsa};
|
||||||
|
/// # use once_cell::sync::Lazy;
|
||||||
|
/// #
|
||||||
|
/// # static MY_SIGNER: Lazy<MySigner> = Lazy::new(|| MySigner::new());
|
||||||
|
/// #
|
||||||
|
/// # struct MySigner {
|
||||||
|
/// # public_key: String,
|
||||||
|
/// # private_key: String,
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # impl MySigner {
|
||||||
|
/// # fn new() -> Self {
|
||||||
|
/// # let (pub_key, priv_key) = gen_keypair();
|
||||||
|
/// # Self {
|
||||||
|
/// # public_key: String::from_utf8(pub_key).unwrap(),
|
||||||
|
/// # private_key: String::from_utf8(priv_key).unwrap(),
|
||||||
|
/// # }
|
||||||
|
/// # }
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # impl Signer for MySigner {
|
||||||
|
/// # fn get_key_id(&self) -> String {
|
||||||
|
/// # "mysigner".into()
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # fn sign(&self, to_sign: &str) -> SignResult<Vec<u8>> {
|
||||||
|
/// # let key = PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.as_ref()).unwrap())
|
||||||
|
/// # .unwrap();
|
||||||
|
/// # let mut signer = openssl::sign::Signer::new(MessageDigest::sha256(), &key).unwrap();
|
||||||
|
/// # signer.update(to_sign.as_bytes()).unwrap();
|
||||||
|
/// # signer.sign_to_vec().map_err(|_| SignError())
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # fn verify(&self, data: &str, signature: &[u8]) -> SignResult<bool> {
|
||||||
|
/// # let key = PKey::from_rsa(Rsa::public_key_from_pem(self.public_key.as_ref()).unwrap())
|
||||||
|
/// # .unwrap();
|
||||||
|
/// # let mut verifier = openssl::sign::Verifier::new(MessageDigest::sha256(), &key).unwrap();
|
||||||
|
/// # verifier.update(data.as_bytes()).unwrap();
|
||||||
|
/// # verifier.verify(&signature).map_err(|_| SignError())
|
||||||
|
/// # }
|
||||||
|
/// # }
|
||||||
|
/// #
|
||||||
/// # struct Account;
|
/// # struct Account;
|
||||||
/// # impl FromId<()> for Account {
|
/// # impl FromId<()> for Account {
|
||||||
/// # type Error = ();
|
/// # type Error = ();
|
||||||
@@ -397,6 +475,10 @@ pub trait AsActor<C> {
|
|||||||
/// # fn from_activity(_: &(), obj: Person) -> Result<Self, Self::Error> {
|
/// # fn from_activity(_: &(), obj: Person) -> Result<Self, Self::Error> {
|
||||||
/// # Ok(Account)
|
/// # Ok(Account)
|
||||||
/// # }
|
/// # }
|
||||||
|
/// #
|
||||||
|
/// # fn get_sender() -> &'static dyn Signer {
|
||||||
|
/// # &*MY_SIGNER
|
||||||
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// # impl AsActor<()> for Account {
|
/// # impl AsActor<()> for Account {
|
||||||
/// # fn get_inbox_url(&self) -> String {
|
/// # fn get_inbox_url(&self) -> String {
|
||||||
@@ -418,7 +500,14 @@ pub trait AsActor<C> {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn from_activity(_: &(), obj: Note) -> Result<Self, Self::Error> {
|
/// fn from_activity(_: &(), obj: Note) -> Result<Self, Self::Error> {
|
||||||
/// Ok(Message { text: obj.object_props.content_string().map_err(|_| ())? })
|
/// Ok(Message {
|
||||||
|
/// text: obj.content()
|
||||||
|
/// .and_then(|content| content.to_owned().single_xsd_string()).ok_or(())?
|
||||||
|
/// })
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// fn get_sender() -> &'static dyn Signer {
|
||||||
|
/// &*MY_SIGNER
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
@@ -434,7 +523,7 @@ pub trait AsActor<C> {
|
|||||||
/// ```
|
/// ```
|
||||||
pub trait AsObject<A, V, C>
|
pub trait AsObject<A, V, C>
|
||||||
where
|
where
|
||||||
V: activitypub::Activity,
|
V: activitystreams::markers::Activity,
|
||||||
{
|
{
|
||||||
/// What kind of error is returned when something fails
|
/// What kind of error is returned when something fails
|
||||||
type Error;
|
type Error;
|
||||||
@@ -459,7 +548,57 @@ where
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use activitypub::{activity::*, actor::Person, object::Note};
|
use crate::activity_pub::sign::{
|
||||||
|
gen_keypair, Error as SignError, Result as SignResult, Signer,
|
||||||
|
};
|
||||||
|
use activitystreams::{
|
||||||
|
activity::{Announce, Create, Delete, Like},
|
||||||
|
actor::Person,
|
||||||
|
base::Base,
|
||||||
|
object::Note,
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
use openssl::{hash::MessageDigest, pkey::PKey, rsa::Rsa};
|
||||||
|
|
||||||
|
static MY_SIGNER: Lazy<MySigner> = Lazy::new(MySigner::new);
|
||||||
|
|
||||||
|
struct MySigner {
|
||||||
|
public_key: String,
|
||||||
|
private_key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MySigner {
|
||||||
|
fn new() -> Self {
|
||||||
|
let (pub_key, priv_key) = gen_keypair();
|
||||||
|
Self {
|
||||||
|
public_key: String::from_utf8(pub_key).unwrap(),
|
||||||
|
private_key: String::from_utf8(priv_key).unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Signer for MySigner {
|
||||||
|
fn get_key_id(&self) -> String {
|
||||||
|
"mysigner".into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sign(&self, to_sign: &str) -> SignResult<Vec<u8>> {
|
||||||
|
let key = PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.as_ref()).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
let mut signer = openssl::sign::Signer::new(MessageDigest::sha256(), &key).unwrap();
|
||||||
|
signer.update(to_sign.as_bytes()).unwrap();
|
||||||
|
signer.sign_to_vec().map_err(|_| SignError())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify(&self, data: &str, signature: &[u8]) -> SignResult<bool> {
|
||||||
|
let key = PKey::from_rsa(Rsa::public_key_from_pem(self.public_key.as_ref()).unwrap())
|
||||||
|
.unwrap();
|
||||||
|
let mut verifier = openssl::sign::Verifier::new(MessageDigest::sha256(), &key).unwrap();
|
||||||
|
verifier.update(data.as_bytes()).unwrap();
|
||||||
|
verifier.verify(signature).map_err(|_| SignError())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct MyActor;
|
struct MyActor;
|
||||||
impl FromId<()> for MyActor {
|
impl FromId<()> for MyActor {
|
||||||
@@ -467,11 +606,15 @@ mod tests {
|
|||||||
type Object = Person;
|
type Object = Person;
|
||||||
|
|
||||||
fn from_db(_: &(), _id: &str) -> Result<Self, Self::Error> {
|
fn from_db(_: &(), _id: &str) -> Result<Self, Self::Error> {
|
||||||
Ok(MyActor)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(_: &(), _obj: Person) -> Result<Self, Self::Error> {
|
fn from_activity(_: &(), _obj: Person) -> Result<Self, Self::Error> {
|
||||||
Ok(MyActor)
|
Ok(Self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_sender() -> &'static dyn Signer {
|
||||||
|
&*MY_SIGNER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,11 +634,15 @@ mod tests {
|
|||||||
type Object = Note;
|
type Object = Note;
|
||||||
|
|
||||||
fn from_db(_: &(), _id: &str) -> Result<Self, Self::Error> {
|
fn from_db(_: &(), _id: &str) -> Result<Self, Self::Error> {
|
||||||
Ok(MyObject)
|
Ok(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(_: &(), _obj: Note) -> Result<Self, Self::Error> {
|
fn from_activity(_: &(), _obj: Note) -> Result<Self, Self::Error> {
|
||||||
Ok(MyObject)
|
Ok(Self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_sender() -> &'static dyn Signer {
|
||||||
|
&*MY_SIGNER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl AsObject<MyActor, Create, &()> for MyObject {
|
impl AsObject<MyActor, Create, &()> for MyObject {
|
||||||
@@ -539,21 +686,15 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn build_create() -> Create {
|
fn build_create() -> Create {
|
||||||
let mut act = Create::default();
|
let mut person = Person::new();
|
||||||
act.object_props
|
person.set_id("https://test.ap/actor".parse().unwrap());
|
||||||
.set_id_string(String::from("https://test.ap/activity"))
|
let mut note = Note::new();
|
||||||
.unwrap();
|
note.set_id("https://test.ap/note".parse().unwrap());
|
||||||
let mut person = Person::default();
|
let mut act = Create::new(
|
||||||
person
|
Base::retract(person).unwrap().into_generic().unwrap(),
|
||||||
.object_props
|
Base::retract(note).unwrap().into_generic().unwrap(),
|
||||||
.set_id_string(String::from("https://test.ap/actor"))
|
);
|
||||||
.unwrap();
|
act.set_id("https://test.ap/activity".parse().unwrap());
|
||||||
act.create_props.set_actor_object(person).unwrap();
|
|
||||||
let mut note = Note::default();
|
|
||||||
note.object_props
|
|
||||||
.set_id_string(String::from("https://test.ap/note"))
|
|
||||||
.unwrap();
|
|
||||||
act.create_props.set_object_object(note).unwrap();
|
|
||||||
act
|
act
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,6 +731,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct FailingActor;
|
struct FailingActor;
|
||||||
|
impl AsActor<&()> for FailingActor {
|
||||||
|
fn get_inbox_url(&self) -> String {
|
||||||
|
String::from("https://test.ap/failing-actor/inbox")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_local(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromId<()> for FailingActor {
|
impl FromId<()> for FailingActor {
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Object = Person;
|
type Object = Person;
|
||||||
@@ -598,17 +749,12 @@ mod tests {
|
|||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(_: &(), _obj: Person) -> Result<Self, Self::Error> {
|
fn from_activity(_: &(), _obj: Self::Object) -> Result<Self, Self::Error> {
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
impl AsActor<&()> for FailingActor {
|
|
||||||
fn get_inbox_url(&self) -> String {
|
|
||||||
String::from("https://test.ap/failing-actor/inbox")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_local(&self) -> bool {
|
fn get_sender() -> &'static dyn Signer {
|
||||||
false
|
&*MY_SIGNER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -636,7 +782,7 @@ mod tests {
|
|||||||
.done();
|
.done();
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
|
|
||||||
let res: Result<(), ()> = Inbox::handle(&(), act.clone())
|
let res: Result<(), ()> = Inbox::handle(&(), act)
|
||||||
.with::<FailingActor, Create, MyObject>(None)
|
.with::<FailingActor, Create, MyObject>(None)
|
||||||
.with::<MyActor, Create, MyObject>(None)
|
.with::<MyActor, Create, MyObject>(None)
|
||||||
.done();
|
.done();
|
||||||
|
|||||||
@@ -1,13 +1,27 @@
|
|||||||
use activitypub::{Activity, Link, Object};
|
use activitystreams::{
|
||||||
|
actor::{ApActor, Group, Person},
|
||||||
|
base::{AnyBase, Base, Extends},
|
||||||
|
iri_string::types::IriString,
|
||||||
|
kind,
|
||||||
|
markers::{self, Activity},
|
||||||
|
object::{ApObject, Article, Object},
|
||||||
|
primitives::{AnyString, OneOrMany},
|
||||||
|
unparsed::UnparsedMutExt,
|
||||||
|
};
|
||||||
|
use activitystreams_ext::{Ext1, Ext2, UnparsedExtension};
|
||||||
use array_tool::vec::Uniq;
|
use array_tool::vec::Uniq;
|
||||||
use reqwest::{header::HeaderValue, r#async::ClientBuilder, Url};
|
use futures::future::join_all;
|
||||||
|
use reqwest::{header::HeaderValue, ClientBuilder, RequestBuilder, Url};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
http::Status,
|
http::Status,
|
||||||
request::{FromRequest, Request},
|
request::{FromRequest, Request},
|
||||||
response::{Responder, Response},
|
response::{Responder, Response},
|
||||||
Outcome,
|
Outcome,
|
||||||
};
|
};
|
||||||
use tokio::prelude::*;
|
use tokio::{
|
||||||
|
runtime,
|
||||||
|
time::{sleep, Duration},
|
||||||
|
};
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
|
|
||||||
use self::sign::Signable;
|
use self::sign::Signable;
|
||||||
@@ -24,8 +38,8 @@ pub const AP_CONTENT_TYPE: &str =
|
|||||||
|
|
||||||
pub fn ap_accept_header() -> Vec<&'static str> {
|
pub fn ap_accept_header() -> Vec<&'static str> {
|
||||||
vec![
|
vec![
|
||||||
"application/ld+json; profile=\"https://w3.org/ns/activitystreams\"",
|
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
||||||
"application/ld+json;profile=\"https://w3.org/ns/activitystreams\"",
|
"application/ld+json;profile=\"https://www.w3.org/ns/activitystreams\"",
|
||||||
"application/activity+json",
|
"application/activity+json",
|
||||||
"application/ld+json",
|
"application/ld+json",
|
||||||
]
|
]
|
||||||
@@ -63,7 +77,7 @@ impl<T> ActivityStream<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r, O: Object> Responder<'r> for ActivityStream<O> {
|
impl<'r, O: serde::Serialize> Responder<'r> for ActivityStream<O> {
|
||||||
fn respond_to(self, request: &Request<'_>) -> Result<Response<'r>, Status> {
|
fn respond_to(self, request: &Request<'_>) -> Result<Response<'r>, Status> {
|
||||||
let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?;
|
let mut json = serde_json::to_value(&self.0).map_err(|_| Status::InternalServerError)?;
|
||||||
json["@context"] = context();
|
json["@context"] = context();
|
||||||
@@ -87,14 +101,16 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
|||||||
.map(|header| {
|
.map(|header| {
|
||||||
header
|
header
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(|ct| match ct.trim() {
|
.map(|ct| {
|
||||||
|
match ct.trim() {
|
||||||
// bool for Forward: true if found a valid Content-Type for Plume first (HTML), false otherwise
|
// bool for Forward: true if found a valid Content-Type for Plume first (HTML), false otherwise
|
||||||
"application/ld+json; profile=\"https://w3.org/ns/activitystreams\""
|
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||||
| "application/ld+json;profile=\"https://w3.org/ns/activitystreams\""
|
| "application/ld+json;profile=\"https://www.w3.org/ns/activitystreams\""
|
||||||
| "application/activity+json"
|
| "application/activity+json"
|
||||||
| "application/ld+json" => Outcome::Success(ApRequest),
|
| "application/ld+json" => Outcome::Success(ApRequest),
|
||||||
"text/html" => Outcome::Forward(true),
|
"text/html" => Outcome::Forward(true),
|
||||||
_ => Outcome::Forward(false),
|
_ => Outcome::Forward(false),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.fold(Outcome::Forward(false), |out, ct| {
|
.fold(Outcome::Forward(false), |out, ct| {
|
||||||
if out.clone().forwarded().unwrap_or_else(|| out.is_success()) {
|
if out.clone().forwarded().unwrap_or_else(|| out.is_success()) {
|
||||||
@@ -108,10 +124,11 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest {
|
|||||||
.unwrap_or(Outcome::Forward(()))
|
.unwrap_or(Outcome::Forward(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn broadcast<S, A, T, C>(sender: &S, act: A, to: Vec<T>, proxy: Option<reqwest::Proxy>)
|
pub fn broadcast<S, A, T, C>(sender: &S, act: A, to: Vec<T>, proxy: Option<reqwest::Proxy>)
|
||||||
where
|
where
|
||||||
S: sign::Signer,
|
S: sign::Signer,
|
||||||
A: Activity,
|
A: Activity + serde::Serialize,
|
||||||
T: inbox::AsActor<C>,
|
T: inbox::AsActor<C>,
|
||||||
{
|
{
|
||||||
let boxes = to
|
let boxes = to
|
||||||
@@ -130,59 +147,79 @@ where
|
|||||||
.sign(sender)
|
.sign(sender)
|
||||||
.expect("activity_pub::broadcast: signature error");
|
.expect("activity_pub::broadcast: signature error");
|
||||||
|
|
||||||
let mut rt = tokio::runtime::current_thread::Runtime::new()
|
let client = if let Some(proxy) = proxy {
|
||||||
|
ClientBuilder::new().proxy(proxy)
|
||||||
|
} else {
|
||||||
|
ClientBuilder::new()
|
||||||
|
}
|
||||||
|
.connect_timeout(std::time::Duration::from_secs(5))
|
||||||
|
.build()
|
||||||
|
.expect("Can't build client");
|
||||||
|
let rt = runtime::Builder::new_current_thread()
|
||||||
|
.enable_all()
|
||||||
|
.build()
|
||||||
.expect("Error while initializing tokio runtime for federation");
|
.expect("Error while initializing tokio runtime for federation");
|
||||||
for inbox in boxes {
|
rt.block_on(async {
|
||||||
let body = signed.to_string();
|
// TODO: should be determined dependent on database connections because
|
||||||
let mut headers = request::headers();
|
// after broadcasting, target instance sends request to this instance,
|
||||||
let url = Url::parse(&inbox);
|
// and Plume accesses database at that time.
|
||||||
if url.is_err() {
|
let capacity = 6;
|
||||||
warn!("Inbox is invalid URL: {:?}", &inbox);
|
let (tx, rx) = flume::bounded::<RequestBuilder>(capacity);
|
||||||
continue;
|
let mut handles = Vec::with_capacity(capacity);
|
||||||
|
for _ in 0..capacity {
|
||||||
|
let rx = rx.clone();
|
||||||
|
let handle = rt.spawn(async move {
|
||||||
|
while let Ok(request_builder) = rx.recv_async().await {
|
||||||
|
// After broadcasting, target instance sends request to this instance.
|
||||||
|
// Sleep here in order to reduce requests at once
|
||||||
|
sleep(Duration::from_millis(500)).await;
|
||||||
|
let _ = request_builder
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map(move |r| {
|
||||||
|
if r.status().is_success() {
|
||||||
|
debug!("Successfully sent activity to inbox ({})", &r.url());
|
||||||
|
} else {
|
||||||
|
warn!("Error while sending to inbox ({:?})", &r)
|
||||||
|
}
|
||||||
|
debug!("Response: \"{:?}\"\n", r);
|
||||||
|
})
|
||||||
|
.map_err(|e| warn!("Error while sending to inbox ({:?})", e));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
handles.push(handle);
|
||||||
}
|
}
|
||||||
let url = url.unwrap();
|
for inbox in boxes {
|
||||||
if !url.has_host() {
|
let body = signed.to_string();
|
||||||
warn!("Inbox doesn't have host: {:?}", &inbox);
|
let mut headers = request::headers();
|
||||||
continue;
|
let url = Url::parse(&inbox);
|
||||||
};
|
if url.is_err() {
|
||||||
let host_header_value = HeaderValue::from_str(&url.host_str().expect("Unreachable"));
|
warn!("Inbox is invalid URL: {:?}", &inbox);
|
||||||
if host_header_value.is_err() {
|
continue;
|
||||||
warn!("Header value is invalid: {:?}", url.host_str());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
headers.insert("Host", host_header_value.unwrap());
|
|
||||||
headers.insert("Digest", request::Digest::digest(&body));
|
|
||||||
rt.spawn(
|
|
||||||
if let Some(proxy) = proxy.clone() {
|
|
||||||
ClientBuilder::new().proxy(proxy)
|
|
||||||
} else {
|
|
||||||
ClientBuilder::new()
|
|
||||||
}
|
}
|
||||||
.connect_timeout(std::time::Duration::from_secs(5))
|
let url = url.unwrap();
|
||||||
.build()
|
if !url.has_host() {
|
||||||
.expect("Can't build client")
|
warn!("Inbox doesn't have host: {:?}", &inbox);
|
||||||
.post(&inbox)
|
continue;
|
||||||
.headers(headers.clone())
|
};
|
||||||
.header(
|
let host_header_value = HeaderValue::from_str(url.host_str().expect("Unreachable"));
|
||||||
|
if host_header_value.is_err() {
|
||||||
|
warn!("Header value is invalid: {:?}", url.host_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
headers.insert("Host", host_header_value.unwrap());
|
||||||
|
headers.insert("Digest", request::Digest::digest(&body));
|
||||||
|
headers.insert(
|
||||||
"Signature",
|
"Signature",
|
||||||
request::signature(sender, &headers, ("post", url.path(), url.query()))
|
request::signature(sender, &headers, ("post", url.path(), url.query()))
|
||||||
.expect("activity_pub::broadcast: request signature error"),
|
.expect("activity_pub::broadcast: request signature error"),
|
||||||
)
|
);
|
||||||
.body(body)
|
let request_builder = client.post(&inbox).headers(headers.clone()).body(body);
|
||||||
.send()
|
let _ = tx.send_async(request_builder).await;
|
||||||
.and_then(move |r| {
|
}
|
||||||
if r.status().is_success() {
|
drop(tx);
|
||||||
debug!("Successfully sent activity to inbox ({})", &inbox);
|
join_all(handles).await;
|
||||||
} else {
|
});
|
||||||
warn!("Error while sending to inbox ({:?})", &r)
|
|
||||||
}
|
|
||||||
r.into_body().concat2()
|
|
||||||
})
|
|
||||||
.map(move |response| debug!("Response: \"{:?}\"\n", response))
|
|
||||||
.map_err(|e| warn!("Error while sending to inbox ({:?})", e)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
rt.run().unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Shrinkwrap, Clone, Serialize, Deserialize)]
|
#[derive(Shrinkwrap, Clone, Serialize, Deserialize)]
|
||||||
@@ -204,46 +241,193 @@ pub trait IntoId {
|
|||||||
fn into_id(self) -> Id;
|
fn into_id(self) -> Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Link for Id {}
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ApSignature {
|
pub struct ApSignature {
|
||||||
#[activitystreams(concrete(PublicKey), functional)]
|
pub public_key: PublicKey,
|
||||||
pub public_key: Option<serde_json::Value>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct PublicKey {
|
pub struct PublicKey {
|
||||||
#[activitystreams(concrete(String), functional)]
|
pub id: IriString,
|
||||||
pub id: Option<serde_json::Value>,
|
pub owner: IriString,
|
||||||
|
pub public_key_pem: String,
|
||||||
#[activitystreams(concrete(String), functional)]
|
|
||||||
pub owner: Option<serde_json::Value>,
|
|
||||||
|
|
||||||
#[activitystreams(concrete(String), functional)]
|
|
||||||
pub public_key_pem: Option<serde_json::Value>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, UnitString)]
|
impl<U> UnparsedExtension<U> for ApSignature
|
||||||
#[activitystreams(Hashtag)]
|
where
|
||||||
pub struct HashtagType;
|
U: UnparsedMutExt,
|
||||||
|
{
|
||||||
|
type Error = serde_json::Error;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
||||||
|
Ok(ApSignature {
|
||||||
|
public_key: unparsed_mut.remove("publicKey")?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
|
||||||
|
unparsed_mut.insert("publicKey", self.public_key)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Hashtag {
|
pub struct SourceProperty {
|
||||||
#[serde(rename = "type")]
|
pub source: Source,
|
||||||
kind: HashtagType,
|
|
||||||
|
|
||||||
#[activitystreams(concrete(String), functional)]
|
|
||||||
pub href: Option<serde_json::Value>,
|
|
||||||
|
|
||||||
#[activitystreams(concrete(String), functional)]
|
|
||||||
pub name: Option<serde_json::Value>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
impl<U> UnparsedExtension<U> for SourceProperty
|
||||||
|
where
|
||||||
|
U: UnparsedMutExt,
|
||||||
|
{
|
||||||
|
type Error = serde_json::Error;
|
||||||
|
|
||||||
|
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
||||||
|
Ok(SourceProperty {
|
||||||
|
source: unparsed_mut.remove("source")?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
|
||||||
|
unparsed_mut.insert("source", self.source)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type CustomPerson = Ext1<ApActor<Person>, ApSignature>;
|
||||||
|
pub type CustomGroup = Ext2<ApActor<Group>, ApSignature, SourceProperty>;
|
||||||
|
|
||||||
|
kind!(HashtagType, Hashtag);
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Hashtag {
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub href: Option<IriString>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub name: Option<AnyString>,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
inner: Object<HashtagType>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Hashtag {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
href: None,
|
||||||
|
name: None,
|
||||||
|
inner: Object::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extending(mut inner: Object<HashtagType>) -> Result<Self, serde_json::Error> {
|
||||||
|
let href = inner.remove("href")?;
|
||||||
|
let name = inner.remove("name")?;
|
||||||
|
|
||||||
|
Ok(Self { href, name, inner })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn retracting(self) -> Result<Object<HashtagType>, serde_json::Error> {
|
||||||
|
let Self {
|
||||||
|
href,
|
||||||
|
name,
|
||||||
|
mut inner,
|
||||||
|
} = self;
|
||||||
|
|
||||||
|
inner.insert("href", href)?;
|
||||||
|
inner.insert("name", name)?;
|
||||||
|
Ok(inner)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait AsHashtag: markers::Object {
|
||||||
|
fn hashtag_ref(&self) -> &Hashtag;
|
||||||
|
|
||||||
|
fn hashtag_mut(&mut self) -> &mut Hashtag;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait HashtagExt: AsHashtag {
|
||||||
|
fn href(&self) -> Option<&IriString> {
|
||||||
|
self.hashtag_ref().href.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_href<T>(&mut self, href: T) -> &mut Self
|
||||||
|
where
|
||||||
|
T: Into<IriString>,
|
||||||
|
{
|
||||||
|
self.hashtag_mut().href = Some(href.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn take_href(&mut self) -> Option<IriString> {
|
||||||
|
self.hashtag_mut().href.take()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_href(&mut self) -> &mut Self {
|
||||||
|
self.hashtag_mut().href = None;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name(&self) -> Option<&AnyString> {
|
||||||
|
self.hashtag_ref().name.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_name<T>(&mut self, name: T) -> &mut Self
|
||||||
|
where
|
||||||
|
T: Into<AnyString>,
|
||||||
|
{
|
||||||
|
self.hashtag_mut().name = Some(name.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn take_name(&mut self) -> Option<AnyString> {
|
||||||
|
self.hashtag_mut().name.take()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_name(&mut self) -> &mut Self {
|
||||||
|
self.hashtag_mut().name = None;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Hashtag {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsHashtag for Hashtag {
|
||||||
|
fn hashtag_ref(&self) -> &Self {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hashtag_mut(&mut self) -> &mut Self {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Extends<HashtagType> for Hashtag {
|
||||||
|
type Error = serde_json::Error;
|
||||||
|
|
||||||
|
fn extends(base: Base<HashtagType>) -> Result<Self, Self::Error> {
|
||||||
|
let inner = Object::extends(base)?;
|
||||||
|
Self::extending(inner)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn retracts(self) -> Result<Base<HashtagType>, Self::Error> {
|
||||||
|
let inner = self.retracting()?;
|
||||||
|
inner.retracts()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl markers::Base for Hashtag {}
|
||||||
|
impl markers::Object for Hashtag {}
|
||||||
|
impl<T> HashtagExt for T where T: AsHashtag {}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Source {
|
pub struct Source {
|
||||||
pub media_type: String,
|
pub media_type: String,
|
||||||
@@ -251,13 +435,366 @@ pub struct Source {
|
|||||||
pub content: String,
|
pub content: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Source {}
|
impl<U> UnparsedExtension<U> for Source
|
||||||
|
where
|
||||||
|
U: UnparsedMutExt,
|
||||||
|
{
|
||||||
|
type Error = serde_json::Error;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
|
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
||||||
#[serde(rename_all = "camelCase")]
|
Ok(Source {
|
||||||
pub struct Licensed {
|
content: unparsed_mut.remove("content")?,
|
||||||
#[activitystreams(concrete(String), functional)]
|
media_type: unparsed_mut.remove("mediaType")?,
|
||||||
pub license: Option<serde_json::Value>,
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
|
||||||
|
unparsed_mut.insert("content", self.content)?;
|
||||||
|
unparsed_mut.insert("mediaType", self.media_type)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Licensed {}
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Licensed {
|
||||||
|
pub license: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<U> UnparsedExtension<U> for Licensed
|
||||||
|
where
|
||||||
|
U: UnparsedMutExt,
|
||||||
|
{
|
||||||
|
type Error = serde_json::Error;
|
||||||
|
|
||||||
|
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
||||||
|
Ok(Licensed {
|
||||||
|
license: unparsed_mut.remove("license")?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
|
||||||
|
unparsed_mut.insert("license", self.license)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type LicensedArticle = Ext1<ApObject<Article>, Licensed>;
|
||||||
|
|
||||||
|
pub trait ToAsString {
|
||||||
|
fn to_as_string(&self) -> Option<String>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToAsString for OneOrMany<&AnyString> {
|
||||||
|
fn to_as_string(&self) -> Option<String> {
|
||||||
|
self.as_as_str().map(|s| s.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait AsAsStr {
|
||||||
|
fn as_as_str(&self) -> Option<&str>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsAsStr for OneOrMany<&AnyString> {
|
||||||
|
fn as_as_str(&self) -> Option<&str> {
|
||||||
|
self.iter().next().map(|prop| prop.as_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait ToAsUri {
|
||||||
|
fn to_as_uri(&self) -> Option<String>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToAsUri for OneOrMany<AnyBase> {
|
||||||
|
fn to_as_uri(&self) -> Option<String> {
|
||||||
|
self.iter()
|
||||||
|
.next()
|
||||||
|
.and_then(|prop| prop.as_xsd_any_uri().map(|uri| uri.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use activitystreams::{
|
||||||
|
activity::{ActorAndObjectRef, Create},
|
||||||
|
object::{kind::ArticleType, Image},
|
||||||
|
prelude::{ApActorExt, BaseExt, ExtendsExt, ObjectExt},
|
||||||
|
};
|
||||||
|
use assert_json_diff::assert_json_eq;
|
||||||
|
use serde_json::{from_str, json, to_value};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn se_ap_signature() {
|
||||||
|
let ap_signature = ApSignature {
|
||||||
|
public_key: PublicKey {
|
||||||
|
id: "https://example.com/pubkey".parse().unwrap(),
|
||||||
|
owner: "https://example.com/owner".parse().unwrap(),
|
||||||
|
public_key_pem: "pubKeyPem".into(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let expected = json!({
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://example.com/pubkey",
|
||||||
|
"owner": "https://example.com/owner",
|
||||||
|
"publicKeyPem": "pubKeyPem"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert_json_eq!(to_value(ap_signature).unwrap(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn de_ap_signature() {
|
||||||
|
let value: ApSignature = from_str(
|
||||||
|
r#"
|
||||||
|
{
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://example.com/",
|
||||||
|
"owner": "https://example.com/",
|
||||||
|
"publicKeyPem": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let expected = ApSignature {
|
||||||
|
public_key: PublicKey {
|
||||||
|
id: "https://example.com/".parse().unwrap(),
|
||||||
|
owner: "https://example.com/".parse().unwrap(),
|
||||||
|
public_key_pem: "".into(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
assert_eq!(value, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn se_custom_person() {
|
||||||
|
let actor = ApActor::new("https://example.com/inbox".parse().unwrap(), Person::new());
|
||||||
|
let person = CustomPerson::new(
|
||||||
|
actor,
|
||||||
|
ApSignature {
|
||||||
|
public_key: PublicKey {
|
||||||
|
id: "https://example.com/pubkey".parse().unwrap(),
|
||||||
|
owner: "https://example.com/owner".parse().unwrap(),
|
||||||
|
public_key_pem: "pubKeyPem".into(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let expected = json!({
|
||||||
|
"inbox": "https://example.com/inbox",
|
||||||
|
"type": "Person",
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://example.com/pubkey",
|
||||||
|
"owner": "https://example.com/owner",
|
||||||
|
"publicKeyPem": "pubKeyPem"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert_eq!(to_value(person).unwrap(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn se_custom_group() {
|
||||||
|
let group = CustomGroup::new(
|
||||||
|
ApActor::new("https://example.com/inbox".parse().unwrap(), Group::new()),
|
||||||
|
ApSignature {
|
||||||
|
public_key: PublicKey {
|
||||||
|
id: "https://example.com/pubkey".parse().unwrap(),
|
||||||
|
owner: "https://example.com/owner".parse().unwrap(),
|
||||||
|
public_key_pem: "pubKeyPem".into(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
SourceProperty {
|
||||||
|
source: Source {
|
||||||
|
content: String::from("This is a *custom* group."),
|
||||||
|
media_type: String::from("text/markdown"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let expected = json!({
|
||||||
|
"inbox": "https://example.com/inbox",
|
||||||
|
"type": "Group",
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://example.com/pubkey",
|
||||||
|
"owner": "https://example.com/owner",
|
||||||
|
"publicKeyPem": "pubKeyPem"
|
||||||
|
},
|
||||||
|
"source": {
|
||||||
|
"content": "This is a *custom* group.",
|
||||||
|
"mediaType": "text/markdown"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert_eq!(to_value(group).unwrap(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn de_custom_group() {
|
||||||
|
let value: CustomGroup = from_str(
|
||||||
|
r#"
|
||||||
|
{
|
||||||
|
"icon": {
|
||||||
|
"type": "Image"
|
||||||
|
},
|
||||||
|
"id": "https://plume01.localhost/~/Plume01%20Blog%202/",
|
||||||
|
"image": {
|
||||||
|
"type": "Image"
|
||||||
|
},
|
||||||
|
"inbox": "https://plume01.localhost/~/Plume01%20Blog%202/inbox",
|
||||||
|
"name": "Plume01 Blog 2",
|
||||||
|
"outbox": "https://plume01.localhost/~/Plume01%20Blog%202/outbox",
|
||||||
|
"preferredUsername": "Plume01 Blog 2",
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://plume01.localhost/~/Plume01%20Blog%202/#main-key",
|
||||||
|
"owner": "https://plume01.localhost/~/Plume01%20Blog%202/",
|
||||||
|
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwPGtKkl/iMsNAyeVaJGz\noEz5PoNkjRnKK7G97MFvb4zw9zs5SpzWW7b/pKHa4dODcGDJXmkCJ1H5JWyguzN8\n2GNoFjtEOJHxEGwBHSYDsTmhuLNB0DKxMU2iu55g8iIiXhZiIW1FBNGs/Geaymvr\nh/TEtzdReN8wzloRR55kOVcU49xBkqx8cfDSk/lrrDLlpveHdqgaFnIvuw2vycK0\nxFzS3xlEUpzJk9kHxoR1uEAfZ+gCv26Sgo/HqOAhqSD5IU3QZC3kdkr/hwVqtr8U\nXGkGG6Mo1rgzhkYiCFkWrV2WoKkcEHD4nEzbgoZZ5MyuSoloxnyF3NiScqmqW+Yx\nkQIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||||
|
},
|
||||||
|
"source": {
|
||||||
|
"content": "",
|
||||||
|
"mediaType": "text/markdown"
|
||||||
|
},
|
||||||
|
"summary": "",
|
||||||
|
"type": "Group"
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
).unwrap();
|
||||||
|
let mut expected = CustomGroup::new(
|
||||||
|
ApActor::new("https://plume01.localhost/~/Plume01%20Blog%202/inbox".parse().unwrap(), Group::new()),
|
||||||
|
ApSignature {
|
||||||
|
public_key: PublicKey {
|
||||||
|
id: "https://plume01.localhost/~/Plume01%20Blog%202/#main-key".parse().unwrap(),
|
||||||
|
owner: "https://plume01.localhost/~/Plume01%20Blog%202/".parse().unwrap(),
|
||||||
|
public_key_pem: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwPGtKkl/iMsNAyeVaJGz\noEz5PoNkjRnKK7G97MFvb4zw9zs5SpzWW7b/pKHa4dODcGDJXmkCJ1H5JWyguzN8\n2GNoFjtEOJHxEGwBHSYDsTmhuLNB0DKxMU2iu55g8iIiXhZiIW1FBNGs/Geaymvr\nh/TEtzdReN8wzloRR55kOVcU49xBkqx8cfDSk/lrrDLlpveHdqgaFnIvuw2vycK0\nxFzS3xlEUpzJk9kHxoR1uEAfZ+gCv26Sgo/HqOAhqSD5IU3QZC3kdkr/hwVqtr8U\nXGkGG6Mo1rgzhkYiCFkWrV2WoKkcEHD4nEzbgoZZ5MyuSoloxnyF3NiScqmqW+Yx\nkQIDAQAB\n-----END PUBLIC KEY-----\n".into(),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
SourceProperty {
|
||||||
|
source: Source {
|
||||||
|
content: String::from(""),
|
||||||
|
media_type: String::from("text/markdown")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
expected.set_icon(Image::new().into_any_base().unwrap());
|
||||||
|
expected.set_id(
|
||||||
|
"https://plume01.localhost/~/Plume01%20Blog%202/"
|
||||||
|
.parse()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
expected.set_image(Image::new().into_any_base().unwrap());
|
||||||
|
expected.set_name("Plume01 Blog 2");
|
||||||
|
expected.set_outbox(
|
||||||
|
"https://plume01.localhost/~/Plume01%20Blog%202/outbox"
|
||||||
|
.parse()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
expected.set_preferred_username("Plume01 Blog 2");
|
||||||
|
expected.set_summary("");
|
||||||
|
|
||||||
|
assert_json_eq!(value, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn se_licensed_article() {
|
||||||
|
let object = ApObject::new(Article::new());
|
||||||
|
let licensed_article = LicensedArticle::new(
|
||||||
|
object,
|
||||||
|
Licensed {
|
||||||
|
license: Some("CC-0".into()),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
let expected = json!({
|
||||||
|
"type": "Article",
|
||||||
|
"license": "CC-0",
|
||||||
|
});
|
||||||
|
assert_json_eq!(to_value(licensed_article).unwrap(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn de_licensed_article() {
|
||||||
|
let value: LicensedArticle = from_str(
|
||||||
|
r#"
|
||||||
|
{
|
||||||
|
"type": "Article",
|
||||||
|
"id": "https://plu.me/~/Blog/my-article",
|
||||||
|
"attributedTo": ["https://plu.me/@/Admin", "https://plu.me/~/Blog"],
|
||||||
|
"content": "Hello.",
|
||||||
|
"name": "My Article",
|
||||||
|
"summary": "Bye.",
|
||||||
|
"source": {
|
||||||
|
"content": "Hello.",
|
||||||
|
"mediaType": "text/markdown"
|
||||||
|
},
|
||||||
|
"published": "2014-12-12T12:12:12Z",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"license": "CC-0"
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let expected = json!({
|
||||||
|
"type": "Article",
|
||||||
|
"id": "https://plu.me/~/Blog/my-article",
|
||||||
|
"attributedTo": ["https://plu.me/@/Admin", "https://plu.me/~/Blog"],
|
||||||
|
"content": "Hello.",
|
||||||
|
"name": "My Article",
|
||||||
|
"summary": "Bye.",
|
||||||
|
"source": {
|
||||||
|
"content": "Hello.",
|
||||||
|
"mediaType": "text/markdown"
|
||||||
|
},
|
||||||
|
"published": "2014-12-12T12:12:12Z",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"license": "CC-0"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(to_value(value).unwrap(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn de_create_with_licensed_article() {
|
||||||
|
let create: Create = from_str(
|
||||||
|
r#"
|
||||||
|
{
|
||||||
|
"id": "https://plu.me/~/Blog/my-article",
|
||||||
|
"type": "Create",
|
||||||
|
"actor": "https://plu.me/@/Admin",
|
||||||
|
"to": "https://www.w3.org/ns/activitystreams#Public",
|
||||||
|
"object": {
|
||||||
|
"type": "Article",
|
||||||
|
"id": "https://plu.me/~/Blog/my-article",
|
||||||
|
"attributedTo": ["https://plu.me/@/Admin", "https://plu.me/~/Blog"],
|
||||||
|
"content": "Hello.",
|
||||||
|
"name": "My Article",
|
||||||
|
"summary": "Bye.",
|
||||||
|
"source": {
|
||||||
|
"content": "Hello.",
|
||||||
|
"mediaType": "text/markdown"
|
||||||
|
},
|
||||||
|
"published": "2014-12-12T12:12:12Z",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"license": "CC-0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let base = create.object_field_ref().as_single_base().unwrap();
|
||||||
|
let any_base = AnyBase::from_base(base.clone());
|
||||||
|
let value = any_base.extend::<LicensedArticle, ArticleType>().unwrap();
|
||||||
|
let expected = json!({
|
||||||
|
"type": "Article",
|
||||||
|
"id": "https://plu.me/~/Blog/my-article",
|
||||||
|
"attributedTo": ["https://plu.me/@/Admin", "https://plu.me/~/Blog"],
|
||||||
|
"content": "Hello.",
|
||||||
|
"name": "My Article",
|
||||||
|
"summary": "Bye.",
|
||||||
|
"source": {
|
||||||
|
"content": "Hello.",
|
||||||
|
"mediaType": "text/markdown"
|
||||||
|
},
|
||||||
|
"published": "2014-12-12T12:12:12Z",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"license": "CC-0"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(to_value(value).unwrap(), expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
use chrono::{offset::Utc, DateTime};
|
use chrono::{offset::Utc, DateTime};
|
||||||
use openssl::hash::{Hasher, MessageDigest};
|
use openssl::hash::{Hasher, MessageDigest};
|
||||||
use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE, DATE, USER_AGENT};
|
use reqwest::{
|
||||||
|
blocking::{ClientBuilder, Response},
|
||||||
|
header::{
|
||||||
|
HeaderMap, HeaderValue, InvalidHeaderValue, ACCEPT, CONTENT_TYPE, DATE, HOST, USER_AGENT,
|
||||||
|
},
|
||||||
|
Proxy, Url,
|
||||||
|
};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
@@ -13,6 +19,24 @@ const PLUME_USER_AGENT: &str = concat!("Plume/", env!("CARGO_PKG_VERSION"));
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Error();
|
pub struct Error();
|
||||||
|
|
||||||
|
impl From<url::ParseError> for Error {
|
||||||
|
fn from(_err: url::ParseError) -> Self {
|
||||||
|
Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<InvalidHeaderValue> for Error {
|
||||||
|
fn from(_err: InvalidHeaderValue) -> Self {
|
||||||
|
Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<reqwest::Error> for Error {
|
||||||
|
fn from(_err: reqwest::Error) -> Self {
|
||||||
|
Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Digest(String);
|
pub struct Digest(String);
|
||||||
|
|
||||||
impl Digest {
|
impl Digest {
|
||||||
@@ -118,8 +142,8 @@ type Path<'a> = &'a str;
|
|||||||
type Query<'a> = &'a str;
|
type Query<'a> = &'a str;
|
||||||
type RequestTarget<'a> = (Method<'a>, Path<'a>, Option<Query<'a>>);
|
type RequestTarget<'a> = (Method<'a>, Path<'a>, Option<Query<'a>>);
|
||||||
|
|
||||||
pub fn signature<S: Signer>(
|
pub fn signature(
|
||||||
signer: &S,
|
signer: &dyn Signer,
|
||||||
headers: &HeaderMap,
|
headers: &HeaderMap,
|
||||||
request_target: RequestTarget,
|
request_target: RequestTarget,
|
||||||
) -> Result<HeaderValue, Error> {
|
) -> Result<HeaderValue, Error> {
|
||||||
@@ -164,10 +188,35 @@ pub fn signature<S: Signer>(
|
|||||||
)).map_err(|_| Error())
|
)).map_err(|_| Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get(url_str: &str, sender: &dyn Signer, proxy: Option<Proxy>) -> Result<Response, Error> {
|
||||||
|
let mut headers = headers();
|
||||||
|
let url = Url::parse(url_str)?;
|
||||||
|
if !url.has_host() {
|
||||||
|
return Err(Error());
|
||||||
|
}
|
||||||
|
let host_header_value = HeaderValue::from_str(url.host_str().expect("Unreachable"))?;
|
||||||
|
headers.insert(HOST, host_header_value);
|
||||||
|
if let Some(proxy) = proxy {
|
||||||
|
ClientBuilder::new().proxy(proxy)
|
||||||
|
} else {
|
||||||
|
ClientBuilder::new()
|
||||||
|
}
|
||||||
|
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||||
|
.build()?
|
||||||
|
.get(url_str)
|
||||||
|
.headers(headers.clone())
|
||||||
|
.header(
|
||||||
|
"Signature",
|
||||||
|
signature(sender, &headers, ("get", url.path(), url.query()))?,
|
||||||
|
)
|
||||||
|
.send()
|
||||||
|
.map_err(|_| Error())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{signature, Error};
|
use super::signature;
|
||||||
use crate::activity_pub::sign::{gen_keypair, Signer};
|
use crate::activity_pub::sign::{gen_keypair, Error, Result, Signer};
|
||||||
use openssl::{hash::MessageDigest, pkey::PKey, rsa::Rsa};
|
use openssl::{hash::MessageDigest, pkey::PKey, rsa::Rsa};
|
||||||
use reqwest::header::HeaderMap;
|
use reqwest::header::HeaderMap;
|
||||||
|
|
||||||
@@ -187,13 +236,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Signer for MySigner {
|
impl Signer for MySigner {
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn get_key_id(&self) -> String {
|
fn get_key_id(&self) -> String {
|
||||||
"mysigner".into()
|
"mysigner".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign(&self, to_sign: &str) -> Result<Vec<u8>, Self::Error> {
|
fn sign(&self, to_sign: &str) -> Result<Vec<u8>> {
|
||||||
let key = PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.as_ref()).unwrap())
|
let key = PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.as_ref()).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut signer = openssl::sign::Signer::new(MessageDigest::sha256(), &key).unwrap();
|
let mut signer = openssl::sign::Signer::new(MessageDigest::sha256(), &key).unwrap();
|
||||||
@@ -201,12 +248,12 @@ mod tests {
|
|||||||
signer.sign_to_vec().map_err(|_| Error())
|
signer.sign_to_vec().map_err(|_| Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify(&self, data: &str, signature: &[u8]) -> Result<bool, Self::Error> {
|
fn verify(&self, data: &str, signature: &[u8]) -> Result<bool> {
|
||||||
let key = PKey::from_rsa(Rsa::public_key_from_pem(self.public_key.as_ref()).unwrap())
|
let key = PKey::from_rsa(Rsa::public_key_from_pem(self.public_key.as_ref()).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut verifier = openssl::sign::Verifier::new(MessageDigest::sha256(), &key).unwrap();
|
let mut verifier = openssl::sign::Verifier::new(MessageDigest::sha256(), &key).unwrap();
|
||||||
verifier.update(data.as_bytes()).unwrap();
|
verifier.update(data.as_bytes()).unwrap();
|
||||||
verifier.verify(&signature).map_err(|_| Error())
|
verifier.verify(signature).map_err(|_| Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +262,7 @@ mod tests {
|
|||||||
let signer = MySigner::new();
|
let signer = MySigner::new();
|
||||||
let headers = HeaderMap::new();
|
let headers = HeaderMap::new();
|
||||||
let result = signature(&signer, &headers, ("post", "/inbox", None)).unwrap();
|
let result = signature(&signer, &headers, ("post", "/inbox", None)).unwrap();
|
||||||
let fields: Vec<&str> = result.to_str().unwrap().split(",").collect();
|
let fields: Vec<&str> = result.to_str().unwrap().split(',').collect();
|
||||||
assert_eq!(r#"headers="(request-target)""#, fields[2]);
|
assert_eq!(r#"headers="(request-target)""#, fields[2]);
|
||||||
let sign = &fields[3][11..(fields[3].len() - 1)];
|
let sign = &fields[3][11..(fields[3].len() - 1)];
|
||||||
assert!(signer.verify("post /inbox", sign.as_bytes()).is_ok());
|
assert!(signer.verify("post /inbox", sign.as_bytes()).is_ok());
|
||||||
|
|||||||
@@ -19,20 +19,25 @@ pub fn gen_keypair() -> (Vec<u8>, Vec<u8>) {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Error();
|
pub struct Error();
|
||||||
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
impl From<openssl::error::ErrorStack> for Error {
|
||||||
|
fn from(_: openssl::error::ErrorStack) -> Self {
|
||||||
|
Self()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Signer {
|
pub trait Signer {
|
||||||
type Error;
|
|
||||||
|
|
||||||
fn get_key_id(&self) -> String;
|
fn get_key_id(&self) -> String;
|
||||||
|
|
||||||
/// Sign some data with the signer keypair
|
/// Sign some data with the signer keypair
|
||||||
fn sign(&self, to_sign: &str) -> Result<Vec<u8>, Self::Error>;
|
fn sign(&self, to_sign: &str) -> Result<Vec<u8>>;
|
||||||
/// Verify if the signature is valid
|
/// Verify if the signature is valid
|
||||||
fn verify(&self, data: &str, signature: &[u8]) -> Result<bool, Self::Error>;
|
fn verify(&self, data: &str, signature: &[u8]) -> Result<bool>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Signable {
|
pub trait Signable {
|
||||||
fn sign<T>(&mut self, creator: &T) -> Result<&mut Self, Error>
|
fn sign<T>(&mut self, creator: &T) -> Result<&mut Self>
|
||||||
where
|
where
|
||||||
T: Signer;
|
T: Signer;
|
||||||
fn verify<T>(self, creator: &T) -> bool
|
fn verify<T>(self, creator: &T) -> bool
|
||||||
@@ -46,7 +51,7 @@ pub trait Signable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Signable for serde_json::Value {
|
impl Signable for serde_json::Value {
|
||||||
fn sign<T: Signer>(&mut self, creator: &T) -> Result<&mut serde_json::Value, Error> {
|
fn sign<T: Signer>(&mut self, creator: &T) -> Result<&mut serde_json::Value> {
|
||||||
let creation_date = Utc::now().to_rfc3339();
|
let creation_date = Utc::now().to_rfc3339();
|
||||||
let mut options = json!({
|
let mut options = json!({
|
||||||
"type": "RsaSignature2017",
|
"type": "RsaSignature2017",
|
||||||
@@ -114,7 +119,7 @@ impl Signable for serde_json::Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub enum SignatureValidity {
|
pub enum SignatureValidity {
|
||||||
Invalid,
|
Invalid,
|
||||||
ValidNoDigest,
|
ValidNoDigest,
|
||||||
@@ -182,7 +187,7 @@ pub fn verify_http_headers<S: Signer + ::std::fmt::Debug>(
|
|||||||
}
|
}
|
||||||
let digest = all_headers.get_one("digest").unwrap_or("");
|
let digest = all_headers.get_one("digest").unwrap_or("");
|
||||||
let digest = request::Digest::from_header(digest);
|
let digest = request::Digest::from_header(digest);
|
||||||
if !digest.map(|d| d.verify_header(&data)).unwrap_or(false) {
|
if !digest.map(|d| d.verify_header(data)).unwrap_or(false) {
|
||||||
// signature was valid, but body content does not match its digest
|
// signature was valid, but body content does not match its digest
|
||||||
return SignatureValidity::Invalid;
|
return SignatureValidity::Invalid;
|
||||||
}
|
}
|
||||||
|
|||||||
Executable → Regular
-2
@@ -1,7 +1,5 @@
|
|||||||
#![feature(associated_type_defaults)]
|
#![feature(associated_type_defaults)]
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate activitystreams_derive;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate shrinkwraprs;
|
extern crate shrinkwraprs;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|||||||
+74
-29
@@ -1,11 +1,7 @@
|
|||||||
use heck::CamelCase;
|
|
||||||
use openssl::rand::rand_bytes;
|
use openssl::rand::rand_bytes;
|
||||||
use pulldown_cmark::{html, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag};
|
use pulldown_cmark::{html, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag};
|
||||||
use regex_syntax::is_word_character;
|
use regex_syntax::is_word_character;
|
||||||
use rocket::{
|
use rocket::http::uri::Uri;
|
||||||
http::uri::Uri,
|
|
||||||
response::{Flash, Redirect},
|
|
||||||
};
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use syntect::html::{ClassStyle, ClassedHTMLGenerator};
|
use syntect::html::{ClassStyle, ClassedHTMLGenerator};
|
||||||
use syntect::parsing::SyntaxSet;
|
use syntect::parsing::SyntaxSet;
|
||||||
@@ -19,25 +15,57 @@ pub fn random_hex() -> String {
|
|||||||
.fold(String::new(), |res, byte| format!("{}{:x}", res, byte))
|
.fold(String::new(), |res, byte| format!("{}{:x}", res, byte))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove non alphanumeric characters and CamelCase a string
|
/**
|
||||||
pub fn make_actor_id(name: &str) -> String {
|
* Percent-encode characters which are not allowed in IRI path segments.
|
||||||
name.to_camel_case()
|
*
|
||||||
.chars()
|
* Intended to be used for generating Post ap_url.
|
||||||
.filter(|c| c.is_alphanumeric())
|
*/
|
||||||
.collect()
|
pub fn iri_percent_encode_seg(segment: &str) -> String {
|
||||||
|
segment.chars().map(iri_percent_encode_seg_char).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
pub fn iri_percent_encode_seg_char(c: char) -> String {
|
||||||
* Redirects to the login page with a given message.
|
if c.is_alphanumeric() {
|
||||||
*
|
c.to_string()
|
||||||
* Note that the message should be translated before passed to this function.
|
} else {
|
||||||
*/
|
match c {
|
||||||
pub fn requires_login<T: Into<Uri<'static>>>(message: &str, url: T) -> Flash<Redirect> {
|
'-'
|
||||||
Flash::new(
|
| '.'
|
||||||
Redirect::to(format!("/login?m={}", Uri::percent_encode(message))),
|
| '_'
|
||||||
"callback",
|
| '~'
|
||||||
url.into().to_string(),
|
| '\u{A0}'..='\u{D7FF}'
|
||||||
)
|
| '\u{20000}'..='\u{2FFFD}'
|
||||||
|
| '\u{30000}'..='\u{3FFFD}'
|
||||||
|
| '\u{40000}'..='\u{4FFFD}'
|
||||||
|
| '\u{50000}'..='\u{5FFFD}'
|
||||||
|
| '\u{60000}'..='\u{6FFFD}'
|
||||||
|
| '\u{70000}'..='\u{7FFFD}'
|
||||||
|
| '\u{80000}'..='\u{8FFFD}'
|
||||||
|
| '\u{90000}'..='\u{9FFFD}'
|
||||||
|
| '\u{A0000}'..='\u{AFFFD}'
|
||||||
|
| '\u{B0000}'..='\u{BFFFD}'
|
||||||
|
| '\u{C0000}'..='\u{CFFFD}'
|
||||||
|
| '\u{D0000}'..='\u{DFFFD}'
|
||||||
|
| '\u{E0000}'..='\u{EFFFD}'
|
||||||
|
| '!'
|
||||||
|
| '$'
|
||||||
|
| '&'
|
||||||
|
| '\''
|
||||||
|
| '('
|
||||||
|
| ')'
|
||||||
|
| '*'
|
||||||
|
| '+'
|
||||||
|
| ','
|
||||||
|
| ';'
|
||||||
|
| '='
|
||||||
|
| ':'
|
||||||
|
| '@' => c.to_string(),
|
||||||
|
_ => {
|
||||||
|
let s = c.to_string();
|
||||||
|
Uri::percent_encode(&s).to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -88,13 +116,13 @@ fn highlight_code<'a>(
|
|||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
let syntax_set = SyntaxSet::load_defaults_newlines();
|
let syntax_set = SyntaxSet::load_defaults_newlines();
|
||||||
let syntax = syntax_set.find_syntax_by_token(&lang).unwrap_or_else(|| {
|
let syntax = syntax_set.find_syntax_by_token(lang).unwrap_or_else(|| {
|
||||||
syntax_set
|
syntax_set
|
||||||
.find_syntax_by_name(&lang)
|
.find_syntax_by_name(lang)
|
||||||
.unwrap_or_else(|| syntax_set.find_syntax_plain_text())
|
.unwrap_or_else(|| syntax_set.find_syntax_plain_text())
|
||||||
});
|
});
|
||||||
let mut html = ClassedHTMLGenerator::new_with_class_style(
|
let mut html = ClassedHTMLGenerator::new_with_class_style(
|
||||||
&syntax,
|
syntax,
|
||||||
&syntax_set,
|
&syntax_set,
|
||||||
ClassStyle::Spaced,
|
ClassStyle::Spaced,
|
||||||
);
|
);
|
||||||
@@ -234,7 +262,7 @@ pub fn md_to_html<'a>(
|
|||||||
media_processor: Option<MediaProcessor<'a>>,
|
media_processor: Option<MediaProcessor<'a>>,
|
||||||
) -> (String, HashSet<String>, HashSet<String>) {
|
) -> (String, HashSet<String>, HashSet<String>) {
|
||||||
let base_url = if let Some(base_url) = base_url {
|
let base_url = if let Some(base_url) = base_url {
|
||||||
format!("//{}/", base_url)
|
format!("https://{}/", base_url)
|
||||||
} else {
|
} else {
|
||||||
"/".to_owned()
|
"/".to_owned()
|
||||||
};
|
};
|
||||||
@@ -281,16 +309,15 @@ pub fn md_to_html<'a>(
|
|||||||
text_acc.push(c)
|
text_acc.push(c)
|
||||||
}
|
}
|
||||||
let mention = text_acc;
|
let mention = text_acc;
|
||||||
let short_mention = mention.splitn(1, '@').next().unwrap_or("");
|
|
||||||
let link = Tag::Link(
|
let link = Tag::Link(
|
||||||
LinkType::Inline,
|
LinkType::Inline,
|
||||||
format!("{}@/{}/", base_url, &mention).into(),
|
format!("{}@/{}/", base_url, &mention).into(),
|
||||||
short_mention.to_owned().into(),
|
mention.clone().into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
mentions.push(mention.clone());
|
mentions.push(mention.clone());
|
||||||
events.push(Event::Start(link.clone()));
|
events.push(Event::Start(link.clone()));
|
||||||
events.push(Event::Text(format!("@{}", &short_mention).into()));
|
events.push(Event::Text(format!("@{}", &mention).into()));
|
||||||
events.push(Event::End(link));
|
events.push(Event::End(link));
|
||||||
|
|
||||||
(
|
(
|
||||||
@@ -414,6 +441,10 @@ pub fn md_to_html<'a>(
|
|||||||
(buf, mentions.collect(), hashtags.collect())
|
(buf, mentions.collect(), hashtags.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn escape(string: &str) -> askama_escape::Escaped<askama_escape::Html> {
|
||||||
|
askama_escape::escape(string, askama_escape::Html)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -476,6 +507,20 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_iri_percent_encode_seg() {
|
||||||
|
assert_eq!(
|
||||||
|
&iri_percent_encode_seg("including whitespace"),
|
||||||
|
"including%20whitespace"
|
||||||
|
);
|
||||||
|
assert_eq!(&iri_percent_encode_seg("%20"), "%2520");
|
||||||
|
assert_eq!(&iri_percent_encode_seg("é"), "é");
|
||||||
|
assert_eq!(
|
||||||
|
&iri_percent_encode_seg("空白入り 日本語"),
|
||||||
|
"空白入り%20日本語"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_inline() {
|
fn test_inline() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
+11
-8
@@ -1,26 +1,29 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "plume-front"
|
name = "plume-front"
|
||||||
version = "0.6.1-dev"
|
version = "0.7.2"
|
||||||
authors = ["Plume contributors"]
|
authors = ["Plume contributors"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
[package.metadata.wasm-pack.profile.release]
|
||||||
|
wasm-opt = false
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gettext = { git = "https://github.com/Plume-org/gettext/", rev = "294c54d74c699fbc66502b480a37cc66c1daa7f3" }
|
gettext = "0.4.0"
|
||||||
gettext-macros = { git = "https://github.com/Plume-org/gettext-macros/", rev = "a7c605f7edd6bfbfbfe7778026bfefd88d82db10" }
|
gettext-macros = "0.6.1"
|
||||||
gettext-utils = { git = "https://github.com/Plume-org/gettext-macros/", rev = "a7c605f7edd6bfbfbfe7778026bfefd88d82db10" }
|
gettext-utils = "0.1.0"
|
||||||
lazy_static = "1.3"
|
lazy_static = "1.3"
|
||||||
serde = "1.0"
|
serde = "1.0.137"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
wasm-bindgen = "0.2.70"
|
wasm-bindgen = "0.2.81"
|
||||||
js-sys = "0.3.47"
|
js-sys = "0.3.58"
|
||||||
serde_derive = "1.0.123"
|
serde_derive = "1.0.123"
|
||||||
console_error_panic_hook = "0.1.6"
|
console_error_panic_hook = "0.1.6"
|
||||||
|
|
||||||
[dependencies.web-sys]
|
[dependencies.web-sys]
|
||||||
version = "0.3.47"
|
version = "0.3.58"
|
||||||
features = [
|
features = [
|
||||||
'console',
|
'console',
|
||||||
'ClipboardEvent',
|
'ClipboardEvent',
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pre-release-hook = ["cargo", "fmt"]
|
pre-release-hook = ["cargo", "fmt"]
|
||||||
pre-release-replacements = []
|
pre-release-replacements = []
|
||||||
|
release = false
|
||||||
|
|||||||
+23
-15
@@ -54,11 +54,6 @@ pub enum EditorError {
|
|||||||
DOMError,
|
DOMError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::option::NoneError> for EditorError {
|
|
||||||
fn from(_: std::option::NoneError) -> Self {
|
|
||||||
EditorError::NoneError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const AUTOSAVE_DEBOUNCE_TIME: i32 = 5000;
|
const AUTOSAVE_DEBOUNCE_TIME: i32 = 5000;
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct AutosaveInformation {
|
struct AutosaveInformation {
|
||||||
@@ -198,7 +193,7 @@ fn clear_autosave() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.remove_item(&get_autosave_id())
|
.remove_item(&get_autosave_id())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
console::log_1(&&format!("Saved to {}", &get_autosave_id()).into());
|
console::log_1(&format!("Saved to {}", &get_autosave_id()).into());
|
||||||
}
|
}
|
||||||
type TimeoutHandle = i32;
|
type TimeoutHandle = i32;
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@@ -366,7 +361,9 @@ fn init_editor() -> Result<(), EditorError> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let old_ed = old_ed.unwrap();
|
let old_ed = old_ed.unwrap();
|
||||||
let old_title = document().get_element_by_id("plume-editor-title")?;
|
let old_title = document()
|
||||||
|
.get_element_by_id("plume-editor-title")
|
||||||
|
.ok_or(EditorError::NoneError)?;
|
||||||
old_ed
|
old_ed
|
||||||
.dyn_ref::<HtmlElement>()
|
.dyn_ref::<HtmlElement>()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -400,7 +397,9 @@ fn init_editor() -> Result<(), EditorError> {
|
|||||||
content_val.clone(),
|
content_val.clone(),
|
||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
content.set_inner_html(&content_val);
|
if !content_val.is_empty() {
|
||||||
|
content.set_inner_html(&content_val);
|
||||||
|
}
|
||||||
|
|
||||||
// character counter
|
// character counter
|
||||||
let character_counter = Closure::wrap(Box::new(mv!(content => move |_| {
|
let character_counter = Closure::wrap(Box::new(mv!(content => move |_| {
|
||||||
@@ -434,7 +433,8 @@ fn init_editor() -> Result<(), EditorError> {
|
|||||||
bg.class_list().add_1("show").unwrap();
|
bg.class_list().add_1("show").unwrap();
|
||||||
})) as Box<dyn FnMut(MouseEvent)>);
|
})) as Box<dyn FnMut(MouseEvent)>);
|
||||||
document()
|
document()
|
||||||
.get_element_by_id("publish")?
|
.get_element_by_id("publish")
|
||||||
|
.ok_or(EditorError::NoneError)?
|
||||||
.add_event_listener_with_callback("click", show_popup.as_ref().unchecked_ref())
|
.add_event_listener_with_callback("click", show_popup.as_ref().unchecked_ref())
|
||||||
.map_err(|_| EditorError::DOMError)?;
|
.map_err(|_| EditorError::DOMError)?;
|
||||||
show_popup.forget();
|
show_popup.forget();
|
||||||
@@ -528,8 +528,14 @@ fn init_popup(
|
|||||||
cover_label
|
cover_label
|
||||||
.set_attribute("for", "cover")
|
.set_attribute("for", "cover")
|
||||||
.map_err(|_| EditorError::DOMError)?;
|
.map_err(|_| EditorError::DOMError)?;
|
||||||
let cover = document.get_element_by_id("cover")?;
|
let cover = document
|
||||||
cover.parent_element()?.remove_child(&cover).ok();
|
.get_element_by_id("cover")
|
||||||
|
.ok_or(EditorError::NoneError)?;
|
||||||
|
cover
|
||||||
|
.parent_element()
|
||||||
|
.ok_or(EditorError::NoneError)?
|
||||||
|
.remove_child(&cover)
|
||||||
|
.ok();
|
||||||
popup
|
popup
|
||||||
.append_child(&cover_label)
|
.append_child(&cover_label)
|
||||||
.map_err(|_| EditorError::DOMError)?;
|
.map_err(|_| EditorError::DOMError)?;
|
||||||
@@ -554,7 +560,7 @@ fn init_popup(
|
|||||||
draft.set_checked(draft_checkbox.checked());
|
draft.set_checked(draft_checkbox.checked());
|
||||||
|
|
||||||
draft_label
|
draft_label
|
||||||
.append_child(&draft)
|
.append_child(draft)
|
||||||
.map_err(|_| EditorError::DOMError)?;
|
.map_err(|_| EditorError::DOMError)?;
|
||||||
draft_label
|
draft_label
|
||||||
.append_child(&document.create_text_node(&i18n!(CATALOG, "This is a draft")))
|
.append_child(&document.create_text_node(&i18n!(CATALOG, "This is a draft")))
|
||||||
@@ -620,11 +626,12 @@ fn init_popup(
|
|||||||
.map_err(|_| EditorError::DOMError)?;
|
.map_err(|_| EditorError::DOMError)?;
|
||||||
callback.forget();
|
callback.forget();
|
||||||
popup
|
popup
|
||||||
.append_child(&button)
|
.append_child(button)
|
||||||
.map_err(|_| EditorError::DOMError)?;
|
.map_err(|_| EditorError::DOMError)?;
|
||||||
|
|
||||||
document
|
document
|
||||||
.body()?
|
.body()
|
||||||
|
.ok_or(EditorError::NoneError)?
|
||||||
.append_child(&popup)
|
.append_child(&popup)
|
||||||
.map_err(|_| EditorError::DOMError)?;
|
.map_err(|_| EditorError::DOMError)?;
|
||||||
Ok(popup)
|
Ok(popup)
|
||||||
@@ -641,7 +648,8 @@ fn init_popup_bg() -> Result<Element, EditorError> {
|
|||||||
.map_err(|_| EditorError::DOMError)?;
|
.map_err(|_| EditorError::DOMError)?;
|
||||||
|
|
||||||
document()
|
document()
|
||||||
.body()?
|
.body()
|
||||||
|
.ok_or(EditorError::NoneError)?
|
||||||
.append_child(&bg)
|
.append_child(&bg)
|
||||||
.map_err(|_| EditorError::DOMError)?;
|
.map_err(|_| EditorError::DOMError)?;
|
||||||
let callback = Closure::wrap(Box::new(|_| close_popup()) as Box<dyn FnMut(MouseEvent)>);
|
let callback = Closure::wrap(Box::new(|_| close_popup()) as Box<dyn FnMut(MouseEvent)>);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#![recursion_limit = "128"]
|
#![recursion_limit = "128"]
|
||||||
#![feature(decl_macro, proc_macro_hygiene, try_trait)]
|
#![feature(decl_macro, proc_macro_hygiene)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate gettext_macros;
|
extern crate gettext_macros;
|
||||||
@@ -23,6 +23,7 @@ init_i18n!(
|
|||||||
en,
|
en,
|
||||||
eo,
|
eo,
|
||||||
es,
|
es,
|
||||||
|
eu,
|
||||||
fa,
|
fa,
|
||||||
fi,
|
fi,
|
||||||
fr,
|
fr,
|
||||||
@@ -61,7 +62,7 @@ lazy_static! {
|
|||||||
static ref CATALOG: gettext::Catalog = {
|
static ref CATALOG: gettext::Catalog = {
|
||||||
let catalogs = include_i18n!();
|
let catalogs = include_i18n!();
|
||||||
let lang = window().unwrap().navigator().language().unwrap();
|
let lang = window().unwrap().navigator().language().unwrap();
|
||||||
let lang = lang.splitn(2, '-').next().unwrap_or("en");
|
let lang = lang.split_once('-').map_or("en", |x| x.0);
|
||||||
|
|
||||||
let english_position = catalogs
|
let english_position = catalogs
|
||||||
.iter()
|
.iter()
|
||||||
@@ -85,7 +86,7 @@ pub fn main() -> Result<(), JsValue> {
|
|||||||
menu();
|
menu();
|
||||||
search();
|
search();
|
||||||
editor::init()
|
editor::init()
|
||||||
.map_err(|e| console::error_1(&&format!("Editor error: {:?}", e).into()))
|
.map_err(|e| console::error_1(&format!("Editor error: {:?}", e).into()))
|
||||||
.ok();
|
.ok();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "plume-macro"
|
name = "plume-macro"
|
||||||
version = "0.6.1-dev"
|
version = "0.7.2"
|
||||||
authors = ["Trinity Pointard <trinity.pointard@insa-rennes.fr>"]
|
authors = ["Trinity Pointard <trinity.pointard@insa-rennes.fr>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Plume procedural macros"
|
description = "Plume procedural macros"
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pre-release-hook = ["cargo", "fmt"]
|
pre-release-hook = ["cargo", "fmt"]
|
||||||
pre-release-replacements = []
|
pre-release-replacements = []
|
||||||
|
release = false
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ pub fn import_migrations(input: TokenStream) -> TokenStream {
|
|||||||
(name, up_sql, down_sql)
|
(name, up_sql, down_sql)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let migrations_name = migrations.iter().map(|m| &m.0).collect::<Vec<_>>();
|
let migrations_name = migrations.iter().map(|m| &m.0);
|
||||||
let migrations_up = migrations
|
let migrations_up = migrations
|
||||||
.iter()
|
.iter()
|
||||||
.map(|m| m.1.as_str())
|
.map(|m| m.1.as_str())
|
||||||
@@ -103,7 +103,7 @@ fn file_to_migration(file: &str) -> TokenStream2 {
|
|||||||
acc.push('\n');
|
acc.push('\n');
|
||||||
}
|
}
|
||||||
} else if let Some(acc_str) = line.strip_prefix("--#!") {
|
} else if let Some(acc_str) = line.strip_prefix("--#!") {
|
||||||
acc.push_str(&acc_str);
|
acc.push_str(acc_str);
|
||||||
acc.push('\n');
|
acc.push('\n');
|
||||||
} else if line.starts_with("--") {
|
} else if line.starts_with("--") {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
+23
-22
@@ -1,40 +1,40 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "plume-models"
|
name = "plume-models"
|
||||||
version = "0.6.1-dev"
|
version = "0.7.2"
|
||||||
authors = ["Plume contributors"]
|
authors = ["Plume contributors"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
activitypub = "0.1.1"
|
ammonia = "3.2.0"
|
||||||
ammonia = "2.1.1"
|
bcrypt = "0.12.1"
|
||||||
askama_escape = "0.1"
|
guid-create = "0.2"
|
||||||
bcrypt = "0.5"
|
itertools = "0.10.3"
|
||||||
guid-create = "0.1"
|
|
||||||
heck = "0.3.0"
|
|
||||||
itertools = "0.8.0"
|
|
||||||
lazy_static = "1.0"
|
lazy_static = "1.0"
|
||||||
ldap3 = "0.7.1"
|
ldap3 = "0.11.1"
|
||||||
migrations_internals= "1.4.0"
|
migrations_internals= "1.4.0"
|
||||||
openssl = "0.10.22"
|
openssl = "0.10.40"
|
||||||
rocket = "0.4.6"
|
rocket = "0.4.11"
|
||||||
rocket_i18n = { git = "https://github.com/Plume-org/rocket_i18n", rev = "e922afa7c366038b3433278c03b1456b346074f2" }
|
rocket_i18n = "0.4.1"
|
||||||
reqwest = "0.9"
|
reqwest = "0.11.11"
|
||||||
scheduled-thread-pool = "0.2.2"
|
scheduled-thread-pool = "0.2.6"
|
||||||
serde = "1.0"
|
serde = "1.0.137"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0.81"
|
||||||
tantivy = "0.13.3"
|
tantivy = "0.13.3"
|
||||||
url = "2.1"
|
url = "2.1"
|
||||||
walkdir = "2.2"
|
walkdir = "2.2"
|
||||||
webfinger = "0.4.1"
|
webfinger = "0.4.1"
|
||||||
whatlang = "0.11.1"
|
whatlang = "0.16.2"
|
||||||
shrinkwraprs = "0.2.1"
|
shrinkwraprs = "0.3.0"
|
||||||
diesel-derive-newtype = "0.1.2"
|
diesel-derive-newtype = "1.0.0"
|
||||||
glob = "0.3.0"
|
glob = "0.3.1"
|
||||||
lindera-tantivy = { version = "0.7.1", optional = true }
|
lindera-tantivy = { version = "0.7.1", optional = true }
|
||||||
tracing = "0.1.22"
|
tracing = "0.1.35"
|
||||||
riker = "0.4.2"
|
riker = "0.4.2"
|
||||||
once_cell = "1.5.2"
|
once_cell = "1.12.0"
|
||||||
|
lettre = "0.9.6"
|
||||||
|
native-tls = "0.2.10"
|
||||||
|
activitystreams = "=0.7.0-alpha.20"
|
||||||
|
|
||||||
[dependencies.chrono]
|
[dependencies.chrono]
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
@@ -54,6 +54,7 @@ path = "../plume-common"
|
|||||||
path = "../plume-macro"
|
path = "../plume-macro"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
assert-json-diff = "2.0.1"
|
||||||
diesel_migrations = "1.3.0"
|
diesel_migrations = "1.3.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pre-release-hook = ["cargo", "fmt"]
|
pre-release-hook = ["cargo", "fmt"]
|
||||||
pre-release-replacements = []
|
pre-release-replacements = []
|
||||||
|
release = false
|
||||||
|
|||||||
@@ -86,20 +86,24 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApiToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut parsed_header = headers[0].split(' ');
|
let mut parsed_header = headers[0].split(' ');
|
||||||
let auth_type = parsed_header.next().map_or_else(
|
let auth_type = parsed_header
|
||||||
|| Outcome::Failure((Status::BadRequest, TokenError::NoType)),
|
.next()
|
||||||
Outcome::Success,
|
.map_or_else::<rocket::Outcome<&str, _, ()>, _, _>(
|
||||||
)?;
|
|| Outcome::Failure((Status::BadRequest, TokenError::NoType)),
|
||||||
let val = parsed_header.next().map_or_else(
|
Outcome::Success,
|
||||||
|| Outcome::Failure((Status::BadRequest, TokenError::NoValue)),
|
)?;
|
||||||
Outcome::Success,
|
let val = parsed_header
|
||||||
)?;
|
.next()
|
||||||
|
.map_or_else::<rocket::Outcome<&str, _, ()>, _, _>(
|
||||||
|
|| Outcome::Failure((Status::BadRequest, TokenError::NoValue)),
|
||||||
|
Outcome::Success,
|
||||||
|
)?;
|
||||||
|
|
||||||
if auth_type == "Bearer" {
|
if auth_type == "Bearer" {
|
||||||
let conn = request
|
let conn = request
|
||||||
.guard::<DbConn>()
|
.guard::<DbConn>()
|
||||||
.map_failure(|_| (Status::InternalServerError, TokenError::DbError))?;
|
.map_failure(|_| (Status::InternalServerError, TokenError::DbError))?;
|
||||||
if let Ok(token) = ApiToken::find_by_value(&*conn, val) {
|
if let Ok(token) = ApiToken::find_by_value(&conn, val) {
|
||||||
return Outcome::Success(token);
|
return Outcome::Success(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ impl BlocklistedEmail {
|
|||||||
pub fn delete_entries(conn: &Connection, ids: Vec<i32>) -> Result<bool> {
|
pub fn delete_entries(conn: &Connection, ids: Vec<i32>) -> Result<bool> {
|
||||||
use diesel::delete;
|
use diesel::delete;
|
||||||
for i in ids {
|
for i in ids {
|
||||||
let be: BlocklistedEmail = BlocklistedEmail::find_by_id(&conn, i)?;
|
let be: BlocklistedEmail = BlocklistedEmail::find_by_id(conn, i)?;
|
||||||
delete(&be).execute(conn)?;
|
delete(&be).execute(conn)?;
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
@@ -126,12 +126,9 @@ pub(crate) mod tests {
|
|||||||
.id,
|
.id,
|
||||||
various[1].id
|
various[1].id
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert!(BlocklistedEmail::matches_blocklist(&conn, no_match)
|
||||||
BlocklistedEmail::matches_blocklist(&conn, no_match)
|
.unwrap()
|
||||||
.unwrap()
|
.is_none());
|
||||||
.is_none(),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+406
-228
@@ -1,12 +1,14 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
ap_url, db_conn::DbConn, instance::*, medias::Media, posts::Post, safe_string::SafeString,
|
instance::*, medias::Media, posts::Post, safe_string::SafeString, schema::blogs, users::User,
|
||||||
schema::blogs, users::User, Connection, Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE,
|
Connection, Error, PlumeRocket, Result, CONFIG, ITEMS_PER_PAGE,
|
||||||
};
|
};
|
||||||
use activitypub::{
|
use activitystreams::{
|
||||||
actor::Group,
|
actor::{ApActor, ApActorExt, AsApActor, Group},
|
||||||
|
base::AnyBase,
|
||||||
collection::{OrderedCollection, OrderedCollectionPage},
|
collection::{OrderedCollection, OrderedCollectionPage},
|
||||||
object::Image,
|
iri_string::types::IriString,
|
||||||
CustomObject,
|
object::{kind::ImageType, ApObject, Image, ObjectExt},
|
||||||
|
prelude::*,
|
||||||
};
|
};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
use diesel::{self, ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
||||||
@@ -16,16 +18,17 @@ use openssl::{
|
|||||||
rsa::Rsa,
|
rsa::Rsa,
|
||||||
sign::{Signer, Verifier},
|
sign::{Signer, Verifier},
|
||||||
};
|
};
|
||||||
use plume_common::activity_pub::{
|
use plume_common::{
|
||||||
inbox::{AsActor, FromId},
|
activity_pub::{
|
||||||
sign, ActivityStream, ApSignature, Id, IntoId, PublicKey, Source,
|
inbox::{AsActor, FromId},
|
||||||
|
sign, ActivityStream, ApSignature, CustomGroup, Id, IntoId, PublicKey, Source,
|
||||||
|
SourceProperty, ToAsString, ToAsUri,
|
||||||
|
},
|
||||||
|
utils::iri_percent_encode_seg,
|
||||||
};
|
};
|
||||||
use url::Url;
|
|
||||||
use webfinger::*;
|
use webfinger::*;
|
||||||
|
|
||||||
pub type CustomGroup = CustomObject<ApSignature, Group>;
|
#[derive(Queryable, Identifiable, Clone, AsChangeset, Debug)]
|
||||||
|
|
||||||
#[derive(Queryable, Identifiable, Clone, AsChangeset)]
|
|
||||||
#[changeset_options(treat_none_as_null = "true")]
|
#[changeset_options(treat_none_as_null = "true")]
|
||||||
pub struct Blog {
|
pub struct Blog {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
@@ -83,9 +86,13 @@ impl Blog {
|
|||||||
|
|
||||||
if inserted.fqn.is_empty() {
|
if inserted.fqn.is_empty() {
|
||||||
if instance.local {
|
if instance.local {
|
||||||
inserted.fqn = inserted.actor_id.clone();
|
inserted.fqn = iri_percent_encode_seg(&inserted.actor_id);
|
||||||
} else {
|
} else {
|
||||||
inserted.fqn = format!("{}@{}", inserted.actor_id, instance.public_domain);
|
inserted.fqn = format!(
|
||||||
|
"{}@{}",
|
||||||
|
iri_percent_encode_seg(&inserted.actor_id),
|
||||||
|
instance.public_domain
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +102,10 @@ impl Blog {
|
|||||||
find_by!(blogs, find_by_ap_url, ap_url as &str);
|
find_by!(blogs, find_by_ap_url, ap_url as &str);
|
||||||
find_by!(blogs, find_by_name, actor_id as &str, instance_id as i32);
|
find_by!(blogs, find_by_name, actor_id as &str, instance_id as i32);
|
||||||
|
|
||||||
|
pub fn slug(title: &str) -> &str {
|
||||||
|
title
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_instance(&self, conn: &Connection) -> Result<Instance> {
|
pub fn get_instance(&self, conn: &Connection) -> Result<Instance> {
|
||||||
Instance::get(conn, self.instance_id)
|
Instance::get(conn, self.instance_id)
|
||||||
}
|
}
|
||||||
@@ -131,10 +142,10 @@ impl Blog {
|
|||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_by_fqn(conn: &DbConn, fqn: &str) -> Result<Blog> {
|
pub fn find_by_fqn(conn: &Connection, fqn: &str) -> Result<Blog> {
|
||||||
let from_db = blogs::table
|
let from_db = blogs::table
|
||||||
.filter(blogs::fqn.eq(fqn))
|
.filter(blogs::fqn.eq(fqn))
|
||||||
.first(&**conn)
|
.first(conn)
|
||||||
.optional()?;
|
.optional()?;
|
||||||
if let Some(from_db) = from_db {
|
if let Some(from_db) = from_db {
|
||||||
Ok(from_db)
|
Ok(from_db)
|
||||||
@@ -143,114 +154,138 @@ impl Blog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_from_webfinger(conn: &DbConn, acct: &str) -> Result<Blog> {
|
fn fetch_from_webfinger(conn: &Connection, acct: &str) -> Result<Blog> {
|
||||||
resolve_with_prefix(Prefix::Group, acct.to_owned(), true)?
|
resolve_with_prefix(Prefix::Group, acct.to_owned(), true)?
|
||||||
.links
|
.links
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|l| l.mime_type == Some(String::from("application/activity+json")))
|
.find(|l| l.mime_type == Some(String::from("application/activity+json")))
|
||||||
.ok_or(Error::Webfinger)
|
.ok_or(Error::Webfinger)
|
||||||
.and_then(|l| Blog::from_id(conn, &l.href?, None, CONFIG.proxy()).map_err(|(_, e)| e))
|
.and_then(|l| {
|
||||||
|
Blog::from_id(
|
||||||
|
conn,
|
||||||
|
&l.href.ok_or(Error::MissingApProperty)?,
|
||||||
|
None,
|
||||||
|
CONFIG.proxy(),
|
||||||
|
)
|
||||||
|
.map_err(|(_, e)| e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_activity(&self, conn: &Connection) -> Result<CustomGroup> {
|
pub fn to_activity(&self, conn: &Connection) -> Result<CustomGroup> {
|
||||||
let mut blog = Group::default();
|
let mut blog = ApActor::new(self.inbox_url.parse()?, Group::new());
|
||||||
blog.ap_actor_props
|
blog.set_preferred_username(iri_percent_encode_seg(&self.actor_id));
|
||||||
.set_preferred_username_string(self.actor_id.clone())?;
|
blog.set_name(self.title.clone());
|
||||||
blog.object_props.set_name_string(self.title.clone())?;
|
blog.set_outbox(self.outbox_url.parse()?);
|
||||||
blog.ap_actor_props
|
blog.set_summary(self.summary_html.to_string());
|
||||||
.set_outbox_string(self.outbox_url.clone())?;
|
let source = SourceProperty {
|
||||||
blog.ap_actor_props
|
source: Source {
|
||||||
.set_inbox_string(self.inbox_url.clone())?;
|
content: self.summary.clone(),
|
||||||
blog.object_props
|
media_type: String::from("text/markdown"),
|
||||||
.set_summary_string(self.summary_html.to_string())?;
|
},
|
||||||
blog.ap_object_props.set_source_object(Source {
|
};
|
||||||
content: self.summary.clone(),
|
|
||||||
media_type: String::from("text/markdown"),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut icon = Image::default();
|
let mut icon = Image::new();
|
||||||
icon.object_props.set_url_string(
|
let _ = self.icon_id.map(|id| {
|
||||||
self.icon_id
|
Media::get(conn, id).and_then(|m| {
|
||||||
.and_then(|id| Media::get(conn, id).and_then(|m| m.url()).ok())
|
let _ = m
|
||||||
.unwrap_or_default(),
|
.url()
|
||||||
)?;
|
.and_then(|url| url.parse::<IriString>().map_err(|_| Error::Url))
|
||||||
icon.object_props.set_attributed_to_link(
|
.map(|url| icon.set_url(url));
|
||||||
self.icon_id
|
icon.set_attributed_to(
|
||||||
.and_then(|id| {
|
User::get(conn, m.owner_id)?
|
||||||
Media::get(conn, id)
|
.into_id()
|
||||||
.and_then(|m| Ok(User::get(conn, m.owner_id)?.into_id()))
|
.parse::<IriString>()?,
|
||||||
.ok()
|
);
|
||||||
})
|
Ok(())
|
||||||
.unwrap_or_else(|| Id::new(String::new())),
|
})
|
||||||
)?;
|
});
|
||||||
blog.object_props.set_icon_object(icon)?;
|
blog.set_icon(icon.into_any_base()?);
|
||||||
|
|
||||||
let mut banner = Image::default();
|
let mut banner = Image::new();
|
||||||
banner.object_props.set_url_string(
|
let _ = self.banner_id.map(|id| {
|
||||||
self.banner_id
|
Media::get(conn, id).and_then(|m| {
|
||||||
.and_then(|id| Media::get(conn, id).and_then(|m| m.url()).ok())
|
let _ = m
|
||||||
.unwrap_or_default(),
|
.url()
|
||||||
)?;
|
.and_then(|url| url.parse::<IriString>().map_err(|_| Error::Url))
|
||||||
banner.object_props.set_attributed_to_link(
|
.map(|url| banner.set_url(url));
|
||||||
self.banner_id
|
banner.set_attributed_to(
|
||||||
.and_then(|id| {
|
User::get(conn, m.owner_id)?
|
||||||
Media::get(conn, id)
|
.into_id()
|
||||||
.and_then(|m| Ok(User::get(conn, m.owner_id)?.into_id()))
|
.parse::<IriString>()?,
|
||||||
.ok()
|
);
|
||||||
})
|
Ok(())
|
||||||
.unwrap_or_else(|| Id::new(String::new())),
|
})
|
||||||
)?;
|
});
|
||||||
blog.object_props.set_image_object(banner)?;
|
blog.set_image(banner.into_any_base()?);
|
||||||
|
|
||||||
blog.object_props.set_id_string(self.ap_url.clone())?;
|
blog.set_id(self.ap_url.parse()?);
|
||||||
|
|
||||||
let mut public_key = PublicKey::default();
|
let pub_key = PublicKey {
|
||||||
public_key.set_id_string(format!("{}#main-key", self.ap_url))?;
|
id: format!("{}#main-key", self.ap_url).parse()?,
|
||||||
public_key.set_owner_string(self.ap_url.clone())?;
|
owner: self.ap_url.parse()?,
|
||||||
public_key.set_public_key_pem_string(self.public_key.clone())?;
|
public_key_pem: self.public_key.clone(),
|
||||||
let mut ap_signature = ApSignature::default();
|
};
|
||||||
ap_signature.set_public_key_publickey(public_key)?;
|
let ap_signature = ApSignature {
|
||||||
|
public_key: pub_key,
|
||||||
|
};
|
||||||
|
|
||||||
Ok(CustomGroup::new(blog, ap_signature))
|
Ok(CustomGroup::new(blog, ap_signature, source))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn outbox(&self, conn: &Connection) -> Result<ActivityStream<OrderedCollection>> {
|
pub fn outbox(&self, conn: &Connection) -> Result<ActivityStream<OrderedCollection>> {
|
||||||
let mut coll = OrderedCollection::default();
|
self.outbox_collection(conn).map(ActivityStream::new)
|
||||||
coll.collection_props.items = serde_json::to_value(self.get_activities(conn))?;
|
}
|
||||||
coll.collection_props
|
pub fn outbox_collection(&self, conn: &Connection) -> Result<OrderedCollection> {
|
||||||
.set_total_items_u64(self.get_activities(conn).len() as u64)?;
|
let acts = self.get_activities(conn);
|
||||||
coll.collection_props
|
let acts = acts
|
||||||
.set_first_link(Id::new(ap_url(&format!("{}?page=1", &self.outbox_url))))?;
|
.iter()
|
||||||
coll.collection_props
|
.filter_map(|value| AnyBase::from_arbitrary_json(value).ok())
|
||||||
.set_last_link(Id::new(ap_url(&format!(
|
.collect::<Vec<AnyBase>>();
|
||||||
|
let n_acts = acts.len();
|
||||||
|
let mut coll = OrderedCollection::new();
|
||||||
|
coll.set_many_items(acts);
|
||||||
|
coll.set_total_items(n_acts as u64);
|
||||||
|
coll.set_first(format!("{}?page=1", &self.outbox_url).parse::<IriString>()?);
|
||||||
|
coll.set_last(
|
||||||
|
format!(
|
||||||
"{}?page={}",
|
"{}?page={}",
|
||||||
&self.outbox_url,
|
&self.outbox_url,
|
||||||
(self.get_activities(conn).len() as u64 + ITEMS_PER_PAGE as u64 - 1) as u64
|
(n_acts as u64 + ITEMS_PER_PAGE as u64 - 1) as u64 / ITEMS_PER_PAGE as u64
|
||||||
/ ITEMS_PER_PAGE as u64
|
)
|
||||||
))))?;
|
.parse::<IriString>()?,
|
||||||
Ok(ActivityStream::new(coll))
|
);
|
||||||
|
Ok(coll)
|
||||||
}
|
}
|
||||||
pub fn outbox_page(
|
pub fn outbox_page(
|
||||||
&self,
|
&self,
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
(min, max): (i32, i32),
|
(min, max): (i32, i32),
|
||||||
) -> Result<ActivityStream<OrderedCollectionPage>> {
|
) -> Result<ActivityStream<OrderedCollectionPage>> {
|
||||||
let mut coll = OrderedCollectionPage::default();
|
self.outbox_collection_page(conn, (min, max))
|
||||||
let acts = self.get_activity_page(&conn, (min, max));
|
.map(ActivityStream::new)
|
||||||
|
}
|
||||||
|
pub fn outbox_collection_page(
|
||||||
|
&self,
|
||||||
|
conn: &Connection,
|
||||||
|
(min, max): (i32, i32),
|
||||||
|
) -> Result<OrderedCollectionPage> {
|
||||||
|
let mut coll = OrderedCollectionPage::new();
|
||||||
|
let acts = self.get_activity_page(conn, (min, max));
|
||||||
//This still doesn't do anything because the outbox
|
//This still doesn't do anything because the outbox
|
||||||
//doesn't do anything yet
|
//doesn't do anything yet
|
||||||
coll.collection_page_props.set_next_link(Id::new(&format!(
|
coll.set_next(
|
||||||
"{}?page={}",
|
format!("{}?page={}", &self.outbox_url, min / ITEMS_PER_PAGE + 1)
|
||||||
&self.outbox_url,
|
.parse::<IriString>()?,
|
||||||
min / ITEMS_PER_PAGE + 1
|
);
|
||||||
)))?;
|
coll.set_prev(
|
||||||
coll.collection_page_props.set_prev_link(Id::new(&format!(
|
format!("{}?page={}", &self.outbox_url, min / ITEMS_PER_PAGE - 1)
|
||||||
"{}?page={}",
|
.parse::<IriString>()?,
|
||||||
&self.outbox_url,
|
);
|
||||||
min / ITEMS_PER_PAGE - 1
|
coll.set_many_items(
|
||||||
)))?;
|
acts.iter()
|
||||||
coll.collection_props.items = serde_json::to_value(acts)?;
|
.filter_map(|value| AnyBase::from_arbitrary_json(value).ok()),
|
||||||
Ok(ActivityStream::new(coll))
|
);
|
||||||
|
Ok(coll)
|
||||||
}
|
}
|
||||||
fn get_activities(&self, _conn: &Connection) -> Vec<serde_json::Value> {
|
fn get_activities(&self, _conn: &Connection) -> Vec<serde_json::Value> {
|
||||||
vec![]
|
vec![]
|
||||||
@@ -265,7 +300,10 @@ impl Blog {
|
|||||||
|
|
||||||
pub fn get_keypair(&self) -> Result<PKey<Private>> {
|
pub fn get_keypair(&self) -> Result<PKey<Private>> {
|
||||||
PKey::from_rsa(Rsa::private_key_from_pem(
|
PKey::from_rsa(Rsa::private_key_from_pem(
|
||||||
self.private_key.clone()?.as_ref(),
|
self.private_key
|
||||||
|
.clone()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.as_ref(),
|
||||||
)?)
|
)?)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
@@ -318,7 +356,7 @@ impl Blog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(&self, conn: &Connection) -> Result<()> {
|
pub fn delete(&self, conn: &Connection) -> Result<()> {
|
||||||
for post in Post::get_for_blog(conn, &self)? {
|
for post in Post::get_for_blog(conn, self)? {
|
||||||
post.delete(conn)?;
|
post.delete(conn)?;
|
||||||
}
|
}
|
||||||
diesel::delete(self)
|
diesel::delete(self)
|
||||||
@@ -334,18 +372,100 @@ impl IntoId for Blog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromId<DbConn> for Blog {
|
impl FromId<Connection> for Blog {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = CustomGroup;
|
type Object = CustomGroup;
|
||||||
|
|
||||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||||
Self::find_by_ap_url(&conn, id)
|
Self::find_by_ap_url(conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(conn: &DbConn, acct: CustomGroup) -> Result<Self> {
|
fn from_activity(conn: &Connection, acct: CustomGroup) -> Result<Self> {
|
||||||
let url = Url::parse(&acct.object.object_props.id_string()?)?;
|
let (name, outbox_url, inbox_url) = {
|
||||||
let inst = url.host_str()?;
|
let actor = acct.ap_actor_ref();
|
||||||
let instance = Instance::find_by_domain(conn, inst).or_else(|_| {
|
let name = actor
|
||||||
|
.preferred_username()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.to_string();
|
||||||
|
if name.contains(&['<', '>', '&', '@', '\'', '"', ' ', '\t'][..]) {
|
||||||
|
tracing::error!("preferredUsername includes invalid character(s): {}", &name);
|
||||||
|
return Err(Error::InvalidValue);
|
||||||
|
}
|
||||||
|
(
|
||||||
|
name,
|
||||||
|
actor.outbox()?.ok_or(Error::MissingApProperty)?.to_string(),
|
||||||
|
actor.inbox()?.to_string(),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut new_blog = NewBlog {
|
||||||
|
actor_id: name.to_string(),
|
||||||
|
outbox_url,
|
||||||
|
inbox_url,
|
||||||
|
public_key: acct.ext_one.public_key.public_key_pem.to_string(),
|
||||||
|
private_key: None,
|
||||||
|
theme: None,
|
||||||
|
..NewBlog::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let object = ApObject::new(acct.inner);
|
||||||
|
new_blog.title = object
|
||||||
|
.name()
|
||||||
|
.and_then(|name| name.to_as_string())
|
||||||
|
.unwrap_or(name);
|
||||||
|
new_blog.summary_html = SafeString::new(
|
||||||
|
&object
|
||||||
|
.summary()
|
||||||
|
.and_then(|summary| summary.to_as_string())
|
||||||
|
.unwrap_or_default(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let icon_id = object
|
||||||
|
.icon()
|
||||||
|
.and_then(|icons| {
|
||||||
|
icons.iter().next().and_then(|icon| {
|
||||||
|
let icon = icon.to_owned().extend::<Image, ImageType>().ok()??;
|
||||||
|
let owner = icon.attributed_to()?.to_as_uri()?;
|
||||||
|
Media::save_remote(
|
||||||
|
conn,
|
||||||
|
icon.url()?.to_as_uri()?,
|
||||||
|
&User::from_id(conn, &owner, None, CONFIG.proxy()).ok()?,
|
||||||
|
)
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.map(|m| m.id);
|
||||||
|
new_blog.icon_id = icon_id;
|
||||||
|
|
||||||
|
let banner_id = object
|
||||||
|
.image()
|
||||||
|
.and_then(|banners| {
|
||||||
|
banners.iter().next().and_then(|banner| {
|
||||||
|
let banner = banner.to_owned().extend::<Image, ImageType>().ok()??;
|
||||||
|
let owner = banner.attributed_to()?.to_as_uri()?;
|
||||||
|
Media::save_remote(
|
||||||
|
conn,
|
||||||
|
banner.url()?.to_as_uri()?,
|
||||||
|
&User::from_id(conn, &owner, None, CONFIG.proxy()).ok()?,
|
||||||
|
)
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.map(|m| m.id);
|
||||||
|
new_blog.banner_id = banner_id;
|
||||||
|
|
||||||
|
new_blog.summary = acct.ext_two.source.content;
|
||||||
|
|
||||||
|
let any_base = AnyBase::from_extended(object)?;
|
||||||
|
let id = any_base.id().ok_or(Error::MissingApProperty)?;
|
||||||
|
new_blog.ap_url = id.to_string();
|
||||||
|
|
||||||
|
let inst = id
|
||||||
|
.authority_components()
|
||||||
|
.ok_or(Error::Url)?
|
||||||
|
.host()
|
||||||
|
.to_string();
|
||||||
|
let instance = Instance::find_by_domain(conn, &inst).or_else(|_| {
|
||||||
Instance::insert(
|
Instance::insert(
|
||||||
conn,
|
conn,
|
||||||
NewInstance {
|
NewInstance {
|
||||||
@@ -362,75 +482,13 @@ impl FromId<DbConn> for Blog {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
let icon_id = acct
|
new_blog.instance_id = instance.id;
|
||||||
.object
|
|
||||||
.object_props
|
|
||||||
.icon_image()
|
|
||||||
.ok()
|
|
||||||
.and_then(|icon| {
|
|
||||||
let owner = icon.object_props.attributed_to_link::<Id>().ok()?;
|
|
||||||
Media::save_remote(
|
|
||||||
conn,
|
|
||||||
icon.object_props.url_string().ok()?,
|
|
||||||
&User::from_id(conn, &owner, None, CONFIG.proxy()).ok()?,
|
|
||||||
)
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.map(|m| m.id);
|
|
||||||
|
|
||||||
let banner_id = acct
|
Blog::insert(conn, new_blog)
|
||||||
.object
|
}
|
||||||
.object_props
|
|
||||||
.image_image()
|
|
||||||
.ok()
|
|
||||||
.and_then(|banner| {
|
|
||||||
let owner = banner.object_props.attributed_to_link::<Id>().ok()?;
|
|
||||||
Media::save_remote(
|
|
||||||
conn,
|
|
||||||
banner.object_props.url_string().ok()?,
|
|
||||||
&User::from_id(conn, &owner, None, CONFIG.proxy()).ok()?,
|
|
||||||
)
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.map(|m| m.id);
|
|
||||||
|
|
||||||
let name = acct.object.ap_actor_props.preferred_username_string()?;
|
fn get_sender() -> &'static dyn sign::Signer {
|
||||||
if name.contains(&['<', '>', '&', '@', '\'', '"', ' ', '\t'][..]) {
|
Instance::get_local_instance_user().expect("Failed to local instance user")
|
||||||
return Err(Error::InvalidValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
Blog::insert(
|
|
||||||
conn,
|
|
||||||
NewBlog {
|
|
||||||
actor_id: name.clone(),
|
|
||||||
title: acct.object.object_props.name_string().unwrap_or(name),
|
|
||||||
outbox_url: acct.object.ap_actor_props.outbox_string()?,
|
|
||||||
inbox_url: acct.object.ap_actor_props.inbox_string()?,
|
|
||||||
summary: acct
|
|
||||||
.object
|
|
||||||
.ap_object_props
|
|
||||||
.source_object::<Source>()
|
|
||||||
.map(|s| s.content)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
instance_id: instance.id,
|
|
||||||
ap_url: acct.object.object_props.id_string()?,
|
|
||||||
public_key: acct
|
|
||||||
.custom_props
|
|
||||||
.public_key_publickey()?
|
|
||||||
.public_key_pem_string()?,
|
|
||||||
private_key: None,
|
|
||||||
banner_id,
|
|
||||||
icon_id,
|
|
||||||
summary_html: SafeString::new(
|
|
||||||
&acct
|
|
||||||
.object
|
|
||||||
.object_props
|
|
||||||
.summary_string()
|
|
||||||
.unwrap_or_default(),
|
|
||||||
),
|
|
||||||
theme: None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,24 +509,22 @@ impl AsActor<&PlumeRocket> for Blog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl sign::Signer for Blog {
|
impl sign::Signer for Blog {
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn get_key_id(&self) -> String {
|
fn get_key_id(&self) -> String {
|
||||||
format!("{}#main-key", self.ap_url)
|
format!("{}#main-key", self.ap_url)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign(&self, to_sign: &str) -> Result<Vec<u8>> {
|
fn sign(&self, to_sign: &str) -> sign::Result<Vec<u8>> {
|
||||||
let key = self.get_keypair()?;
|
let key = self.get_keypair().map_err(|_| sign::Error())?;
|
||||||
let mut signer = Signer::new(MessageDigest::sha256(), &key)?;
|
let mut signer = Signer::new(MessageDigest::sha256(), &key)?;
|
||||||
signer.update(to_sign.as_bytes())?;
|
signer.update(to_sign.as_bytes())?;
|
||||||
signer.sign_to_vec().map_err(Error::from)
|
signer.sign_to_vec().map_err(sign::Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify(&self, data: &str, signature: &[u8]) -> Result<bool> {
|
fn verify(&self, data: &str, signature: &[u8]) -> sign::Result<bool> {
|
||||||
let key = PKey::from_rsa(Rsa::public_key_from_pem(self.public_key.as_ref())?)?;
|
let key = PKey::from_rsa(Rsa::public_key_from_pem(self.public_key.as_ref())?)?;
|
||||||
let mut verifier = Verifier::new(MessageDigest::sha256(), &key)?;
|
let mut verifier = Verifier::new(MessageDigest::sha256(), &key)?;
|
||||||
verifier.update(data.as_bytes())?;
|
verifier.update(data.as_bytes())?;
|
||||||
verifier.verify(&signature).map_err(Error::from)
|
verifier.verify(signature).map_err(sign::Error::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,12 +555,14 @@ pub(crate) mod tests {
|
|||||||
blog_authors::*, instance::tests as instance_tests, medias::NewMedia, tests::db,
|
blog_authors::*, instance::tests as instance_tests, medias::NewMedia, tests::db,
|
||||||
users::tests as usersTests, Connection as Conn,
|
users::tests as usersTests, Connection as Conn,
|
||||||
};
|
};
|
||||||
|
use assert_json_diff::assert_json_eq;
|
||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
|
use serde_json::to_value;
|
||||||
|
|
||||||
pub(crate) fn fill_database(conn: &Conn) -> (Vec<User>, Vec<Blog>) {
|
pub(crate) fn fill_database(conn: &Conn) -> (Vec<User>, Vec<Blog>) {
|
||||||
instance_tests::fill_database(conn);
|
instance_tests::fill_database(conn);
|
||||||
let users = usersTests::fill_database(conn);
|
let users = usersTests::fill_database(conn);
|
||||||
let blog1 = Blog::insert(
|
let mut blog1 = Blog::insert(
|
||||||
conn,
|
conn,
|
||||||
NewBlog::new_local(
|
NewBlog::new_local(
|
||||||
"BlogName".to_owned(),
|
"BlogName".to_owned(),
|
||||||
@@ -577,6 +635,41 @@ pub(crate) mod tests {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
blog1.icon_id = Some(
|
||||||
|
Media::insert(
|
||||||
|
conn,
|
||||||
|
NewMedia {
|
||||||
|
file_path: "aaa.png".into(),
|
||||||
|
alt_text: String::new(),
|
||||||
|
is_remote: false,
|
||||||
|
remote_url: None,
|
||||||
|
sensitive: false,
|
||||||
|
content_warning: None,
|
||||||
|
owner_id: users[0].id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.id,
|
||||||
|
);
|
||||||
|
blog1.banner_id = Some(
|
||||||
|
Media::insert(
|
||||||
|
conn,
|
||||||
|
NewMedia {
|
||||||
|
file_path: "bbb.png".into(),
|
||||||
|
alt_text: String::new(),
|
||||||
|
is_remote: false,
|
||||||
|
remote_url: None,
|
||||||
|
sensitive: false,
|
||||||
|
content_warning: None,
|
||||||
|
owner_id: users[0].id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.id,
|
||||||
|
);
|
||||||
|
let _: Blog = blog1.save_changes(conn).unwrap();
|
||||||
|
|
||||||
(users, vec![blog1, blog2, blog3])
|
(users, vec![blog1, blog2, blog3])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,10 +677,10 @@ pub(crate) mod tests {
|
|||||||
fn get_instance() {
|
fn get_instance() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
fill_database(&conn);
|
fill_database(conn);
|
||||||
|
|
||||||
let blog = Blog::insert(
|
let blog = Blog::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlog::new_local(
|
NewBlog::new_local(
|
||||||
"SomeName".to_owned(),
|
"SomeName".to_owned(),
|
||||||
"Some name".to_owned(),
|
"Some name".to_owned(),
|
||||||
@@ -599,7 +692,7 @@ pub(crate) mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
blog.get_instance(&conn).unwrap().id,
|
blog.get_instance(conn).unwrap().id,
|
||||||
Instance::get_local().unwrap().id
|
Instance::get_local().unwrap().id
|
||||||
);
|
);
|
||||||
// TODO add tests for remote instance
|
// TODO add tests for remote instance
|
||||||
@@ -611,10 +704,10 @@ pub(crate) mod tests {
|
|||||||
fn authors() {
|
fn authors() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (user, _) = fill_database(&conn);
|
let (user, _) = fill_database(conn);
|
||||||
|
|
||||||
let b1 = Blog::insert(
|
let b1 = Blog::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlog::new_local(
|
NewBlog::new_local(
|
||||||
"SomeName".to_owned(),
|
"SomeName".to_owned(),
|
||||||
"Some name".to_owned(),
|
"Some name".to_owned(),
|
||||||
@@ -625,7 +718,7 @@ pub(crate) mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let b2 = Blog::insert(
|
let b2 = Blog::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlog::new_local(
|
NewBlog::new_local(
|
||||||
"Blog".to_owned(),
|
"Blog".to_owned(),
|
||||||
"Blog".to_owned(),
|
"Blog".to_owned(),
|
||||||
@@ -638,7 +731,7 @@ pub(crate) mod tests {
|
|||||||
let blog = vec![b1, b2];
|
let blog = vec![b1, b2];
|
||||||
|
|
||||||
BlogAuthor::insert(
|
BlogAuthor::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlogAuthor {
|
NewBlogAuthor {
|
||||||
blog_id: blog[0].id,
|
blog_id: blog[0].id,
|
||||||
author_id: user[0].id,
|
author_id: user[0].id,
|
||||||
@@ -648,7 +741,7 @@ pub(crate) mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
BlogAuthor::insert(
|
BlogAuthor::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlogAuthor {
|
NewBlogAuthor {
|
||||||
blog_id: blog[0].id,
|
blog_id: blog[0].id,
|
||||||
author_id: user[1].id,
|
author_id: user[1].id,
|
||||||
@@ -658,7 +751,7 @@ pub(crate) mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
BlogAuthor::insert(
|
BlogAuthor::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlogAuthor {
|
NewBlogAuthor {
|
||||||
blog_id: blog[1].id,
|
blog_id: blog[1].id,
|
||||||
author_id: user[0].id,
|
author_id: user[0].id,
|
||||||
@@ -668,39 +761,39 @@ pub(crate) mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert!(blog[0]
|
assert!(blog[0]
|
||||||
.list_authors(&conn)
|
.list_authors(conn)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|a| a.id == user[0].id));
|
.any(|a| a.id == user[0].id));
|
||||||
assert!(blog[0]
|
assert!(blog[0]
|
||||||
.list_authors(&conn)
|
.list_authors(conn)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|a| a.id == user[1].id));
|
.any(|a| a.id == user[1].id));
|
||||||
assert!(blog[1]
|
assert!(blog[1]
|
||||||
.list_authors(&conn)
|
.list_authors(conn)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|a| a.id == user[0].id));
|
.any(|a| a.id == user[0].id));
|
||||||
assert!(!blog[1]
|
assert!(!blog[1]
|
||||||
.list_authors(&conn)
|
.list_authors(conn)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|a| a.id == user[1].id));
|
.any(|a| a.id == user[1].id));
|
||||||
|
|
||||||
assert!(Blog::find_for_author(&conn, &user[0])
|
assert!(Blog::find_for_author(conn, &user[0])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|b| b.id == blog[0].id));
|
.any(|b| b.id == blog[0].id));
|
||||||
assert!(Blog::find_for_author(&conn, &user[1])
|
assert!(Blog::find_for_author(conn, &user[1])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|b| b.id == blog[0].id));
|
.any(|b| b.id == blog[0].id));
|
||||||
assert!(Blog::find_for_author(&conn, &user[0])
|
assert!(Blog::find_for_author(conn, &user[0])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|b| b.id == blog[1].id));
|
.any(|b| b.id == blog[1].id));
|
||||||
assert!(!Blog::find_for_author(&conn, &user[1])
|
assert!(!Blog::find_for_author(conn, &user[1])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|b| b.id == blog[1].id));
|
.any(|b| b.id == blog[1].id));
|
||||||
@@ -712,10 +805,10 @@ pub(crate) mod tests {
|
|||||||
fn find_local() {
|
fn find_local() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
fill_database(&conn);
|
fill_database(conn);
|
||||||
|
|
||||||
let blog = Blog::insert(
|
let blog = Blog::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlog::new_local(
|
NewBlog::new_local(
|
||||||
"SomeName".to_owned(),
|
"SomeName".to_owned(),
|
||||||
"Some name".to_owned(),
|
"Some name".to_owned(),
|
||||||
@@ -726,7 +819,7 @@ pub(crate) mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(Blog::find_by_fqn(&conn, "SomeName").unwrap().id, blog.id);
|
assert_eq!(Blog::find_by_fqn(conn, "SomeName").unwrap().id, blog.id);
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -735,10 +828,10 @@ pub(crate) mod tests {
|
|||||||
fn get_fqn() {
|
fn get_fqn() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
fill_database(&conn);
|
fill_database(conn);
|
||||||
|
|
||||||
let blog = Blog::insert(
|
let blog = Blog::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlog::new_local(
|
NewBlog::new_local(
|
||||||
"SomeName".to_owned(),
|
"SomeName".to_owned(),
|
||||||
"Some name".to_owned(),
|
"Some name".to_owned(),
|
||||||
@@ -758,10 +851,10 @@ pub(crate) mod tests {
|
|||||||
fn delete() {
|
fn delete() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (_, blogs) = fill_database(&conn);
|
let (_, blogs) = fill_database(conn);
|
||||||
|
|
||||||
blogs[0].delete(&conn).unwrap();
|
blogs[0].delete(conn).unwrap();
|
||||||
assert!(Blog::get(&conn, blogs[0].id).is_err());
|
assert!(Blog::get(conn, blogs[0].id).is_err());
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -770,10 +863,10 @@ pub(crate) mod tests {
|
|||||||
fn delete_via_user() {
|
fn delete_via_user() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (user, _) = fill_database(&conn);
|
let (user, _) = fill_database(conn);
|
||||||
|
|
||||||
let b1 = Blog::insert(
|
let b1 = Blog::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlog::new_local(
|
NewBlog::new_local(
|
||||||
"SomeName".to_owned(),
|
"SomeName".to_owned(),
|
||||||
"Some name".to_owned(),
|
"Some name".to_owned(),
|
||||||
@@ -784,7 +877,7 @@ pub(crate) mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let b2 = Blog::insert(
|
let b2 = Blog::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlog::new_local(
|
NewBlog::new_local(
|
||||||
"Blog".to_owned(),
|
"Blog".to_owned(),
|
||||||
"Blog".to_owned(),
|
"Blog".to_owned(),
|
||||||
@@ -797,7 +890,7 @@ pub(crate) mod tests {
|
|||||||
let blog = vec![b1, b2];
|
let blog = vec![b1, b2];
|
||||||
|
|
||||||
BlogAuthor::insert(
|
BlogAuthor::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlogAuthor {
|
NewBlogAuthor {
|
||||||
blog_id: blog[0].id,
|
blog_id: blog[0].id,
|
||||||
author_id: user[0].id,
|
author_id: user[0].id,
|
||||||
@@ -807,7 +900,7 @@ pub(crate) mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
BlogAuthor::insert(
|
BlogAuthor::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlogAuthor {
|
NewBlogAuthor {
|
||||||
blog_id: blog[0].id,
|
blog_id: blog[0].id,
|
||||||
author_id: user[1].id,
|
author_id: user[1].id,
|
||||||
@@ -817,7 +910,7 @@ pub(crate) mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
BlogAuthor::insert(
|
BlogAuthor::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewBlogAuthor {
|
NewBlogAuthor {
|
||||||
blog_id: blog[1].id,
|
blog_id: blog[1].id,
|
||||||
author_id: user[0].id,
|
author_id: user[0].id,
|
||||||
@@ -826,11 +919,11 @@ pub(crate) mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
user[0].delete(&conn).unwrap();
|
user[0].delete(conn).unwrap();
|
||||||
assert!(Blog::get(&conn, blog[0].id).is_ok());
|
assert!(Blog::get(conn, blog[0].id).is_ok());
|
||||||
assert!(Blog::get(&conn, blog[1].id).is_err());
|
assert!(Blog::get(conn, blog[1].id).is_err());
|
||||||
user[1].delete(&conn).unwrap();
|
user[1].delete(conn).unwrap();
|
||||||
assert!(Blog::get(&conn, blog[0].id).is_err());
|
assert!(Blog::get(conn, blog[0].id).is_err());
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -839,10 +932,10 @@ pub(crate) mod tests {
|
|||||||
fn self_federation() {
|
fn self_federation() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (users, mut blogs) = fill_database(&conn);
|
let (users, mut blogs) = fill_database(conn);
|
||||||
blogs[0].icon_id = Some(
|
blogs[0].icon_id = Some(
|
||||||
Media::insert(
|
Media::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewMedia {
|
NewMedia {
|
||||||
file_path: "aaa.png".into(),
|
file_path: "aaa.png".into(),
|
||||||
alt_text: String::new(),
|
alt_text: String::new(),
|
||||||
@@ -858,7 +951,7 @@ pub(crate) mod tests {
|
|||||||
);
|
);
|
||||||
blogs[0].banner_id = Some(
|
blogs[0].banner_id = Some(
|
||||||
Media::insert(
|
Media::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewMedia {
|
NewMedia {
|
||||||
file_path: "bbb.png".into(),
|
file_path: "bbb.png".into(),
|
||||||
alt_text: String::new(),
|
alt_text: String::new(),
|
||||||
@@ -873,10 +966,9 @@ pub(crate) mod tests {
|
|||||||
.id,
|
.id,
|
||||||
);
|
);
|
||||||
let _: Blog = blogs[0].save_changes(&**conn).unwrap();
|
let _: Blog = blogs[0].save_changes(&**conn).unwrap();
|
||||||
|
let ap_repr = blogs[0].to_activity(conn).unwrap();
|
||||||
let ap_repr = blogs[0].to_activity(&conn).unwrap();
|
blogs[0].delete(conn).unwrap();
|
||||||
blogs[0].delete(&conn).unwrap();
|
let blog = Blog::from_activity(conn, ap_repr).unwrap();
|
||||||
let blog = Blog::from_activity(&conn, ap_repr).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(blog.actor_id, blogs[0].actor_id);
|
assert_eq!(blog.actor_id, blogs[0].actor_id);
|
||||||
assert_eq!(blog.title, blogs[0].title);
|
assert_eq!(blog.title, blogs[0].title);
|
||||||
@@ -888,10 +980,96 @@ pub(crate) mod tests {
|
|||||||
assert_eq!(blog.public_key, blogs[0].public_key);
|
assert_eq!(blog.public_key, blogs[0].public_key);
|
||||||
assert_eq!(blog.fqn, blogs[0].fqn);
|
assert_eq!(blog.fqn, blogs[0].fqn);
|
||||||
assert_eq!(blog.summary_html, blogs[0].summary_html);
|
assert_eq!(blog.summary_html, blogs[0].summary_html);
|
||||||
assert_eq!(blog.icon_url(&conn), blogs[0].icon_url(&conn));
|
assert_eq!(blog.icon_url(conn), blogs[0].icon_url(conn));
|
||||||
assert_eq!(blog.banner_url(&conn), blogs[0].banner_url(&conn));
|
assert_eq!(blog.banner_url(conn), blogs[0].banner_url(conn));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_activity() {
|
||||||
|
let conn = &db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (_users, blogs) = fill_database(conn);
|
||||||
|
let blog = &blogs[0];
|
||||||
|
let act = blog.to_activity(conn)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"icon": {
|
||||||
|
"attributedTo": "https://plu.me/@/admin/",
|
||||||
|
"type": "Image",
|
||||||
|
"url": "https://plu.me/aaa.png"
|
||||||
|
},
|
||||||
|
"id": "https://plu.me/~/BlogName/",
|
||||||
|
"image": {
|
||||||
|
"attributedTo": "https://plu.me/@/admin/",
|
||||||
|
"type": "Image",
|
||||||
|
"url": "https://plu.me/bbb.png"
|
||||||
|
},
|
||||||
|
"inbox": "https://plu.me/~/BlogName/inbox",
|
||||||
|
"name": "Blog name",
|
||||||
|
"outbox": "https://plu.me/~/BlogName/outbox",
|
||||||
|
"preferredUsername": "BlogName",
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://plu.me/~/BlogName/#main-key",
|
||||||
|
"owner": "https://plu.me/~/BlogName/",
|
||||||
|
"publicKeyPem": blog.public_key
|
||||||
|
},
|
||||||
|
"source": {
|
||||||
|
"content": "This is a small blog",
|
||||||
|
"mediaType": "text/markdown"
|
||||||
|
},
|
||||||
|
"summary": "",
|
||||||
|
"type": "Group"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn outbox_collection() {
|
||||||
|
let conn = &db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (_users, blogs) = fill_database(conn);
|
||||||
|
let blog = &blogs[0];
|
||||||
|
let act = blog.outbox_collection(conn)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"items": [],
|
||||||
|
"totalItems": 0,
|
||||||
|
"first": "https://plu.me/~/BlogName/outbox?page=1",
|
||||||
|
"last": "https://plu.me/~/BlogName/outbox?page=0",
|
||||||
|
"type": "OrderedCollection"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn outbox_collection_page() {
|
||||||
|
let conn = &db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (_users, blogs) = fill_database(conn);
|
||||||
|
let blog = &blogs[0];
|
||||||
|
let act = blog.outbox_collection_page(conn, (33, 36))?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"next": "https://plu.me/~/BlogName/outbox?page=3",
|
||||||
|
"prev": "https://plu.me/~/BlogName/outbox?page=1",
|
||||||
|
"items": [],
|
||||||
|
"type": "OrderedCollectionPage"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+292
-130
@@ -1,6 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comment_seers::{CommentSeers, NewCommentSeers},
|
comment_seers::{CommentSeers, NewCommentSeers},
|
||||||
db_conn::DbConn,
|
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
medias::Media,
|
medias::Media,
|
||||||
mentions::Mention,
|
mentions::Mention,
|
||||||
@@ -11,17 +10,23 @@ use crate::{
|
|||||||
users::User,
|
users::User,
|
||||||
Connection, Error, Result, CONFIG,
|
Connection, Error, Result, CONFIG,
|
||||||
};
|
};
|
||||||
use activitypub::{
|
use activitystreams::{
|
||||||
activity::{Create, Delete},
|
activity::{Create, Delete},
|
||||||
link,
|
base::{AnyBase, Base},
|
||||||
|
iri_string::types::IriString,
|
||||||
|
link::{self, kind::MentionType},
|
||||||
object::{Note, Tombstone},
|
object::{Note, Tombstone},
|
||||||
|
prelude::*,
|
||||||
|
primitives::OneOrMany,
|
||||||
|
time::OffsetDateTime,
|
||||||
};
|
};
|
||||||
use chrono::{self, NaiveDateTime};
|
use chrono::{self, NaiveDateTime};
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
||||||
use plume_common::{
|
use plume_common::{
|
||||||
activity_pub::{
|
activity_pub::{
|
||||||
inbox::{AsActor, AsObject, FromId},
|
inbox::{AsActor, AsObject, FromId},
|
||||||
Id, IntoId, PUBLIC_VISIBILITY,
|
sign::Signer,
|
||||||
|
IntoId, ToAsString, ToAsUri, PUBLIC_VISIBILITY,
|
||||||
},
|
},
|
||||||
utils,
|
utils,
|
||||||
};
|
};
|
||||||
@@ -58,7 +63,7 @@ impl Comment {
|
|||||||
insert!(comments, NewComment, |inserted, conn| {
|
insert!(comments, NewComment, |inserted, conn| {
|
||||||
if inserted.ap_url.is_none() {
|
if inserted.ap_url.is_none() {
|
||||||
inserted.ap_url = Some(format!(
|
inserted.ap_url = Some(format!(
|
||||||
"{}comment/{}",
|
"{}/comment/{}",
|
||||||
inserted.get_post(conn)?.ap_url,
|
inserted.get_post(conn)?.ap_url,
|
||||||
inserted.id
|
inserted.id
|
||||||
));
|
));
|
||||||
@@ -68,6 +73,7 @@ impl Comment {
|
|||||||
});
|
});
|
||||||
get!(comments);
|
get!(comments);
|
||||||
list_by!(comments, list_by_post, post_id as i32);
|
list_by!(comments, list_by_post, post_id as i32);
|
||||||
|
list_by!(comments, list_by_author, author_id as i32);
|
||||||
find_by!(comments, find_by_ap_url, ap_url as &str);
|
find_by!(comments, find_by_ap_url, ap_url as &str);
|
||||||
|
|
||||||
pub fn get_author(&self, conn: &Connection) -> Result<User> {
|
pub fn get_author(&self, conn: &Connection) -> Result<User> {
|
||||||
@@ -105,7 +111,7 @@ impl Comment {
|
|||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_activity(&self, conn: &DbConn) -> Result<Note> {
|
pub fn to_activity(&self, conn: &Connection) -> Result<Note> {
|
||||||
let author = User::get(conn, self.author_id)?;
|
let author = User::get(conn, self.author_id)?;
|
||||||
let (html, mentions, _hashtags) = utils::md_to_html(
|
let (html, mentions, _hashtags) = utils::md_to_html(
|
||||||
self.content.get().as_ref(),
|
self.content.get().as_ref(),
|
||||||
@@ -114,45 +120,59 @@ impl Comment {
|
|||||||
Some(Media::get_media_processor(conn, vec![&author])),
|
Some(Media::get_media_processor(conn, vec![&author])),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut note = Note::default();
|
let mut note = Note::new();
|
||||||
let to = vec![Id::new(PUBLIC_VISIBILITY.to_string())];
|
let to = vec![PUBLIC_VISIBILITY.parse::<IriString>()?];
|
||||||
|
|
||||||
note.object_props
|
note.set_id(
|
||||||
.set_id_string(self.ap_url.clone().unwrap_or_default())?;
|
self.ap_url
|
||||||
note.object_props
|
.clone()
|
||||||
.set_summary_string(self.spoiler_text.clone())?;
|
.unwrap_or_default()
|
||||||
note.object_props.set_content_string(html)?;
|
.parse::<IriString>()?,
|
||||||
note.object_props
|
);
|
||||||
.set_in_reply_to_link(Id::new(self.in_response_to_id.map_or_else(
|
note.set_summary(self.spoiler_text.clone());
|
||||||
|| Ok(Post::get(conn, self.post_id)?.ap_url),
|
note.set_content(html);
|
||||||
|id| Ok(Comment::get(conn, id)?.ap_url.unwrap_or_default()) as Result<String>,
|
note.set_in_reply_to(self.in_response_to_id.map_or_else(
|
||||||
)?))?;
|
|| Post::get(conn, self.post_id).map(|post| post.ap_url),
|
||||||
note.object_props
|
|id| Comment::get(conn, id).map(|comment| comment.ap_url.unwrap_or_default()),
|
||||||
.set_published_string(chrono::Utc::now().to_rfc3339())?;
|
)?);
|
||||||
note.object_props.set_attributed_to_link(author.into_id())?;
|
note.set_published(
|
||||||
note.object_props.set_to_link_vec(to)?;
|
OffsetDateTime::from_unix_timestamp_nanos(self.creation_date.timestamp_nanos().into())
|
||||||
note.object_props.set_tag_link_vec(
|
.expect("OffsetDateTime"),
|
||||||
mentions
|
);
|
||||||
.into_iter()
|
note.set_attributed_to(author.into_id().parse::<IriString>()?);
|
||||||
.filter_map(|m| Mention::build_activity(conn, &m).ok())
|
note.set_many_tos(to);
|
||||||
.collect::<Vec<link::Mention>>(),
|
note.set_many_tags(mentions.into_iter().filter_map(|m| {
|
||||||
)?;
|
Mention::build_activity(conn, &m)
|
||||||
|
.map(|mention| mention.into_any_base().expect("Can convert"))
|
||||||
|
.ok()
|
||||||
|
}));
|
||||||
Ok(note)
|
Ok(note)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_activity(&self, conn: &DbConn) -> Result<Create> {
|
pub fn create_activity(&self, conn: &Connection) -> Result<Create> {
|
||||||
let author = User::get(&conn, self.author_id)?;
|
let author = User::get(conn, self.author_id)?;
|
||||||
|
|
||||||
let note = self.to_activity(conn)?;
|
let note = self.to_activity(conn)?;
|
||||||
let mut act = Create::default();
|
let note_clone = note.clone();
|
||||||
act.create_props.set_actor_link(author.into_id())?;
|
|
||||||
act.create_props.set_object_object(note.clone())?;
|
let mut act = Create::new(
|
||||||
act.object_props
|
author.into_id().parse::<IriString>()?,
|
||||||
.set_id_string(format!("{}/activity", self.ap_url.clone()?,))?;
|
Base::retract(note)?.into_generic()?,
|
||||||
act.object_props
|
);
|
||||||
.set_to_link_vec(note.object_props.to_link_vec::<Id>()?)?;
|
act.set_id(
|
||||||
act.object_props
|
format!(
|
||||||
.set_cc_link_vec(vec![Id::new(self.get_author(&conn)?.followers_endpoint)])?;
|
"{}/activity",
|
||||||
|
self.ap_url.clone().ok_or(Error::MissingApProperty)?,
|
||||||
|
)
|
||||||
|
.parse::<IriString>()?,
|
||||||
|
);
|
||||||
|
act.set_many_tos(
|
||||||
|
note_clone
|
||||||
|
.to()
|
||||||
|
.iter()
|
||||||
|
.flat_map(|tos| tos.iter().map(|to| to.to_owned())),
|
||||||
|
);
|
||||||
|
act.set_many_ccs(vec![self.get_author(conn)?.followers_endpoint]);
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,130 +197,140 @@ impl Comment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_delete(&self, conn: &Connection) -> Result<Delete> {
|
pub fn build_delete(&self, conn: &Connection) -> Result<Delete> {
|
||||||
let mut act = Delete::default();
|
let mut tombstone = Tombstone::new();
|
||||||
act.delete_props
|
tombstone.set_id(
|
||||||
.set_actor_link(self.get_author(conn)?.into_id())?;
|
self.ap_url
|
||||||
|
.as_ref()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.parse::<IriString>()?,
|
||||||
|
);
|
||||||
|
|
||||||
let mut tombstone = Tombstone::default();
|
let mut act = Delete::new(
|
||||||
tombstone.object_props.set_id_string(self.ap_url.clone()?)?;
|
self.get_author(conn)?.into_id().parse::<IriString>()?,
|
||||||
act.delete_props.set_object_object(tombstone)?;
|
Base::retract(tombstone)?.into_generic()?,
|
||||||
|
);
|
||||||
|
|
||||||
act.object_props
|
act.set_id(format!("{}#delete", self.ap_url.clone().unwrap()).parse::<IriString>()?);
|
||||||
.set_id_string(format!("{}#delete", self.ap_url.clone().unwrap()))?;
|
act.set_many_tos(vec![PUBLIC_VISIBILITY.parse::<IriString>()?]);
|
||||||
act.object_props
|
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY)])?;
|
|
||||||
|
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromId<DbConn> for Comment {
|
impl FromId<Connection> for Comment {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = Note;
|
type Object = Note;
|
||||||
|
|
||||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||||
Self::find_by_ap_url(conn, id)
|
Self::find_by_ap_url(conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(conn: &DbConn, note: Note) -> Result<Self> {
|
fn from_activity(conn: &Connection, note: Note) -> Result<Self> {
|
||||||
let comm = {
|
let comm = {
|
||||||
let previous_url = note.object_props.in_reply_to.as_ref()?.as_str()?;
|
let previous_url = note
|
||||||
let previous_comment = Comment::find_by_ap_url(conn, previous_url);
|
.in_reply_to()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.iter()
|
||||||
|
.next()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.id()
|
||||||
|
.ok_or(Error::MissingApProperty)?;
|
||||||
|
let previous_comment = Comment::find_by_ap_url(conn, previous_url.as_str());
|
||||||
|
|
||||||
let is_public = |v: &Option<serde_json::Value>| match v
|
let is_public = |v: &Option<&OneOrMany<AnyBase>>| match v {
|
||||||
.as_ref()
|
Some(one_or_many) => one_or_many.iter().any(|any_base| {
|
||||||
.unwrap_or(&serde_json::Value::Null)
|
let id = any_base.id();
|
||||||
{
|
id.is_some() && id.unwrap() == PUBLIC_VISIBILITY
|
||||||
serde_json::Value::Array(v) => v
|
}),
|
||||||
.iter()
|
None => false,
|
||||||
.filter_map(serde_json::Value::as_str)
|
|
||||||
.any(|s| s == PUBLIC_VISIBILITY),
|
|
||||||
serde_json::Value::String(s) => s == PUBLIC_VISIBILITY,
|
|
||||||
_ => false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let public_visibility = is_public(¬e.object_props.to)
|
let public_visibility = is_public(¬e.to())
|
||||||
|| is_public(¬e.object_props.bto)
|
|| is_public(¬e.bto())
|
||||||
|| is_public(¬e.object_props.cc)
|
|| is_public(¬e.cc())
|
||||||
|| is_public(¬e.object_props.bcc);
|
|| is_public(¬e.bcc());
|
||||||
|
|
||||||
|
let summary = note.summary().and_then(|summary| summary.to_as_string());
|
||||||
|
let sensitive = summary.is_some();
|
||||||
let comm = Comment::insert(
|
let comm = Comment::insert(
|
||||||
conn,
|
conn,
|
||||||
NewComment {
|
NewComment {
|
||||||
content: SafeString::new(¬e.object_props.content_string()?),
|
content: SafeString::new(
|
||||||
spoiler_text: note.object_props.summary_string().unwrap_or_default(),
|
¬e
|
||||||
ap_url: note.object_props.id_string().ok(),
|
.content()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.to_as_string()
|
||||||
|
.ok_or(Error::InvalidValue)?,
|
||||||
|
),
|
||||||
|
spoiler_text: summary.unwrap_or_default(),
|
||||||
|
ap_url: Some(
|
||||||
|
note.id_unchecked()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
in_response_to_id: previous_comment.iter().map(|c| c.id).next(),
|
in_response_to_id: previous_comment.iter().map(|c| c.id).next(),
|
||||||
post_id: previous_comment.map(|c| c.post_id).or_else(|_| {
|
post_id: previous_comment.map(|c| c.post_id).or_else(|_| {
|
||||||
Ok(Post::find_by_ap_url(conn, previous_url)?.id) as Result<i32>
|
Ok(Post::find_by_ap_url(conn, previous_url.as_str())?.id) as Result<i32>
|
||||||
})?,
|
})?,
|
||||||
author_id: User::from_id(
|
author_id: User::from_id(
|
||||||
conn,
|
conn,
|
||||||
¬e.object_props.attributed_to_link::<Id>()?,
|
¬e
|
||||||
|
.attributed_to()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.to_as_uri()
|
||||||
|
.ok_or(Error::MissingApProperty)?,
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
.map_err(|(_, e)| e)?
|
.map_err(|(_, e)| e)?
|
||||||
.id,
|
.id,
|
||||||
sensitive: note.object_props.summary_string().is_ok(),
|
sensitive,
|
||||||
public_visibility,
|
public_visibility,
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// save mentions
|
// save mentions
|
||||||
if let Some(serde_json::Value::Array(tags)) = note.object_props.tag.clone() {
|
if let Some(tags) = note.tag() {
|
||||||
for tag in tags {
|
let author_url = &Post::get(conn, comm.post_id)?.get_authors(conn)?[0].ap_url;
|
||||||
serde_json::from_value::<link::Mention>(tag)
|
for tag in tags.iter() {
|
||||||
.map_err(Error::from)
|
let m = tag.clone().extend::<link::Mention, MentionType>()?; // FIXME: Don't clone
|
||||||
.and_then(|m| {
|
if m.is_none() {
|
||||||
let author = &Post::get(conn, comm.post_id)?.get_authors(conn)?[0];
|
continue;
|
||||||
let not_author = m.link_props.href_string()? != author.ap_url.clone();
|
}
|
||||||
Mention::from_activity(conn, &m, comm.id, false, not_author)
|
let m = m.unwrap();
|
||||||
})
|
let not_author = m.href().ok_or(Error::MissingApProperty)? != author_url;
|
||||||
.ok();
|
let _ = Mention::from_activity(conn, &m, comm.id, false, not_author);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
comm
|
comm
|
||||||
};
|
};
|
||||||
|
|
||||||
if !comm.public_visibility {
|
if !comm.public_visibility {
|
||||||
let receivers_ap_url = |v: Option<serde_json::Value>| {
|
let mut receiver_ids = HashSet::new();
|
||||||
let filter = |e: serde_json::Value| {
|
let mut receivers_id = |v: Option<&'_ OneOrMany<AnyBase>>| {
|
||||||
if let serde_json::Value::String(s) = e {
|
if let Some(one_or_many) = v {
|
||||||
Some(s)
|
for any_base in one_or_many.iter() {
|
||||||
} else {
|
if let Some(id) = any_base.id() {
|
||||||
None
|
receiver_ids.insert(id.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
match v.unwrap_or(serde_json::Value::Null) {
|
|
||||||
serde_json::Value::Array(v) => v,
|
|
||||||
v => vec![v],
|
|
||||||
}
|
}
|
||||||
.into_iter()
|
|
||||||
.filter_map(filter)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut note = note;
|
receivers_id(note.to());
|
||||||
|
receivers_id(note.cc());
|
||||||
|
receivers_id(note.bto());
|
||||||
|
receivers_id(note.bcc());
|
||||||
|
|
||||||
let to = receivers_ap_url(note.object_props.to.take());
|
let receivers_ap_url = receiver_ids
|
||||||
let cc = receivers_ap_url(note.object_props.cc.take());
|
|
||||||
let bto = receivers_ap_url(note.object_props.bto.take());
|
|
||||||
let bcc = receivers_ap_url(note.object_props.bcc.take());
|
|
||||||
|
|
||||||
let receivers_ap_url = to
|
|
||||||
.chain(cc)
|
|
||||||
.chain(bto)
|
|
||||||
.chain(bcc)
|
|
||||||
.collect::<HashSet<_>>() // remove duplicates (don't do a query more than once)
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v| {
|
.flat_map(|v| {
|
||||||
if let Ok(user) = User::from_id(conn, &v, None, CONFIG.proxy()) {
|
if let Ok(user) = User::from_id(conn, v.as_ref(), None, CONFIG.proxy()) {
|
||||||
vec![user]
|
vec![user]
|
||||||
} else {
|
} else {
|
||||||
vec![] // TODO try to fetch collection
|
vec![] // TODO try to fetch collection
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten()
|
|
||||||
.filter(|u| u.get_instance(conn).map(|i| i.local).unwrap_or(false))
|
.filter(|u| u.get_instance(conn).map(|i| i.local).unwrap_or(false))
|
||||||
.collect::<HashSet<User>>(); //remove duplicates (prevent db error)
|
.collect::<HashSet<User>>(); //remove duplicates (prevent db error)
|
||||||
|
|
||||||
@@ -318,23 +348,27 @@ impl FromId<DbConn> for Comment {
|
|||||||
comm.notify(conn)?;
|
comm.notify(conn)?;
|
||||||
Ok(comm)
|
Ok(comm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_sender() -> &'static dyn Signer {
|
||||||
|
Instance::get_local_instance_user().expect("Failed to local instance user")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Create, &DbConn> for Comment {
|
impl AsObject<User, Create, &Connection> for Comment {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn activity(self, _conn: &DbConn, _actor: User, _id: &str) -> Result<Self> {
|
fn activity(self, _conn: &Connection, _actor: User, _id: &str) -> Result<Self> {
|
||||||
// The actual creation takes place in the FromId impl
|
// The actual creation takes place in the FromId impl
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Delete, &DbConn> for Comment {
|
impl AsObject<User, Delete, &Connection> for Comment {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||||
if self.author_id != actor.id {
|
if self.author_id != actor.id {
|
||||||
return Err(Error::Unauthorized);
|
return Err(Error::Unauthorized);
|
||||||
}
|
}
|
||||||
@@ -346,15 +380,15 @@ impl AsObject<User, Delete, &DbConn> for Comment {
|
|||||||
m.delete(conn)?;
|
m.delete(conn)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for n in Notification::find_for_comment(&conn, &self)? {
|
for n in Notification::find_for_comment(conn, &self)? {
|
||||||
n.delete(&**conn)?;
|
n.delete(conn)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
diesel::update(comments::table)
|
diesel::update(comments::table)
|
||||||
.filter(comments::in_response_to_id.eq(self.id))
|
.filter(comments::in_response_to_id.eq(self.id))
|
||||||
.set(comments::in_response_to_id.eq(self.in_response_to_id))
|
.set(comments::in_response_to_id.eq(self.in_response_to_id))
|
||||||
.execute(&**conn)?;
|
.execute(conn)?;
|
||||||
diesel::delete(&self).execute(&**conn)?;
|
diesel::delete(&self).execute(conn)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,10 +422,35 @@ impl CommentTree {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::blogs::Blog;
|
||||||
|
use crate::db_conn::DbConn;
|
||||||
use crate::inbox::{inbox, tests::fill_database, InboxResult};
|
use crate::inbox::{inbox, tests::fill_database, InboxResult};
|
||||||
use crate::safe_string::SafeString;
|
use crate::safe_string::SafeString;
|
||||||
use crate::tests::db;
|
use crate::tests::{db, format_datetime};
|
||||||
|
use assert_json_diff::assert_json_eq;
|
||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
|
use serde_json::{json, to_value};
|
||||||
|
|
||||||
|
fn prepare_activity(conn: &DbConn) -> (Comment, Vec<Post>, Vec<User>, Vec<Blog>) {
|
||||||
|
let (posts, users, blogs) = fill_database(conn);
|
||||||
|
|
||||||
|
let comment = Comment::insert(
|
||||||
|
conn,
|
||||||
|
NewComment {
|
||||||
|
content: SafeString::new("My comment, mentioning to @user"),
|
||||||
|
in_response_to_id: None,
|
||||||
|
post_id: posts[0].id,
|
||||||
|
author_id: users[0].id,
|
||||||
|
ap_url: None,
|
||||||
|
sensitive: true,
|
||||||
|
spoiler_text: "My CW".into(),
|
||||||
|
public_visibility: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
(comment, posts, users, blogs)
|
||||||
|
}
|
||||||
|
|
||||||
// creates a post, get it's Create activity, delete the post,
|
// creates a post, get it's Create activity, delete the post,
|
||||||
// "send" the Create to the inbox, and check it works
|
// "send" the Create to the inbox, and check it works
|
||||||
@@ -399,30 +458,77 @@ mod tests {
|
|||||||
fn self_federation() {
|
fn self_federation() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (posts, users, _) = fill_database(&conn);
|
let (original_comm, posts, users, _blogs) = prepare_activity(conn);
|
||||||
|
let act = original_comm.create_activity(conn).unwrap();
|
||||||
|
|
||||||
let original_comm = Comment::insert(
|
assert_json_eq!(to_value(&act).unwrap(), json!({
|
||||||
|
"actor": "https://plu.me/@/admin/",
|
||||||
|
"cc": ["https://plu.me/@/admin/followers"],
|
||||||
|
"id": format!("https://plu.me/~/BlogName/testing/comment/{}/activity", original_comm.id),
|
||||||
|
"object": {
|
||||||
|
"attributedTo": "https://plu.me/@/admin/",
|
||||||
|
"content": r###"<p dir="auto">My comment, mentioning to <a href="https://plu.me/@/user/" title="user">@user</a></p>
|
||||||
|
"###,
|
||||||
|
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", original_comm.id),
|
||||||
|
"inReplyTo": "https://plu.me/~/BlogName/testing",
|
||||||
|
"published": format_datetime(&original_comm.creation_date),
|
||||||
|
"summary": "My CW",
|
||||||
|
"tag": [
|
||||||
|
{
|
||||||
|
"href": "https://plu.me/@/user/",
|
||||||
|
"name": "@user",
|
||||||
|
"type": "Mention"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Note"
|
||||||
|
},
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Create",
|
||||||
|
}));
|
||||||
|
|
||||||
|
let reply = Comment::insert(
|
||||||
conn,
|
conn,
|
||||||
NewComment {
|
NewComment {
|
||||||
content: SafeString::new("My comment"),
|
content: SafeString::new(""),
|
||||||
in_response_to_id: None,
|
in_response_to_id: Some(original_comm.id),
|
||||||
post_id: posts[0].id,
|
post_id: posts[0].id,
|
||||||
author_id: users[0].id,
|
author_id: users[1].id,
|
||||||
ap_url: None,
|
ap_url: None,
|
||||||
sensitive: true,
|
sensitive: false,
|
||||||
spoiler_text: "My CW".into(),
|
spoiler_text: "".into(),
|
||||||
public_visibility: true,
|
public_visibility: true,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let act = original_comm.create_activity(&conn).unwrap();
|
let reply_act = reply.create_activity(conn).unwrap();
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(&reply_act).unwrap(), json!({
|
||||||
|
"actor": "https://plu.me/@/user/",
|
||||||
|
"cc": ["https://plu.me/@/user/followers"],
|
||||||
|
"id": format!("https://plu.me/~/BlogName/testing/comment/{}/activity", reply.id),
|
||||||
|
"object": {
|
||||||
|
"attributedTo": "https://plu.me/@/user/",
|
||||||
|
"content": "",
|
||||||
|
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", reply.id),
|
||||||
|
"inReplyTo": format!("https://plu.me/~/BlogName/testing/comment/{}", original_comm.id),
|
||||||
|
"published": format_datetime(&reply.creation_date),
|
||||||
|
"summary": "",
|
||||||
|
"tag": [],
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Note"
|
||||||
|
},
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Create"
|
||||||
|
}));
|
||||||
|
|
||||||
inbox(
|
inbox(
|
||||||
&conn,
|
conn,
|
||||||
serde_json::to_value(original_comm.build_delete(&conn).unwrap()).unwrap(),
|
serde_json::to_value(original_comm.build_delete(conn).unwrap()).unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match inbox(&conn, serde_json::to_value(act).unwrap()).unwrap() {
|
match inbox(conn, to_value(act).unwrap()).unwrap() {
|
||||||
InboxResult::Commented(c) => {
|
InboxResult::Commented(c) => {
|
||||||
// TODO: one is HTML, the other markdown: assert_eq!(c.content, original_comm.content);
|
// TODO: one is HTML, the other markdown: assert_eq!(c.content, original_comm.content);
|
||||||
assert_eq!(c.in_response_to_id, original_comm.in_response_to_id);
|
assert_eq!(c.in_response_to_id, original_comm.in_response_to_id);
|
||||||
@@ -437,4 +543,60 @@ mod tests {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_activity() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (comment, _posts, _users, _blogs) = prepare_activity(&conn);
|
||||||
|
let act = comment.to_activity(&conn)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"attributedTo": "https://plu.me/@/admin/",
|
||||||
|
"content": r###"<p dir="auto">My comment, mentioning to <a href="https://plu.me/@/user/" title="user">@user</a></p>
|
||||||
|
"###,
|
||||||
|
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", comment.id),
|
||||||
|
"inReplyTo": "https://plu.me/~/BlogName/testing",
|
||||||
|
"published": format_datetime(&comment.creation_date),
|
||||||
|
"summary": "My CW",
|
||||||
|
"tag": [
|
||||||
|
{
|
||||||
|
"href": "https://plu.me/@/user/",
|
||||||
|
"name": "@user",
|
||||||
|
"type": "Mention"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Note"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_delete() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (comment, _posts, _users, _blogs) = prepare_activity(&conn);
|
||||||
|
let act = comment.build_delete(&conn)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"actor": "https://plu.me/@/admin/",
|
||||||
|
"id": format!("https://plu.me/~/BlogName/testing/comment/{}#delete", comment.id),
|
||||||
|
"object": {
|
||||||
|
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", comment.id),
|
||||||
|
"type": "Tombstone"
|
||||||
|
},
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Delete"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-11
@@ -1,4 +1,6 @@
|
|||||||
use crate::search::TokenizerKind as SearchTokenizer;
|
use crate::search::TokenizerKind as SearchTokenizer;
|
||||||
|
use crate::signups::Strategy as SignupStrategy;
|
||||||
|
use crate::smtp::{SMTP_PORT, SUBMISSIONS_PORT, SUBMISSION_PORT};
|
||||||
use rocket::config::Limits;
|
use rocket::config::Limits;
|
||||||
use rocket::Config as RocketConfig;
|
use rocket::Config as RocketConfig;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@@ -15,12 +17,14 @@ pub struct Config {
|
|||||||
pub db_name: &'static str,
|
pub db_name: &'static str,
|
||||||
pub db_max_size: Option<u32>,
|
pub db_max_size: Option<u32>,
|
||||||
pub db_min_idle: Option<u32>,
|
pub db_min_idle: Option<u32>,
|
||||||
|
pub signup: SignupStrategy,
|
||||||
pub search_index: String,
|
pub search_index: String,
|
||||||
pub search_tokenizers: SearchTokenizerConfig,
|
pub search_tokenizers: SearchTokenizerConfig,
|
||||||
pub rocket: Result<RocketConfig, RocketError>,
|
pub rocket: Result<RocketConfig, InvalidRocketConfig>,
|
||||||
pub logo: LogoConfig,
|
pub logo: LogoConfig,
|
||||||
pub default_theme: String,
|
pub default_theme: String,
|
||||||
pub media_directory: String,
|
pub media_directory: String,
|
||||||
|
pub mail: Option<MailConfig>,
|
||||||
pub ldap: Option<LdapConfig>,
|
pub ldap: Option<LdapConfig>,
|
||||||
pub proxy: Option<ProxyConfig>,
|
pub proxy: Option<ProxyConfig>,
|
||||||
}
|
}
|
||||||
@@ -31,21 +35,21 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum RocketError {
|
pub enum InvalidRocketConfig {
|
||||||
InvalidEnv,
|
Env,
|
||||||
InvalidAddress,
|
Address,
|
||||||
InvalidSecretKey,
|
SecretKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_rocket_config() -> Result<RocketConfig, RocketError> {
|
fn get_rocket_config() -> Result<RocketConfig, InvalidRocketConfig> {
|
||||||
let mut c = RocketConfig::active().map_err(|_| RocketError::InvalidEnv)?;
|
let mut c = RocketConfig::active().map_err(|_| InvalidRocketConfig::Env)?;
|
||||||
|
|
||||||
let address = var("ROCKET_ADDRESS").unwrap_or_else(|_| "localhost".to_owned());
|
let address = var("ROCKET_ADDRESS").unwrap_or_else(|_| "localhost".to_owned());
|
||||||
let port = var("ROCKET_PORT")
|
let port = var("ROCKET_PORT")
|
||||||
.ok()
|
.ok()
|
||||||
.map(|s| s.parse::<u16>().unwrap())
|
.map(|s| s.parse::<u16>().unwrap())
|
||||||
.unwrap_or(7878);
|
.unwrap_or(7878);
|
||||||
let secret_key = var("ROCKET_SECRET_KEY").map_err(|_| RocketError::InvalidSecretKey)?;
|
let secret_key = var("ROCKET_SECRET_KEY").map_err(|_| InvalidRocketConfig::SecretKey)?;
|
||||||
let form_size = var("FORM_SIZE")
|
let form_size = var("FORM_SIZE")
|
||||||
.unwrap_or_else(|_| "128".to_owned())
|
.unwrap_or_else(|_| "128".to_owned())
|
||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
@@ -56,10 +60,10 @@ fn get_rocket_config() -> Result<RocketConfig, RocketError> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
c.set_address(address)
|
c.set_address(address)
|
||||||
.map_err(|_| RocketError::InvalidAddress)?;
|
.map_err(|_| InvalidRocketConfig::Address)?;
|
||||||
c.set_port(port);
|
c.set_port(port);
|
||||||
c.set_secret_key(secret_key)
|
c.set_secret_key(secret_key)
|
||||||
.map_err(|_| RocketError::InvalidSecretKey)?;
|
.map_err(|_| InvalidRocketConfig::SecretKey)?;
|
||||||
|
|
||||||
c.set_limits(
|
c.set_limits(
|
||||||
Limits::new()
|
Limits::new()
|
||||||
@@ -155,7 +159,7 @@ impl Default for LogoConfig {
|
|||||||
.ok()
|
.ok()
|
||||||
.or_else(|| custom_main.clone());
|
.or_else(|| custom_main.clone());
|
||||||
let other = if let Some(main) = custom_main.clone() {
|
let other = if let Some(main) = custom_main.clone() {
|
||||||
let ext = |path: &str| match path.rsplitn(2, '.').next() {
|
let ext = |path: &str| match path.rsplit_once('.').map(|x| x.1) {
|
||||||
Some("png") => Some("image/png".to_owned()),
|
Some("png") => Some("image/png".to_owned()),
|
||||||
Some("jpg") | Some("jpeg") => Some("image/jpeg".to_owned()),
|
Some("jpg") | Some("jpeg") => Some("image/jpeg".to_owned()),
|
||||||
Some("svg") => Some("image/svg+xml".to_owned()),
|
Some("svg") => Some("image/svg+xml".to_owned()),
|
||||||
@@ -245,6 +249,31 @@ impl SearchTokenizerConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct MailConfig {
|
||||||
|
pub server: String,
|
||||||
|
pub port: u16,
|
||||||
|
pub helo_name: String,
|
||||||
|
pub username: String,
|
||||||
|
pub password: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_mail_config() -> Option<MailConfig> {
|
||||||
|
Some(MailConfig {
|
||||||
|
server: env::var("MAIL_SERVER").ok()?,
|
||||||
|
port: env::var("MAIL_PORT").map_or(SUBMISSIONS_PORT, |port| match port.as_str() {
|
||||||
|
"smtp" => SMTP_PORT,
|
||||||
|
"submissions" => SUBMISSIONS_PORT,
|
||||||
|
"submission" => SUBMISSION_PORT,
|
||||||
|
number => number
|
||||||
|
.parse()
|
||||||
|
.expect(r#"MAIL_PORT must be "smtp", "submissions", "submission" or an integer."#),
|
||||||
|
}),
|
||||||
|
helo_name: env::var("MAIL_HELO_NAME").unwrap_or_else(|_| "localhost".to_owned()),
|
||||||
|
username: env::var("MAIL_USER").ok()?,
|
||||||
|
password: env::var("MAIL_PASSWORD").ok()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub struct LdapConfig {
|
pub struct LdapConfig {
|
||||||
pub addr: String,
|
pub addr: String,
|
||||||
pub base_dn: String,
|
pub base_dn: String,
|
||||||
@@ -335,6 +364,7 @@ lazy_static! {
|
|||||||
s.parse::<u32>()
|
s.parse::<u32>()
|
||||||
.expect("Couldn't parse DB_MIN_IDLE into u32")
|
.expect("Couldn't parse DB_MIN_IDLE into u32")
|
||||||
)),
|
)),
|
||||||
|
signup: var("SIGNUP").map_or(SignupStrategy::default(), |s| s.parse().unwrap()),
|
||||||
#[cfg(feature = "postgres")]
|
#[cfg(feature = "postgres")]
|
||||||
database_url: var("DATABASE_URL")
|
database_url: var("DATABASE_URL")
|
||||||
.unwrap_or_else(|_| format!("postgres://plume:plume@localhost/{}", DB_NAME)),
|
.unwrap_or_else(|_| format!("postgres://plume:plume@localhost/{}", DB_NAME)),
|
||||||
@@ -347,6 +377,7 @@ lazy_static! {
|
|||||||
default_theme: var("DEFAULT_THEME").unwrap_or_else(|_| "default-light".to_owned()),
|
default_theme: var("DEFAULT_THEME").unwrap_or_else(|_| "default-light".to_owned()),
|
||||||
media_directory: var("MEDIA_UPLOAD_DIRECTORY")
|
media_directory: var("MEDIA_UPLOAD_DIRECTORY")
|
||||||
.unwrap_or_else(|_| "static/media".to_owned()),
|
.unwrap_or_else(|_| "static/media".to_owned()),
|
||||||
|
mail: get_mail_config(),
|
||||||
ldap: get_ldap_config(),
|
ldap: get_ldap_config(),
|
||||||
proxy: get_proxy_config(),
|
proxy: get_proxy_config(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ pub(crate) mod tests {
|
|||||||
impl CustomizeConnection<Connection, ConnError> for TestConnectionCustomizer {
|
impl CustomizeConnection<Connection, ConnError> for TestConnectionCustomizer {
|
||||||
fn on_acquire(&self, conn: &mut Connection) -> Result<(), ConnError> {
|
fn on_acquire(&self, conn: &mut Connection) -> Result<(), ConnError> {
|
||||||
PragmaForeignKey.on_acquire(conn)?;
|
PragmaForeignKey.on_acquire(conn)?;
|
||||||
Ok(conn.begin_test_transaction().unwrap())
|
conn.begin_test_transaction().unwrap();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
use crate::{
|
||||||
|
blocklisted_emails::BlocklistedEmail,
|
||||||
|
db_conn::DbConn,
|
||||||
|
schema::email_signups,
|
||||||
|
users::{NewUser, Role, User},
|
||||||
|
Error, Result,
|
||||||
|
};
|
||||||
|
use chrono::{offset::Utc, Duration, NaiveDateTime};
|
||||||
|
use diesel::{
|
||||||
|
Connection as _, ExpressionMethods, Identifiable, Insertable, QueryDsl, Queryable, RunQueryDsl,
|
||||||
|
};
|
||||||
|
use plume_common::utils::random_hex;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
const TOKEN_VALIDITY_HOURS: i64 = 2;
|
||||||
|
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct Token(String);
|
||||||
|
|
||||||
|
impl From<String> for Token {
|
||||||
|
fn from(string: String) -> Self {
|
||||||
|
Token(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Token> for String {
|
||||||
|
fn from(token: Token) -> Self {
|
||||||
|
token.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for Token {
|
||||||
|
type Target = String;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Token {
|
||||||
|
fn generate() -> Self {
|
||||||
|
Self(random_hex())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Identifiable, Queryable)]
|
||||||
|
pub struct EmailSignup {
|
||||||
|
pub id: i32,
|
||||||
|
pub email: String,
|
||||||
|
pub token: String,
|
||||||
|
pub expiration_date: NaiveDateTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable)]
|
||||||
|
#[table_name = "email_signups"]
|
||||||
|
pub struct NewEmailSignup<'a> {
|
||||||
|
pub email: &'a str,
|
||||||
|
pub token: &'a str,
|
||||||
|
pub expiration_date: NaiveDateTime,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EmailSignup {
|
||||||
|
pub fn start(conn: &DbConn, email: &str) -> Result<Token> {
|
||||||
|
Self::ensure_email_not_blocked(conn, email)?;
|
||||||
|
|
||||||
|
conn.transaction(|| {
|
||||||
|
Self::ensure_user_not_exist_by_email(conn, email)?;
|
||||||
|
let _rows = Self::delete_existings_by_email(conn, email)?;
|
||||||
|
let token = Token::generate();
|
||||||
|
let expiration_date = Utc::now()
|
||||||
|
.naive_utc()
|
||||||
|
.checked_add_signed(Duration::hours(TOKEN_VALIDITY_HOURS))
|
||||||
|
.expect("could not calculate expiration date");
|
||||||
|
let new_signup = NewEmailSignup {
|
||||||
|
email,
|
||||||
|
token: &token,
|
||||||
|
expiration_date,
|
||||||
|
};
|
||||||
|
let _rows = diesel::insert_into(email_signups::table)
|
||||||
|
.values(new_signup)
|
||||||
|
.execute(&**conn)?;
|
||||||
|
|
||||||
|
Ok(token)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find_by_token(conn: &DbConn, token: Token) -> Result<Self> {
|
||||||
|
let signup = email_signups::table
|
||||||
|
.filter(email_signups::token.eq(token.as_str()))
|
||||||
|
.first::<Self>(&**conn)
|
||||||
|
.map_err(Error::from)?;
|
||||||
|
Ok(signup)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn confirm(&self, conn: &DbConn) -> Result<()> {
|
||||||
|
Self::ensure_email_not_blocked(conn, &self.email)?;
|
||||||
|
|
||||||
|
conn.transaction(|| {
|
||||||
|
Self::ensure_user_not_exist_by_email(conn, &self.email)?;
|
||||||
|
if self.expired() {
|
||||||
|
Self::delete_existings_by_email(conn, &self.email)?;
|
||||||
|
return Err(Error::Expired);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn complete(&self, conn: &DbConn, username: String, password: String) -> Result<User> {
|
||||||
|
Self::ensure_email_not_blocked(conn, &self.email)?;
|
||||||
|
|
||||||
|
conn.transaction(|| {
|
||||||
|
Self::ensure_user_not_exist_by_email(conn, &self.email)?;
|
||||||
|
let user = NewUser::new_local(
|
||||||
|
conn,
|
||||||
|
username,
|
||||||
|
"".to_string(),
|
||||||
|
Role::Normal,
|
||||||
|
"",
|
||||||
|
self.email.clone(),
|
||||||
|
Some(User::hash_pass(&password)?),
|
||||||
|
)?;
|
||||||
|
self.delete(conn)?;
|
||||||
|
Ok(user)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete(&self, conn: &DbConn) -> Result<()> {
|
||||||
|
let _rows = diesel::delete(self).execute(&**conn).map_err(Error::from)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ensure_email_not_blocked(conn: &DbConn, email: &str) -> Result<()> {
|
||||||
|
if let Some(x) = BlocklistedEmail::matches_blocklist(conn, email)? {
|
||||||
|
Err(Error::Blocklisted(x.notify_user, x.notification_text))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ensure_user_not_exist_by_email(conn: &DbConn, email: &str) -> Result<()> {
|
||||||
|
if User::email_used(conn, email)? {
|
||||||
|
let _rows = Self::delete_existings_by_email(conn, email)?;
|
||||||
|
return Err(Error::UserAlreadyExists);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_existings_by_email(conn: &DbConn, email: &str) -> Result<usize> {
|
||||||
|
let existing_signups = email_signups::table.filter(email_signups::email.eq(email));
|
||||||
|
diesel::delete(existing_signups)
|
||||||
|
.execute(&**conn)
|
||||||
|
.map_err(Error::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn expired(&self) -> bool {
|
||||||
|
self.expiration_date < Utc::now().naive_utc()
|
||||||
|
}
|
||||||
|
}
|
||||||
+176
-63
@@ -1,8 +1,13 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
ap_url, db_conn::DbConn, notifications::*, schema::follows, users::User, Connection, Error,
|
ap_url, instance::Instance, notifications::*, schema::follows, users::User, Connection, Error,
|
||||||
Result, CONFIG,
|
Result, CONFIG,
|
||||||
};
|
};
|
||||||
use activitypub::activity::{Accept, Follow as FollowAct, Undo};
|
use activitystreams::{
|
||||||
|
activity::{Accept, ActorAndObjectRef, Follow as FollowAct, Undo},
|
||||||
|
base::AnyBase,
|
||||||
|
iri_string::types::IriString,
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
||||||
use plume_common::activity_pub::{
|
use plume_common::activity_pub::{
|
||||||
broadcast,
|
broadcast,
|
||||||
@@ -53,15 +58,13 @@ impl Follow {
|
|||||||
pub fn to_activity(&self, conn: &Connection) -> Result<FollowAct> {
|
pub fn to_activity(&self, conn: &Connection) -> Result<FollowAct> {
|
||||||
let user = User::get(conn, self.follower_id)?;
|
let user = User::get(conn, self.follower_id)?;
|
||||||
let target = User::get(conn, self.following_id)?;
|
let target = User::get(conn, self.following_id)?;
|
||||||
|
let target_id = target.ap_url.parse::<IriString>()?;
|
||||||
|
|
||||||
|
let mut act = FollowAct::new(user.ap_url.parse::<IriString>()?, target_id.clone());
|
||||||
|
act.set_id(self.ap_url.parse::<IriString>()?);
|
||||||
|
act.set_many_tos(vec![target_id]);
|
||||||
|
act.set_many_ccs(vec![PUBLIC_VISIBILITY.parse::<IriString>()?]);
|
||||||
|
|
||||||
let mut act = FollowAct::default();
|
|
||||||
act.follow_props.set_actor_link::<Id>(user.into_id())?;
|
|
||||||
act.follow_props
|
|
||||||
.set_object_link::<Id>(target.clone().into_id())?;
|
|
||||||
act.object_props.set_id_string(self.ap_url.clone())?;
|
|
||||||
act.object_props.set_to_link_vec(vec![target.into_id()])?;
|
|
||||||
act.object_props
|
|
||||||
.set_cc_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,81 +97,87 @@ impl Follow {
|
|||||||
NewFollow {
|
NewFollow {
|
||||||
follower_id: from_id,
|
follower_id: from_id,
|
||||||
following_id: target_id,
|
following_id: target_id,
|
||||||
ap_url: follow.object_props.id_string()?,
|
ap_url: follow
|
||||||
|
.object_field_ref()
|
||||||
|
.as_single_id()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.to_string(),
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
res.notify(conn)?;
|
res.notify(conn)?;
|
||||||
|
|
||||||
let mut accept = Accept::default();
|
let accept = res.build_accept(from, target, follow)?;
|
||||||
let accept_id = ap_url(&format!(
|
broadcast(target, accept, vec![from.clone()], CONFIG.proxy().cloned());
|
||||||
"{}/follow/{}/accept",
|
|
||||||
CONFIG.base_url.as_str(),
|
|
||||||
&res.id
|
|
||||||
));
|
|
||||||
accept.object_props.set_id_string(accept_id)?;
|
|
||||||
accept
|
|
||||||
.object_props
|
|
||||||
.set_to_link_vec(vec![from.clone().into_id()])?;
|
|
||||||
accept
|
|
||||||
.object_props
|
|
||||||
.set_cc_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
|
||||||
accept
|
|
||||||
.accept_props
|
|
||||||
.set_actor_link::<Id>(target.clone().into_id())?;
|
|
||||||
accept.accept_props.set_object_object(follow)?;
|
|
||||||
broadcast(
|
|
||||||
&*target,
|
|
||||||
accept,
|
|
||||||
vec![from.clone()],
|
|
||||||
CONFIG.proxy().cloned(),
|
|
||||||
);
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn build_accept<A: Signer + IntoId + Clone, B: Clone + AsActor<T> + IntoId, T>(
|
||||||
|
&self,
|
||||||
|
from: &B,
|
||||||
|
target: &A,
|
||||||
|
follow: FollowAct,
|
||||||
|
) -> Result<Accept> {
|
||||||
|
let mut accept = Accept::new(
|
||||||
|
target.clone().into_id().parse::<IriString>()?,
|
||||||
|
AnyBase::from_extended(follow)?,
|
||||||
|
);
|
||||||
|
let accept_id = ap_url(&format!(
|
||||||
|
"{}/follows/{}/accept",
|
||||||
|
CONFIG.base_url.as_str(),
|
||||||
|
self.id
|
||||||
|
));
|
||||||
|
accept.set_id(accept_id.parse::<IriString>()?);
|
||||||
|
accept.set_many_tos(vec![from.clone().into_id().parse::<IriString>()?]);
|
||||||
|
accept.set_many_ccs(vec![PUBLIC_VISIBILITY.parse::<IriString>()?]);
|
||||||
|
|
||||||
|
Ok(accept)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> {
|
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> {
|
||||||
let mut undo = Undo::default();
|
let mut undo = Undo::new(
|
||||||
undo.undo_props
|
User::get(conn, self.follower_id)?
|
||||||
.set_actor_link(User::get(conn, self.follower_id)?.into_id())?;
|
.ap_url
|
||||||
undo.object_props
|
.parse::<IriString>()?,
|
||||||
.set_id_string(format!("{}/undo", self.ap_url))?;
|
self.ap_url.parse::<IriString>()?,
|
||||||
undo.undo_props
|
);
|
||||||
.set_object_link::<Id>(self.clone().into_id())?;
|
undo.set_id(format!("{}/undo", self.ap_url).parse::<IriString>()?);
|
||||||
undo.object_props
|
undo.set_many_tos(vec![User::get(conn, self.following_id)?
|
||||||
.set_to_link_vec(vec![User::get(conn, self.following_id)?.into_id()])?;
|
.ap_url
|
||||||
undo.object_props
|
.parse::<IriString>()?]);
|
||||||
.set_cc_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
undo.set_many_ccs(vec![PUBLIC_VISIBILITY.parse::<IriString>()?]);
|
||||||
|
|
||||||
Ok(undo)
|
Ok(undo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, FollowAct, &DbConn> for User {
|
impl AsObject<User, FollowAct, &Connection> for User {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = Follow;
|
type Output = Follow;
|
||||||
|
|
||||||
fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Follow> {
|
fn activity(self, conn: &Connection, actor: User, id: &str) -> Result<Follow> {
|
||||||
// Mastodon (at least) requires the full Follow object when accepting it,
|
// Mastodon (at least) requires the full Follow object when accepting it,
|
||||||
// so we rebuilt it here
|
// so we rebuilt it here
|
||||||
let mut follow = FollowAct::default();
|
let follow = FollowAct::new(actor.ap_url.parse::<IriString>()?, id.parse::<IriString>()?);
|
||||||
follow.object_props.set_id_string(id.to_string())?;
|
|
||||||
follow
|
|
||||||
.follow_props
|
|
||||||
.set_actor_link::<Id>(actor.clone().into_id())?;
|
|
||||||
Follow::accept_follow(conn, &actor, &self, follow, actor.id, self.id)
|
Follow::accept_follow(conn, &actor, &self, follow, actor.id, self.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromId<DbConn> for Follow {
|
impl FromId<Connection> for Follow {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = FollowAct;
|
type Object = FollowAct;
|
||||||
|
|
||||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||||
Follow::find_by_ap_url(conn, id)
|
Follow::find_by_ap_url(conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(conn: &DbConn, follow: FollowAct) -> Result<Self> {
|
fn from_activity(conn: &Connection, follow: FollowAct) -> Result<Self> {
|
||||||
let actor = User::from_id(
|
let actor = User::from_id(
|
||||||
conn,
|
conn,
|
||||||
&follow.follow_props.actor_link::<Id>()?,
|
follow
|
||||||
|
.actor_field_ref()
|
||||||
|
.as_single_id()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
@@ -176,27 +185,35 @@ impl FromId<DbConn> for Follow {
|
|||||||
|
|
||||||
let target = User::from_id(
|
let target = User::from_id(
|
||||||
conn,
|
conn,
|
||||||
&follow.follow_props.object_link::<Id>()?,
|
follow
|
||||||
|
.object_field_ref()
|
||||||
|
.as_single_id()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
.map_err(|(_, e)| e)?;
|
.map_err(|(_, e)| e)?;
|
||||||
Follow::accept_follow(conn, &actor, &target, follow, actor.id, target.id)
|
Follow::accept_follow(conn, &actor, &target, follow, actor.id, target.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_sender() -> &'static dyn Signer {
|
||||||
|
Instance::get_local_instance_user().expect("Failed to local instance user")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Undo, &DbConn> for Follow {
|
impl AsObject<User, Undo, &Connection> for Follow {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||||
let conn = conn;
|
let conn = conn;
|
||||||
if self.follower_id == actor.id {
|
if self.follower_id == actor.id {
|
||||||
diesel::delete(&self).execute(&**conn)?;
|
diesel::delete(&self).execute(conn)?;
|
||||||
|
|
||||||
// delete associated notification if any
|
// delete associated notification if any
|
||||||
if let Ok(notif) = Notification::find(&conn, notification_kind::FOLLOW, self.id) {
|
if let Ok(notif) = Notification::find(conn, notification_kind::FOLLOW, self.id) {
|
||||||
diesel::delete(¬if).execute(&**conn)?;
|
diesel::delete(¬if).execute(conn)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -215,8 +232,31 @@ impl IntoId for Follow {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{tests::db, users::tests as user_tests};
|
use crate::{
|
||||||
|
db_conn::DbConn, tests::db, users::tests as user_tests, users::tests::fill_database,
|
||||||
|
};
|
||||||
|
use assert_json_diff::assert_json_eq;
|
||||||
use diesel::Connection;
|
use diesel::Connection;
|
||||||
|
use serde_json::{json, to_value};
|
||||||
|
|
||||||
|
fn prepare_activity(conn: &DbConn) -> (Follow, User, User, Vec<User>) {
|
||||||
|
let users = fill_database(conn);
|
||||||
|
let following = &users[1];
|
||||||
|
let follower = &users[2];
|
||||||
|
let mut follow = Follow::insert(
|
||||||
|
conn,
|
||||||
|
NewFollow {
|
||||||
|
follower_id: follower.id,
|
||||||
|
following_id: following.id,
|
||||||
|
ap_url: "".into(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
// following.ap_url = format!("https://plu.me/follows/{}", follow.id);
|
||||||
|
follow.ap_url = format!("https://plu.me/follows/{}", follow.id);
|
||||||
|
|
||||||
|
(follow, following.to_owned(), follower.to_owned(), users)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_id() {
|
fn test_id() {
|
||||||
@@ -251,4 +291,77 @@ mod tests {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_activity() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (follow, _following, _follower, _users) = prepare_activity(&conn);
|
||||||
|
let act = follow.to_activity(&conn)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"actor": "https://plu.me/@/other/",
|
||||||
|
"cc": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"id": format!("https://plu.me/follows/{}", follow.id),
|
||||||
|
"object": "https://plu.me/@/user/",
|
||||||
|
"to": ["https://plu.me/@/user/"],
|
||||||
|
"type": "Follow"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_accept() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (follow, following, follower, _users) = prepare_activity(&conn);
|
||||||
|
let act = follow.build_accept(&follower, &following, follow.to_activity(&conn)?)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"actor": "https://plu.me/@/user/",
|
||||||
|
"cc": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"id": format!("https://127.0.0.1:7878/follows/{}/accept", follow.id),
|
||||||
|
"object": {
|
||||||
|
"actor": "https://plu.me/@/other/",
|
||||||
|
"cc": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"id": format!("https://plu.me/follows/{}", follow.id),
|
||||||
|
"object": "https://plu.me/@/user/",
|
||||||
|
"to": ["https://plu.me/@/user/"],
|
||||||
|
"type": "Follow"
|
||||||
|
},
|
||||||
|
"to": ["https://plu.me/@/other/"],
|
||||||
|
"type": "Accept"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_undo() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (follow, _following, _follower, _users) = prepare_activity(&conn);
|
||||||
|
let act = follow.build_undo(&conn)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"actor": "https://plu.me/@/other/",
|
||||||
|
"cc": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"id": format!("https://plu.me/follows/{}/undo", follow.id),
|
||||||
|
"object": format!("https://plu.me/follows/{}", follow.id),
|
||||||
|
"to": ["https://plu.me/@/user/"],
|
||||||
|
"type": "Undo"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-19
@@ -1,4 +1,4 @@
|
|||||||
use activitypub::activity::*;
|
use activitystreams::activity::{Announce, Create, Delete, Follow, Like, Undo, Update};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
comments::Comment,
|
comments::Comment,
|
||||||
@@ -7,7 +7,7 @@ use crate::{
|
|||||||
posts::{Post, PostUpdate},
|
posts::{Post, PostUpdate},
|
||||||
reshares::Reshare,
|
reshares::Reshare,
|
||||||
users::User,
|
users::User,
|
||||||
Error, CONFIG,
|
Connection, Error, CONFIG,
|
||||||
};
|
};
|
||||||
use plume_common::activity_pub::inbox::Inbox;
|
use plume_common::activity_pub::inbox::Inbox;
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ impl_into_inbox_result! {
|
|||||||
Reshare => Reshared
|
Reshare => Reshared
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inbox(conn: &DbConn, act: serde_json::Value) -> Result<InboxResult, Error> {
|
pub fn inbox(conn: &Connection, act: serde_json::Value) -> Result<InboxResult, Error> {
|
||||||
Inbox::handle(conn, act)
|
Inbox::handle(conn, act)
|
||||||
.with::<User, Announce, Post>(CONFIG.proxy())
|
.with::<User, Announce, Post>(CONFIG.proxy())
|
||||||
.with::<User, Create, Comment>(CONFIG.proxy())
|
.with::<User, Create, Comment>(CONFIG.proxy())
|
||||||
@@ -82,9 +82,9 @@ pub(crate) mod tests {
|
|||||||
use crate::post_authors::*;
|
use crate::post_authors::*;
|
||||||
use crate::posts::*;
|
use crate::posts::*;
|
||||||
|
|
||||||
let (users, blogs) = blog_fill_db(&conn);
|
let (users, blogs) = blog_fill_db(conn);
|
||||||
let post = Post::insert(
|
let post = Post::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blogs[0].id,
|
blog_id: blogs[0].id,
|
||||||
slug: "testing".to_owned(),
|
slug: "testing".to_owned(),
|
||||||
@@ -94,15 +94,15 @@ pub(crate) mod tests {
|
|||||||
license: "WTFPL".to_owned(),
|
license: "WTFPL".to_owned(),
|
||||||
creation_date: None,
|
creation_date: None,
|
||||||
ap_url: format!("https://plu.me/~/{}/testing", blogs[0].actor_id),
|
ap_url: format!("https://plu.me/~/{}/testing", blogs[0].actor_id),
|
||||||
subtitle: String::new(),
|
subtitle: "Bye".to_string(),
|
||||||
source: String::new(),
|
source: "Hello".to_string(),
|
||||||
cover_id: None,
|
cover_id: None,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
PostAuthor::insert(
|
PostAuthor::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPostAuthor {
|
NewPostAuthor {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
author_id: users[0].id,
|
author_id: users[0].id,
|
||||||
@@ -190,7 +190,7 @@ pub(crate) mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
super::inbox(&conn, act.clone()),
|
super::inbox(&conn, act),
|
||||||
Err(super::Error::Inbox(
|
Err(super::Error::Inbox(
|
||||||
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
||||||
))
|
))
|
||||||
@@ -221,7 +221,7 @@ pub(crate) mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
super::inbox(&conn, act.clone()),
|
super::inbox(&conn, act),
|
||||||
Err(super::Error::Inbox(
|
Err(super::Error::Inbox(
|
||||||
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
||||||
))
|
))
|
||||||
@@ -249,7 +249,7 @@ pub(crate) mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
super::inbox(&conn, act.clone()),
|
super::inbox(&conn, act),
|
||||||
Err(super::Error::Inbox(
|
Err(super::Error::Inbox(
|
||||||
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
||||||
))
|
))
|
||||||
@@ -268,7 +268,7 @@ pub(crate) mod tests {
|
|||||||
"actor": users[0].ap_url,
|
"actor": users[0].ap_url,
|
||||||
"object": {
|
"object": {
|
||||||
"type": "Article",
|
"type": "Article",
|
||||||
"id": "https://plu.me/~/Blog/my-article",
|
"id": "https://plu.me/~/BlogName/testing",
|
||||||
"attributedTo": [users[0].ap_url, blogs[0].ap_url],
|
"attributedTo": [users[0].ap_url, blogs[0].ap_url],
|
||||||
"content": "Hello.",
|
"content": "Hello.",
|
||||||
"name": "My Article",
|
"name": "My Article",
|
||||||
@@ -286,11 +286,11 @@ pub(crate) mod tests {
|
|||||||
match super::inbox(&conn, act).unwrap() {
|
match super::inbox(&conn, act).unwrap() {
|
||||||
super::InboxResult::Post(p) => {
|
super::InboxResult::Post(p) => {
|
||||||
assert!(p.is_author(&conn, users[0].id).unwrap());
|
assert!(p.is_author(&conn, users[0].id).unwrap());
|
||||||
assert_eq!(p.source, "Hello.".to_owned());
|
assert_eq!(p.source, "Hello".to_owned());
|
||||||
assert_eq!(p.blog_id, blogs[0].id);
|
assert_eq!(p.blog_id, blogs[0].id);
|
||||||
assert_eq!(p.content, SafeString::new("Hello."));
|
assert_eq!(p.content, SafeString::new("Hello"));
|
||||||
assert_eq!(p.subtitle, "Bye.".to_owned());
|
assert_eq!(p.subtitle, "Bye".to_owned());
|
||||||
assert_eq!(p.title, "My Article".to_owned());
|
assert_eq!(p.title, "Testing".to_owned());
|
||||||
}
|
}
|
||||||
_ => panic!("Unexpected result"),
|
_ => panic!("Unexpected result"),
|
||||||
};
|
};
|
||||||
@@ -324,7 +324,7 @@ pub(crate) mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
super::inbox(&conn, act.clone()),
|
super::inbox(&conn, act),
|
||||||
Err(super::Error::Inbox(
|
Err(super::Error::Inbox(
|
||||||
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
||||||
))
|
))
|
||||||
@@ -362,7 +362,7 @@ pub(crate) mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
super::inbox(&conn, act.clone()),
|
super::inbox(&conn, act),
|
||||||
Err(super::Error::Inbox(
|
Err(super::Error::Inbox(
|
||||||
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
||||||
))
|
))
|
||||||
@@ -397,7 +397,7 @@ pub(crate) mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
super::inbox(&conn, act.clone()),
|
super::inbox(&conn, act),
|
||||||
Err(super::Error::Inbox(
|
Err(super::Error::Inbox(
|
||||||
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
box plume_common::activity_pub::inbox::InboxError::InvalidObject(_),
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ use crate::{
|
|||||||
medias::Media,
|
medias::Media,
|
||||||
safe_string::SafeString,
|
safe_string::SafeString,
|
||||||
schema::{instances, users},
|
schema::{instances, users},
|
||||||
users::{Role, User},
|
users::{NewUser, Role, User},
|
||||||
Connection, Error, Result,
|
Connection, Error, Result,
|
||||||
};
|
};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, result::Error::NotFound, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use plume_common::utils::md_to_html;
|
use once_cell::sync::OnceCell;
|
||||||
|
use plume_common::utils::{iri_percent_encode_seg, md_to_html};
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
#[derive(Clone, Identifiable, Queryable)]
|
#[derive(Clone, Identifiable, Queryable)]
|
||||||
@@ -45,6 +46,9 @@ lazy_static! {
|
|||||||
static ref LOCAL_INSTANCE: RwLock<Option<Instance>> = RwLock::new(None);
|
static ref LOCAL_INSTANCE: RwLock<Option<Instance>> = RwLock::new(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LOCAL_INSTANCE_USERNAME: &str = "__instance__";
|
||||||
|
static LOCAL_INSTANCE_USER: OnceCell<User> = OnceCell::new();
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
pub fn set_local(self) {
|
pub fn set_local(self) {
|
||||||
LOCAL_INSTANCE.write().unwrap().replace(self);
|
LOCAL_INSTANCE.write().unwrap().replace(self);
|
||||||
@@ -76,6 +80,42 @@ impl Instance {
|
|||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_local_instance_user(conn: &Connection) -> Result<User> {
|
||||||
|
let instance = Instance::get_local()?;
|
||||||
|
let email = format!("{}@{}", LOCAL_INSTANCE_USERNAME, &instance.public_domain);
|
||||||
|
NewUser::new_local(
|
||||||
|
conn,
|
||||||
|
LOCAL_INSTANCE_USERNAME.into(),
|
||||||
|
instance.public_domain,
|
||||||
|
Role::Instance,
|
||||||
|
"Local instance",
|
||||||
|
email,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_local_instance_user() -> Option<&'static User> {
|
||||||
|
LOCAL_INSTANCE_USER.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_local_instance_user_uncached(conn: &Connection) -> Result<User> {
|
||||||
|
users::table
|
||||||
|
.filter(users::role.eq(3))
|
||||||
|
.first(conn)
|
||||||
|
.or_else(|err| match err {
|
||||||
|
NotFound => Self::create_local_instance_user(conn),
|
||||||
|
_ => Err(Error::Db(err)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cache_local_instance_user(conn: &Connection) {
|
||||||
|
let _ = LOCAL_INSTANCE_USER.get_or_init(|| {
|
||||||
|
Self::get_local_instance_user_uncached(conn)
|
||||||
|
.or_else(|_| Self::create_local_instance_user(conn))
|
||||||
|
.expect("Failed to cache local instance user")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn page(conn: &Connection, (min, max): (i32, i32)) -> Result<Vec<Instance>> {
|
pub fn page(conn: &Connection, (min, max): (i32, i32)) -> Result<Vec<Instance>> {
|
||||||
instances::table
|
instances::table
|
||||||
.order(instances::public_domain.asc())
|
.order(instances::public_domain.asc())
|
||||||
@@ -133,8 +173,8 @@ impl Instance {
|
|||||||
"{instance}/{prefix}/{name}/{box_name}",
|
"{instance}/{prefix}/{name}/{box_name}",
|
||||||
instance = self.public_domain,
|
instance = self.public_domain,
|
||||||
prefix = prefix,
|
prefix = prefix,
|
||||||
name = name,
|
name = iri_percent_encode_seg(name),
|
||||||
box_name = box_name
|
box_name = iri_percent_encode_seg(box_name)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,6 +344,7 @@ pub(crate) mod tests {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Instance::cache_local(conn);
|
Instance::cache_local(conn);
|
||||||
|
Instance::cache_local_instance_user(conn);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,7 +523,7 @@ pub(crate) mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let inst = Instance::get(conn, inst.id).unwrap();
|
let inst = Instance::get(conn, inst.id).unwrap();
|
||||||
assert_eq!(inst.name, "NewName".to_owned());
|
assert_eq!(inst.name, "NewName".to_owned());
|
||||||
assert_eq!(inst.open_registrations, false);
|
assert!(!inst.open_registrations);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
inst.long_description.get(),
|
inst.long_description.get(),
|
||||||
"[long_description](/with_link)"
|
"[long_description](/with_link)"
|
||||||
|
|||||||
Executable → Regular
+88
-19
@@ -1,4 +1,3 @@
|
|||||||
#![feature(try_trait)]
|
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(proc_macro_hygiene)]
|
#![feature(proc_macro_hygiene)]
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
@@ -17,8 +16,11 @@ extern crate serde_json;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tantivy;
|
extern crate tantivy;
|
||||||
|
|
||||||
|
use activitystreams::iri_string;
|
||||||
|
pub use lettre;
|
||||||
|
pub use lettre::smtp;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use plume_common::activity_pub::inbox::InboxError;
|
use plume_common::activity_pub::{inbox::InboxError, request, sign};
|
||||||
use posts::PostEvent;
|
use posts::PostEvent;
|
||||||
use riker::actors::{channel, ActorSystem, ChannelRef, SystemBuilder};
|
use riker::actors::{channel, ActorSystem, ChannelRef, SystemBuilder};
|
||||||
use users::UserEvent;
|
use users::UserEvent;
|
||||||
@@ -66,6 +68,7 @@ pub enum Error {
|
|||||||
Url,
|
Url,
|
||||||
Webfinger,
|
Webfinger,
|
||||||
Expired,
|
Expired,
|
||||||
|
UserAlreadyExists,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<bcrypt::BcryptError> for Error {
|
impl From<bcrypt::BcryptError> for Error {
|
||||||
@@ -80,20 +83,26 @@ impl From<openssl::error::ErrorStack> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<sign::Error> for Error {
|
||||||
|
fn from(_: sign::Error) -> Self {
|
||||||
|
Error::Signature
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<diesel::result::Error> for Error {
|
impl From<diesel::result::Error> for Error {
|
||||||
fn from(err: diesel::result::Error) -> Self {
|
fn from(err: diesel::result::Error) -> Self {
|
||||||
Error::Db(err)
|
Error::Db(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::option::NoneError> for Error {
|
impl From<url::ParseError> for Error {
|
||||||
fn from(_: std::option::NoneError) -> Self {
|
fn from(_: url::ParseError) -> Self {
|
||||||
Error::NotFound
|
Error::Url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<url::ParseError> for Error {
|
impl From<iri_string::validate::Error> for Error {
|
||||||
fn from(_: url::ParseError) -> Self {
|
fn from(_: iri_string::validate::Error) -> Self {
|
||||||
Error::Url
|
Error::Url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,12 +125,9 @@ impl From<reqwest::header::InvalidHeaderValue> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<activitypub::Error> for Error {
|
impl From<activitystreams::checked::CheckError> for Error {
|
||||||
fn from(err: activitypub::Error) -> Self {
|
fn from(_: activitystreams::checked::CheckError) -> Error {
|
||||||
match err {
|
Error::MissingApProperty
|
||||||
activitypub::Error::NotFound => Error::MissingApProperty,
|
|
||||||
_ => Error::SerDe,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +164,12 @@ impl From<InboxError<Error>> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<request::Error> for Error {
|
||||||
|
fn from(_err: request::Error) -> Error {
|
||||||
|
Error::Request
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
/// Adds a function to a model, that returns the first
|
/// Adds a function to a model, that returns the first
|
||||||
@@ -165,7 +177,7 @@ pub type Result<T> = std::result::Result<T, Error>;
|
|||||||
///
|
///
|
||||||
/// Usage:
|
/// Usage:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// impl Model {
|
/// impl Model {
|
||||||
/// find_by!(model_table, name_of_the_function, field1 as String, field2 as i32);
|
/// find_by!(model_table, name_of_the_function, field1 as String, field2 as i32);
|
||||||
/// }
|
/// }
|
||||||
@@ -189,7 +201,7 @@ macro_rules! find_by {
|
|||||||
///
|
///
|
||||||
/// Usage:
|
/// Usage:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// impl Model {
|
/// impl Model {
|
||||||
/// list_by!(model_table, name_of_the_function, field1 as String);
|
/// list_by!(model_table, name_of_the_function, field1 as String);
|
||||||
/// }
|
/// }
|
||||||
@@ -213,7 +225,7 @@ macro_rules! list_by {
|
|||||||
///
|
///
|
||||||
/// # Usage
|
/// # Usage
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// impl Model {
|
/// impl Model {
|
||||||
/// get!(model_table);
|
/// get!(model_table);
|
||||||
/// }
|
/// }
|
||||||
@@ -236,7 +248,7 @@ macro_rules! get {
|
|||||||
///
|
///
|
||||||
/// # Usage
|
/// # Usage
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// impl Model {
|
/// impl Model {
|
||||||
/// insert!(model_table, NewModelType);
|
/// insert!(model_table, NewModelType);
|
||||||
/// }
|
/// }
|
||||||
@@ -268,7 +280,7 @@ macro_rules! insert {
|
|||||||
///
|
///
|
||||||
/// # Usage
|
/// # Usage
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```ignore
|
||||||
/// impl Model {
|
/// impl Model {
|
||||||
/// last!(model_table);
|
/// last!(model_table);
|
||||||
/// }
|
/// }
|
||||||
@@ -295,10 +307,38 @@ pub fn ap_url(url: &str) -> String {
|
|||||||
format!("https://{}", url)
|
format!("https://{}", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait SmtpNewWithAddr {
|
||||||
|
fn new_with_addr(
|
||||||
|
addr: (&str, u16),
|
||||||
|
) -> std::result::Result<smtp::SmtpClient, smtp::error::Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SmtpNewWithAddr for smtp::SmtpClient {
|
||||||
|
// Stolen from lettre::smtp::SmtpClient::new_simple()
|
||||||
|
fn new_with_addr(addr: (&str, u16)) -> std::result::Result<Self, smtp::error::Error> {
|
||||||
|
use native_tls::TlsConnector;
|
||||||
|
use smtp::{
|
||||||
|
client::net::{ClientTlsParameters, DEFAULT_TLS_PROTOCOLS},
|
||||||
|
ClientSecurity, SmtpClient,
|
||||||
|
};
|
||||||
|
|
||||||
|
let (domain, port) = addr;
|
||||||
|
|
||||||
|
let mut tls_builder = TlsConnector::builder();
|
||||||
|
tls_builder.min_protocol_version(Some(DEFAULT_TLS_PROTOCOLS[0]));
|
||||||
|
|
||||||
|
let tls_parameters =
|
||||||
|
ClientTlsParameters::new(domain.to_string(), tls_builder.build().unwrap());
|
||||||
|
|
||||||
|
SmtpClient::new((domain, port), ClientSecurity::Wrapper(tls_parameters))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{db_conn, migrations::IMPORTED_MIGRATIONS, Connection as Conn, CONFIG};
|
use crate::{db_conn, migrations::IMPORTED_MIGRATIONS, Connection as Conn, CONFIG};
|
||||||
|
use chrono::{naive::NaiveDateTime, Datelike, Timelike};
|
||||||
use diesel::r2d2::ConnectionManager;
|
use diesel::r2d2::ConnectionManager;
|
||||||
use plume_common::utils::random_hex;
|
use plume_common::utils::random_hex;
|
||||||
use std::env::temp_dir;
|
use std::env::temp_dir;
|
||||||
@@ -314,7 +354,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn db<'a>() -> db_conn::DbConn {
|
pub fn db() -> db_conn::DbConn {
|
||||||
db_conn::DbConn((*DB_POOL).get().unwrap())
|
db_conn::DbConn((*DB_POOL).get().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,6 +371,33 @@ mod tests {
|
|||||||
pool
|
pool
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "postgres")]
|
||||||
|
pub(crate) fn format_datetime(dt: &NaiveDateTime) -> String {
|
||||||
|
format!(
|
||||||
|
"{:04}-{:02}-{:02}T{:02}:{:02}:{:02}.{:06}Z",
|
||||||
|
dt.year(),
|
||||||
|
dt.month(),
|
||||||
|
dt.day(),
|
||||||
|
dt.hour(),
|
||||||
|
dt.minute(),
|
||||||
|
dt.second(),
|
||||||
|
dt.timestamp_subsec_micros()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "sqlite")]
|
||||||
|
pub(crate) fn format_datetime(dt: &NaiveDateTime) -> String {
|
||||||
|
format!(
|
||||||
|
"{:04}-{:02}-{:02}T{:02}:{:02}:{:02}Z",
|
||||||
|
dt.year(),
|
||||||
|
dt.month(),
|
||||||
|
dt.day(),
|
||||||
|
dt.hour(),
|
||||||
|
dt.minute(),
|
||||||
|
dt.second()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod admin;
|
pub mod admin;
|
||||||
@@ -342,6 +409,7 @@ pub mod blogs;
|
|||||||
pub mod comment_seers;
|
pub mod comment_seers;
|
||||||
pub mod comments;
|
pub mod comments;
|
||||||
pub mod db_conn;
|
pub mod db_conn;
|
||||||
|
pub mod email_signups;
|
||||||
pub mod follows;
|
pub mod follows;
|
||||||
pub mod headers;
|
pub mod headers;
|
||||||
pub mod inbox;
|
pub mod inbox;
|
||||||
@@ -362,6 +430,7 @@ pub mod safe_string;
|
|||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
|
pub mod signups;
|
||||||
pub mod tags;
|
pub mod tags;
|
||||||
pub mod timeline;
|
pub mod timeline;
|
||||||
pub mod users;
|
pub mod users;
|
||||||
|
|||||||
+121
-43
@@ -1,13 +1,19 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
db_conn::DbConn, notifications::*, posts::Post, schema::likes, timeline::*, users::User,
|
instance::Instance, notifications::*, posts::Post, schema::likes, timeline::*, users::User,
|
||||||
Connection, Error, Result, CONFIG,
|
Connection, Error, Result, CONFIG,
|
||||||
};
|
};
|
||||||
use activitypub::activity;
|
use activitystreams::{
|
||||||
|
activity::{ActorAndObjectRef, Like as LikeAct, Undo},
|
||||||
|
base::AnyBase,
|
||||||
|
iri_string::types::IriString,
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use plume_common::activity_pub::{
|
use plume_common::activity_pub::{
|
||||||
inbox::{AsActor, AsObject, FromId},
|
inbox::{AsActor, AsObject, FromId},
|
||||||
Id, IntoId, PUBLIC_VISIBILITY,
|
sign::Signer,
|
||||||
|
PUBLIC_VISIBILITY,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Identifiable)]
|
#[derive(Clone, Queryable, Identifiable)]
|
||||||
@@ -33,18 +39,16 @@ impl Like {
|
|||||||
find_by!(likes, find_by_ap_url, ap_url as &str);
|
find_by!(likes, find_by_ap_url, ap_url as &str);
|
||||||
find_by!(likes, find_by_user_on_post, user_id as i32, post_id as i32);
|
find_by!(likes, find_by_user_on_post, user_id as i32, post_id as i32);
|
||||||
|
|
||||||
pub fn to_activity(&self, conn: &Connection) -> Result<activity::Like> {
|
pub fn to_activity(&self, conn: &Connection) -> Result<LikeAct> {
|
||||||
let mut act = activity::Like::default();
|
let mut act = LikeAct::new(
|
||||||
act.like_props
|
User::get(conn, self.user_id)?.ap_url.parse::<IriString>()?,
|
||||||
.set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
Post::get(conn, self.post_id)?.ap_url.parse::<IriString>()?,
|
||||||
act.like_props
|
);
|
||||||
.set_object_link(Post::get(conn, self.post_id)?.into_id())?;
|
act.set_many_tos(vec![PUBLIC_VISIBILITY.parse::<IriString>()?]);
|
||||||
act.object_props
|
act.set_many_ccs(vec![User::get(conn, self.user_id)?
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
.followers_endpoint
|
||||||
act.object_props.set_cc_link_vec(vec![Id::new(
|
.parse::<IriString>()?]);
|
||||||
User::get(conn, self.user_id)?.followers_endpoint,
|
act.set_id(self.ap_url.parse::<IriString>()?);
|
||||||
)])?;
|
|
||||||
act.object_props.set_id_string(self.ap_url.clone())?;
|
|
||||||
|
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
@@ -66,28 +70,26 @@ impl Like {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_undo(&self, conn: &Connection) -> Result<activity::Undo> {
|
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> {
|
||||||
let mut act = activity::Undo::default();
|
let mut act = Undo::new(
|
||||||
act.undo_props
|
User::get(conn, self.user_id)?.ap_url.parse::<IriString>()?,
|
||||||
.set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
AnyBase::from_extended(self.to_activity(conn)?)?,
|
||||||
act.undo_props.set_object_object(self.to_activity(conn)?)?;
|
);
|
||||||
act.object_props
|
act.set_id(format!("{}#delete", self.ap_url).parse::<IriString>()?);
|
||||||
.set_id_string(format!("{}#delete", self.ap_url))?;
|
act.set_many_tos(vec![PUBLIC_VISIBILITY.parse::<IriString>()?]);
|
||||||
act.object_props
|
act.set_many_ccs(vec![User::get(conn, self.user_id)?
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
.followers_endpoint
|
||||||
act.object_props.set_cc_link_vec(vec![Id::new(
|
.parse::<IriString>()?]);
|
||||||
User::get(conn, self.user_id)?.followers_endpoint,
|
|
||||||
)])?;
|
|
||||||
|
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, activity::Like, &DbConn> for Post {
|
impl AsObject<User, LikeAct, &Connection> for Post {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = Like;
|
type Output = Like;
|
||||||
|
|
||||||
fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Like> {
|
fn activity(self, conn: &Connection, actor: User, id: &str) -> Result<Like> {
|
||||||
let res = Like::insert(
|
let res = Like::insert(
|
||||||
conn,
|
conn,
|
||||||
NewLike {
|
NewLike {
|
||||||
@@ -103,21 +105,24 @@ impl AsObject<User, activity::Like, &DbConn> for Post {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromId<DbConn> for Like {
|
impl FromId<Connection> for Like {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = activity::Like;
|
type Object = LikeAct;
|
||||||
|
|
||||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||||
Like::find_by_ap_url(conn, id)
|
Like::find_by_ap_url(conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(conn: &DbConn, act: activity::Like) -> Result<Self> {
|
fn from_activity(conn: &Connection, act: LikeAct) -> Result<Self> {
|
||||||
let res = Like::insert(
|
let res = Like::insert(
|
||||||
conn,
|
conn,
|
||||||
NewLike {
|
NewLike {
|
||||||
post_id: Post::from_id(
|
post_id: Post::from_id(
|
||||||
conn,
|
conn,
|
||||||
&act.like_props.object_link::<Id>()?,
|
act.object_field_ref()
|
||||||
|
.as_single_id()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
@@ -125,31 +130,41 @@ impl FromId<DbConn> for Like {
|
|||||||
.id,
|
.id,
|
||||||
user_id: User::from_id(
|
user_id: User::from_id(
|
||||||
conn,
|
conn,
|
||||||
&act.like_props.actor_link::<Id>()?,
|
act.actor_field_ref()
|
||||||
|
.as_single_id()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
.map_err(|(_, e)| e)?
|
.map_err(|(_, e)| e)?
|
||||||
.id,
|
.id,
|
||||||
ap_url: act.object_props.id_string()?,
|
ap_url: act
|
||||||
|
.id_unchecked()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.to_string(),
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
res.notify(conn)?;
|
res.notify(conn)?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_sender() -> &'static dyn Signer {
|
||||||
|
Instance::get_local_instance_user().expect("Failed to local instance user")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, activity::Undo, &DbConn> for Like {
|
impl AsObject<User, Undo, &Connection> for Like {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||||
if actor.id == self.user_id {
|
if actor.id == self.user_id {
|
||||||
diesel::delete(&self).execute(&**conn)?;
|
diesel::delete(&self).execute(conn)?;
|
||||||
|
|
||||||
// delete associated notification if any
|
// delete associated notification if any
|
||||||
if let Ok(notif) = Notification::find(&conn, notification_kind::LIKE, self.id) {
|
if let Ok(notif) = Notification::find(conn, notification_kind::LIKE, self.id) {
|
||||||
diesel::delete(¬if).execute(&**conn)?;
|
diesel::delete(¬if).execute(conn)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
@@ -160,8 +175,7 @@ impl AsObject<User, activity::Undo, &DbConn> for Like {
|
|||||||
|
|
||||||
impl NewLike {
|
impl NewLike {
|
||||||
pub fn new(p: &Post, u: &User) -> Self {
|
pub fn new(p: &Post, u: &User) -> Self {
|
||||||
// TODO: this URL is not valid
|
let ap_url = format!("{}like/{}", u.ap_url, p.ap_url);
|
||||||
let ap_url = format!("{}/like/{}", u.ap_url, p.ap_url);
|
|
||||||
NewLike {
|
NewLike {
|
||||||
post_id: p.id,
|
post_id: p.id,
|
||||||
user_id: u.id,
|
user_id: u.id,
|
||||||
@@ -169,3 +183,67 @@ impl NewLike {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::diesel::Connection;
|
||||||
|
use crate::{inbox::tests::fill_database, tests::db};
|
||||||
|
use assert_json_diff::assert_json_eq;
|
||||||
|
use serde_json::{json, to_value};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_activity() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (posts, _users, _blogs) = fill_database(&conn);
|
||||||
|
let post = &posts[0];
|
||||||
|
let user = &post.get_authors(&conn)?[0];
|
||||||
|
let like = Like::insert(&conn, NewLike::new(post, user))?;
|
||||||
|
let act = like.to_activity(&conn).unwrap();
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"actor": "https://plu.me/@/admin/",
|
||||||
|
"cc": ["https://plu.me/@/admin/followers"],
|
||||||
|
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing",
|
||||||
|
"object": "https://plu.me/~/BlogName/testing",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Like",
|
||||||
|
});
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_undo() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (posts, _users, _blogs) = fill_database(&conn);
|
||||||
|
let post = &posts[0];
|
||||||
|
let user = &post.get_authors(&conn)?[0];
|
||||||
|
let like = Like::insert(&conn, NewLike::new(post, user))?;
|
||||||
|
let act = like.build_undo(&conn)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"actor": "https://plu.me/@/admin/",
|
||||||
|
"cc": ["https://plu.me/@/admin/followers"],
|
||||||
|
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing#delete",
|
||||||
|
"object": {
|
||||||
|
"actor": "https://plu.me/@/admin/",
|
||||||
|
"cc": ["https://plu.me/@/admin/followers"],
|
||||||
|
"id": "https://plu.me/@/admin/like/https://plu.me/~/BlogName/testing",
|
||||||
|
"object": "https://plu.me/~/BlogName/testing",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Like",
|
||||||
|
},
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Undo",
|
||||||
|
});
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ macro_rules! func {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Clone, Queryable, Identifiable)]
|
#[derive(Clone, Queryable, Identifiable)]
|
||||||
struct ListElem {
|
struct ListElem {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
@@ -296,6 +297,28 @@ impl List {
|
|||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete(&self, conn: &Connection) -> Result<()> {
|
||||||
|
if let Some(user_id) = self.user_id {
|
||||||
|
diesel::delete(
|
||||||
|
lists::table
|
||||||
|
.filter(lists::user_id.eq(user_id))
|
||||||
|
.filter(lists::name.eq(&self.name)),
|
||||||
|
)
|
||||||
|
.execute(conn)
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(Error::from)
|
||||||
|
} else {
|
||||||
|
diesel::delete(
|
||||||
|
lists::table
|
||||||
|
.filter(lists::user_id.is_null())
|
||||||
|
.filter(lists::name.eq(&self.name)),
|
||||||
|
)
|
||||||
|
.execute(conn)
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(Error::from)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func! {set: set_users, User, add_users}
|
func! {set: set_users, User, add_users}
|
||||||
func! {set: set_blogs, Blog, add_blogs}
|
func! {set: set_blogs, Blog, add_blogs}
|
||||||
func! {set: set_words, Word, add_words}
|
func! {set: set_words, Word, add_words}
|
||||||
@@ -412,7 +435,7 @@ mod tests {
|
|||||||
&List::find_for_user_by_name(conn, l1.user_id, &l1.name).unwrap(),
|
&List::find_for_user_by_name(conn, l1.user_id, &l1.name).unwrap(),
|
||||||
);
|
);
|
||||||
l_eq(
|
l_eq(
|
||||||
&&l1u,
|
&l1u,
|
||||||
&List::find_for_user_by_name(conn, l1u.user_id, &l1u.name).unwrap(),
|
&List::find_for_user_by_name(conn, l1u.user_id, &l1u.name).unwrap(),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
+59
-44
@@ -1,14 +1,13 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
ap_url, db_conn::DbConn, instance::Instance, safe_string::SafeString, schema::medias,
|
ap_url, instance::Instance, safe_string::SafeString, schema::medias, users::User, Connection,
|
||||||
users::User, Connection, Error, Result, CONFIG,
|
Error, Result, CONFIG,
|
||||||
};
|
};
|
||||||
use activitypub::object::Image;
|
use activitystreams::{object::Image, prelude::*};
|
||||||
use askama_escape::escape;
|
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use guid_create::GUID;
|
use guid_create::GUID;
|
||||||
use plume_common::{
|
use plume_common::{
|
||||||
activity_pub::{inbox::FromId, Id},
|
activity_pub::{inbox::FromId, request, ToAsString, ToAsUri},
|
||||||
utils::MediaProcessor,
|
utils::{escape, MediaProcessor},
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, DirBuilder},
|
fs::{self, DirBuilder},
|
||||||
@@ -43,7 +42,7 @@ pub struct NewMedia {
|
|||||||
pub owner_id: i32,
|
pub owner_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub enum MediaCategory {
|
pub enum MediaCategory {
|
||||||
Image,
|
Image,
|
||||||
Audio,
|
Audio,
|
||||||
@@ -104,8 +103,8 @@ impl Media {
|
|||||||
pub fn category(&self) -> MediaCategory {
|
pub fn category(&self) -> MediaCategory {
|
||||||
match &*self
|
match &*self
|
||||||
.file_path
|
.file_path
|
||||||
.rsplitn(2, '.')
|
.rsplit_once('.')
|
||||||
.next()
|
.map(|x| x.1)
|
||||||
.expect("Media::category: extension error")
|
.expect("Media::category: extension error")
|
||||||
.to_lowercase()
|
.to_lowercase()
|
||||||
{
|
{
|
||||||
@@ -156,7 +155,11 @@ impl Media {
|
|||||||
if self.is_remote {
|
if self.is_remote {
|
||||||
Ok(self.remote_url.clone().unwrap_or_default())
|
Ok(self.remote_url.clone().unwrap_or_default())
|
||||||
} else {
|
} else {
|
||||||
let file_path = self.file_path.replace(path::MAIN_SEPARATOR, "/");
|
let file_path = self.file_path.replace(path::MAIN_SEPARATOR, "/").replacen(
|
||||||
|
&CONFIG.media_directory,
|
||||||
|
"static/media",
|
||||||
|
1,
|
||||||
|
); // "static/media" from plume::routs::plume_media_files()
|
||||||
Ok(ap_url(&format!(
|
Ok(ap_url(&format!(
|
||||||
"{}/{}",
|
"{}/{}",
|
||||||
Instance::get_local()?.public_domain,
|
Instance::get_local()?.public_domain,
|
||||||
@@ -203,34 +206,37 @@ impl Media {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: merge with save_remote?
|
// TODO: merge with save_remote?
|
||||||
pub fn from_activity(conn: &DbConn, image: &Image) -> Result<Media> {
|
pub fn from_activity(conn: &Connection, image: &Image) -> Result<Media> {
|
||||||
let remote_url = image.object_props.url_string().ok()?;
|
let remote_url = image
|
||||||
|
.url()
|
||||||
|
.and_then(|url| url.to_as_uri())
|
||||||
|
.ok_or(Error::MissingApProperty)?;
|
||||||
let path = determine_mirror_file_path(&remote_url);
|
let path = determine_mirror_file_path(&remote_url);
|
||||||
let parent = path.parent()?;
|
let parent = path.parent().ok_or(Error::InvalidValue)?;
|
||||||
if !parent.is_dir() {
|
if !parent.is_dir() {
|
||||||
DirBuilder::new().recursive(true).create(parent)?;
|
DirBuilder::new().recursive(true).create(parent)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut dest = fs::File::create(path.clone()).ok()?;
|
let mut dest = fs::File::create(path.clone())?;
|
||||||
// TODO: conditional GET
|
// TODO: conditional GET
|
||||||
if let Some(proxy) = CONFIG.proxy() {
|
request::get(
|
||||||
reqwest::ClientBuilder::new().proxy(proxy.clone()).build()?
|
remote_url.as_str(),
|
||||||
} else {
|
User::get_sender(),
|
||||||
reqwest::Client::new()
|
CONFIG.proxy().cloned(),
|
||||||
}
|
)?
|
||||||
.get(remote_url.as_str())
|
.copy_to(&mut dest)?;
|
||||||
.send()
|
|
||||||
.ok()?
|
|
||||||
.copy_to(&mut dest)
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
Media::find_by_file_path(conn, &path.to_str()?)
|
Media::find_by_file_path(conn, path.to_str().ok_or(Error::InvalidValue)?)
|
||||||
.and_then(|mut media| {
|
.and_then(|mut media| {
|
||||||
let mut updated = false;
|
let mut updated = false;
|
||||||
|
|
||||||
let alt_text = image.object_props.content_string().ok()?;
|
let alt_text = image
|
||||||
let sensitive = image.object_props.summary_string().is_ok();
|
.content()
|
||||||
let content_warning = image.object_props.summary_string().ok();
|
.and_then(|content| content.to_as_string())
|
||||||
|
.ok_or(Error::NotFound)?;
|
||||||
|
let summary = image.summary().and_then(|summary| summary.to_as_string());
|
||||||
|
let sensitive = summary.is_some();
|
||||||
|
let content_warning = summary;
|
||||||
if media.alt_text != alt_text {
|
if media.alt_text != alt_text {
|
||||||
media.alt_text = alt_text;
|
media.alt_text = alt_text;
|
||||||
updated = true;
|
updated = true;
|
||||||
@@ -252,29 +258,30 @@ impl Media {
|
|||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
if updated {
|
if updated {
|
||||||
diesel::update(&media).set(&media).execute(&**conn)?;
|
diesel::update(&media).set(&media).execute(conn)?;
|
||||||
}
|
}
|
||||||
Ok(media)
|
Ok(media)
|
||||||
})
|
})
|
||||||
.or_else(|_| {
|
.or_else(|_| {
|
||||||
|
let summary = image.summary().and_then(|summary| summary.to_as_string());
|
||||||
Media::insert(
|
Media::insert(
|
||||||
conn,
|
conn,
|
||||||
NewMedia {
|
NewMedia {
|
||||||
file_path: path.to_str()?.to_string(),
|
file_path: path.to_str().ok_or(Error::InvalidValue)?.to_string(),
|
||||||
alt_text: image.object_props.content_string().ok()?,
|
alt_text: image
|
||||||
|
.content()
|
||||||
|
.and_then(|content| content.to_as_string())
|
||||||
|
.ok_or(Error::NotFound)?,
|
||||||
is_remote: false,
|
is_remote: false,
|
||||||
remote_url: None,
|
remote_url: None,
|
||||||
sensitive: image.object_props.summary_string().is_ok(),
|
sensitive: summary.is_some(),
|
||||||
content_warning: image.object_props.summary_string().ok(),
|
content_warning: summary,
|
||||||
owner_id: User::from_id(
|
owner_id: User::from_id(
|
||||||
conn,
|
conn,
|
||||||
image
|
&image
|
||||||
.object_props
|
.attributed_to()
|
||||||
.attributed_to_link_vec::<Id>()
|
.and_then(|attributed_to| attributed_to.to_as_uri())
|
||||||
.ok()?
|
.ok_or(Error::MissingApProperty)?,
|
||||||
.into_iter()
|
|
||||||
.next()?
|
|
||||||
.as_ref(),
|
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
@@ -321,7 +328,7 @@ fn determine_mirror_file_path(url: &str) -> PathBuf {
|
|||||||
.next()
|
.next()
|
||||||
.map(ToOwned::to_owned)
|
.map(ToOwned::to_owned)
|
||||||
.unwrap_or_else(|| String::from("png"));
|
.unwrap_or_else(|| String::from("png"));
|
||||||
file_path.push(format!("{}.{}", GUID::rand().to_string(), ext));
|
file_path.push(format!("{}.{}", GUID::rand(), ext));
|
||||||
});
|
});
|
||||||
file_path
|
file_path
|
||||||
}
|
}
|
||||||
@@ -336,7 +343,7 @@ pub(crate) mod tests {
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub(crate) fn fill_database(conn: &Conn) -> (Vec<User>, Vec<Media>) {
|
pub(crate) fn fill_database(conn: &Conn) -> (Vec<User>, Vec<Media>) {
|
||||||
let mut wd = current_dir().unwrap().to_path_buf();
|
let mut wd = current_dir().unwrap();
|
||||||
while wd.pop() {
|
while wd.pop() {
|
||||||
if wd.join(".git").exists() {
|
if wd.join(".git").exists() {
|
||||||
set_current_dir(wd).unwrap();
|
set_current_dir(wd).unwrap();
|
||||||
@@ -391,7 +398,15 @@ pub(crate) mod tests {
|
|||||||
pub(crate) fn clean(conn: &Conn) {
|
pub(crate) fn clean(conn: &Conn) {
|
||||||
//used to remove files generated by tests
|
//used to remove files generated by tests
|
||||||
for media in Media::list_all_medias(conn).unwrap() {
|
for media in Media::list_all_medias(conn).unwrap() {
|
||||||
media.delete(conn).unwrap();
|
if let Some(err) = media.delete(conn).err() {
|
||||||
|
match &err {
|
||||||
|
Error::Io(e) => match e.kind() {
|
||||||
|
std::io::ErrorKind::NotFound => (),
|
||||||
|
_ => panic!("{:?}", err),
|
||||||
|
},
|
||||||
|
_ => panic!("{:?}", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,7 +456,7 @@ pub(crate) mod tests {
|
|||||||
let media = Media::insert(
|
let media = Media::insert(
|
||||||
conn,
|
conn,
|
||||||
NewMedia {
|
NewMedia {
|
||||||
file_path: path.clone(),
|
file_path: path,
|
||||||
alt_text: "alt message".to_owned(),
|
alt_text: "alt message".to_owned(),
|
||||||
is_remote: false,
|
is_remote: false,
|
||||||
remote_url: None,
|
remote_url: None,
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comments::Comment, db_conn::DbConn, notifications::*, posts::Post, schema::mentions,
|
comments::Comment, notifications::*, posts::Post, schema::mentions, users::User, Connection,
|
||||||
users::User, Connection, Error, Result,
|
Error, Result,
|
||||||
|
};
|
||||||
|
use activitystreams::{
|
||||||
|
base::BaseExt,
|
||||||
|
iri_string::types::IriString,
|
||||||
|
link::{self, LinkExt},
|
||||||
};
|
};
|
||||||
use activitypub::link;
|
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use plume_common::activity_pub::inbox::AsActor;
|
use plume_common::activity_pub::inbox::AsActor;
|
||||||
|
|
||||||
@@ -47,26 +51,28 @@ impl Mention {
|
|||||||
|
|
||||||
pub fn get_user(&self, conn: &Connection) -> Result<User> {
|
pub fn get_user(&self, conn: &Connection) -> Result<User> {
|
||||||
match self.get_post(conn) {
|
match self.get_post(conn) {
|
||||||
Ok(p) => Ok(p.get_authors(conn)?.into_iter().next()?),
|
Ok(p) => Ok(p
|
||||||
|
.get_authors(conn)?
|
||||||
|
.into_iter()
|
||||||
|
.next()
|
||||||
|
.ok_or(Error::NotFound)?),
|
||||||
Err(_) => self.get_comment(conn).and_then(|c| c.get_author(conn)),
|
Err(_) => self.get_comment(conn).and_then(|c| c.get_author(conn)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_activity(conn: &DbConn, ment: &str) -> Result<link::Mention> {
|
pub fn build_activity(conn: &Connection, ment: &str) -> Result<link::Mention> {
|
||||||
let user = User::find_by_fqn(conn, ment)?;
|
let user = User::find_by_fqn(conn, ment)?;
|
||||||
let mut mention = link::Mention::default();
|
let mut mention = link::Mention::new();
|
||||||
mention.link_props.set_href_string(user.ap_url)?;
|
mention.set_href(user.ap_url.parse::<IriString>()?);
|
||||||
mention.link_props.set_name_string(format!("@{}", ment))?;
|
mention.set_name(format!("@{}", ment));
|
||||||
Ok(mention)
|
Ok(mention)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_activity(&self, conn: &Connection) -> Result<link::Mention> {
|
pub fn to_activity(&self, conn: &Connection) -> Result<link::Mention> {
|
||||||
let user = self.get_mentioned(conn)?;
|
let user = self.get_mentioned(conn)?;
|
||||||
let mut mention = link::Mention::default();
|
let mut mention = link::Mention::new();
|
||||||
mention.link_props.set_href_string(user.ap_url.clone())?;
|
mention.set_href(user.ap_url.parse::<IriString>()?);
|
||||||
mention
|
mention.set_name(format!("@{}", user.fqn));
|
||||||
.link_props
|
|
||||||
.set_name_string(format!("@{}", user.fqn))?;
|
|
||||||
Ok(mention)
|
Ok(mention)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +83,8 @@ impl Mention {
|
|||||||
in_post: bool,
|
in_post: bool,
|
||||||
notify: bool,
|
notify: bool,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let ap_url = ment.link_props.href_string().ok()?;
|
let ap_url = ment.href().ok_or(Error::NotFound)?.as_str();
|
||||||
let mentioned = User::find_by_ap_url(conn, &ap_url)?;
|
let mentioned = User::find_by_ap_url(conn, ap_url)?;
|
||||||
|
|
||||||
if in_post {
|
if in_post {
|
||||||
Post::get(conn, inside).and_then(|post| {
|
Post::get(conn, inside).and_then(|post| {
|
||||||
@@ -141,3 +147,62 @@ impl Mention {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::{inbox::tests::fill_database, tests::db, Error};
|
||||||
|
use assert_json_diff::assert_json_eq;
|
||||||
|
use diesel::Connection;
|
||||||
|
use serde_json::{json, to_value};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_activity() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (_posts, users, _blogs) = fill_database(&conn);
|
||||||
|
let user = &users[0];
|
||||||
|
let name = &user.username;
|
||||||
|
let act = Mention::build_activity(&conn, name)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"href": "https://plu.me/@/admin/",
|
||||||
|
"name": "@admin",
|
||||||
|
"type": "Mention",
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_activity() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (posts, users, _blogs) = fill_database(&conn);
|
||||||
|
let post = &posts[0];
|
||||||
|
let user = &users[0];
|
||||||
|
let mention = Mention::insert(
|
||||||
|
&conn,
|
||||||
|
NewMention {
|
||||||
|
mentioned_id: user.id,
|
||||||
|
post_id: Some(post.id),
|
||||||
|
comment_id: None,
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
let act = mention.to_activity(&conn)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"href": "https://plu.me/@/admin/",
|
||||||
|
"name": "@admin",
|
||||||
|
"type": "Mention",
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -105,7 +105,8 @@ impl ImportedMigrations {
|
|||||||
pub fn rerun_last_migration(&self, conn: &Connection, path: &Path) -> Result<()> {
|
pub fn rerun_last_migration(&self, conn: &Connection, path: &Path) -> Result<()> {
|
||||||
let latest_migration = conn.latest_run_migration_version()?;
|
let latest_migration = conn.latest_run_migration_version()?;
|
||||||
let id = latest_migration
|
let id = latest_migration
|
||||||
.and_then(|m| self.0.binary_search_by_key(&m.as_str(), |m| m.name).ok())?;
|
.and_then(|m| self.0.binary_search_by_key(&m.as_str(), |m| m.name).ok())
|
||||||
|
.ok_or(Error::NotFound)?;
|
||||||
let migration = &self.0[id];
|
let migration = &self.0[id];
|
||||||
conn.transaction(|| {
|
conn.transaction(|| {
|
||||||
migration.revert(conn, path)?;
|
migration.revert(conn, path)?;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ impl PasswordResetRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_and_delete_by_token(conn: &Connection, token: &str) -> Result<Self> {
|
pub fn find_and_delete_by_token(conn: &Connection, token: &str) -> Result<Self> {
|
||||||
let request = Self::find_by_token(&conn, &token)?;
|
let request = Self::find_by_token(conn, token)?;
|
||||||
|
|
||||||
let filter =
|
let filter =
|
||||||
password_reset_requests::table.filter(password_reset_requests::id.eq(request.id));
|
password_reset_requests::table.filter(password_reset_requests::id.eq(request.id));
|
||||||
@@ -89,7 +89,7 @@ mod tests {
|
|||||||
let request = PasswordResetRequest::find_by_token(&conn, &token)
|
let request = PasswordResetRequest::find_by_token(&conn, &token)
|
||||||
.expect("couldn't retrieve request");
|
.expect("couldn't retrieve request");
|
||||||
|
|
||||||
assert!(&token.len() > &32);
|
assert!(token.len() > 32);
|
||||||
assert_eq!(&request.email, &admin_email);
|
assert_eq!(&request.email, &admin_email);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -103,8 +103,8 @@ mod tests {
|
|||||||
user_tests::fill_database(&conn);
|
user_tests::fill_database(&conn);
|
||||||
let admin_email = "admin@example.com";
|
let admin_email = "admin@example.com";
|
||||||
|
|
||||||
PasswordResetRequest::insert(&conn, &admin_email).expect("couldn't insert new request");
|
PasswordResetRequest::insert(&conn, admin_email).expect("couldn't insert new request");
|
||||||
PasswordResetRequest::insert(&conn, &admin_email)
|
PasswordResetRequest::insert(&conn, admin_email)
|
||||||
.expect("couldn't insert second request");
|
.expect("couldn't insert second request");
|
||||||
|
|
||||||
let count = password_reset_requests::table.count().get_result(&*conn);
|
let count = password_reset_requests::table.count().get_result(&*conn);
|
||||||
@@ -132,7 +132,7 @@ mod tests {
|
|||||||
.execute(&*conn)
|
.execute(&*conn)
|
||||||
.expect("could not insert request");
|
.expect("could not insert request");
|
||||||
|
|
||||||
match PasswordResetRequest::find_by_token(&conn, &token) {
|
match PasswordResetRequest::find_by_token(&conn, token) {
|
||||||
Err(Error::Expired) => (),
|
Err(Error::Expired) => (),
|
||||||
_ => panic!("Received unexpected result finding expired token"),
|
_ => panic!("Received unexpected result finding expired token"),
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ mod tests {
|
|||||||
user_tests::fill_database(&conn);
|
user_tests::fill_database(&conn);
|
||||||
let admin_email = "admin@example.com";
|
let admin_email = "admin@example.com";
|
||||||
|
|
||||||
let token = PasswordResetRequest::insert(&conn, &admin_email)
|
let token = PasswordResetRequest::insert(&conn, admin_email)
|
||||||
.expect("couldn't insert new request");
|
.expect("couldn't insert new request");
|
||||||
PasswordResetRequest::find_and_delete_by_token(&conn, &token)
|
PasswordResetRequest::find_and_delete_by_token(&conn, &token)
|
||||||
.expect("couldn't find and delete request");
|
.expect("couldn't find and delete request");
|
||||||
|
|||||||
+502
-247
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,16 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
db_conn::{DbConn, DbPool},
|
db_conn::{DbConn, DbPool},
|
||||||
follows,
|
follows,
|
||||||
posts::{LicensedArticle, Post},
|
posts::Post,
|
||||||
users::{User, UserEvent},
|
users::{User, UserEvent},
|
||||||
ACTOR_SYS, CONFIG, USER_CHAN,
|
ACTOR_SYS, CONFIG, USER_CHAN,
|
||||||
};
|
};
|
||||||
use activitypub::activity::Create;
|
use activitystreams::{
|
||||||
use plume_common::activity_pub::inbox::FromId;
|
activity::{ActorAndObjectRef, Create},
|
||||||
|
base::AnyBase,
|
||||||
|
object::kind::ArticleType,
|
||||||
|
};
|
||||||
|
use plume_common::activity_pub::{inbox::FromId, LicensedArticle};
|
||||||
use riker::actors::{Actor, ActorFactoryArgs, ActorRefFactory, Context, Sender, Subscribe, Tell};
|
use riker::actors::{Actor, ActorFactoryArgs, ActorRefFactory, Context, Sender, Subscribe, Tell};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
@@ -41,6 +45,12 @@ impl Actor for RemoteFetchActor {
|
|||||||
RemoteUserFound(user) => match self.conn.get() {
|
RemoteUserFound(user) => match self.conn.get() {
|
||||||
Ok(conn) => {
|
Ok(conn) => {
|
||||||
let conn = DbConn(conn);
|
let conn = DbConn(conn);
|
||||||
|
if user
|
||||||
|
.get_instance(&conn)
|
||||||
|
.map_or(false, |instance| instance.blocked)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Don't call these functions in parallel
|
// Don't call these functions in parallel
|
||||||
// for the case database connections limit is too small
|
// for the case database connections limit is too small
|
||||||
fetch_and_cache_articles(&user, &conn);
|
fetch_and_cache_articles(&user, &conn);
|
||||||
@@ -68,13 +78,17 @@ fn fetch_and_cache_articles(user: &Arc<User>, conn: &DbConn) {
|
|||||||
match create_acts {
|
match create_acts {
|
||||||
Ok(create_acts) => {
|
Ok(create_acts) => {
|
||||||
for create_act in create_acts {
|
for create_act in create_acts {
|
||||||
match create_act.create_props.object_object::<LicensedArticle>() {
|
match create_act.object_field_ref().as_single_base().map(|base| {
|
||||||
Ok(article) => {
|
let any_base = AnyBase::from_base(base.clone()); // FIXME: Don't clone()
|
||||||
|
any_base.extend::<LicensedArticle, ArticleType>()
|
||||||
|
}) {
|
||||||
|
Some(Ok(Some(article))) => {
|
||||||
Post::from_activity(conn, article)
|
Post::from_activity(conn, article)
|
||||||
.expect("Article from remote user couldn't be saved");
|
.expect("Article from remote user couldn't be saved");
|
||||||
info!("Fetched article from remote user");
|
info!("Fetched article from remote user");
|
||||||
}
|
}
|
||||||
Err(e) => warn!("Error while fetching articles in background: {:?}", e),
|
Some(Err(e)) => warn!("Error while fetching articles in background: {:?}", e),
|
||||||
|
_ => warn!("Error while fetching articles in background"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+120
-37
@@ -1,13 +1,19 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
db_conn::DbConn, notifications::*, posts::Post, schema::reshares, timeline::*, users::User,
|
instance::Instance, notifications::*, posts::Post, schema::reshares, timeline::*, users::User,
|
||||||
Connection, Error, Result, CONFIG,
|
Connection, Error, Result, CONFIG,
|
||||||
};
|
};
|
||||||
use activitypub::activity::{Announce, Undo};
|
use activitystreams::{
|
||||||
|
activity::{ActorAndObjectRef, Announce, Undo},
|
||||||
|
base::AnyBase,
|
||||||
|
iri_string::types::IriString,
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use plume_common::activity_pub::{
|
use plume_common::activity_pub::{
|
||||||
inbox::{AsActor, AsObject, FromId},
|
inbox::{AsActor, AsObject, FromId},
|
||||||
Id, IntoId, PUBLIC_VISIBILITY,
|
sign::Signer,
|
||||||
|
PUBLIC_VISIBILITY,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Identifiable)]
|
#[derive(Clone, Queryable, Identifiable)]
|
||||||
@@ -60,16 +66,16 @@ impl Reshare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_activity(&self, conn: &Connection) -> Result<Announce> {
|
pub fn to_activity(&self, conn: &Connection) -> Result<Announce> {
|
||||||
let mut act = Announce::default();
|
let mut act = Announce::new(
|
||||||
act.announce_props
|
User::get(conn, self.user_id)?.ap_url.parse::<IriString>()?,
|
||||||
.set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
Post::get(conn, self.post_id)?.ap_url.parse::<IriString>()?,
|
||||||
act.announce_props
|
);
|
||||||
.set_object_link(Post::get(conn, self.post_id)?.into_id())?;
|
act.set_id(self.ap_url.parse::<IriString>()?);
|
||||||
act.object_props.set_id_string(self.ap_url.clone())?;
|
act.set_many_tos(vec![PUBLIC_VISIBILITY.parse::<IriString>()?]);
|
||||||
act.object_props
|
act.set_many_ccs(vec![self
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
.get_user(conn)?
|
||||||
act.object_props
|
.followers_endpoint
|
||||||
.set_cc_link_vec(vec![Id::new(self.get_user(conn)?.followers_endpoint)])?;
|
.parse::<IriString>()?]);
|
||||||
|
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
@@ -92,26 +98,26 @@ impl Reshare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> {
|
pub fn build_undo(&self, conn: &Connection) -> Result<Undo> {
|
||||||
let mut act = Undo::default();
|
let mut act = Undo::new(
|
||||||
act.undo_props
|
User::get(conn, self.user_id)?.ap_url.parse::<IriString>()?,
|
||||||
.set_actor_link(User::get(conn, self.user_id)?.into_id())?;
|
AnyBase::from_extended(self.to_activity(conn)?)?,
|
||||||
act.undo_props.set_object_object(self.to_activity(conn)?)?;
|
);
|
||||||
act.object_props
|
act.set_id(format!("{}#delete", self.ap_url).parse::<IriString>()?);
|
||||||
.set_id_string(format!("{}#delete", self.ap_url))?;
|
act.set_many_tos(vec![PUBLIC_VISIBILITY.parse::<IriString>()?]);
|
||||||
act.object_props
|
act.set_many_ccs(vec![self
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY.to_string())])?;
|
.get_user(conn)?
|
||||||
act.object_props
|
.followers_endpoint
|
||||||
.set_cc_link_vec(vec![Id::new(self.get_user(conn)?.followers_endpoint)])?;
|
.parse::<IriString>()?]);
|
||||||
|
|
||||||
Ok(act)
|
Ok(act)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Announce, &DbConn> for Post {
|
impl AsObject<User, Announce, &Connection> for Post {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = Reshare;
|
type Output = Reshare;
|
||||||
|
|
||||||
fn activity(self, conn: &DbConn, actor: User, id: &str) -> Result<Reshare> {
|
fn activity(self, conn: &Connection, actor: User, id: &str) -> Result<Reshare> {
|
||||||
let conn = conn;
|
let conn = conn;
|
||||||
let reshare = Reshare::insert(
|
let reshare = Reshare::insert(
|
||||||
conn,
|
conn,
|
||||||
@@ -128,21 +134,24 @@ impl AsObject<User, Announce, &DbConn> for Post {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromId<DbConn> for Reshare {
|
impl FromId<Connection> for Reshare {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Object = Announce;
|
type Object = Announce;
|
||||||
|
|
||||||
fn from_db(conn: &DbConn, id: &str) -> Result<Self> {
|
fn from_db(conn: &Connection, id: &str) -> Result<Self> {
|
||||||
Reshare::find_by_ap_url(conn, id)
|
Reshare::find_by_ap_url(conn, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_activity(conn: &DbConn, act: Announce) -> Result<Self> {
|
fn from_activity(conn: &Connection, act: Announce) -> Result<Self> {
|
||||||
let res = Reshare::insert(
|
let res = Reshare::insert(
|
||||||
conn,
|
conn,
|
||||||
NewReshare {
|
NewReshare {
|
||||||
post_id: Post::from_id(
|
post_id: Post::from_id(
|
||||||
conn,
|
conn,
|
||||||
&act.announce_props.object_link::<Id>()?,
|
act.object_field_ref()
|
||||||
|
.as_single_id()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
@@ -150,31 +159,41 @@ impl FromId<DbConn> for Reshare {
|
|||||||
.id,
|
.id,
|
||||||
user_id: User::from_id(
|
user_id: User::from_id(
|
||||||
conn,
|
conn,
|
||||||
&act.announce_props.actor_link::<Id>()?,
|
act.actor_field_ref()
|
||||||
|
.as_single_id()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.as_str(),
|
||||||
None,
|
None,
|
||||||
CONFIG.proxy(),
|
CONFIG.proxy(),
|
||||||
)
|
)
|
||||||
.map_err(|(_, e)| e)?
|
.map_err(|(_, e)| e)?
|
||||||
.id,
|
.id,
|
||||||
ap_url: act.object_props.id_string()?,
|
ap_url: act
|
||||||
|
.id_unchecked()
|
||||||
|
.ok_or(Error::MissingApProperty)?
|
||||||
|
.to_string(),
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
res.notify(conn)?;
|
res.notify(conn)?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_sender() -> &'static dyn Signer {
|
||||||
|
Instance::get_local_instance_user().expect("Failed to local instance user")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Undo, &DbConn> for Reshare {
|
impl AsObject<User, Undo, &Connection> for Reshare {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn activity(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> {
|
fn activity(self, conn: &Connection, actor: User, _id: &str) -> Result<()> {
|
||||||
if actor.id == self.user_id {
|
if actor.id == self.user_id {
|
||||||
diesel::delete(&self).execute(&**conn)?;
|
diesel::delete(&self).execute(conn)?;
|
||||||
|
|
||||||
// delete associated notification if any
|
// delete associated notification if any
|
||||||
if let Ok(notif) = Notification::find(&conn, notification_kind::RESHARE, self.id) {
|
if let Ok(notif) = Notification::find(conn, notification_kind::RESHARE, self.id) {
|
||||||
diesel::delete(¬if).execute(&**conn)?;
|
diesel::delete(¬if).execute(conn)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -186,7 +205,7 @@ impl AsObject<User, Undo, &DbConn> for Reshare {
|
|||||||
|
|
||||||
impl NewReshare {
|
impl NewReshare {
|
||||||
pub fn new(p: &Post, u: &User) -> Self {
|
pub fn new(p: &Post, u: &User) -> Self {
|
||||||
let ap_url = format!("{}/reshare/{}", u.ap_url, p.ap_url);
|
let ap_url = format!("{}reshare/{}", u.ap_url, p.ap_url);
|
||||||
NewReshare {
|
NewReshare {
|
||||||
post_id: p.id,
|
post_id: p.id,
|
||||||
user_id: u.id,
|
user_id: u.id,
|
||||||
@@ -194,3 +213,67 @@ impl NewReshare {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
use crate::diesel::Connection;
|
||||||
|
use crate::{inbox::tests::fill_database, tests::db};
|
||||||
|
use assert_json_diff::assert_json_eq;
|
||||||
|
use serde_json::{json, to_value};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_activity() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (posts, _users, _blogs) = fill_database(&conn);
|
||||||
|
let post = &posts[0];
|
||||||
|
let user = &post.get_authors(&conn)?[0];
|
||||||
|
let reshare = Reshare::insert(&conn, NewReshare::new(post, user))?;
|
||||||
|
let act = reshare.to_activity(&conn).unwrap();
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"actor": "https://plu.me/@/admin/",
|
||||||
|
"cc": ["https://plu.me/@/admin/followers"],
|
||||||
|
"id": "https://plu.me/@/admin/reshare/https://plu.me/~/BlogName/testing",
|
||||||
|
"object": "https://plu.me/~/BlogName/testing",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Announce",
|
||||||
|
});
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_undo() {
|
||||||
|
let conn = db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (posts, _users, _blogs) = fill_database(&conn);
|
||||||
|
let post = &posts[0];
|
||||||
|
let user = &post.get_authors(&conn)?[0];
|
||||||
|
let reshare = Reshare::insert(&conn, NewReshare::new(post, user))?;
|
||||||
|
let act = reshare.build_undo(&conn)?;
|
||||||
|
|
||||||
|
let expected = json!({
|
||||||
|
"actor": "https://plu.me/@/admin/",
|
||||||
|
"cc": ["https://plu.me/@/admin/followers"],
|
||||||
|
"id": "https://plu.me/@/admin/reshare/https://plu.me/~/BlogName/testing#delete",
|
||||||
|
"object": {
|
||||||
|
"actor": "https://plu.me/@/admin/",
|
||||||
|
"cc": ["https://plu.me/@/admin/followers"],
|
||||||
|
"id": "https://plu.me/@/admin/reshare/https://plu.me/~/BlogName/testing",
|
||||||
|
"object": "https://plu.me/~/BlogName/testing",
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Announce"
|
||||||
|
},
|
||||||
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
|
"type": "Undo",
|
||||||
|
});
|
||||||
|
assert_json_eq!(to_value(act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ fn url_add_prefix(url: &str) -> Option<Cow<'_, str>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, AsExpression, FromSqlRow, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, AsExpression, FromSqlRow, Default)]
|
||||||
#[sql_type = "Text"]
|
#[sql_type = "Text"]
|
||||||
pub struct SafeString {
|
pub struct SafeString {
|
||||||
value: String,
|
value: String,
|
||||||
@@ -102,7 +102,7 @@ pub struct SafeString {
|
|||||||
impl SafeString {
|
impl SafeString {
|
||||||
pub fn new(value: &str) -> Self {
|
pub fn new(value: &str) -> Self {
|
||||||
SafeString {
|
SafeString {
|
||||||
value: CLEAN.clean(&value).to_string(),
|
value: CLEAN.clean(value).to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,16 +73,26 @@ table! {
|
|||||||
user_id -> Int4,
|
user_id -> Int4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
email_blocklist(id){
|
email_blocklist (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
email_address -> VarChar,
|
email_address -> Text,
|
||||||
note -> Text,
|
note -> Text,
|
||||||
notify_user -> Bool,
|
notify_user -> Bool,
|
||||||
notification_text -> Text,
|
notification_text -> Text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
email_signups (id) {
|
||||||
|
id -> Int4,
|
||||||
|
email -> Varchar,
|
||||||
|
token -> Varchar,
|
||||||
|
expiration_date -> Timestamp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
follows (id) {
|
follows (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
@@ -306,6 +316,8 @@ allow_tables_to_appear_in_same_query!(
|
|||||||
blogs,
|
blogs,
|
||||||
comments,
|
comments,
|
||||||
comment_seers,
|
comment_seers,
|
||||||
|
email_blocklist,
|
||||||
|
email_signups,
|
||||||
follows,
|
follows,
|
||||||
instances,
|
instances,
|
||||||
likes,
|
likes,
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ mod tests {
|
|||||||
|
|
||||||
let searcher = Arc::new(get_searcher(&CONFIG.search_tokenizers));
|
let searcher = Arc::new(get_searcher(&CONFIG.search_tokenizers));
|
||||||
SearchActor::init(searcher.clone(), db_pool.clone());
|
SearchActor::init(searcher.clone(), db_pool.clone());
|
||||||
let conn = db_pool.clone().get().unwrap();
|
let conn = db_pool.get().unwrap();
|
||||||
|
|
||||||
let title = random_hex()[..8].to_owned();
|
let title = random_hex()[..8].to_owned();
|
||||||
let (_instance, _user, blog) = fill_database(&conn);
|
let (_instance, _user, blog) = fill_database(&conn);
|
||||||
@@ -161,41 +161,43 @@ mod tests {
|
|||||||
long_description_html: "<p>Good morning</p>".to_string(),
|
long_description_html: "<p>Good morning</p>".to_string(),
|
||||||
short_description: SafeString::new("Hello"),
|
short_description: SafeString::new("Hello"),
|
||||||
short_description_html: "<p>Hello</p>".to_string(),
|
short_description_html: "<p>Hello</p>".to_string(),
|
||||||
name: random_hex().to_string(),
|
name: random_hex(),
|
||||||
open_registrations: true,
|
open_registrations: true,
|
||||||
public_domain: random_hex().to_string(),
|
public_domain: random_hex(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let user = User::insert(
|
let user = User::insert(
|
||||||
conn,
|
conn,
|
||||||
NewUser {
|
NewUser {
|
||||||
username: random_hex().to_string(),
|
username: random_hex(),
|
||||||
display_name: random_hex().to_string(),
|
display_name: random_hex(),
|
||||||
outbox_url: random_hex().to_string(),
|
outbox_url: random_hex(),
|
||||||
inbox_url: random_hex().to_string(),
|
inbox_url: random_hex(),
|
||||||
summary: "".to_string(),
|
summary: "".to_string(),
|
||||||
email: None,
|
email: None,
|
||||||
hashed_password: None,
|
hashed_password: None,
|
||||||
instance_id: instance.id,
|
instance_id: instance.id,
|
||||||
ap_url: random_hex().to_string(),
|
ap_url: random_hex(),
|
||||||
private_key: None,
|
private_key: None,
|
||||||
public_key: "".to_string(),
|
public_key: "".to_string(),
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
followers_endpoint: random_hex().to_string(),
|
followers_endpoint: random_hex(),
|
||||||
avatar_id: None,
|
avatar_id: None,
|
||||||
summary_html: SafeString::new(""),
|
summary_html: SafeString::new(""),
|
||||||
role: 0,
|
role: 0,
|
||||||
fqn: random_hex().to_string(),
|
fqn: random_hex(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut blog = NewBlog::default();
|
let blog = NewBlog {
|
||||||
blog.instance_id = instance.id;
|
instance_id: instance.id,
|
||||||
blog.actor_id = random_hex().to_string();
|
actor_id: random_hex(),
|
||||||
blog.ap_url = random_hex().to_string();
|
ap_url: random_hex(),
|
||||||
blog.inbox_url = random_hex().to_string();
|
inbox_url: random_hex(),
|
||||||
blog.outbox_url = random_hex().to_string();
|
outbox_url: random_hex(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
let blog = Blog::insert(conn, blog).unwrap();
|
let blog = Blog::insert(conn, blog).unwrap();
|
||||||
BlogAuthor::insert(
|
BlogAuthor::insert(
|
||||||
conn,
|
conn,
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ pub(crate) mod tests {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
searcher.add_document(&conn, &post).unwrap();
|
searcher.add_document(conn, &post).unwrap();
|
||||||
searcher.commit();
|
searcher.commit();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
searcher.search_document(conn, Query::from_str(&title).unwrap(), (0, 1))[0].id,
|
searcher.search_document(conn, Query::from_str(&title).unwrap(), (0, 1))[0].id,
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ macro_rules! gen_to_string {
|
|||||||
)*
|
)*
|
||||||
$(
|
$(
|
||||||
for val in &$self.$date {
|
for val in &$self.$date {
|
||||||
$result.push_str(&format!("{}:{} ", stringify!($date), NaiveDate::from_num_days_from_ce(*val as i32).format("%Y-%m-%d")));
|
$result.push_str(&format!("{}:{} ", stringify!($date), NaiveDate::from_num_days_from_ce_opt(*val as i32).unwrap().format("%Y-%m-%d")));
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ impl PlumeQuery {
|
|||||||
|
|
||||||
/// Parse a query string into this Query
|
/// Parse a query string into this Query
|
||||||
pub fn parse_query(&mut self, query: &str) -> &mut Self {
|
pub fn parse_query(&mut self, query: &str) -> &mut Self {
|
||||||
self.from_str_req(&query.trim())
|
self.from_str_req(query.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert this Query to a Tantivy Query
|
/// Convert this Query to a Tantivy Query
|
||||||
@@ -180,12 +180,16 @@ impl PlumeQuery {
|
|||||||
|
|
||||||
if self.before.is_some() || self.after.is_some() {
|
if self.before.is_some() || self.after.is_some() {
|
||||||
// if at least one range bound is provided
|
// if at least one range bound is provided
|
||||||
let after = self
|
let after = self.after.unwrap_or_else(|| {
|
||||||
.after
|
i64::from(
|
||||||
.unwrap_or_else(|| i64::from(NaiveDate::from_ymd(2000, 1, 1).num_days_from_ce()));
|
NaiveDate::from_ymd_opt(2000, 1, 1)
|
||||||
|
.unwrap()
|
||||||
|
.num_days_from_ce(),
|
||||||
|
)
|
||||||
|
});
|
||||||
let before = self
|
let before = self
|
||||||
.before
|
.before
|
||||||
.unwrap_or_else(|| i64::from(Utc::today().num_days_from_ce()));
|
.unwrap_or_else(|| i64::from(Utc::now().date_naive().num_days_from_ce()));
|
||||||
let field = Searcher::schema().get_field("creation_date").unwrap();
|
let field = Searcher::schema().get_field("creation_date").unwrap();
|
||||||
let range =
|
let range =
|
||||||
RangeQuery::new_i64_bounds(field, Bound::Included(after), Bound::Included(before));
|
RangeQuery::new_i64_bounds(field, Bound::Included(after), Bound::Included(before));
|
||||||
@@ -202,16 +206,20 @@ impl PlumeQuery {
|
|||||||
pub fn before<D: Datelike>(&mut self, date: &D) -> &mut Self {
|
pub fn before<D: Datelike>(&mut self, date: &D) -> &mut Self {
|
||||||
let before = self
|
let before = self
|
||||||
.before
|
.before
|
||||||
.unwrap_or_else(|| i64::from(Utc::today().num_days_from_ce()));
|
.unwrap_or_else(|| i64::from(Utc::now().date_naive().num_days_from_ce()));
|
||||||
self.before = Some(cmp::min(before, i64::from(date.num_days_from_ce())));
|
self.before = Some(cmp::min(before, i64::from(date.num_days_from_ce())));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
// documents older than the provided date will be ignored
|
// documents older than the provided date will be ignored
|
||||||
pub fn after<D: Datelike>(&mut self, date: &D) -> &mut Self {
|
pub fn after<D: Datelike>(&mut self, date: &D) -> &mut Self {
|
||||||
let after = self
|
let after = self.after.unwrap_or_else(|| {
|
||||||
.after
|
i64::from(
|
||||||
.unwrap_or_else(|| i64::from(NaiveDate::from_ymd(2000, 1, 1).num_days_from_ce()));
|
NaiveDate::from_ymd_opt(2000, 1, 1)
|
||||||
|
.unwrap()
|
||||||
|
.num_days_from_ce(),
|
||||||
|
)
|
||||||
|
});
|
||||||
self.after = Some(cmp::max(after, i64::from(date.num_days_from_ce())));
|
self.after = Some(cmp::max(after, i64::from(date.num_days_from_ce())));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -360,7 +368,7 @@ impl std::str::FromStr for PlumeQuery {
|
|||||||
fn from_str(query: &str) -> Result<PlumeQuery, !> {
|
fn from_str(query: &str) -> Result<PlumeQuery, !> {
|
||||||
let mut res: PlumeQuery = Default::default();
|
let mut res: PlumeQuery = Default::default();
|
||||||
|
|
||||||
res.from_str_req(&query.trim());
|
res.from_str_req(query.trim());
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ impl<'a> WhitespaceTokenStream<'a> {
|
|||||||
.filter(|&(_, ref c)| c.is_whitespace())
|
.filter(|&(_, ref c)| c.is_whitespace())
|
||||||
.map(|(offset, _)| offset)
|
.map(|(offset, _)| offset)
|
||||||
.next()
|
.next()
|
||||||
.unwrap_or_else(|| self.text.len())
|
.unwrap_or(self.text.len())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
use crate::CONFIG;
|
||||||
|
use rocket::request::{FromRequest, Outcome, Request};
|
||||||
|
use std::fmt;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
pub enum Strategy {
|
||||||
|
Password,
|
||||||
|
Email,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Strategy {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Strategy {
|
||||||
|
type Err = StrategyError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
use self::Strategy::*;
|
||||||
|
|
||||||
|
match s {
|
||||||
|
"password" => Ok(Password),
|
||||||
|
"email" => Ok(Email),
|
||||||
|
s => Err(StrategyError::Unsupported(s.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum StrategyError {
|
||||||
|
Unsupported(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for StrategyError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
use self::StrategyError::*;
|
||||||
|
|
||||||
|
match self {
|
||||||
|
// FIXME: Calc option strings from enum
|
||||||
|
Unsupported(s) => write!(f, "Unsupported strategy: {}. Choose password or email", s),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for StrategyError {}
|
||||||
|
|
||||||
|
pub struct Password();
|
||||||
|
pub struct Email();
|
||||||
|
|
||||||
|
impl<'a, 'r> FromRequest<'a, 'r> for Password {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn from_request(_request: &'a Request<'r>) -> Outcome<Self, ()> {
|
||||||
|
match matches!(CONFIG.signup, Strategy::Password) {
|
||||||
|
true => Outcome::Success(Self()),
|
||||||
|
false => Outcome::Forward(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, 'r> FromRequest<'a, 'r> for Email {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn from_request(_request: &'a Request<'r>) -> Outcome<Self, ()> {
|
||||||
|
match matches!(CONFIG.signup, Strategy::Email) {
|
||||||
|
true => Outcome::Success(Self()),
|
||||||
|
false => Outcome::Forward(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+92
-16
@@ -1,6 +1,7 @@
|
|||||||
use crate::{ap_url, instance::Instance, schema::tags, Connection, Error, Result};
|
use crate::{ap_url, instance::Instance, schema::tags, Connection, Error, Result};
|
||||||
|
use activitystreams::iri_string::types::IriString;
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use plume_common::activity_pub::Hashtag;
|
use plume_common::activity_pub::{Hashtag, HashtagExt};
|
||||||
|
|
||||||
#[derive(Clone, Identifiable, Queryable)]
|
#[derive(Clone, Identifiable, Queryable)]
|
||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
@@ -25,13 +26,16 @@ impl Tag {
|
|||||||
list_by!(tags, for_post, post_id as i32);
|
list_by!(tags, for_post, post_id as i32);
|
||||||
|
|
||||||
pub fn to_activity(&self) -> Result<Hashtag> {
|
pub fn to_activity(&self) -> Result<Hashtag> {
|
||||||
let mut ht = Hashtag::default();
|
let mut ht = Hashtag::new();
|
||||||
ht.set_href_string(ap_url(&format!(
|
ht.set_href(
|
||||||
"{}/tag/{}",
|
ap_url(&format!(
|
||||||
Instance::get_local()?.public_domain,
|
"{}/tag/{}",
|
||||||
self.tag
|
Instance::get_local()?.public_domain,
|
||||||
)))?;
|
self.tag
|
||||||
ht.set_name_string(self.tag.clone())?;
|
))
|
||||||
|
.parse::<IriString>()?,
|
||||||
|
);
|
||||||
|
ht.set_name(self.tag.clone());
|
||||||
Ok(ht)
|
Ok(ht)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +48,7 @@ impl Tag {
|
|||||||
Tag::insert(
|
Tag::insert(
|
||||||
conn,
|
conn,
|
||||||
NewTag {
|
NewTag {
|
||||||
tag: tag.name_string()?,
|
tag: tag.name().ok_or(Error::MissingApProperty)?.as_str().into(),
|
||||||
is_hashtag,
|
is_hashtag,
|
||||||
post_id: post,
|
post_id: post,
|
||||||
},
|
},
|
||||||
@@ -52,13 +56,16 @@ impl Tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_activity(tag: String) -> Result<Hashtag> {
|
pub fn build_activity(tag: String) -> Result<Hashtag> {
|
||||||
let mut ht = Hashtag::default();
|
let mut ht = Hashtag::new();
|
||||||
ht.set_href_string(ap_url(&format!(
|
ht.set_href(
|
||||||
"{}/tag/{}",
|
ap_url(&format!(
|
||||||
Instance::get_local()?.public_domain,
|
"{}/tag/{}",
|
||||||
tag
|
Instance::get_local()?.public_domain,
|
||||||
)))?;
|
tag
|
||||||
ht.set_name_string(tag)?;
|
))
|
||||||
|
.parse::<IriString>()?,
|
||||||
|
);
|
||||||
|
ht.set_name(tag);
|
||||||
Ok(ht)
|
Ok(ht)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,3 +76,72 @@ impl Tag {
|
|||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::tests::db;
|
||||||
|
use crate::{diesel::Connection, inbox::tests::fill_database};
|
||||||
|
use assert_json_diff::assert_json_eq;
|
||||||
|
use serde_json::to_value;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_activity() {
|
||||||
|
let conn = &db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
let (posts, _users, _blogs) = fill_database(conn);
|
||||||
|
let post_id = posts[0].id;
|
||||||
|
let mut ht = Hashtag::new();
|
||||||
|
ht.set_href(ap_url("https://plu.me/tag/a_tag").parse::<IriString>()?);
|
||||||
|
ht.set_name("a_tag".to_string());
|
||||||
|
let tag = Tag::from_activity(conn, &ht, post_id, true)?;
|
||||||
|
|
||||||
|
assert_eq!(&tag.tag, "a_tag");
|
||||||
|
assert!(tag.is_hashtag);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_activity() {
|
||||||
|
let conn = &db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
fill_database(conn);
|
||||||
|
let tag = Tag {
|
||||||
|
id: 0,
|
||||||
|
tag: "a_tag".into(),
|
||||||
|
is_hashtag: false,
|
||||||
|
post_id: 0,
|
||||||
|
};
|
||||||
|
let act = tag.to_activity()?;
|
||||||
|
let expected = json!({
|
||||||
|
"href": "https://plu.me/tag/a_tag",
|
||||||
|
"name": "a_tag",
|
||||||
|
"type": "Hashtag"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(&act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_activity() {
|
||||||
|
let conn = &db();
|
||||||
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
|
fill_database(conn);
|
||||||
|
let act = Tag::build_activity("a_tag".into())?;
|
||||||
|
let expected = json!({
|
||||||
|
"href": "https://plu.me/tag/a_tag",
|
||||||
|
"name": "a_tag",
|
||||||
|
"type": "Hashtag"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_eq!(to_value(&act)?, expected);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+154
-122
@@ -1,19 +1,19 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
db_conn::DbConn,
|
|
||||||
lists::List,
|
lists::List,
|
||||||
posts::Post,
|
posts::Post,
|
||||||
schema::{posts, timeline, timeline_definition},
|
schema::{posts, timeline, timeline_definition},
|
||||||
Connection, Error, Result,
|
Connection, Error, Result,
|
||||||
};
|
};
|
||||||
use diesel::{self, BoolExpressionMethods, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, BoolExpressionMethods, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
pub(crate) mod query;
|
pub(crate) mod query;
|
||||||
|
|
||||||
pub use self::query::Kind;
|
pub use self::query::Kind;
|
||||||
use self::query::{QueryError, TimelineQuery};
|
pub use self::query::{QueryError, TimelineQuery};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Queryable, Identifiable, AsChangeset)]
|
#[derive(Clone, Debug, PartialEq, Eq, Queryable, Identifiable, AsChangeset)]
|
||||||
#[table_name = "timeline_definition"]
|
#[table_name = "timeline_definition"]
|
||||||
pub struct Timeline {
|
pub struct Timeline {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
@@ -92,6 +92,16 @@ impl Timeline {
|
|||||||
.load::<Self>(conn)
|
.load::<Self>(conn)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
.map(|mut timelines| {
|
||||||
|
timelines.sort_by(|t1, t2| {
|
||||||
|
if t1.user_id.is_some() && t2.user_id.is_none() {
|
||||||
|
Ordering::Less
|
||||||
|
} else {
|
||||||
|
t1.id.cmp(&t2.id)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timelines
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_for_user(
|
pub fn new_for_user(
|
||||||
@@ -209,7 +219,7 @@ impl Timeline {
|
|||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_to_all_timelines(conn: &DbConn, post: &Post, kind: Kind<'_>) -> Result<()> {
|
pub fn add_to_all_timelines(conn: &Connection, post: &Post, kind: Kind<'_>) -> Result<()> {
|
||||||
let timelines = timeline_definition::table
|
let timelines = timeline_definition::table
|
||||||
.load::<Self>(conn.deref())
|
.load::<Self>(conn.deref())
|
||||||
.map_err(Error::from)?;
|
.map_err(Error::from)?;
|
||||||
@@ -223,6 +233,9 @@ impl Timeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_post(&self, conn: &Connection, post: &Post) -> Result<()> {
|
pub fn add_post(&self, conn: &Connection, post: &Post) -> Result<()> {
|
||||||
|
if self.includes_post(conn, post)? {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
diesel::insert_into(timeline::table)
|
diesel::insert_into(timeline::table)
|
||||||
.values(TimelineEntry {
|
.values(TimelineEntry {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
@@ -232,10 +245,39 @@ impl Timeline {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn matches(&self, conn: &DbConn, post: &Post, kind: Kind<'_>) -> Result<bool> {
|
pub fn remove_post(&self, conn: &Connection, post: &Post) -> Result<bool> {
|
||||||
|
if self.includes_post(conn, post)? {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
diesel::delete(
|
||||||
|
timeline::table
|
||||||
|
.filter(timeline::timeline_id.eq(self.id))
|
||||||
|
.filter(timeline::post_id.eq(post.id)),
|
||||||
|
)
|
||||||
|
.execute(conn)?;
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_all_posts(&self, conn: &Connection) -> Result<u64> {
|
||||||
|
let count = diesel::delete(timeline::table.filter(timeline::timeline_id.eq(self.id)))
|
||||||
|
.execute(conn)?;
|
||||||
|
Ok(count as u64)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn matches(&self, conn: &Connection, post: &Post, kind: Kind<'_>) -> Result<bool> {
|
||||||
let query = TimelineQuery::parse(&self.query)?;
|
let query = TimelineQuery::parse(&self.query)?;
|
||||||
query.matches(conn, self, post, kind)
|
query.matches(conn, self, post, kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn includes_post(&self, conn: &Connection, post: &Post) -> Result<bool> {
|
||||||
|
diesel::dsl::select(diesel::dsl::exists(
|
||||||
|
timeline::table
|
||||||
|
.filter(timeline::timeline_id.eq(self.id))
|
||||||
|
.filter(timeline::post_id.eq(post.id)),
|
||||||
|
))
|
||||||
|
.get_result(conn)
|
||||||
|
.map_err(Error::from)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -258,73 +300,63 @@ mod tests {
|
|||||||
fn test_timeline() {
|
fn test_timeline() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let users = userTests::fill_database(&conn);
|
let users = userTests::fill_database(conn);
|
||||||
|
|
||||||
let mut tl1_u1 = Timeline::new_for_user(
|
let mut tl1_u1 = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"my timeline".to_owned(),
|
"my timeline".to_owned(),
|
||||||
"all".to_owned(),
|
"all".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
List::new(
|
List::new(conn, "languages I speak", Some(&users[1]), ListType::Prefix).unwrap();
|
||||||
&conn,
|
|
||||||
"languages I speak",
|
|
||||||
Some(&users[1]),
|
|
||||||
ListType::Prefix,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let tl2_u1 = Timeline::new_for_user(
|
let tl2_u1 = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"another timeline".to_owned(),
|
"another timeline".to_owned(),
|
||||||
"followed".to_owned(),
|
"followed".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let tl1_u2 = Timeline::new_for_user(
|
let tl1_u2 = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[1].id,
|
users[1].id,
|
||||||
"english posts".to_owned(),
|
"english posts".to_owned(),
|
||||||
"lang in \"languages I speak\"".to_owned(),
|
"lang in \"languages I speak\"".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let tl1_instance = Timeline::new_for_instance(
|
let tl1_instance = Timeline::new_for_instance(
|
||||||
&conn,
|
conn,
|
||||||
"english posts".to_owned(),
|
"english posts".to_owned(),
|
||||||
"license in [cc]".to_owned(),
|
"license in [cc]".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(tl1_u1, Timeline::get(&conn, tl1_u1.id).unwrap());
|
assert_eq!(tl1_u1, Timeline::get(conn, tl1_u1.id).unwrap());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tl2_u1,
|
tl2_u1,
|
||||||
Timeline::find_for_user_by_name(&conn, Some(users[0].id), "another timeline")
|
Timeline::find_for_user_by_name(conn, Some(users[0].id), "another timeline")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tl1_instance,
|
tl1_instance,
|
||||||
Timeline::find_for_user_by_name(&conn, None, "english posts").unwrap()
|
Timeline::find_for_user_by_name(conn, None, "english posts").unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
let tl_u1 = Timeline::list_for_user(&conn, Some(users[0].id)).unwrap();
|
let tl_u1 = Timeline::list_for_user(conn, Some(users[0].id)).unwrap();
|
||||||
assert_eq!(3, tl_u1.len()); // it is not 2 because there is a "Your feed" tl created for each user automatically
|
assert_eq!(3, tl_u1.len()); // it is not 2 because there is a "Your feed" tl created for each user automatically
|
||||||
assert!(tl_u1.iter().fold(false, |res, tl| { res || *tl == tl1_u1 }));
|
assert!(tl_u1.iter().any(|tl| *tl == tl1_u1));
|
||||||
assert!(tl_u1.iter().fold(false, |res, tl| { res || *tl == tl2_u1 }));
|
assert!(tl_u1.iter().any(|tl| *tl == tl2_u1));
|
||||||
|
|
||||||
let tl_instance = Timeline::list_for_user(&conn, None).unwrap();
|
let tl_instance = Timeline::list_for_user(conn, None).unwrap();
|
||||||
assert_eq!(3, tl_instance.len()); // there are also the local and federated feed by default
|
assert_eq!(3, tl_instance.len()); // there are also the local and federated feed by default
|
||||||
assert!(tl_instance
|
assert!(tl_instance.iter().any(|tl| *tl == tl1_instance));
|
||||||
.iter()
|
|
||||||
.fold(false, |res, tl| { res || *tl == tl1_instance }));
|
|
||||||
|
|
||||||
tl1_u1.name = "My Super TL".to_owned();
|
tl1_u1.name = "My Super TL".to_owned();
|
||||||
let new_tl1_u2 = tl1_u2.update(&conn).unwrap();
|
let new_tl1_u2 = tl1_u2.update(conn).unwrap();
|
||||||
|
|
||||||
let tl_u2 = Timeline::list_for_user(&conn, Some(users[1].id)).unwrap();
|
let tl_u2 = Timeline::list_for_user(conn, Some(users[1].id)).unwrap();
|
||||||
assert_eq!(2, tl_u2.len()); // same here
|
assert_eq!(2, tl_u2.len()); // same here
|
||||||
assert!(tl_u2
|
assert!(tl_u2.iter().any(|tl| *tl == new_tl1_u2));
|
||||||
.iter()
|
|
||||||
.fold(false, |res, tl| { res || *tl == new_tl1_u2 }));
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
@@ -334,48 +366,48 @@ mod tests {
|
|||||||
fn test_timeline_creation_error() {
|
fn test_timeline_creation_error() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let users = userTests::fill_database(&conn);
|
let users = userTests::fill_database(conn);
|
||||||
|
|
||||||
assert!(Timeline::new_for_user(
|
assert!(Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"my timeline".to_owned(),
|
"my timeline".to_owned(),
|
||||||
"invalid keyword".to_owned(),
|
"invalid keyword".to_owned(),
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
assert!(Timeline::new_for_instance(
|
assert!(Timeline::new_for_instance(
|
||||||
&conn,
|
conn,
|
||||||
"my timeline".to_owned(),
|
"my timeline".to_owned(),
|
||||||
"invalid keyword".to_owned(),
|
"invalid keyword".to_owned(),
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
|
|
||||||
assert!(Timeline::new_for_user(
|
assert!(Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"my timeline".to_owned(),
|
"my timeline".to_owned(),
|
||||||
"author in non_existant_list".to_owned(),
|
"author in non_existant_list".to_owned(),
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
assert!(Timeline::new_for_instance(
|
assert!(Timeline::new_for_instance(
|
||||||
&conn,
|
conn,
|
||||||
"my timeline".to_owned(),
|
"my timeline".to_owned(),
|
||||||
"lang in dont-exist".to_owned(),
|
"lang in dont-exist".to_owned(),
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
|
|
||||||
List::new(&conn, "friends", Some(&users[0]), ListType::User).unwrap();
|
List::new(conn, "friends", Some(&users[0]), ListType::User).unwrap();
|
||||||
List::new(&conn, "idk", None, ListType::Blog).unwrap();
|
List::new(conn, "idk", None, ListType::Blog).unwrap();
|
||||||
|
|
||||||
assert!(Timeline::new_for_user(
|
assert!(Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"my timeline".to_owned(),
|
"my timeline".to_owned(),
|
||||||
"blog in friends".to_owned(),
|
"blog in friends".to_owned(),
|
||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
assert!(Timeline::new_for_instance(
|
assert!(Timeline::new_for_instance(
|
||||||
&conn,
|
conn,
|
||||||
"my timeline".to_owned(),
|
"my timeline".to_owned(),
|
||||||
"not author in idk".to_owned(),
|
"not author in idk".to_owned(),
|
||||||
)
|
)
|
||||||
@@ -389,10 +421,10 @@ mod tests {
|
|||||||
fn test_simple_match() {
|
fn test_simple_match() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (users, blogs) = blogTests::fill_database(&conn);
|
let (users, blogs) = blogTests::fill_database(conn);
|
||||||
|
|
||||||
let gnu_tl = Timeline::new_for_user(
|
let gnu_tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"GNU timeline".to_owned(),
|
"GNU timeline".to_owned(),
|
||||||
"license in [AGPL, LGPL, GPL]".to_owned(),
|
"license in [AGPL, LGPL, GPL]".to_owned(),
|
||||||
@@ -400,7 +432,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let gnu_post = Post::insert(
|
let gnu_post = Post::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blogs[0].id,
|
blog_id: blogs[0].id,
|
||||||
slug: "slug".to_string(),
|
slug: "slug".to_string(),
|
||||||
@@ -416,10 +448,10 @@ mod tests {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(gnu_tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(gnu_tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
|
|
||||||
let non_free_post = Post::insert(
|
let non_free_post = Post::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blogs[0].id,
|
blog_id: blogs[0].id,
|
||||||
slug: "slug2".to_string(),
|
slug: "slug2".to_string(),
|
||||||
@@ -436,7 +468,7 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!gnu_tl
|
assert!(!gnu_tl
|
||||||
.matches(&conn, &non_free_post, Kind::Original)
|
.matches(conn, &non_free_post, Kind::Original)
|
||||||
.unwrap());
|
.unwrap());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -447,9 +479,9 @@ mod tests {
|
|||||||
fn test_complex_match() {
|
fn test_complex_match() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (users, blogs) = blogTests::fill_database(&conn);
|
let (users, blogs) = blogTests::fill_database(conn);
|
||||||
Follow::insert(
|
Follow::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewFollow {
|
NewFollow {
|
||||||
follower_id: users[0].id,
|
follower_id: users[0].id,
|
||||||
following_id: users[1].id,
|
following_id: users[1].id,
|
||||||
@@ -459,11 +491,11 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let fav_blogs_list =
|
let fav_blogs_list =
|
||||||
List::new(&conn, "fav_blogs", Some(&users[0]), ListType::Blog).unwrap();
|
List::new(conn, "fav_blogs", Some(&users[0]), ListType::Blog).unwrap();
|
||||||
fav_blogs_list.add_blogs(&conn, &[blogs[0].id]).unwrap();
|
fav_blogs_list.add_blogs(conn, &[blogs[0].id]).unwrap();
|
||||||
|
|
||||||
let my_tl = Timeline::new_for_user(
|
let my_tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"My timeline".to_owned(),
|
"My timeline".to_owned(),
|
||||||
"blog in fav_blogs and not has_cover or local and followed exclude likes"
|
"blog in fav_blogs and not has_cover or local and followed exclude likes"
|
||||||
@@ -472,7 +504,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let post = Post::insert(
|
let post = Post::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blogs[0].id,
|
blog_id: blogs[0].id,
|
||||||
slug: "about-linux".to_string(),
|
slug: "about-linux".to_string(),
|
||||||
@@ -488,10 +520,10 @@ mod tests {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(my_tl.matches(&conn, &post, Kind::Original).unwrap()); // matches because of "blog in fav_blogs" (and there is no cover)
|
assert!(my_tl.matches(conn, &post, Kind::Original).unwrap()); // matches because of "blog in fav_blogs" (and there is no cover)
|
||||||
|
|
||||||
let post = Post::insert(
|
let post = Post::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blogs[1].id,
|
blog_id: blogs[1].id,
|
||||||
slug: "about-linux-2".to_string(),
|
slug: "about-linux-2".to_string(),
|
||||||
@@ -509,7 +541,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!my_tl.matches(&conn, &post, Kind::Like(&users[1])).unwrap());
|
assert!(!my_tl.matches(conn, &post, Kind::Like(&users[1])).unwrap());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
@@ -519,17 +551,17 @@ mod tests {
|
|||||||
fn test_add_to_all_timelines() {
|
fn test_add_to_all_timelines() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (users, blogs) = blogTests::fill_database(&conn);
|
let (users, blogs) = blogTests::fill_database(conn);
|
||||||
|
|
||||||
let gnu_tl = Timeline::new_for_user(
|
let gnu_tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"GNU timeline".to_owned(),
|
"GNU timeline".to_owned(),
|
||||||
"license in [AGPL, LGPL, GPL]".to_owned(),
|
"license in [AGPL, LGPL, GPL]".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let non_gnu_tl = Timeline::new_for_user(
|
let non_gnu_tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"Stallman disapproved timeline".to_owned(),
|
"Stallman disapproved timeline".to_owned(),
|
||||||
"not license in [AGPL, LGPL, GPL]".to_owned(),
|
"not license in [AGPL, LGPL, GPL]".to_owned(),
|
||||||
@@ -537,7 +569,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let gnu_post = Post::insert(
|
let gnu_post = Post::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blogs[0].id,
|
blog_id: blogs[0].id,
|
||||||
slug: "slug".to_string(),
|
slug: "slug".to_string(),
|
||||||
@@ -555,7 +587,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let non_free_post = Post::insert(
|
let non_free_post = Post::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blogs[0].id,
|
blog_id: blogs[0].id,
|
||||||
slug: "slug2".to_string(),
|
slug: "slug2".to_string(),
|
||||||
@@ -572,13 +604,13 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Timeline::add_to_all_timelines(&conn, &gnu_post, Kind::Original).unwrap();
|
Timeline::add_to_all_timelines(conn, &gnu_post, Kind::Original).unwrap();
|
||||||
Timeline::add_to_all_timelines(&conn, &non_free_post, Kind::Original).unwrap();
|
Timeline::add_to_all_timelines(conn, &non_free_post, Kind::Original).unwrap();
|
||||||
|
|
||||||
let res = gnu_tl.get_latest(&conn, 2).unwrap();
|
let res = gnu_tl.get_latest(conn, 2).unwrap();
|
||||||
assert_eq!(res.len(), 1);
|
assert_eq!(res.len(), 1);
|
||||||
assert_eq!(res[0].id, gnu_post.id);
|
assert_eq!(res[0].id, gnu_post.id);
|
||||||
let res = non_gnu_tl.get_latest(&conn, 2).unwrap();
|
let res = non_gnu_tl.get_latest(conn, 2).unwrap();
|
||||||
assert_eq!(res.len(), 1);
|
assert_eq!(res.len(), 1);
|
||||||
assert_eq!(res[0].id, non_free_post.id);
|
assert_eq!(res[0].id, non_free_post.id);
|
||||||
|
|
||||||
@@ -590,10 +622,10 @@ mod tests {
|
|||||||
fn test_matches_lists_direct() {
|
fn test_matches_lists_direct() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (users, blogs) = blogTests::fill_database(&conn);
|
let (users, blogs) = blogTests::fill_database(conn);
|
||||||
|
|
||||||
let gnu_post = Post::insert(
|
let gnu_post = Post::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blogs[0].id,
|
blog_id: blogs[0].id,
|
||||||
slug: "slug".to_string(),
|
slug: "slug".to_string(),
|
||||||
@@ -610,63 +642,63 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
gnu_post
|
gnu_post
|
||||||
.update_tags(&conn, vec![Tag::build_activity("free".to_owned()).unwrap()])
|
.update_tags(conn, vec![Tag::build_activity("free".to_owned()).unwrap()])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
PostAuthor::insert(
|
PostAuthor::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPostAuthor {
|
NewPostAuthor {
|
||||||
post_id: gnu_post.id,
|
post_id: gnu_post.id,
|
||||||
author_id: blogs[0].list_authors(&conn).unwrap()[0].id,
|
author_id: blogs[0].list_authors(conn).unwrap()[0].id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"blog timeline".to_owned(),
|
"blog timeline".to_owned(),
|
||||||
format!("blog in [{}]", blogs[0].fqn),
|
format!("blog in [{}]", blogs[0].fqn),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"blog timeline".to_owned(),
|
"blog timeline".to_owned(),
|
||||||
"blog in [no_one@nowhere]".to_owned(),
|
"blog in [no_one@nowhere]".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
|
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"author timeline".to_owned(),
|
"author timeline".to_owned(),
|
||||||
format!(
|
format!(
|
||||||
"author in [{}]",
|
"author in [{}]",
|
||||||
blogs[0].list_authors(&conn).unwrap()[0].fqn
|
blogs[0].list_authors(conn).unwrap()[0].fqn
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"author timeline".to_owned(),
|
"author timeline".to_owned(),
|
||||||
format!("author in [{}]", users[2].fqn),
|
format!("author in [{}]", users[2].fqn),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
assert!(tl
|
assert!(tl
|
||||||
.matches(&conn, &gnu_post, Kind::Reshare(&users[2]))
|
.matches(conn, &gnu_post, Kind::Reshare(&users[2]))
|
||||||
.unwrap());
|
.unwrap());
|
||||||
assert!(!tl.matches(&conn, &gnu_post, Kind::Like(&users[2])).unwrap());
|
assert!(!tl.matches(conn, &gnu_post, Kind::Like(&users[2])).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"author timeline".to_owned(),
|
"author timeline".to_owned(),
|
||||||
format!(
|
format!(
|
||||||
@@ -675,50 +707,50 @@ mod tests {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
assert!(!tl
|
assert!(!tl
|
||||||
.matches(&conn, &gnu_post, Kind::Reshare(&users[2]))
|
.matches(conn, &gnu_post, Kind::Reshare(&users[2]))
|
||||||
.unwrap());
|
.unwrap());
|
||||||
assert!(tl.matches(&conn, &gnu_post, Kind::Like(&users[2])).unwrap());
|
assert!(tl.matches(conn, &gnu_post, Kind::Like(&users[2])).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
|
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"tag timeline".to_owned(),
|
"tag timeline".to_owned(),
|
||||||
"tags in [free]".to_owned(),
|
"tags in [free]".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"tag timeline".to_owned(),
|
"tag timeline".to_owned(),
|
||||||
"tags in [private]".to_owned(),
|
"tags in [private]".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
|
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"english timeline".to_owned(),
|
"english timeline".to_owned(),
|
||||||
"lang in [en]".to_owned(),
|
"lang in [en]".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"franco-italian timeline".to_owned(),
|
"franco-italian timeline".to_owned(),
|
||||||
"lang in [fr, it]".to_owned(),
|
"lang in [fr, it]".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
@@ -762,10 +794,10 @@ mod tests {
|
|||||||
fn test_matches_keyword() {
|
fn test_matches_keyword() {
|
||||||
let conn = &db();
|
let conn = &db();
|
||||||
conn.test_transaction::<_, (), _>(|| {
|
conn.test_transaction::<_, (), _>(|| {
|
||||||
let (users, blogs) = blogTests::fill_database(&conn);
|
let (users, blogs) = blogTests::fill_database(conn);
|
||||||
|
|
||||||
let gnu_post = Post::insert(
|
let gnu_post = Post::insert(
|
||||||
&conn,
|
conn,
|
||||||
NewPost {
|
NewPost {
|
||||||
blog_id: blogs[0].id,
|
blog_id: blogs[0].id,
|
||||||
slug: "slug".to_string(),
|
slug: "slug".to_string(),
|
||||||
@@ -783,61 +815,61 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"Linux title".to_owned(),
|
"Linux title".to_owned(),
|
||||||
"title contains Linux".to_owned(),
|
"title contains Linux".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"Microsoft title".to_owned(),
|
"Microsoft title".to_owned(),
|
||||||
"title contains Microsoft".to_owned(),
|
"title contains Microsoft".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
|
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"Linux subtitle".to_owned(),
|
"Linux subtitle".to_owned(),
|
||||||
"subtitle contains Stallman".to_owned(),
|
"subtitle contains Stallman".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"Microsoft subtitle".to_owned(),
|
"Microsoft subtitle".to_owned(),
|
||||||
"subtitle contains Nadella".to_owned(),
|
"subtitle contains Nadella".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
|
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"Linux content".to_owned(),
|
"Linux content".to_owned(),
|
||||||
"content contains Linux".to_owned(),
|
"content contains Linux".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
let tl = Timeline::new_for_user(
|
let tl = Timeline::new_for_user(
|
||||||
&conn,
|
conn,
|
||||||
users[0].id,
|
users[0].id,
|
||||||
"Microsoft content".to_owned(),
|
"Microsoft content".to_owned(),
|
||||||
"subtitle contains Windows".to_owned(),
|
"subtitle contains Windows".to_owned(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap());
|
||||||
tl.delete(&conn).unwrap();
|
tl.delete(conn).unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,32 +1,25 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
blogs::Blog,
|
blogs::Blog,
|
||||||
db_conn::DbConn,
|
|
||||||
lists::{self, ListType},
|
lists::{self, ListType},
|
||||||
posts::Post,
|
posts::Post,
|
||||||
tags::Tag,
|
tags::Tag,
|
||||||
timeline::Timeline,
|
timeline::Timeline,
|
||||||
users::User,
|
users::User,
|
||||||
Result,
|
Connection, Result,
|
||||||
};
|
};
|
||||||
use plume_common::activity_pub::inbox::AsActor;
|
use plume_common::activity_pub::inbox::AsActor;
|
||||||
use whatlang::{self, Lang};
|
use whatlang::{self, Lang};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum QueryError {
|
pub enum QueryError {
|
||||||
SyntaxError(usize, usize, String),
|
SyntaxError(usize, usize, String),
|
||||||
UnexpectedEndOfQuery,
|
UnexpectedEndOfQuery,
|
||||||
RuntimeError(String),
|
RuntimeError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::option::NoneError> for QueryError {
|
|
||||||
fn from(_: std::option::NoneError) -> Self {
|
|
||||||
QueryError::UnexpectedEndOfQuery
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type QueryResult<T> = std::result::Result<T, QueryError>;
|
pub type QueryResult<T> = std::result::Result<T, QueryError>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Kind<'a> {
|
pub enum Kind<'a> {
|
||||||
Original,
|
Original,
|
||||||
Reshare(&'a User),
|
Reshare(&'a User),
|
||||||
@@ -161,7 +154,7 @@ enum TQ<'a> {
|
|||||||
impl<'a> TQ<'a> {
|
impl<'a> TQ<'a> {
|
||||||
fn matches(
|
fn matches(
|
||||||
&self,
|
&self,
|
||||||
conn: &DbConn,
|
conn: &Connection,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
kind: Kind<'_>,
|
kind: Kind<'_>,
|
||||||
@@ -206,7 +199,7 @@ enum Arg<'a> {
|
|||||||
impl<'a> Arg<'a> {
|
impl<'a> Arg<'a> {
|
||||||
pub fn matches(
|
pub fn matches(
|
||||||
&self,
|
&self,
|
||||||
conn: &DbConn,
|
conn: &Connection,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
kind: Kind<'_>,
|
kind: Kind<'_>,
|
||||||
@@ -231,7 +224,7 @@ enum WithList {
|
|||||||
impl WithList {
|
impl WithList {
|
||||||
pub fn matches(
|
pub fn matches(
|
||||||
&self,
|
&self,
|
||||||
conn: &DbConn,
|
conn: &Connection,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
list: &List<'_>,
|
list: &List<'_>,
|
||||||
@@ -239,7 +232,7 @@ impl WithList {
|
|||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
match list {
|
match list {
|
||||||
List::List(name) => {
|
List::List(name) => {
|
||||||
let list = lists::List::find_for_user_by_name(conn, timeline.user_id, &name)?;
|
let list = lists::List::find_for_user_by_name(conn, timeline.user_id, name)?;
|
||||||
match (self, list.kind()) {
|
match (self, list.kind()) {
|
||||||
(WithList::Blog, ListType::Blog) => list.contains_blog(conn, post.blog_id),
|
(WithList::Blog, ListType::Blog) => list.contains_blog(conn, post.blog_id),
|
||||||
(WithList::Author { boosts, likes }, ListType::User) => match kind {
|
(WithList::Author { boosts, likes }, ListType::User) => match kind {
|
||||||
@@ -298,7 +291,7 @@ impl WithList {
|
|||||||
WithList::Author { boosts, likes } => match kind {
|
WithList::Author { boosts, likes } => match kind {
|
||||||
Kind::Original => Ok(list
|
Kind::Original => Ok(list
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|a| User::find_by_fqn(&*conn, a).ok())
|
.filter_map(|a| User::find_by_fqn(conn, a).ok())
|
||||||
.any(|a| post.is_author(conn, a.id).unwrap_or(false))),
|
.any(|a| post.is_author(conn, a.id).unwrap_or(false))),
|
||||||
Kind::Reshare(u) => {
|
Kind::Reshare(u) => {
|
||||||
if *boosts {
|
if *boosts {
|
||||||
@@ -367,7 +360,7 @@ enum Bool {
|
|||||||
impl Bool {
|
impl Bool {
|
||||||
pub fn matches(
|
pub fn matches(
|
||||||
&self,
|
&self,
|
||||||
conn: &DbConn,
|
conn: &Connection,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
kind: Kind<'_>,
|
kind: Kind<'_>,
|
||||||
@@ -414,7 +407,7 @@ enum List<'a> {
|
|||||||
|
|
||||||
fn parse_s<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], TQ<'a>)> {
|
fn parse_s<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], TQ<'a>)> {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
let (left, token) = parse_a(&stream)?;
|
let (left, token) = parse_a(stream)?;
|
||||||
res.push(token);
|
res.push(token);
|
||||||
stream = left;
|
stream = left;
|
||||||
while !stream.is_empty() {
|
while !stream.is_empty() {
|
||||||
@@ -436,7 +429,7 @@ fn parse_s<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>],
|
|||||||
|
|
||||||
fn parse_a<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], TQ<'a>)> {
|
fn parse_a<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], TQ<'a>)> {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
let (left, token) = parse_b(&stream)?;
|
let (left, token) = parse_b(stream)?;
|
||||||
res.push(token);
|
res.push(token);
|
||||||
stream = left;
|
stream = left;
|
||||||
while !stream.is_empty() {
|
while !stream.is_empty() {
|
||||||
@@ -463,7 +456,7 @@ fn parse_b<'a, 'b>(stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], TQ<
|
|||||||
match left.get(0) {
|
match left.get(0) {
|
||||||
Some(Token::RParent(_)) => Ok((&left[1..], token)),
|
Some(Token::RParent(_)) => Ok((&left[1..], token)),
|
||||||
Some(t) => t.get_error(Token::RParent(0)),
|
Some(t) => t.get_error(Token::RParent(0)),
|
||||||
None => None?,
|
None => Err(QueryError::UnexpectedEndOfQuery),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => parse_c(stream),
|
_ => parse_c(stream),
|
||||||
@@ -484,9 +477,13 @@ fn parse_c<'a, 'b>(stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], TQ<
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_d<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], Arg<'a>)> {
|
fn parse_d<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], Arg<'a>)> {
|
||||||
match stream.get(0).map(Token::get_text)? {
|
match stream
|
||||||
|
.get(0)
|
||||||
|
.map(Token::get_text)
|
||||||
|
.ok_or(QueryError::UnexpectedEndOfQuery)?
|
||||||
|
{
|
||||||
s @ "blog" | s @ "author" | s @ "license" | s @ "tags" | s @ "lang" => {
|
s @ "blog" | s @ "author" | s @ "license" | s @ "tags" | s @ "lang" => {
|
||||||
match stream.get(1)? {
|
match stream.get(1).ok_or(QueryError::UnexpectedEndOfQuery)? {
|
||||||
Token::Word(_, _, r#in) if r#in == &"in" => {
|
Token::Word(_, _, r#in) if r#in == &"in" => {
|
||||||
let (mut left, list) = parse_l(&stream[2..])?;
|
let (mut left, list) = parse_l(&stream[2..])?;
|
||||||
let kind = match s {
|
let kind = match s {
|
||||||
@@ -498,7 +495,12 @@ fn parse_d<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>],
|
|||||||
if *clude != "include" && *clude != "exclude" {
|
if *clude != "include" && *clude != "exclude" {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
match (*clude, left.get(1).map(Token::get_text)?) {
|
match (
|
||||||
|
*clude,
|
||||||
|
left.get(1)
|
||||||
|
.map(Token::get_text)
|
||||||
|
.ok_or(QueryError::UnexpectedEndOfQuery)?,
|
||||||
|
) {
|
||||||
("include", "reshares") | ("include", "reshare") => {
|
("include", "reshares") | ("include", "reshare") => {
|
||||||
boosts = true
|
boosts = true
|
||||||
}
|
}
|
||||||
@@ -529,7 +531,10 @@ fn parse_d<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>],
|
|||||||
t => t.get_error(Token::Word(0, 0, "'in'")),
|
t => t.get_error(Token::Word(0, 0, "'in'")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s @ "title" | s @ "subtitle" | s @ "content" => match (stream.get(1)?, stream.get(2)?) {
|
s @ "title" | s @ "subtitle" | s @ "content" => match (
|
||||||
|
stream.get(1).ok_or(QueryError::UnexpectedEndOfQuery)?,
|
||||||
|
stream.get(2).ok_or(QueryError::UnexpectedEndOfQuery)?,
|
||||||
|
) {
|
||||||
(Token::Word(_, _, contains), Token::Word(_, _, w)) if contains == &"contains" => Ok((
|
(Token::Word(_, _, contains), Token::Word(_, _, w)) if contains == &"contains" => Ok((
|
||||||
&stream[3..],
|
&stream[3..],
|
||||||
Arg::Contains(
|
Arg::Contains(
|
||||||
@@ -555,7 +560,13 @@ fn parse_d<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>],
|
|||||||
if *clude != "include" && *clude != "exclude" {
|
if *clude != "include" && *clude != "exclude" {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
match (*clude, stream.get(2).map(Token::get_text)?) {
|
match (
|
||||||
|
*clude,
|
||||||
|
stream
|
||||||
|
.get(2)
|
||||||
|
.map(Token::get_text)
|
||||||
|
.ok_or(QueryError::UnexpectedEndOfQuery)?,
|
||||||
|
) {
|
||||||
("include", "reshares") | ("include", "reshare") => boosts = true,
|
("include", "reshares") | ("include", "reshare") => boosts = true,
|
||||||
("exclude", "reshares") | ("exclude", "reshare") => boosts = false,
|
("exclude", "reshares") | ("exclude", "reshare") => boosts = false,
|
||||||
("include", "likes") | ("include", "like") => likes = true,
|
("include", "likes") | ("include", "like") => likes = true,
|
||||||
@@ -577,20 +588,23 @@ fn parse_d<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>],
|
|||||||
"all" => Ok((&stream[1..], Arg::Boolean(Bool::All))),
|
"all" => Ok((&stream[1..], Arg::Boolean(Bool::All))),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
_ => stream.get(0)?.get_error(Token::Word(
|
_ => stream
|
||||||
0,
|
.get(0)
|
||||||
0,
|
.ok_or(QueryError::UnexpectedEndOfQuery)?
|
||||||
"one of 'blog', 'author', 'license', 'tags', 'lang', \
|
.get_error(Token::Word(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
"one of 'blog', 'author', 'license', 'tags', 'lang', \
|
||||||
'title', 'subtitle', 'content', 'followed', 'has_cover', 'local' or 'all'",
|
'title', 'subtitle', 'content', 'followed', 'has_cover', 'local' or 'all'",
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_l<'a, 'b>(stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], List<'a>)> {
|
fn parse_l<'a, 'b>(stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], List<'a>)> {
|
||||||
match stream.get(0)? {
|
match stream.get(0).ok_or(QueryError::UnexpectedEndOfQuery)? {
|
||||||
Token::LBracket(_) => {
|
Token::LBracket(_) => {
|
||||||
let (left, list) = parse_m(&stream[1..])?;
|
let (left, list) = parse_m(&stream[1..])?;
|
||||||
match left.get(0)? {
|
match left.get(0).ok_or(QueryError::UnexpectedEndOfQuery)? {
|
||||||
Token::RBracket(_) => Ok((&left[1..], List::Array(list))),
|
Token::RBracket(_) => Ok((&left[1..], List::Array(list))),
|
||||||
t => t.get_error(Token::Word(0, 0, "one of ']' or ','")),
|
t => t.get_error(Token::Word(0, 0, "one of ']' or ','")),
|
||||||
}
|
}
|
||||||
@@ -601,16 +615,20 @@ fn parse_l<'a, 'b>(stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], Lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_m<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], Vec<&'a str>)> {
|
fn parse_m<'a, 'b>(mut stream: &'b [Token<'a>]) -> QueryResult<(&'b [Token<'a>], Vec<&'a str>)> {
|
||||||
let mut res: Vec<&str> = vec![match stream.get(0)? {
|
let mut res: Vec<&str> = vec![
|
||||||
Token::Word(_, _, w) => w,
|
match stream.get(0).ok_or(QueryError::UnexpectedEndOfQuery)? {
|
||||||
t => return t.get_error(Token::Word(0, 0, "any word")),
|
|
||||||
}];
|
|
||||||
stream = &stream[1..];
|
|
||||||
while let Token::Comma(_) = stream[0] {
|
|
||||||
res.push(match stream.get(1)? {
|
|
||||||
Token::Word(_, _, w) => w,
|
Token::Word(_, _, w) => w,
|
||||||
t => return t.get_error(Token::Word(0, 0, "any word")),
|
t => return t.get_error(Token::Word(0, 0, "any word")),
|
||||||
});
|
},
|
||||||
|
];
|
||||||
|
stream = &stream[1..];
|
||||||
|
while let Token::Comma(_) = stream[0] {
|
||||||
|
res.push(
|
||||||
|
match stream.get(1).ok_or(QueryError::UnexpectedEndOfQuery)? {
|
||||||
|
Token::Word(_, _, w) => w,
|
||||||
|
t => return t.get_error(Token::Word(0, 0, "any word")),
|
||||||
|
},
|
||||||
|
);
|
||||||
stream = &stream[2..];
|
stream = &stream[2..];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,7 +653,7 @@ impl<'a> TimelineQuery<'a> {
|
|||||||
|
|
||||||
pub fn matches(
|
pub fn matches(
|
||||||
&self,
|
&self,
|
||||||
conn: &DbConn,
|
conn: &Connection,
|
||||||
timeline: &Timeline,
|
timeline: &Timeline,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
kind: Kind<'_>,
|
kind: Kind<'_>,
|
||||||
|
|||||||
+513
-287
File diff suppressed because it is too large
Load Diff
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Afrikaans\n"
|
"Language-Team: Afrikaans\n"
|
||||||
"Language: af_ZA\n"
|
"Language: af_ZA\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Arabic\n"
|
"Language-Team: Arabic\n"
|
||||||
"Language: ar_SA\n"
|
"Language: ar_SA\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "فتح محرر النصوص الغني"
|
msgstr "فتح محرر النصوص الغني"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "العنوان"
|
msgstr "العنوان"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "العنوان الثانوي أو الملخص"
|
msgstr "العنوان الثانوي أو الملخص"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "اكتب مقالك هنا. ماركداون مُدَعَّم."
|
msgstr "اكتب مقالك هنا. ماركداون مُدَعَّم."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "يتبقا {} حرفا تقريبا"
|
msgstr "يتبقا {} حرفا تقريبا"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "الوسوم"
|
msgstr "الوسوم"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "الرخصة"
|
msgstr "الرخصة"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "الغلاف"
|
msgstr "الغلاف"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "هذه مسودة"
|
msgstr "هذه مسودة"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "نشر كتابا"
|
msgstr "نشر كتابا"
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Bulgarian\n"
|
"Language-Team: Bulgarian\n"
|
||||||
"Language: bg_BG\n"
|
"Language: bg_BG\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr "Искате ли да активирате локално автоматично запаметяване, последно редактирано в {}?"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "Отворете редактора с богат текст"
|
msgstr "Отворете редактора с богат текст"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Заглавие"
|
msgstr "Заглавие"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "Подзаглавие или резюме"
|
msgstr "Подзаглавие или резюме"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "Напишете статията си тук. Поддържа се Markdown."
|
msgstr "Напишете статията си тук. Поддържа се Markdown."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "Остават {} знака вляво"
|
msgstr "Остават {} знака вляво"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Етикети"
|
msgstr "Етикети"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Лиценз"
|
msgstr "Лиценз"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "Основно изображение"
|
msgstr "Основно изображение"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "Това е проект"
|
msgstr "Това е проект"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Публикувай"
|
msgstr "Публикувай"
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Catalan\n"
|
"Language-Team: Catalan\n"
|
||||||
"Language: ca_ES\n"
|
"Language: ca_ES\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "Obre l’editor de text enriquit"
|
msgstr "Obre l’editor de text enriquit"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Títol"
|
msgstr "Títol"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "Subtítol o resum"
|
msgstr "Subtítol o resum"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "Escriviu el vostre article ací. Podeu fer servir el Markdown."
|
msgstr "Escriviu el vostre article ací. Podeu fer servir el Markdown."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "Queden uns {} caràcters"
|
msgstr "Queden uns {} caràcters"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Etiquetes"
|
msgstr "Etiquetes"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Llicència"
|
msgstr "Llicència"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "Coberta"
|
msgstr "Coberta"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "Açò és un esborrany"
|
msgstr "Açò és un esborrany"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Publica"
|
msgstr "Publica"
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-05-09 09:58\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Czech\n"
|
"Language-Team: Czech\n"
|
||||||
"Language: cs_CZ\n"
|
"Language: cs_CZ\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "Otevřít editor formátovaného textu"
|
msgstr "Otevřít editor formátovaného textu"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Nadpis"
|
msgstr "Nadpis"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "Podnadpis, nebo shrnutí"
|
msgstr "Podnadpis, nebo shrnutí"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "Sem napište svůj článek. Markdown je podporován."
|
msgstr "Sem napište svůj článek. Markdown je podporován."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "Zbývá kolem {} znaků"
|
msgstr "Zbývá kolem {} znaků"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Tagy"
|
msgstr "Tagy"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Licence"
|
msgstr "Licence"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "Titulka"
|
msgstr "Titulka"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "Tohle je koncept"
|
msgstr "Tohle je koncept"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Zveřejnit"
|
msgstr "Zveřejnit"
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Danish\n"
|
"Language-Team: Danish\n"
|
||||||
"Language: da_DK\n"
|
"Language: da_DK\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-26 13:16\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: German\n"
|
"Language-Team: German\n"
|
||||||
"Language: de_DE\n"
|
"Language: de_DE\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr "Möchten Sie die lokale automatische Speicherung laden, die zuletzt um {} bearbeitet wurde?"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr " Rich Text Editor (RTE) öffnen"
|
msgstr " Rich Text Editor (RTE) öffnen"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Titel"
|
msgstr "Titel"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "Untertitel oder Zusammenfassung"
|
msgstr "Untertitel oder Zusammenfassung"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "Schreiben deinen Artikel hier. Markdown wird unterstützt."
|
msgstr "Schreiben deinen Artikel hier. Markdown wird unterstützt."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "Ungefähr {} Zeichen übrig"
|
msgstr "Ungefähr {} Zeichen übrig"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Schlagwörter"
|
msgstr "Schlagwörter"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Lizenz"
|
msgstr "Lizenz"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "Einband"
|
msgstr "Einband"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "Dies ist ein Entwurf"
|
msgstr "Dies ist ein Entwurf"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Veröffentlichen"
|
msgstr "Veröffentlichen"
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Greek\n"
|
"Language-Team: Greek\n"
|
||||||
"Language: el_GR\n"
|
"Language: el_GR\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: English\n"
|
"Language-Team: English\n"
|
||||||
"Language: en_US\n"
|
"Language: en_US\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Esperanto\n"
|
"Language-Team: Esperanto\n"
|
||||||
"Language: eo_UY\n"
|
"Language: eo_UY\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "Malfermi la riĉan redaktilon"
|
msgstr "Malfermi la riĉan redaktilon"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Titolo"
|
msgstr "Titolo"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "Verku vian artikolon ĉi tie. Markdown estas subtenita."
|
msgstr "Verku vian artikolon ĉi tie. Markdown estas subtenita."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "Proksimume {} signoj restantaj"
|
msgstr "Proksimume {} signoj restantaj"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Etikedoj"
|
msgstr "Etikedoj"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Permesilo"
|
msgstr "Permesilo"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "Kovro"
|
msgstr "Kovro"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "Malfinias"
|
msgstr "Malfinias"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Eldoni"
|
msgstr "Eldoni"
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:56\n"
|
"PO-Revision-Date: 2022-01-26 13:16\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Spanish\n"
|
"Language-Team: Spanish\n"
|
||||||
"Language: es_ES\n"
|
"Language: es_ES\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr "¿Quieres cargar el guardado automático local editado por última vez en {}?"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "Abrir el editor de texto enriquecido"
|
msgstr "Abrir el editor de texto enriquecido"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Título"
|
msgstr "Título"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "Subtítulo, o resumen"
|
msgstr "Subtítulo, o resumen"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "Escriba su artículo aquí. Puede utilizar Markdown."
|
msgstr "Escriba su artículo aquí. Puede utilizar Markdown."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "Quedan unos {} caracteres"
|
msgstr "Quedan unos {} caracteres"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Etiquetas"
|
msgstr "Etiquetas"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Licencia"
|
msgstr "Licencia"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "Cubierta"
|
msgstr "Cubierta"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "Esto es un borrador"
|
msgstr "Esto es un borrador"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Publicar"
|
msgstr "Publicar"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plume\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
|
"PO-Revision-Date: 2022-05-09 09:58\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language-Team: Basque\n"
|
||||||
|
"Language: eu_ES\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Crowdin-Project: plume\n"
|
||||||
|
"X-Crowdin-Project-ID: 352097\n"
|
||||||
|
"X-Crowdin-Language: eu\n"
|
||||||
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:172
|
||||||
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
|
msgstr "{}(t)an automatikoki gordetako azken kopia lokala kargatu nahi al duzu?"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:326
|
||||||
|
msgid "Open the rich text editor"
|
||||||
|
msgstr "Ireki testu-formatutzaile aberatsa"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:385
|
||||||
|
msgid "Title"
|
||||||
|
msgstr "Izenburua"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:389
|
||||||
|
msgid "Subtitle, or summary"
|
||||||
|
msgstr "Azpititulua edo laburpena"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:396
|
||||||
|
msgid "Write your article here. Markdown is supported."
|
||||||
|
msgstr "Idatzi hemen testua. Markdown erabil dezakezu."
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:407
|
||||||
|
msgid "Around {} characters left"
|
||||||
|
msgstr "%{count} karaktere geratzen dira"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:517
|
||||||
|
msgid "Tags"
|
||||||
|
msgstr "Etiketak"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:518
|
||||||
|
msgid "License"
|
||||||
|
msgstr "Lizentzia"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:524
|
||||||
|
msgid "Cover"
|
||||||
|
msgstr "Azala"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:564
|
||||||
|
msgid "This is a draft"
|
||||||
|
msgstr "Zirriborro bat da"
|
||||||
|
|
||||||
|
# plume-front/src/editor.rs:575
|
||||||
|
msgid "Publish"
|
||||||
|
msgstr "Argitaratu"
|
||||||
|
|
||||||
+16
-16
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:56\n"
|
"PO-Revision-Date: 2022-05-10 17:54\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Persian\n"
|
"Language-Team: Persian\n"
|
||||||
"Language: fa_IR\n"
|
"Language: fa_IR\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr "آیا میخواهید نسخهٔ ذخیره شدهٔ خودکار محلّی از آخرین ویرایش در {} را بار کنید؟"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "باز کردن ویرایشگر غنی"
|
msgstr "گشودن ویرایشگر غنی"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "عنوان"
|
msgstr "عنوان"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "زیرعنوان، یا چکیده"
|
msgstr "زیرعنوان، یا چکیده"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "مقاله را اینجا بنویسید. از مارکداون پشتیبانی میشود."
|
msgstr "مقالهتان را اینجا بنویسید. از مارکداون پشتیبانی میشود."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "نزدیک به {} حرف باقی مانده است"
|
msgstr "نزدیک به {} حرف باقی مانده است"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "برچسبها"
|
msgstr "برچسبها"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "پروانه"
|
msgstr "پروانه"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "تصویر شاخص"
|
msgstr "جلد"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "این، یک پیشنویس است"
|
msgstr "این، یک پیشنویس است"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "انتشار"
|
msgstr "انتشار"
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Finnish\n"
|
"Language-Team: Finnish\n"
|
||||||
"Language: fi_FI\n"
|
"Language: fi_FI\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "Avaa edistynyt tekstieditori"
|
msgstr "Avaa edistynyt tekstieditori"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Otsikko"
|
msgstr "Otsikko"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "Alaotsikko tai tiivistelmä"
|
msgstr "Alaotsikko tai tiivistelmä"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "Kirjoita artikkelisi tähän. Markdown -kuvauskieli on tuettu."
|
msgstr "Kirjoita artikkelisi tähän. Markdown -kuvauskieli on tuettu."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "%{count} merkkiä jäljellä"
|
msgstr "%{count} merkkiä jäljellä"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Tagit"
|
msgstr "Tagit"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Lisenssi"
|
msgstr "Lisenssi"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "Kansi"
|
msgstr "Kansi"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "Tämä on luonnos"
|
msgstr "Tämä on luonnos"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Julkaise"
|
msgstr "Julkaise"
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-05-09 09:59\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: French\n"
|
"Language-Team: French\n"
|
||||||
"Language: fr_FR\n"
|
"Language: fr_FR\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr "Voulez vous charger la sauvegarde automatique locale, éditée la dernière fois à {}?"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "Ouvrir l'éditeur de texte avancé"
|
msgstr "Ouvrir l'éditeur de texte avancé"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Titre"
|
msgstr "Titre"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "Sous-titre ou résumé"
|
msgstr "Sous-titre ou résumé"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "Écrivez votre article ici. Vous pouvez utiliser du Markdown."
|
msgstr "Écrivez votre article ici. Vous pouvez utiliser du Markdown."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "Environ {} caractères restant"
|
msgstr "Environ {} caractères restant"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Étiquettes"
|
msgstr "Étiquettes"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Licence"
|
msgstr "Licence"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "Illustration"
|
msgstr "Illustration"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "Ceci est un brouillon"
|
msgstr "Ceci est un brouillon"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Publier"
|
msgstr "Publier"
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-26 13:16\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Galician\n"
|
"Language-Team: Galician\n"
|
||||||
"Language: gl_ES\n"
|
"Language: gl_ES\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr "Queres cargar a última copia gardada editada o {}?"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr "Abre o editor de texto enriquecido"
|
msgstr "Abre o editor de texto enriquecido"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Título"
|
msgstr "Título"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr "Subtítulo, ou resumo"
|
msgstr "Subtítulo, ou resumo"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "Escribe aquí o teu artigo: podes utilizar Markdown."
|
msgstr "Escribe aquí o teu artigo: podes utilizar Markdown."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "Dispós de {} caracteres"
|
msgstr "Dispós de {} caracteres"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Etiquetas"
|
msgstr "Etiquetas"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Licenza"
|
msgstr "Licenza"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr "Portada"
|
msgstr "Portada"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr "Este é un borrador"
|
msgstr "Este é un borrador"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Publicar"
|
msgstr "Publicar"
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Hebrew\n"
|
"Language-Team: Hebrew\n"
|
||||||
"Language: he_IL\n"
|
"Language: he_IL\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Hindi\n"
|
"Language-Team: Hindi\n"
|
||||||
"Language: hi_IN\n"
|
"Language: hi_IN\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "शीर्षक"
|
msgstr "शीर्षक"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr "अपना आर्टिकल या लेख यहाँ लिखें. Markdown उपलब्ध है."
|
msgstr "अपना आर्टिकल या लेख यहाँ लिखें. Markdown उपलब्ध है."
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr "लगभग {} अक्षर बाकी हैं"
|
msgstr "लगभग {} अक्षर बाकी हैं"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "टैग्स"
|
msgstr "टैग्स"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "लाइसेंस"
|
msgstr "लाइसेंस"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "पब्लिश करें"
|
msgstr "पब्लिश करें"
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -3,7 +3,7 @@ msgstr ""
|
|||||||
"Project-Id-Version: plume\n"
|
"Project-Id-Version: plume\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||||
"PO-Revision-Date: 2020-12-19 09:55\n"
|
"PO-Revision-Date: 2022-01-12 01:20\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: Croatian\n"
|
"Language-Team: Croatian\n"
|
||||||
"Language: hr_HR\n"
|
"Language: hr_HR\n"
|
||||||
@@ -17,47 +17,47 @@ msgstr ""
|
|||||||
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
"X-Crowdin-File: /master/po/plume-front/plume-front.pot\n"
|
||||||
"X-Crowdin-File-ID: 12\n"
|
"X-Crowdin-File-ID: 12\n"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:189
|
# plume-front/src/editor.rs:172
|
||||||
msgid "Do you want to load the local autosave last edited at {}?"
|
msgid "Do you want to load the local autosave last edited at {}?"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:282
|
# plume-front/src/editor.rs:326
|
||||||
msgid "Open the rich text editor"
|
msgid "Open the rich text editor"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:315
|
# plume-front/src/editor.rs:385
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Naslov"
|
msgstr "Naslov"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:319
|
# plume-front/src/editor.rs:389
|
||||||
msgid "Subtitle, or summary"
|
msgid "Subtitle, or summary"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:326
|
# plume-front/src/editor.rs:396
|
||||||
msgid "Write your article here. Markdown is supported."
|
msgid "Write your article here. Markdown is supported."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:337
|
# plume-front/src/editor.rs:407
|
||||||
msgid "Around {} characters left"
|
msgid "Around {} characters left"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:414
|
# plume-front/src/editor.rs:517
|
||||||
msgid "Tags"
|
msgid "Tags"
|
||||||
msgstr "Tagovi"
|
msgstr "Tagovi"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:415
|
# plume-front/src/editor.rs:518
|
||||||
msgid "License"
|
msgid "License"
|
||||||
msgstr "Licenca"
|
msgstr "Licenca"
|
||||||
|
|
||||||
# plume-front/src/editor.rs:418
|
# plume-front/src/editor.rs:524
|
||||||
msgid "Cover"
|
msgid "Cover"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:438
|
# plume-front/src/editor.rs:564
|
||||||
msgid "This is a draft"
|
msgid "This is a draft"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
# plume-front/src/editor.rs:445
|
# plume-front/src/editor.rs:575
|
||||||
msgid "Publish"
|
msgid "Publish"
|
||||||
msgstr "Objavi"
|
msgstr "Objavi"
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user